├── .circleci └── config.yml ├── .gitignore ├── Dockerfile ├── Gemfile ├── Gemfile.lock ├── LICENSE ├── README.md ├── Rakefile ├── _config.yml ├── appveyor.yml ├── bin ├── console └── setup ├── docs ├── _config.yml ├── bio.html ├── charty.html ├── graph.html ├── index.html ├── rbplotly-bar.html ├── rbplotly-basic.html ├── rbplotly-boxplot.html ├── rbplotly-heatmap.html ├── rbplotly-hist.html ├── rbplotly-line.html ├── rbplotly-pie.html ├── rbplotly-scatter.html ├── rumale-kmeans.html ├── rumale.html └── table.html ├── examples ├── bio.md ├── charty.md ├── graph.md ├── index.md ├── numo-gnuplot.ipynb ├── rbplotly-bar.md ├── rbplotly-basic.md ├── rbplotly-boxplot.md ├── rbplotly-heatmap.md ├── rbplotly-hist.md ├── rbplotly-line.md ├── rbplotly-pie.md ├── rbplotly-scatter.md ├── rumale-kmeans.md ├── rumale.md └── table.md ├── exe └── rubydown ├── lib ├── rubydown.rb └── rubydown │ └── version.rb ├── rubydown.gemspec ├── templates └── template.html.erb └── test └── test-table.rb /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | # Ruby CircleCI 2.0 configuration file 2 | # 3 | # Check https://circleci.com/docs/2.0/language-ruby/ for more details 4 | # 5 | version: 2 6 | jobs: 7 | build: 8 | docker: 9 | - image: ruby 10 | 11 | working_directory: ~/repo 12 | 13 | steps: 14 | - checkout 15 | 16 | - run: 17 | name: install rubydown 18 | command: | 19 | apt-get update 20 | apt-get install -y gnuplot 21 | gem build rubydown.gemspec 22 | gem install rubydown-0.2.0.gem 23 | gem install bio 24 | 25 | # run tests! 26 | - run: 27 | name: run tests 28 | command: | 29 | rubydown -i examples/bio.md -e templates/template.html.erb -o /tmp/bio.html 30 | rubydown -i examples/table.md -e templates/template.html.erb -o /tmp/table.html 31 | rubydown -i examples/graph.md -e templates/template.html.erb -o /tmp/graph.html 32 | 33 | # collect reports 34 | - store_artifacts: 35 | path: /tmp 36 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | pkg/ 3 | .bundle/ 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby 2 | 3 | USER root 4 | 5 | RUN apt-get update && apt-get install -y emacs25-nox vim-nox mlocate locales-all tmux gnuplot && gem install numo-gnuplot\ 6 | git config --global alias.co checkout && \ 7 | git config --global alias.br branch && \ 8 | git config --global alias.ci commit && \ 9 | git config --global alias.st status 10 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | git_source(:github) {|repo_name| "https://github.com/#{repo_name}" } 4 | 5 | # Specify your gem's dependencies in rubydown.gemspec 6 | gemspec 7 | 8 | gem "test-unit", "~> 3.2" 9 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | PATH 2 | remote: . 3 | specs: 4 | rubydown (0.1.0) 5 | daru 6 | kramdown 7 | numo-gnuplot 8 | numo-narray 9 | pry 10 | 11 | GEM 12 | remote: https://rubygems.org/ 13 | specs: 14 | backports (3.11.4) 15 | coderay (1.1.2) 16 | daru (0.2.1) 17 | backports 18 | packable (~> 1.3.9) 19 | kramdown (1.17.0) 20 | method_source (0.9.2) 21 | numo-gnuplot (0.2.4) 22 | numo-narray (0.9.1.3) 23 | packable (1.3.10) 24 | backports 25 | power_assert (1.1.3) 26 | pry (0.12.2) 27 | coderay (~> 1.1.0) 28 | method_source (~> 0.9.0) 29 | rake (10.5.0) 30 | test-unit (3.2.9) 31 | power_assert 32 | 33 | PLATFORMS 34 | ruby 35 | 36 | DEPENDENCIES 37 | bundler (~> 1.17) 38 | rake (~> 10.0) 39 | rubydown! 40 | test-unit 41 | 42 | BUNDLED WITH 43 | 1.17.3 44 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Yusuke Sangenya 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rubydown 2 | 3 | [![CircleCI](https://circleci.com/gh/RubyData/rubydown/tree/master.svg?style=svg)](https://circleci.com/gh/RubyData/rubydown/tree/master) 4 | [![Build status](https://ci.appveyor.com/api/projects/status/rroa24x9jgdwuka5?svg=true)](https://ci.appveyor.com/project/kozo2/rubydown) 5 | 6 | *rubydown* is pure-Ruby [R Markdown](https://rmarkdown.rstudio.com/) clone. 7 | It takes a markdown source file, executes the code chunks, captures the output, and stitches the output into the destination file. 8 | 9 | Python also has R Markdown like packages. 10 | If you have interest about making reproducible reports, please also refer to the following projects. 11 | 12 | https://github.com/jankatins/knitpy 13 | https://github.com/pystitch/stitch 14 | https://github.com/danijar/handout 15 | 16 | 17 | ## Install 18 | 19 | ``` 20 | sudo apt install gnuplot # When you use numo-gnuplot with rubydown 21 | 22 | sudo apt install python3-pip # When you use charty with rubydown 23 | sudo python3 -m pip install -U pip matplotlib # When you use charty with rubydown 24 | 25 | gem install rubydown 26 | ``` 27 | 28 | ## Usage (example with [rumale](https://github.com/yoshoku/rumale) and [rdatasets](https://github.com/kojix2/rdatasets)) 29 | 30 | ``` 31 | gem install rumale rdatasets 32 | git clone git://github.com/RubyData/rubydown 33 | cd rubydown/examples 34 | rubydown -i rumale.md 35 | ``` 36 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | task :default => :spec 3 | -------------------------------------------------------------------------------- /_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /appveyor.yml: -------------------------------------------------------------------------------- 1 | # appveyor.yml 2 | install: 3 | - set PATH=C:\Ruby25-x64\bin;%PATH% 4 | - gem build rubydown.gemspec 5 | - gem install rubydown-0.2.0.gem 6 | 7 | build: off 8 | 9 | before_test: 10 | - ruby -v 11 | - gem -v 12 | - bundle -v 13 | - rubydown --version 14 | - gem install bio 15 | 16 | test_script: 17 | - choco install gnuplot 18 | - set PATH=C:\Program Files\gnuplot\bin;%PATH% 19 | - gnuplot --version 20 | - rubydown -i examples\bio.md -e templates\template.html.erb -o bio.html 21 | - rubydown -i examples\graph.md -e templates\template.html.erb -o graph.html 22 | - rubydown -i examples\table.md -e templates\template.html.erb -o table.html 23 | 24 | artifacts: 25 | - path: '*.html' 26 | -------------------------------------------------------------------------------- /bin/console: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require "bundler/setup" 4 | require "rubydown" 5 | 6 | # You can add fixtures and/or initialization code here to make experimenting 7 | # with your gem easier. You can also use a different console, if you like. 8 | 9 | # (If you use this, don't forget to add pry to your Gemfile!) 10 | # require "pry" 11 | # Pry.start 12 | 13 | require "irb" 14 | IRB.start(__FILE__) 15 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -euo pipefail 3 | IFS=$'\n\t' 4 | set -vx 5 | 6 | bundle install 7 | 8 | # Do any other automated setup that you need to do here 9 | -------------------------------------------------------------------------------- /docs/_config.yml: -------------------------------------------------------------------------------- 1 | theme: jekyll-theme-cayman -------------------------------------------------------------------------------- /docs/bio.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

BioRuby Tutorial

24 | 25 |

Trying Bioruby

26 | 27 |

Now test the following:

28 | 29 |
require 'bio'
 30 | seq = Bio::Sequence::NA.new("atgcatgcaaaa")
 31 | 
32 |

=> atgcatgcaaaa
 33 | 
34 |

35 | 36 |
seq.complement
 37 | 
38 |

=> ttttgcatgcat
 39 | 
40 |

41 | 42 |

Working with nucleic / amino acid sequences (Bio::Sequence class)

43 | 44 |

The Bio::Sequence class allows the usual sequence transformations and translations.

45 | 46 |

In the example below the DNA sequence atgcatgcaaaa is converted into the complemental strand and spliced into a subsequence; next, the nucleic acid composition is calculated and the sequence is translated into the amino acid sequence, the molecular weight calculated, and so on. When translating into amino acid sequences, the frame can be specified and optionally the codon table selected (as defined in codontable.rb).

47 | 48 |
seq = Bio::Sequence::NA.new("atgcatgcaaaa")
 49 | 
50 |

=> atgcatgcaaaa
 51 | 
52 |

53 | 54 |
# complemental sequence (Bio::Sequence::NA object)
 55 | seq.complement
 56 | 
57 |

=> ttttgcatgcat
 58 | 
59 |

60 | 61 |
seq.subseq(3,8) # gets subsequence of positions 3 to 8 (starting from 1)
 62 | 
63 |

=> gcatgc
 64 | 
65 |

66 | 67 |
seq.gc_percent
 68 | 
69 |

=> 33
 70 | 
71 |

72 | 73 |
seq.composition
 74 | 
75 |

=> {"a"=>6, "t"=>2, "g"=>2, "c"=>2}
 76 | 
77 |

78 | 79 |
seq.translate
 80 | 
81 |

=> MHAK
 82 | 
83 |

84 | 85 |
seq.translate(2)
 86 | 
87 |

=> CMQ
 88 | 
89 |

90 | 91 |
seq.translate(1,11)
 92 | 
93 |

=> MHAK
 94 | 
95 |

96 | 97 |
seq.translate.codes
 98 | 
99 |

=> ["Met", "His", "Ala", "Lys"]
100 | 
101 |

102 | 103 |
seq.translate.names
104 | 
105 |

=> ["methionine", "histidine", "alanine", "lysine"]
106 | 
107 |

108 | 109 |
seq.translate.composition
110 | 
111 |

=> {"M"=>1, "H"=>1, "A"=>1, "K"=>1}
112 | 
113 |

114 | 115 |
seq.translate.molecular_weight
116 | 
117 |

=> 485.6050000000001
118 | 
119 |

120 | 121 |
seq.complement.translate
122 | 
123 |

=> FCMH
124 | 
125 |

126 | 127 |
128 | 129 | 130 | -------------------------------------------------------------------------------- /docs/charty.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 | 24 |

Charty Usage

25 | 26 |

You can write Markdown!

27 | 28 | 32 | 33 |

 34 | require 'charty'
 35 | charty = Charty::Plotter.new(:pyplot)
 36 | 
 37 | bar = charty.bar do
 38 |   series [0,1,2,3,4], [10,40,20,90,70]
 39 |   series [0,1,2,3,4], [90,80,70,60,50]
 40 |   series [0,1,2,3,4,5,6,7,8], [50,60,20,30,10, 90, 0, 100, 50]
 41 |   range x: 0..10, y: 1..100
 42 |   xlabel 'foo'
 43 |   ylabel 'bar'
 44 |   title 'bar plot'
 45 | end
 46 | bar.render("bar_matplot.png")
 47 | 
48 | 290 | 291 |
292 | 293 | 294 | -------------------------------------------------------------------------------- /docs/graph.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

Graph generation example

24 | 25 |

With Numo::Gnuplot

26 | 27 |

Rubydown::RbMarkPlot is extended class of Numo::Gnuplot

28 | 29 |
rp = Rubydown::RbMarkPlot.new
 30 | rp.set title: "Example Plot"
 31 | rp.plot "sin(x)", w:"lines"
 32 | 
33 | 158 |
159 | 160 | 161 | -------------------------------------------------------------------------------- /docs/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

テスト

24 | 25 |

コードを書く

26 | 27 |

~~~ruby~~~ でコードを囲むと、そのブロックが評価される。

28 | 29 |
array = [1,2,3,4]
 30 | converted = array.map { |e| e * 100 }
 31 | 
 32 | converted # 最後の行が出力される
 33 | 
34 |

=> [100, 200, 300, 400]
 35 | 
36 |

37 | 38 |

標準出力も表示される

39 | 40 |
puts :hoge
 41 | 
 42 | "fuga\npiyo".inspect
 43 | 
44 |

hoge
 45 | 
 46 | => "fuga\npiyo"
 47 | 
48 |

49 | 50 |

ブロックは全部同じスコープ

51 | 52 |

先程定義した変数convertedが以下でも使える。

53 | 54 |
converted.map { |e| e / 100 }
 55 | 
56 |

=> [1, 2, 3, 4]
 57 | 
58 |

59 | 60 |

ライブラリを使う

61 | 62 |

もちろん外部のライブラリをロードすることもできる。

63 | 64 |
require 'matrix'
 65 | 
 66 | Matrix.identity(10)
 67 | 
68 |

=> Matrix[[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 1, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 1, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 1]]
 69 | 
70 |

71 | 72 |

to_htmlを実装する

73 | 74 |

to_html メソッドを実装すると、その結果が出力される。

75 | 76 |
class Matrix # オープンクラス
 77 |   def to_html
 78 |     rows = self.to_a.map do |row|
 79 |       elems = row.map do |elem|
 80 |         "<td>#{elem}</td>"
 81 |       end
 82 |       "<tr>#{elems}</tr>"
 83 |     end
 84 |     "<table>#{rows.join}</table>"
 85 |   end
 86 | end
 87 | 
 88 | Matrix.identity(10)
 89 | 
90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 |
1000000000
0100000000
0010000000
0001000000
0000100000
0000010000
0000001000
0000000100
0000000010
0000000001
214 | 215 |
216 | 217 | 218 | -------------------------------------------------------------------------------- /docs/rbplotly-bar.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly bar chart usage

24 | 25 |
require 'rbplotly'
 26 | 
 27 | trace = {
 28 |   x: %w(giraffes orangutans monkeys),
 29 |   y: [20, 14, 23],
 30 |   type: :bar
 31 | }
 32 | 
 33 | plot = Plotly::Plot.new(data: [trace])
 34 | 
35 | 38 |
39 | 53 | 54 |
trace1 = {
 55 |   x:    %w(giraffes orangutans monkeys),
 56 |   y:    [20, 14, 23],
 57 |   type: :bar,
 58 |   name: 'SF Zoo'
 59 | }
 60 | trace2 = {
 61 |   x:    %w(giraffes orangutans monkeys),
 62 |   y:    [12, 18, 29],
 63 |   type: :bar,
 64 |   name: 'LA Zoo'
 65 | }
 66 | 
 67 | plot = Plotly::Plot.new(data: [trace1, trace2])
 68 | 
69 | 72 |
73 | 87 | 88 |
plot.layout.barmode = :stack
 89 | plot
 90 | 
91 | 94 |
95 | 109 | 110 |
trace1 = {
111 |   x:    %w(giraffes orangutans monkeys),
112 |   y:    [20, 14, 23],
113 |   type: :bar,
114 |   name: 'SF Zoo'
115 | }
116 | trace2 = {
117 |   x:    %w(giraffes orangutans monkeys),
118 |   y:    [12, 18, 29],
119 |   type: :bar,
120 |   name: 'LA Zoo'
121 | }
122 | 
123 | plot = Plotly::Plot.new(data: [trace1, trace2], layout: { barmode: :stack } )
124 | 
125 | 128 |
129 | 143 | 144 |
145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/rbplotly-basic.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly basic usage

24 | 25 |
require 'rbplotly'
 26 | 
 27 | n = 100
 28 | 
 29 | x  = n.times.map { |i| i.to_f / (n - 1) }
 30 | y0 = n.times.map { rand(-2.0..2.0) + 5 }
 31 | y1 = n.times.map { rand(-2.0..2.0) }
 32 | 
 33 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers }
 34 | trace1 = trace0.merge(y: y1, mode: :'markers+lines')
 35 | 
 36 | plot = Plotly::Plot.new(data: [trace0, trace1])
 37 | 
38 | 41 |
42 | 56 | 57 |

Here we replace the last trace range from -0.5 to 0.5

58 | 59 |
plot.data.last.y = n.times.map { rand(-0.5..0.5) }
 60 | plot
 61 | 
62 | 65 |
66 | 80 | 81 |

Next we add a line trace with the center -5 and the range from -2.0 to 2.0.

82 | 83 |
new_trace = { x: x, y: n.times.map { rand(-2.0..2.0) - 5 }, type: :scatter, mode: :lines }
 84 | plot.data.push(new_trace)
 85 | plot
 86 | 
87 | 90 |
91 | 105 | 106 |

Last of all we add the x,y titles.

107 | 108 |
plot.layout.xaxis = { title: 'x title' }
109 | plot.layout.yaxis = { title: 'y title' }
110 | plot
111 | 
112 | 115 |
116 | 130 | 131 | 132 |
133 | 134 | 135 | -------------------------------------------------------------------------------- /docs/rbplotly-boxplot.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly boxplot usage

24 | 25 |
require 'rbplotly'
 26 | 
 27 | n = 50
 28 | y0 = n.times.map { rand(-1.0..0.0) }
 29 | y1 = n.times.map { rand(0.0..1.0) }
 30 | 
 31 | trace0 = {
 32 |   y: y0,
 33 |   type: :box
 34 | }
 35 | 
 36 | trace1 = {
 37 |   y: y1,
 38 |   type: :box
 39 | }
 40 | 
 41 | data = [trace0, trace1]
 42 | 
 43 | plot = Plotly::Plot.new(data: data)
 44 | 
45 | 48 |
49 | 63 | 64 |

Horizontal boxplot

65 | 66 |
n = 50
 67 | x0 = n.times.map { rand(-1.0..0.0) }
 68 | x1 = n.times.map { rand(0.0..1.0) }
 69 | 
 70 | trace0 = {
 71 |   x: x0,
 72 |   type: :box
 73 | }
 74 | 
 75 | trace1 = {
 76 |   x: x1,
 77 |   type: :box
 78 | }
 79 | 
 80 | data = [trace0, trace1]
 81 | 
 82 | plot = Plotly::Plot.new(data: data)
 83 | 
84 | 87 |
88 | 102 | 103 |

boxplot with the points

104 | 105 |
trace = {
106 |     y: [0, 1, 1, 2, 3, 5, 8, 13, 21],
107 |     boxpoints: :all,
108 |     jitter: 0.3,
109 |     pointpos: -1.8,
110 |     type: :box
111 |   }
112 | 
113 | plot = Plotly::Plot.new(data: [trace])
114 | 
115 | 118 |
119 | 133 | 134 |
135 | 136 | 137 | -------------------------------------------------------------------------------- /docs/rbplotly-heatmap.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly heatmap usage

24 | 25 |
require 'rbplotly'
26 | 
27 | z = [
28 |   [1, 20, 30],
29 |   [20, 1, 60],
30 |   [30, 60, 1]
31 | ]
32 | 
33 | data = [{
34 |   z: z,
35 |   type: :heatmap
36 | }]
37 | 
38 | plot = Plotly::Plot.new(data: data)
39 | 
40 | 43 |
44 | 58 | 59 |
n = 10
60 | data = {
61 |   x: (1..n).map { |i| "x#{i}" },
62 |   y: (1..n).map { |i| "y#{i}" },
63 |   z: (1..n).map { (1..n).map { rand(10) } },
64 |   type: :heatmap
65 | }
66 | 
67 | layout = {
68 |   width:  500,
69 |   height: 500
70 | }
71 | 
72 | plot = Plotly::Plot.new(data: [data], layout: layout)
73 | 
74 | 77 |
78 | 92 | 93 |
94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/rbplotly-hist.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly histogram usage

24 | 25 |
require 'rbplotly'
26 | 
27 | data = [{ x: (1..500).map { rand }, type: :histogram }]
28 | 
29 | plot = Plotly::Plot.new(data: data)
30 | 
31 | 34 |
35 | 49 | 50 |
51 | 52 | 53 | -------------------------------------------------------------------------------- /docs/rbplotly-line.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly line plot usage

24 | 25 |
require 'rbplotly'
26 | 
27 | plot = Plotly::Plot.new
28 | flip = -1
29 | x = (0...100).map { |i| i.to_f / 10 }
30 | (0..5).each do |i|
31 |   trace = {
32 |     x: x,
33 |     y: (1...100).map { |j| Math.sin(j.to_f / 10 + i) },
34 |     line: { shape: :spline },
35 |     mode: :lines
36 |   }
37 |   plot.data.push(trace)
38 | end
39 | plot
40 | 
41 | 44 |
45 | 59 | 60 |
61 | 62 | 63 | -------------------------------------------------------------------------------- /docs/rbplotly-pie.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly pie chart usage

24 | 25 |

Basic pie chart

26 | 27 |
require 'rbplotly'
 28 | 
 29 | data = [{
 30 |   labels: %w(Residential Non-Residential Utility),
 31 |   values: [19, 26, 55],
 32 |   type: :pie
 33 | }]
 34 | 
 35 | layout = { title: 'Forcasted 2014 U.S. PV Installations by Market Segment' }
 36 | 
 37 | plot = Plotly::Plot.new(data: data, layout: layout )
 38 | 
39 | 42 |
43 | 57 | 58 |

Donut chart

59 | 60 |
trace1 = {
 61 |   name: 'GHG Emissions',
 62 |   values: [16, 15, 12, 6, 5, 4, 42],
 63 |   domain: { x: [0, 0.5] },
 64 | 
 65 |   labels: %w(US China European Union Russian Federation Brazil India Rest\ of\ World),
 66 |   hoverinfo: :'label+percent+name',
 67 |   hole: 0.4,
 68 |   type: :pie,
 69 | }
 70 | 
 71 | trace2 = trace1.merge({
 72 |   name: 'CO2 Emissions',
 73 |   values: [27, 11, 25, 8, 1, 3, 25],
 74 |   domain: { x: [0.5, 1] }
 75 | })
 76 | 
 77 | plot = Plotly::Plot.new(data: [trace1, trace2])
 78 | 
79 | 82 |
83 | 97 | 98 |
99 | 100 | 101 | -------------------------------------------------------------------------------- /docs/rbplotly-scatter.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

rbplotly scatter plot usage

24 | 25 |

Simple scatter Plot

26 | 27 |
require 'rbplotly'
 28 | 
 29 | n = 100
 30 | x = n.times.map { rand(-2.0..2.0) }
 31 | y = n.times.map { rand(-1.0..1.0) }
 32 | trace = { x: x, y: y, mode: :markers }
 33 | 
 34 | plot = Plotly::Plot.new(data: [trace])
 35 | plot.layout.title = 'Simple Scatter Plot'
 36 | plot
 37 | 
38 | 41 |
42 | 56 | 57 |

Line and scatter plots

58 | 59 |
n = 100
 60 | 
 61 | x  = n.times.map { |i| i.to_f / (n - 1) }
 62 | y0 = n.times.map { rand(-2.0..2.0) + 5 }
 63 | y1 = n.times.map { rand(-2.0..2.0) }
 64 | y2 = n.times.map { rand(-2.0..2.0) - 5 }
 65 | 
 66 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers }
 67 | trace1 = { x: x, y: y1, type: :scatter, mode: :'markers+lines' }
 68 | trace2 = { x: x, y: y2, type: :scatter, mode: :lines }
 69 | 
 70 | plot = Plotly::Plot.new(data: [trace0, trace1, trace2])
 71 | plot.layout.title = 'Line and Scatter Plots'
 72 | plot
 73 | 
74 | 77 |
78 | 92 | 93 |

Style scatter plots

94 | 95 |
n = 100
 96 | trace0 = {
 97 |   x: n.times.map { rand(-2.0..2.0) },
 98 |   y: n.times.map { rand(-1.0..1.0) },
 99 |   name: 'Red',
100 |   mode: :markers,
101 |   marker: {
102 |     size: 15,
103 |     color: 'rgba(200, 0, 0, .5)',
104 |     line: { width: 2, color: 'rgb(0, 0, 0, .5)' }
105 |   }
106 | }
107 | trace1 = {
108 |   x: n.times.map { rand(-2.0..2.0) },
109 |   y: n.times.map { rand(-1.0..1.0) },
110 |   name: 'Blue',
111 |   mode: :markers,
112 |   marker: {
113 |     size: 10,
114 |     color: 'rgba(0, 0, 200, .5)',
115 |     line: { width: 1, color: 'rgb(0, 0, 0, .5)' }
116 |   }
117 | }
118 | 
119 | layout = {
120 |   title: 'Styled Scatter',
121 |   xaxis: { zeroline: false },
122 |   yaxis: { zeroline: false }
123 | }
124 | 
125 | plot = Plotly::Plot.new(data: [trace0, trace1], layout: layout)
126 | 
127 | 130 |
131 | 145 | 146 |
147 | 148 | 149 | -------------------------------------------------------------------------------- /docs/rumale-kmeans.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 | 24 |

k-means clustering with rumale

25 | 26 |

super simple k-means clustering demo

27 | 28 |
require "numo/narray"
29 | require "rumale"
30 | samples = Numo::DFloat[[1, 2], [1, 4], [1, 0],[10, 2], [10, 4], [10, 0]]
31 | analyzer = Rumale::Clustering::KMeans.new(n_clusters: 2, max_iter: 50)
32 | cluster_labels = analyzer.fit_predict(samples)
33 | 
34 | [1, 1, 1, 0, 0, 0] 35 | 36 |

We can see that the rumale analyzer separately labeled the first 3points and the last 3points.

37 | 38 |

Visualizing clusters with rbplotly

39 | 40 |

Next we visualize the cluster with rbplotly

41 | 42 |
cluster0 = samples[0..2,0..1]
43 | cluster1 = samples[3..5,0..1]
44 | x0 = cluster0[0..-1,0].to_a
45 | y0 = cluster0[0..-1,1].to_a
46 | x1 = cluster1[0..-1,0].to_a
47 | y1 = cluster1[0..-1,1].to_a
48 | trace0 = {x:x0, y:y0, type: :scatter, mode: :markers}
49 | trace1 = {x:x1, y:y1, type: :scatter, mode: :markers}
50 | plot = Plotly::Plot.new(data: [trace0, trace1])
51 | 
52 | 55 |
56 | 70 | 71 |

The end

72 | 73 |
74 | 75 | 76 | -------------------------------------------------------------------------------- /docs/rumale.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

Rumale machine learning examples

24 | 25 |
require 'rumale'
 26 | require 'rdatasets'
 27 | 
 28 | iris = RDatasets.load(:datasets, :iris)
 29 | 
 30 | iris_labels = iris['Species'].to_a
 31 | encoder = Rumale::Preprocessing::LabelEncoder.new
 32 | labels = encoder.fit_transform(iris_labels)
 33 | p "hoge"
 34 | 
35 |

"hoge"
 36 | 
 37 | => hoge
 38 | 
39 |

40 | 41 |
samples = Numo::DFloat[*iris[0..3].to_matrix.to_a]
 42 | 
43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | 510 | 511 | 512 | 513 | 514 | 515 | 516 | 517 | 518 | 519 | 520 | 521 | 522 | 523 | 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | 535 | 536 | 537 | 538 | 539 | 540 | 541 | 542 | 543 | 544 | 545 | 546 | 547 | 548 | 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 685 | 686 | 687 | 688 | 689 | 690 | 691 | 692 | 693 | 694 | 695 | 696 | 697 | 698 | 699 | 700 | 701 | 702 | 703 | 704 | 705 | 706 | 707 | 708 | 709 | 710 | 711 | 712 | 713 | 714 | 715 | 716 | 717 | 718 | 719 | 720 | 721 | 722 | 723 | 724 | 725 | 726 | 727 | 728 | 729 | 730 | 731 | 732 | 733 | 734 | 735 | 736 | 737 | 738 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 814 | 815 | 816 | 817 | 818 | 819 | 820 | 821 | 822 | 823 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | 873 | 874 | 875 | 876 | 877 | 878 | 879 | 880 | 881 | 882 | 883 | 884 | 885 | 886 | 887 | 888 | 889 | 890 | 891 | 892 | 893 | 894 | 895 | 896 | 897 | 898 | 899 | 900 | 901 | 902 | 903 | 904 | 905 | 906 | 907 | 908 | 909 | 910 | 911 | 912 | 913 | 914 | 915 | 916 | 917 | 918 | 919 | 920 | 921 | 922 | 923 | 924 | 925 | 926 | 927 | 928 | 929 | 930 | 931 | 932 | 933 | 934 | 935 | 936 | 937 | 938 | 939 | 940 | 941 | 942 | 943 | 944 | 945 | 946 |
5.13.51.40.2
4.93.01.40.2
4.73.21.30.2
4.63.11.50.2
5.03.61.40.2
5.43.91.70.4
4.63.41.40.3
5.03.41.50.2
4.42.91.40.2
4.93.11.50.1
5.43.71.50.2
4.83.41.60.2
4.83.01.40.1
4.33.01.10.1
5.84.01.20.2
5.74.41.50.4
5.43.91.30.4
5.13.51.40.3
5.73.81.70.3
5.13.81.50.3
5.43.41.70.2
5.13.71.50.4
4.63.61.00.2
5.13.31.70.5
4.83.41.90.2
5.03.01.60.2
5.03.41.60.4
5.23.51.50.2
5.23.41.40.2
4.73.21.60.2
4.83.11.60.2
5.43.41.50.4
5.24.11.50.1
5.54.21.40.2
4.93.11.50.2
5.03.21.20.2
5.53.51.30.2
4.93.61.40.1
4.43.01.30.2
5.13.41.50.2
5.03.51.30.3
4.52.31.30.3
4.43.21.30.2
5.03.51.60.6
5.13.81.90.4
4.83.01.40.3
5.13.81.60.2
4.63.21.40.2
5.33.71.50.2
5.03.31.40.2
7.03.24.71.4
6.43.24.51.5
6.93.14.91.5
5.52.34.01.3
6.52.84.61.5
5.72.84.51.3
6.33.34.71.6
4.92.43.31.0
6.62.94.61.3
5.22.73.91.4
5.02.03.51.0
5.93.04.21.5
6.02.24.01.0
6.12.94.71.4
5.62.93.61.3
6.73.14.41.4
5.63.04.51.5
5.82.74.11.0
6.22.24.51.5
5.62.53.91.1
5.93.24.81.8
6.12.84.01.3
6.32.54.91.5
6.12.84.71.2
6.42.94.31.3
6.63.04.41.4
6.82.84.81.4
6.73.05.01.7
6.02.94.51.5
5.72.63.51.0
5.52.43.81.1
5.52.43.71.0
5.82.73.91.2
6.02.75.11.6
5.43.04.51.5
6.03.44.51.6
6.73.14.71.5
6.32.34.41.3
5.63.04.11.3
5.52.54.01.3
5.52.64.41.2
6.13.04.61.4
5.82.64.01.2
5.02.33.31.0
5.62.74.21.3
5.73.04.21.2
5.72.94.21.3
6.22.94.31.3
5.12.53.01.1
5.72.84.11.3
6.33.36.02.5
5.82.75.11.9
7.13.05.92.1
6.32.95.61.8
6.53.05.82.2
7.63.06.62.1
4.92.54.51.7
7.32.96.31.8
6.72.55.81.8
7.23.66.12.5
6.53.25.12.0
6.42.75.31.9
6.83.05.52.1
5.72.55.02.0
5.82.85.12.4
6.43.25.32.3
6.53.05.51.8
7.73.86.72.2
7.72.66.92.3
6.02.25.01.5
6.93.25.72.3
5.62.84.92.0
7.72.86.72.0
6.32.74.91.8
6.73.35.72.1
7.23.26.01.8
6.22.84.81.8
6.13.04.91.8
6.42.85.62.1
7.23.05.81.6
7.42.86.11.9
7.93.86.42.0
6.42.85.62.2
6.32.85.11.5
6.12.65.61.4
7.73.06.12.3
6.33.45.62.4
6.43.15.51.8
6.03.04.81.8
6.93.15.42.1
6.73.15.62.4
6.93.15.12.3
5.82.75.11.9
6.83.25.92.3
6.73.35.72.5
6.73.05.22.3
6.32.55.01.9
6.53.05.22.0
6.23.45.42.3
5.93.05.11.8
947 | 948 |
model = Rumale::LinearModel::SVC.new(
949 |   reg_param: 0.0001,
950 |   fit_bias: true,
951 |   max_iter: 3000,
952 |   random_seed: 1
953 | )
954 | 
955 | model.fit(samples, labels)
956 | 
957 | p model.predict(samples).to_a
958 | 
959 |

[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
960 | 
961 | => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
962 | 
963 |

964 | 965 |
966 | 967 | 968 | -------------------------------------------------------------------------------- /docs/table.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | 20 | 21 | 22 |
23 |

Table generation example

24 | 25 |

With Numo::Narray

26 | 27 |
a = Numo::DFloat.new(3, 5).seq
28 | 
29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 |
0.01.02.03.04.0
5.06.07.08.09.0
10.011.012.013.014.0
54 | 55 |
56 | 57 | 58 | -------------------------------------------------------------------------------- /examples/bio.md: -------------------------------------------------------------------------------- 1 | # BioRuby Tutorial 2 | 3 | ## Trying Bioruby 4 | 5 | Now test the following: 6 | 7 | ~~~ruby 8 | require 'bio' 9 | seq = Bio::Sequence::NA.new("atgcatgcaaaa") 10 | ~~~ 11 | 12 | ~~~ruby 13 | seq.complement 14 | ~~~ 15 | 16 | ## Working with nucleic / amino acid sequences (Bio::Sequence class) 17 | 18 | The `Bio::Sequence` class allows the usual sequence transformations and translations. 19 | 20 | In the example below the DNA sequence `atgcatgcaaaa` is converted into the complemental strand and spliced into a subsequence; next, the nucleic acid composition is calculated and the sequence is translated into the amino acid sequence, the molecular weight calculated, and so on. When translating into amino acid sequences, the frame can be specified and optionally the codon table selected (as defined in [codontable.rb](https://github.com/bioruby/bioruby/blob/master/lib/bio/data/codontable.rb)). 21 | 22 | ~~~ruby 23 | seq = Bio::Sequence::NA.new("atgcatgcaaaa") 24 | ~~~ 25 | 26 | ~~~ruby 27 | # complemental sequence (Bio::Sequence::NA object) 28 | seq.complement 29 | ~~~ 30 | 31 | ~~~ruby 32 | seq.subseq(3,8) # gets subsequence of positions 3 to 8 (starting from 1) 33 | ~~~ 34 | 35 | ~~~ruby 36 | seq.gc_percent 37 | ~~~ 38 | 39 | ~~~ruby 40 | seq.composition 41 | ~~~ 42 | 43 | ~~~ruby 44 | seq.translate 45 | ~~~ 46 | 47 | ~~~ruby 48 | seq.translate(2) 49 | ~~~ 50 | 51 | ~~~ruby 52 | seq.translate(1,11) 53 | ~~~ 54 | 55 | ~~~ruby 56 | seq.translate.codes 57 | ~~~ 58 | 59 | ~~~ruby 60 | seq.translate.names 61 | ~~~ 62 | 63 | ~~~ruby 64 | seq.translate.composition 65 | ~~~ 66 | 67 | ~~~ruby 68 | seq.translate.molecular_weight 69 | ~~~ 70 | 71 | ~~~ruby 72 | seq.complement.translate 73 | ~~~ 74 | -------------------------------------------------------------------------------- /examples/charty.md: -------------------------------------------------------------------------------- 1 | 2 | # Charty Usage 3 | 4 | ## You can write Markdown! 5 | 6 | - item1 7 | - item2 8 | 9 | ~~~ruby 10 | 11 | require 'charty' 12 | charty = Charty::Plotter.new(:pyplot) 13 | 14 | bar = charty.bar do 15 | series [0,1,2,3,4], [10,40,20,90,70] 16 | series [0,1,2,3,4], [90,80,70,60,50] 17 | series [0,1,2,3,4,5,6,7,8], [50,60,20,30,10, 90, 0, 100, 50] 18 | range x: 0..10, y: 1..100 19 | xlabel 'foo' 20 | ylabel 'bar' 21 | title 'bar plot' 22 | end 23 | bar.render("bar_matplot.png") 24 | ~~~ 25 | 26 | -------------------------------------------------------------------------------- /examples/graph.md: -------------------------------------------------------------------------------- 1 | # Graph generation example 2 | 3 | ## With [Numo::Gnuplot](https://github.com/ruby-numo/numo-gnuplot) 4 | 5 | `Rubydown::RbMarkPlot` is extended class of `Numo::Gnuplot` 6 | 7 | ~~~ruby 8 | rp = Rubydown::RbMarkPlot.new 9 | rp.set title: "Example Plot" 10 | rp.plot "sin(x)", w:"lines" 11 | ~~~ 12 | -------------------------------------------------------------------------------- /examples/index.md: -------------------------------------------------------------------------------- 1 | ## テスト 2 | 3 | ### コードを書く 4 | 5 | *~~~ruby* と *~~~* でコードを囲むと、そのブロックが評価される。 6 | 7 | ~~~ruby 8 | array = [1,2,3,4] 9 | converted = array.map { |e| e * 100 } 10 | 11 | converted # 最後の行が出力される 12 | ~~~ 13 | 14 | 標準出力も表示される 15 | 16 | ~~~ruby 17 | puts :hoge 18 | 19 | "fuga\npiyo".inspect 20 | ~~~ 21 | 22 | ### ブロックは全部同じスコープ 23 | 24 | 先程定義した変数`converted`が以下でも使える。 25 | 26 | ~~~ruby 27 | converted.map { |e| e / 100 } 28 | ~~~ 29 | 30 | ### ライブラリを使う 31 | 32 | もちろん外部のライブラリをロードすることもできる。 33 | 34 | ~~~ruby 35 | require 'matrix' 36 | 37 | Matrix.identity(10) 38 | ~~~ 39 | 40 | ### to_htmlを実装する 41 | 42 | `to_html` メソッドを実装すると、その結果が出力される。 43 | 44 | ~~~ruby 45 | class Matrix # オープンクラス 46 | def to_html 47 | rows = self.to_a.map do |row| 48 | elems = row.map do |elem| 49 | "#{elem}" 50 | end 51 | "#{elems}" 52 | end 53 | "#{rows.join}
" 54 | end 55 | end 56 | 57 | Matrix.identity(10) 58 | ~~~ 59 | -------------------------------------------------------------------------------- /examples/rbplotly-bar.md: -------------------------------------------------------------------------------- 1 | # rbplotly bar chart usage 2 | 3 | 4 | ~~~ruby 5 | require 'rbplotly' 6 | 7 | trace = { 8 | x: %w(giraffes orangutans monkeys), 9 | y: [20, 14, 23], 10 | type: :bar 11 | } 12 | 13 | plot = Plotly::Plot.new(data: [trace]) 14 | ~~~ 15 | 16 | 17 | ~~~ruby 18 | trace1 = { 19 | x: %w(giraffes orangutans monkeys), 20 | y: [20, 14, 23], 21 | type: :bar, 22 | name: 'SF Zoo' 23 | } 24 | trace2 = { 25 | x: %w(giraffes orangutans monkeys), 26 | y: [12, 18, 29], 27 | type: :bar, 28 | name: 'LA Zoo' 29 | } 30 | 31 | plot = Plotly::Plot.new(data: [trace1, trace2]) 32 | ~~~ 33 | 34 | ~~~ruby 35 | plot.layout.barmode = :stack 36 | plot 37 | ~~~ 38 | 39 | ~~~ruby 40 | trace1 = { 41 | x: %w(giraffes orangutans monkeys), 42 | y: [20, 14, 23], 43 | type: :bar, 44 | name: 'SF Zoo' 45 | } 46 | trace2 = { 47 | x: %w(giraffes orangutans monkeys), 48 | y: [12, 18, 29], 49 | type: :bar, 50 | name: 'LA Zoo' 51 | } 52 | 53 | plot = Plotly::Plot.new(data: [trace1, trace2], layout: { barmode: :stack } ) 54 | ~~~ 55 | -------------------------------------------------------------------------------- /examples/rbplotly-basic.md: -------------------------------------------------------------------------------- 1 | # rbplotly basic usage 2 | 3 | 4 | ~~~ruby 5 | require 'rbplotly' 6 | 7 | n = 100 8 | 9 | x = n.times.map { |i| i.to_f / (n - 1) } 10 | y0 = n.times.map { rand(-2.0..2.0) + 5 } 11 | y1 = n.times.map { rand(-2.0..2.0) } 12 | 13 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers } 14 | trace1 = trace0.merge(y: y1, mode: :'markers+lines') 15 | 16 | plot = Plotly::Plot.new(data: [trace0, trace1]) 17 | ~~~ 18 | 19 | Here we replace the last trace range from -0.5 to 0.5 20 | 21 | 22 | ~~~ruby 23 | plot.data.last.y = n.times.map { rand(-0.5..0.5) } 24 | plot 25 | ~~~ 26 | 27 | Next we add a line trace with the center -5 and the range from -2.0 to 2.0. 28 | 29 | ~~~ruby 30 | new_trace = { x: x, y: n.times.map { rand(-2.0..2.0) - 5 }, type: :scatter, mode: :lines } 31 | plot.data.push(new_trace) 32 | plot 33 | ~~~ 34 | 35 | Last of all we add the x,y titles. 36 | 37 | 38 | ~~~ruby 39 | plot.layout.xaxis = { title: 'x title' } 40 | plot.layout.yaxis = { title: 'y title' } 41 | plot 42 | ~~~ 43 | 44 | -------------------------------------------------------------------------------- /examples/rbplotly-boxplot.md: -------------------------------------------------------------------------------- 1 | # rbplotly boxplot usage 2 | 3 | ~~~ruby 4 | require 'rbplotly' 5 | 6 | n = 50 7 | y0 = n.times.map { rand(-1.0..0.0) } 8 | y1 = n.times.map { rand(0.0..1.0) } 9 | 10 | trace0 = { 11 | y: y0, 12 | type: :box 13 | } 14 | 15 | trace1 = { 16 | y: y1, 17 | type: :box 18 | } 19 | 20 | data = [trace0, trace1] 21 | 22 | plot = Plotly::Plot.new(data: data) 23 | ~~~ 24 | 25 | ## Horizontal boxplot 26 | 27 | ~~~ruby 28 | n = 50 29 | x0 = n.times.map { rand(-1.0..0.0) } 30 | x1 = n.times.map { rand(0.0..1.0) } 31 | 32 | trace0 = { 33 | x: x0, 34 | type: :box 35 | } 36 | 37 | trace1 = { 38 | x: x1, 39 | type: :box 40 | } 41 | 42 | data = [trace0, trace1] 43 | 44 | plot = Plotly::Plot.new(data: data) 45 | ~~~ 46 | 47 | 48 | ## boxplot with the points 49 | 50 | ~~~ruby 51 | trace = { 52 | y: [0, 1, 1, 2, 3, 5, 8, 13, 21], 53 | boxpoints: :all, 54 | jitter: 0.3, 55 | pointpos: -1.8, 56 | type: :box 57 | } 58 | 59 | plot = Plotly::Plot.new(data: [trace]) 60 | ~~~ 61 | -------------------------------------------------------------------------------- /examples/rbplotly-heatmap.md: -------------------------------------------------------------------------------- 1 | # rbplotly heatmap usage 2 | 3 | ~~~ruby 4 | require 'rbplotly' 5 | 6 | z = [ 7 | [1, 20, 30], 8 | [20, 1, 60], 9 | [30, 60, 1] 10 | ] 11 | 12 | data = [{ 13 | z: z, 14 | type: :heatmap 15 | }] 16 | 17 | plot = Plotly::Plot.new(data: data) 18 | ~~~ 19 | 20 | ~~~ruby 21 | n = 10 22 | data = { 23 | x: (1..n).map { |i| "x#{i}" }, 24 | y: (1..n).map { |i| "y#{i}" }, 25 | z: (1..n).map { (1..n).map { rand(10) } }, 26 | type: :heatmap 27 | } 28 | 29 | layout = { 30 | width: 500, 31 | height: 500 32 | } 33 | 34 | plot = Plotly::Plot.new(data: [data], layout: layout) 35 | ~~~ 36 | -------------------------------------------------------------------------------- /examples/rbplotly-hist.md: -------------------------------------------------------------------------------- 1 | # rbplotly histogram usage 2 | 3 | ~~~ruby 4 | require 'rbplotly' 5 | 6 | data = [{ x: (1..500).map { rand }, type: :histogram }] 7 | 8 | plot = Plotly::Plot.new(data: data) 9 | ~~~ 10 | -------------------------------------------------------------------------------- /examples/rbplotly-line.md: -------------------------------------------------------------------------------- 1 | # rbplotly line plot usage 2 | 3 | ~~~ruby 4 | require 'rbplotly' 5 | 6 | plot = Plotly::Plot.new 7 | flip = -1 8 | x = (0...100).map { |i| i.to_f / 10 } 9 | (0..5).each do |i| 10 | trace = { 11 | x: x, 12 | y: (1...100).map { |j| Math.sin(j.to_f / 10 + i) }, 13 | line: { shape: :spline }, 14 | mode: :lines 15 | } 16 | plot.data.push(trace) 17 | end 18 | plot 19 | ~~~ 20 | -------------------------------------------------------------------------------- /examples/rbplotly-pie.md: -------------------------------------------------------------------------------- 1 | # rbplotly pie chart usage 2 | 3 | ## Basic pie chart 4 | 5 | ~~~ruby 6 | require 'rbplotly' 7 | 8 | data = [{ 9 | labels: %w(Residential Non-Residential Utility), 10 | values: [19, 26, 55], 11 | type: :pie 12 | }] 13 | 14 | layout = { title: 'Forcasted 2014 U.S. PV Installations by Market Segment' } 15 | 16 | plot = Plotly::Plot.new(data: data, layout: layout ) 17 | ~~~ 18 | 19 | ## Donut chart 20 | 21 | ~~~ruby 22 | trace1 = { 23 | name: 'GHG Emissions', 24 | values: [16, 15, 12, 6, 5, 4, 42], 25 | domain: { x: [0, 0.5] }, 26 | 27 | labels: %w(US China European Union Russian Federation Brazil India Rest\ of\ World), 28 | hoverinfo: :'label+percent+name', 29 | hole: 0.4, 30 | type: :pie, 31 | } 32 | 33 | trace2 = trace1.merge({ 34 | name: 'CO2 Emissions', 35 | values: [27, 11, 25, 8, 1, 3, 25], 36 | domain: { x: [0.5, 1] } 37 | }) 38 | 39 | plot = Plotly::Plot.new(data: [trace1, trace2]) 40 | ~~~ 41 | -------------------------------------------------------------------------------- /examples/rbplotly-scatter.md: -------------------------------------------------------------------------------- 1 | # rbplotly scatter plot usage 2 | 3 | ## Simple scatter Plot 4 | 5 | ~~~ruby 6 | require 'rbplotly' 7 | 8 | n = 100 9 | x = n.times.map { rand(-2.0..2.0) } 10 | y = n.times.map { rand(-1.0..1.0) } 11 | trace = { x: x, y: y, mode: :markers } 12 | 13 | plot = Plotly::Plot.new(data: [trace]) 14 | plot.layout.title = 'Simple Scatter Plot' 15 | plot 16 | ~~~ 17 | 18 | ## Line and scatter plots 19 | 20 | ~~~ruby 21 | n = 100 22 | 23 | x = n.times.map { |i| i.to_f / (n - 1) } 24 | y0 = n.times.map { rand(-2.0..2.0) + 5 } 25 | y1 = n.times.map { rand(-2.0..2.0) } 26 | y2 = n.times.map { rand(-2.0..2.0) - 5 } 27 | 28 | trace0 = { x: x, y: y0, type: :scatter, mode: :markers } 29 | trace1 = { x: x, y: y1, type: :scatter, mode: :'markers+lines' } 30 | trace2 = { x: x, y: y2, type: :scatter, mode: :lines } 31 | 32 | plot = Plotly::Plot.new(data: [trace0, trace1, trace2]) 33 | plot.layout.title = 'Line and Scatter Plots' 34 | plot 35 | ~~~ 36 | 37 | ## Style scatter plots 38 | 39 | ~~~ruby 40 | n = 100 41 | trace0 = { 42 | x: n.times.map { rand(-2.0..2.0) }, 43 | y: n.times.map { rand(-1.0..1.0) }, 44 | name: 'Red', 45 | mode: :markers, 46 | marker: { 47 | size: 15, 48 | color: 'rgba(200, 0, 0, .5)', 49 | line: { width: 2, color: 'rgb(0, 0, 0, .5)' } 50 | } 51 | } 52 | trace1 = { 53 | x: n.times.map { rand(-2.0..2.0) }, 54 | y: n.times.map { rand(-1.0..1.0) }, 55 | name: 'Blue', 56 | mode: :markers, 57 | marker: { 58 | size: 10, 59 | color: 'rgba(0, 0, 200, .5)', 60 | line: { width: 1, color: 'rgb(0, 0, 0, .5)' } 61 | } 62 | } 63 | 64 | layout = { 65 | title: 'Styled Scatter', 66 | xaxis: { zeroline: false }, 67 | yaxis: { zeroline: false } 68 | } 69 | 70 | plot = Plotly::Plot.new(data: [trace0, trace1], layout: layout) 71 | ~~~ 72 | -------------------------------------------------------------------------------- /examples/rumale-kmeans.md: -------------------------------------------------------------------------------- 1 | 2 | # k-means clustering with [rumale](https://github.com/yoshoku/rumale) 3 | 4 | ## super simple k-means clustering demo 5 | 6 | ~~~ruby 7 | require "numo/narray" 8 | require "rumale" 9 | samples = Numo::DFloat[[1, 2], [1, 4], [1, 0],[10, 2], [10, 4], [10, 0]] 10 | analyzer = Rumale::Clustering::KMeans.new(n_clusters: 2, max_iter: 50) 11 | cluster_labels = analyzer.fit_predict(samples) 12 | ~~~ 13 | 14 | 15 | We can see that the rumale `analyzer` separately labeled the first 3points and the last 3points. 16 | 17 | ## Visualizing clusters with [rbplotly](https://github.com/ash1day/rbplotly) 18 | 19 | Next we visualize the cluster with rbplotly 20 | 21 | ~~~ruby 22 | cluster0 = samples[0..2,0..1] 23 | cluster1 = samples[3..5,0..1] 24 | x0 = cluster0[0..-1,0].to_a 25 | y0 = cluster0[0..-1,1].to_a 26 | x1 = cluster1[0..-1,0].to_a 27 | y1 = cluster1[0..-1,1].to_a 28 | trace0 = {x:x0, y:y0, type: :scatter, mode: :markers} 29 | trace1 = {x:x1, y:y1, type: :scatter, mode: :markers} 30 | plot = Plotly::Plot.new(data: [trace0, trace1]) 31 | ~~~ 32 | 33 | The end 34 | -------------------------------------------------------------------------------- /examples/rumale.md: -------------------------------------------------------------------------------- 1 | Rumale machine learning examples 2 | 3 | 4 | ~~~ruby 5 | require 'rumale' 6 | require 'rdatasets' 7 | 8 | iris = RDatasets.load(:datasets, :iris) 9 | 10 | iris_labels = iris['Species'].to_a 11 | encoder = Rumale::Preprocessing::LabelEncoder.new 12 | labels = encoder.fit_transform(iris_labels) 13 | p "hoge" 14 | ~~~ 15 | 16 | ~~~ruby 17 | samples = Numo::DFloat[*iris[0..3].to_matrix.to_a] 18 | ~~~ 19 | 20 | ~~~ruby 21 | model = Rumale::LinearModel::SVC.new( 22 | reg_param: 0.0001, 23 | fit_bias: true, 24 | max_iter: 3000, 25 | random_seed: 1 26 | ) 27 | 28 | model.fit(samples, labels) 29 | 30 | p model.predict(samples).to_a 31 | ~~~ 32 | -------------------------------------------------------------------------------- /examples/table.md: -------------------------------------------------------------------------------- 1 | # Table generation example 2 | 3 | ## With [Numo::Narray](https://github.com/ruby-numo/numo-narray) 4 | 5 | ~~~ruby 6 | a = Numo::DFloat.new(3, 5).seq 7 | ~~~ 8 | -------------------------------------------------------------------------------- /exe/rubydown: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | 3 | require 'kramdown' 4 | require 'erb' 5 | require 'stringio' 6 | require 'base64' 7 | require 'optparse' 8 | 9 | require 'rubydown' 10 | 11 | def get_context 12 | binding 13 | end 14 | 15 | class EvalDoc < Kramdown::Document 16 | attr_accessor :context, :stdout 17 | attr_reader :javascripts 18 | 19 | def initialize(text, *opts) 20 | super(text, *opts) 21 | 22 | @javascripts = {} 23 | self.context = get_context 24 | self.root = scan_el(self.root) 25 | end 26 | 27 | REQUIREJS_SCRIPT_TAG = '' 28 | MATHJAX_SCRIPT_TAG = "" 29 | 30 | private 31 | def scan_el(el) 32 | @javascripts[:mathjax] ||= MATHJAX_SCRIPT_TAG if el.type == :math 33 | 34 | new_children = [] 35 | el.children.each do |child_el| 36 | child_el = scan_el(child_el) 37 | new_children << child_el 38 | 39 | is_code = child_el.type == :codeblock || child_el.type == :codespan 40 | 41 | if is_code && child_el.options[:lang] == 'ruby' 42 | code = child_el.value.gsub(/^ *ruby *\n/, '') 43 | new_children << eval_and_elementize(code) 44 | @javascripts[:requirejs] ||= REQUIREJS_SCRIPT_TAG 45 | end 46 | end 47 | 48 | el.children = new_children 49 | 50 | return el 51 | end 52 | 53 | def eval_and_elementize(code) 54 | stdout = StringIO.new 55 | 56 | $stdout = stdout 57 | eval_result = self.context.eval(code) 58 | $stdout = STDOUT 59 | 60 | stdout_string = stdout.string.empty? ? '' : stdout.string + "\n" 61 | 62 | case 63 | when eval_result.respond_to?(:to_html) 64 | Kramdown::Document.new(eval_result.to_html, input: :html).root 65 | when eval_result.instance_of?(File) && File.extname(eval_result.path) == ".png" 66 | img_b64 = Base64.encode64(File.binread(eval_result.path)) 67 | Kramdown::Document.new("", input: :html).root 68 | else 69 | text_result_el(stdout_string + "=> #{eval_result}") 70 | end 71 | end 72 | 73 | def text_result_el(text) 74 | text_el = Kramdown::Element.new(:codeblock, text) 75 | p_el = Kramdown::Element.new(:p) 76 | p_el.children << text_el 77 | p_el 78 | end 79 | end 80 | 81 | def main # to separate binding 82 | 83 | options = {} 84 | options[:erb] = File.expand_path('../../templates/template.html.erb', __FILE__) 85 | option_parser = OptionParser.new do |opts| 86 | opts.on("-i INPUT", "Input form the file") do |input| 87 | options[:input] = input 88 | end 89 | opts.on("-e ERB", "Specify template file") do |erb| 90 | options[:erb] = erb 91 | end 92 | opts.on("-o OUTPUT", "Output html to OUTPUT") do |output| 93 | options[:output] = output 94 | end 95 | opts.on("-h", "--help", "Prints this help") do 96 | puts opts 97 | exit 98 | end 99 | opts.on_tail("--version", "Show version") do 100 | puts Rubydown::VERSION 101 | exit 102 | end 103 | end 104 | 105 | option_parser.parse! 106 | # puts options.inspect 107 | # puts options[:input] 108 | # puts options[:erb] 109 | # puts options[:output] 110 | 111 | case options[:input] 112 | when /\.md\z/i 113 | options[:output] ||= options[:input].sub(/\.md\z/i, '.html') 114 | when /./ 115 | abort("Input file must be markdown (*.md)") 116 | else 117 | abort(option_parser.help) 118 | end 119 | 120 | doc = EvalDoc.new(File.read(options[:input], encoding: 'utf-8')) # using in ERB 121 | File.write(options[:output], ERB.new(File.read(options[:erb])).result(binding)) 122 | # puts ERB.new(File.read(options[:erb])).result(binding) 123 | end 124 | 125 | main 126 | -------------------------------------------------------------------------------- /lib/rubydown.rb: -------------------------------------------------------------------------------- 1 | require "rubydown/version" 2 | 3 | require 'numo/narray' 4 | require 'rbplotly' 5 | require 'numo/gnuplot' 6 | require 'base64' 7 | require 'tempfile' 8 | require 'charty' 9 | 10 | 11 | class Numo::NArray 12 | def to_html 13 | case ndim 14 | when 2 15 | rows = self.to_a.map do |row| 16 | elems = row.map do |elem| 17 | "#{elem}" 18 | end 19 | "#{elems.join}" 20 | end 21 | "#{rows.join}
" 22 | when 1 23 | cols = self.to_a.map do |elem| 24 | "#{elem}" 25 | end 26 | "#{cols.join}
" 27 | else 28 | inspect 29 | end 30 | end 31 | end 32 | 33 | Charty::RenderContext.prepend Module.new { 34 | def render(filename=nil) 35 | super 36 | if filename.nil? 37 | p "The image could not be rendered. In the environment without IRuby, the file name for the charty render method is required." 38 | else 39 | File.open(filename) 40 | end 41 | end 42 | } 43 | 44 | module Rubydown 45 | class RbMarkPlot < Numo::Gnuplot 46 | def plot(*args) 47 | super(*args) 48 | self 49 | end 50 | 51 | def splot(*args) 52 | super(*args) 53 | self 54 | end 55 | 56 | def _plot_splot(*args) 57 | @tempfile = Tempfile.open(['plot', '.png']) 58 | set terminal: 'png' 59 | set output: @tempfile.path 60 | super(*args) 61 | end 62 | 63 | def to_html 64 | img_b64 = Base64.encode64(File.binread(@tempfile)) 65 | <<-HTML 66 | 67 | HTML 68 | end 69 | end 70 | 71 | class Error < StandardError; end 72 | # Your code goes here... 73 | end 74 | -------------------------------------------------------------------------------- /lib/rubydown/version.rb: -------------------------------------------------------------------------------- 1 | module Rubydown 2 | VERSION = "0.2.0" 3 | end 4 | -------------------------------------------------------------------------------- /rubydown.gemspec: -------------------------------------------------------------------------------- 1 | 2 | lib = File.expand_path("../lib", __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require "rubydown/version" 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "rubydown" 8 | spec.version = Rubydown::VERSION 9 | spec.authors = ["Yusuke Sangenya", "Kozo Nishida", "Kazuhiro Nishiyama"] 10 | spec.email = ["kozo.nishida@gmail.com"] 11 | spec.license = 'MIT' 12 | spec.summary = "Pure Ruby R Markdown clone." 13 | spec.description = "rubydown is R Markdown clone for Rubyists." 14 | spec.homepage = "https://github.com/sciruby-jp/rubydown" 15 | 16 | # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' 17 | # to allow pushing to a single host or delete this section to allow pushing to any host. 18 | if spec.respond_to?(:metadata) 19 | # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'" 20 | 21 | spec.metadata["homepage_uri"] = spec.homepage 22 | spec.metadata["source_code_uri"] = "https://github.com/sciruby-jp/rubydown" 23 | # spec.metadata["changelog_uri"] = "https//github.com/sciruby-jp/rubydown/blob/master/CHANGELOG.md" 24 | else 25 | raise "RubyGems 2.0 or newer is required to protect against " \ 26 | "public gem pushes." 27 | end 28 | 29 | # Specify which files should be added to the gem when it is released. 30 | # The `git ls-files -z` loads the files in the RubyGem that have been added into git. 31 | spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do 32 | `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } 33 | end 34 | spec.bindir = "exe" 35 | spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } 36 | spec.require_paths = ["lib"] 37 | 38 | spec.add_dependency "kramdown", "~> 2.1" 39 | spec.add_dependency "daru", "~> 0.2" 40 | spec.add_dependency "numo-narray", "~> 0.9.1" 41 | spec.add_dependency "numo-gnuplot", "~> 0.2.4" 42 | spec.add_dependency "rbplotly", "~> 0.1.2" 43 | spec.add_dependency "charty", "~> 0.2.0" 44 | spec.add_dependency "matplotlib", "~> 1.0.0" 45 | 46 | spec.add_development_dependency "bundler", "~> 1.17" 47 | spec.add_development_dependency "rake", "~> 10.0" 48 | spec.add_development_dependency "test-unit", "~> 3.3" 49 | end 50 | -------------------------------------------------------------------------------- /templates/template.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 19 | <%= doc.javascripts.values.join('') %> 20 | 21 | 22 |
23 | <%= doc.to_html %> 24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /test/test-table.rb: -------------------------------------------------------------------------------- 1 | require 'test/unit' 2 | require 'numo/narray' 3 | require 'rubydown' 4 | 5 | class TableTest < Test::Unit::TestCase 6 | def setup 7 | @table = Numo::DFloat.new(3, 5).seq.to_html 8 | end 9 | 10 | def test_to_html 11 | assert_equal( 12 | "
0.01.02.03.04.0
5.06.07.08.09.0
10.011.012.013.014.0
", 13 | @table 14 | ) 15 | end 16 | end --------------------------------------------------------------------------------