BioDSL 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +10 -0
- data/BioDSL.gemspec +64 -0
- data/LICENSE +339 -0
- data/README.md +205 -0
- data/Rakefile +94 -0
- data/examples/fastq_to_fasta.rb +8 -0
- data/lib/BioDSL/cary.rb +242 -0
- data/lib/BioDSL/command.rb +133 -0
- data/lib/BioDSL/commands/add_key.rb +110 -0
- data/lib/BioDSL/commands/align_seq_mothur.rb +194 -0
- data/lib/BioDSL/commands/analyze_residue_distribution.rb +222 -0
- data/lib/BioDSL/commands/assemble_pairs.rb +336 -0
- data/lib/BioDSL/commands/assemble_seq_idba.rb +230 -0
- data/lib/BioDSL/commands/assemble_seq_ray.rb +345 -0
- data/lib/BioDSL/commands/assemble_seq_spades.rb +252 -0
- data/lib/BioDSL/commands/classify_seq.rb +217 -0
- data/lib/BioDSL/commands/classify_seq_mothur.rb +226 -0
- data/lib/BioDSL/commands/clip_primer.rb +318 -0
- data/lib/BioDSL/commands/cluster_otus.rb +181 -0
- data/lib/BioDSL/commands/collapse_otus.rb +170 -0
- data/lib/BioDSL/commands/collect_otus.rb +150 -0
- data/lib/BioDSL/commands/complement_seq.rb +117 -0
- data/lib/BioDSL/commands/count.rb +135 -0
- data/lib/BioDSL/commands/count_values.rb +149 -0
- data/lib/BioDSL/commands/degap_seq.rb +253 -0
- data/lib/BioDSL/commands/dereplicate_seq.rb +168 -0
- data/lib/BioDSL/commands/dump.rb +157 -0
- data/lib/BioDSL/commands/filter_rrna.rb +239 -0
- data/lib/BioDSL/commands/genecall.rb +237 -0
- data/lib/BioDSL/commands/grab.rb +535 -0
- data/lib/BioDSL/commands/index_taxonomy.rb +226 -0
- data/lib/BioDSL/commands/mask_seq.rb +175 -0
- data/lib/BioDSL/commands/mean_scores.rb +168 -0
- data/lib/BioDSL/commands/merge_pair_seq.rb +175 -0
- data/lib/BioDSL/commands/merge_table.rb +225 -0
- data/lib/BioDSL/commands/merge_values.rb +113 -0
- data/lib/BioDSL/commands/plot_heatmap.rb +233 -0
- data/lib/BioDSL/commands/plot_histogram.rb +306 -0
- data/lib/BioDSL/commands/plot_matches.rb +282 -0
- data/lib/BioDSL/commands/plot_residue_distribution.rb +278 -0
- data/lib/BioDSL/commands/plot_scores.rb +285 -0
- data/lib/BioDSL/commands/random.rb +153 -0
- data/lib/BioDSL/commands/read_fasta.rb +222 -0
- data/lib/BioDSL/commands/read_fastq.rb +414 -0
- data/lib/BioDSL/commands/read_table.rb +329 -0
- data/lib/BioDSL/commands/reverse_seq.rb +113 -0
- data/lib/BioDSL/commands/slice_align.rb +400 -0
- data/lib/BioDSL/commands/slice_seq.rb +151 -0
- data/lib/BioDSL/commands/sort.rb +223 -0
- data/lib/BioDSL/commands/split_pair_seq.rb +220 -0
- data/lib/BioDSL/commands/split_values.rb +165 -0
- data/lib/BioDSL/commands/trim_primer.rb +314 -0
- data/lib/BioDSL/commands/trim_seq.rb +192 -0
- data/lib/BioDSL/commands/uchime_ref.rb +170 -0
- data/lib/BioDSL/commands/uclust.rb +286 -0
- data/lib/BioDSL/commands/unique_values.rb +145 -0
- data/lib/BioDSL/commands/usearch_global.rb +171 -0
- data/lib/BioDSL/commands/usearch_local.rb +171 -0
- data/lib/BioDSL/commands/write_fasta.rb +207 -0
- data/lib/BioDSL/commands/write_fastq.rb +191 -0
- data/lib/BioDSL/commands/write_table.rb +419 -0
- data/lib/BioDSL/commands/write_tree.rb +167 -0
- data/lib/BioDSL/commands.rb +31 -0
- data/lib/BioDSL/config.rb +55 -0
- data/lib/BioDSL/csv.rb +307 -0
- data/lib/BioDSL/debug.rb +42 -0
- data/lib/BioDSL/fasta.rb +133 -0
- data/lib/BioDSL/fastq.rb +77 -0
- data/lib/BioDSL/filesys.rb +137 -0
- data/lib/BioDSL/fork.rb +145 -0
- data/lib/BioDSL/hamming.rb +128 -0
- data/lib/BioDSL/helpers/aux_helper.rb +44 -0
- data/lib/BioDSL/helpers/email_helper.rb +66 -0
- data/lib/BioDSL/helpers/history_helper.rb +40 -0
- data/lib/BioDSL/helpers/log_helper.rb +55 -0
- data/lib/BioDSL/helpers/options_helper.rb +405 -0
- data/lib/BioDSL/helpers/status_helper.rb +132 -0
- data/lib/BioDSL/helpers.rb +35 -0
- data/lib/BioDSL/html_report.rb +200 -0
- data/lib/BioDSL/math.rb +55 -0
- data/lib/BioDSL/mummer.rb +216 -0
- data/lib/BioDSL/pipeline.rb +354 -0
- data/lib/BioDSL/seq/ambiguity.rb +66 -0
- data/lib/BioDSL/seq/assemble.rb +240 -0
- data/lib/BioDSL/seq/backtrack.rb +252 -0
- data/lib/BioDSL/seq/digest.rb +99 -0
- data/lib/BioDSL/seq/dynamic.rb +263 -0
- data/lib/BioDSL/seq/homopolymer.rb +59 -0
- data/lib/BioDSL/seq/kmer.rb +293 -0
- data/lib/BioDSL/seq/levenshtein.rb +113 -0
- data/lib/BioDSL/seq/translate.rb +109 -0
- data/lib/BioDSL/seq/trim.rb +188 -0
- data/lib/BioDSL/seq.rb +742 -0
- data/lib/BioDSL/serializer.rb +98 -0
- data/lib/BioDSL/stream.rb +113 -0
- data/lib/BioDSL/taxonomy.rb +691 -0
- data/lib/BioDSL/test.rb +42 -0
- data/lib/BioDSL/tmp_dir.rb +68 -0
- data/lib/BioDSL/usearch.rb +301 -0
- data/lib/BioDSL/verbose.rb +42 -0
- data/lib/BioDSL/version.rb +31 -0
- data/lib/BioDSL.rb +81 -0
- data/test/BioDSL/commands/test_add_key.rb +105 -0
- data/test/BioDSL/commands/test_align_seq_mothur.rb +99 -0
- data/test/BioDSL/commands/test_analyze_residue_distribution.rb +134 -0
- data/test/BioDSL/commands/test_assemble_pairs.rb +459 -0
- data/test/BioDSL/commands/test_assemble_seq_idba.rb +50 -0
- data/test/BioDSL/commands/test_assemble_seq_ray.rb +51 -0
- data/test/BioDSL/commands/test_assemble_seq_spades.rb +50 -0
- data/test/BioDSL/commands/test_classify_seq.rb +50 -0
- data/test/BioDSL/commands/test_classify_seq_mothur.rb +59 -0
- data/test/BioDSL/commands/test_clip_primer.rb +377 -0
- data/test/BioDSL/commands/test_cluster_otus.rb +128 -0
- data/test/BioDSL/commands/test_collapse_otus.rb +81 -0
- data/test/BioDSL/commands/test_collect_otus.rb +82 -0
- data/test/BioDSL/commands/test_complement_seq.rb +78 -0
- data/test/BioDSL/commands/test_count.rb +103 -0
- data/test/BioDSL/commands/test_count_values.rb +85 -0
- data/test/BioDSL/commands/test_degap_seq.rb +96 -0
- data/test/BioDSL/commands/test_dereplicate_seq.rb +92 -0
- data/test/BioDSL/commands/test_dump.rb +109 -0
- data/test/BioDSL/commands/test_filter_rrna.rb +128 -0
- data/test/BioDSL/commands/test_genecall.rb +50 -0
- data/test/BioDSL/commands/test_grab.rb +398 -0
- data/test/BioDSL/commands/test_index_taxonomy.rb +62 -0
- data/test/BioDSL/commands/test_mask_seq.rb +98 -0
- data/test/BioDSL/commands/test_mean_scores.rb +111 -0
- data/test/BioDSL/commands/test_merge_pair_seq.rb +115 -0
- data/test/BioDSL/commands/test_merge_table.rb +131 -0
- data/test/BioDSL/commands/test_merge_values.rb +83 -0
- data/test/BioDSL/commands/test_plot_heatmap.rb +185 -0
- data/test/BioDSL/commands/test_plot_histogram.rb +194 -0
- data/test/BioDSL/commands/test_plot_matches.rb +157 -0
- data/test/BioDSL/commands/test_plot_residue_distribution.rb +309 -0
- data/test/BioDSL/commands/test_plot_scores.rb +308 -0
- data/test/BioDSL/commands/test_random.rb +88 -0
- data/test/BioDSL/commands/test_read_fasta.rb +229 -0
- data/test/BioDSL/commands/test_read_fastq.rb +552 -0
- data/test/BioDSL/commands/test_read_table.rb +327 -0
- data/test/BioDSL/commands/test_reverse_seq.rb +79 -0
- data/test/BioDSL/commands/test_slice_align.rb +218 -0
- data/test/BioDSL/commands/test_slice_seq.rb +131 -0
- data/test/BioDSL/commands/test_sort.rb +128 -0
- data/test/BioDSL/commands/test_split_pair_seq.rb +164 -0
- data/test/BioDSL/commands/test_split_values.rb +95 -0
- data/test/BioDSL/commands/test_trim_primer.rb +329 -0
- data/test/BioDSL/commands/test_trim_seq.rb +150 -0
- data/test/BioDSL/commands/test_uchime_ref.rb +113 -0
- data/test/BioDSL/commands/test_uclust.rb +139 -0
- data/test/BioDSL/commands/test_unique_values.rb +98 -0
- data/test/BioDSL/commands/test_usearch_global.rb +123 -0
- data/test/BioDSL/commands/test_usearch_local.rb +125 -0
- data/test/BioDSL/commands/test_write_fasta.rb +159 -0
- data/test/BioDSL/commands/test_write_fastq.rb +166 -0
- data/test/BioDSL/commands/test_write_table.rb +411 -0
- data/test/BioDSL/commands/test_write_tree.rb +122 -0
- data/test/BioDSL/helpers/test_options_helper.rb +272 -0
- data/test/BioDSL/seq/test_assemble.rb +98 -0
- data/test/BioDSL/seq/test_backtrack.rb +176 -0
- data/test/BioDSL/seq/test_digest.rb +71 -0
- data/test/BioDSL/seq/test_dynamic.rb +133 -0
- data/test/BioDSL/seq/test_homopolymer.rb +58 -0
- data/test/BioDSL/seq/test_kmer.rb +134 -0
- data/test/BioDSL/seq/test_translate.rb +75 -0
- data/test/BioDSL/seq/test_trim.rb +101 -0
- data/test/BioDSL/test_cary.rb +176 -0
- data/test/BioDSL/test_command.rb +45 -0
- data/test/BioDSL/test_csv.rb +514 -0
- data/test/BioDSL/test_debug.rb +42 -0
- data/test/BioDSL/test_fasta.rb +154 -0
- data/test/BioDSL/test_fastq.rb +46 -0
- data/test/BioDSL/test_filesys.rb +145 -0
- data/test/BioDSL/test_fork.rb +85 -0
- data/test/BioDSL/test_math.rb +41 -0
- data/test/BioDSL/test_mummer.rb +79 -0
- data/test/BioDSL/test_pipeline.rb +187 -0
- data/test/BioDSL/test_seq.rb +790 -0
- data/test/BioDSL/test_serializer.rb +72 -0
- data/test/BioDSL/test_stream.rb +55 -0
- data/test/BioDSL/test_taxonomy.rb +336 -0
- data/test/BioDSL/test_test.rb +42 -0
- data/test/BioDSL/test_tmp_dir.rb +58 -0
- data/test/BioDSL/test_usearch.rb +33 -0
- data/test/BioDSL/test_verbose.rb +42 -0
- data/test/helper.rb +82 -0
- data/www/command.html.haml +14 -0
- data/www/css.html.haml +55 -0
- data/www/input_files.html.haml +3 -0
- data/www/layout.html.haml +12 -0
- data/www/output_files.html.haml +3 -0
- data/www/overview.html.haml +15 -0
- data/www/pipeline.html.haml +4 -0
- data/www/png.html.haml +2 -0
- data/www/status.html.haml +9 -0
- data/www/time.html.haml +11 -0
- metadata +503 -0
@@ -0,0 +1,185 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
|
3
|
+
|
4
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2007-2015 Martin Asser Hansen (mail@maasha.dk). #
|
7
|
+
# #
|
8
|
+
# This program is free software; you can redistribute it and/or #
|
9
|
+
# modify it under the terms of the GNU General Public License #
|
10
|
+
# as published by the Free Software Foundation; either version 2 #
|
11
|
+
# of the License, or (at your option) any later version. #
|
12
|
+
# #
|
13
|
+
# This program is distributed in the hope that it will be useful, #
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
16
|
+
# GNU General Public License for more details. #
|
17
|
+
# #
|
18
|
+
# You should have received a copy of the GNU General Public License #
|
19
|
+
# along with this program; if not, write to the Free Software #
|
20
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, #
|
21
|
+
# USA. #
|
22
|
+
# #
|
23
|
+
# http://www.gnu.org/copyleft/gpl.html #
|
24
|
+
# #
|
25
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
26
|
+
# #
|
27
|
+
# This software is part of BioDSL (www.github.com/maasha/BioDSL). #
|
28
|
+
# #
|
29
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
30
|
+
|
31
|
+
require 'test/helper'
|
32
|
+
|
33
|
+
# Test class for PlotHeatmap.
|
34
|
+
# rubocop:disable ClassLength
|
35
|
+
# rubocop:disable MethodLength
|
36
|
+
class TestPlotHeatmap < Test::Unit::TestCase
|
37
|
+
def setup
|
38
|
+
omit('gnuplot not found') unless BioDSL::Filesys.which('gnuplot')
|
39
|
+
|
40
|
+
@tmpdir = Dir.mktmpdir('BioDSL')
|
41
|
+
@file = File.join(@tmpdir, 'test.plot')
|
42
|
+
|
43
|
+
@input, @output = BioDSL::Stream.pipe
|
44
|
+
@input2, @output2 = BioDSL::Stream.pipe
|
45
|
+
|
46
|
+
setup_data
|
47
|
+
setup_expected1
|
48
|
+
setup_expected2
|
49
|
+
|
50
|
+
@p = BioDSL::Pipeline.new
|
51
|
+
end
|
52
|
+
|
53
|
+
def setup_data
|
54
|
+
@output.write(V0: 1, V1: 2, V2: 3, V3: 4)
|
55
|
+
@output.write(V0: 5, V1: 6, V2: 7, V3: 8)
|
56
|
+
@output.write(V0: 9, V1: 10, V2: 11, V3: 12)
|
57
|
+
@output.close
|
58
|
+
end
|
59
|
+
|
60
|
+
def setup_expected1
|
61
|
+
@expected = <<-EOF.gsub(/^\s+\|/, '')
|
62
|
+
|set terminal dumb
|
63
|
+
|set title \"Heatmap\"
|
64
|
+
|set xlabel \"x\"
|
65
|
+
|set ylabel \"y\"
|
66
|
+
|set output \"\"
|
67
|
+
|set view map
|
68
|
+
|set autoscale xfix
|
69
|
+
|set autoscale yfix
|
70
|
+
|set nokey
|
71
|
+
|set tic scale 0
|
72
|
+
|set palette rgbformulae 22,13,10
|
73
|
+
|unset xtics
|
74
|
+
|unset ytics
|
75
|
+
|plot \"-\" matrix with image
|
76
|
+
|1 2 3 4
|
77
|
+
|5 6 7 8
|
78
|
+
|9 10 11 12
|
79
|
+
|e
|
80
|
+
EOF
|
81
|
+
end
|
82
|
+
|
83
|
+
def setup_expected2
|
84
|
+
@expected2 = <<-EOF.gsub(/^\s+\|/, '')
|
85
|
+
|set terminal dumb
|
86
|
+
|set title \"Heatmap\"
|
87
|
+
|set xlabel \"x\"
|
88
|
+
|set ylabel \"y\"
|
89
|
+
|set output \"\"
|
90
|
+
|set view map
|
91
|
+
|set autoscale xfix
|
92
|
+
|set autoscale yfix
|
93
|
+
|set nokey
|
94
|
+
|set tic scale 0
|
95
|
+
|set palette rgbformulae 22,13,10
|
96
|
+
|set logscale cb
|
97
|
+
|unset xtics
|
98
|
+
|unset ytics
|
99
|
+
|plot \"-\" matrix with image
|
100
|
+
|1 2 3 4
|
101
|
+
|5 6 7 8
|
102
|
+
|9 10 11 12
|
103
|
+
|e
|
104
|
+
EOF
|
105
|
+
end
|
106
|
+
|
107
|
+
def teardown
|
108
|
+
FileUtils.rm_r @tmpdir
|
109
|
+
end
|
110
|
+
|
111
|
+
test 'BioDSL::Pipeline::PlotHeatmap with invalid options raises' do
|
112
|
+
assert_raise(BioDSL::OptionError) { @p.plot_heatmap(foo: 'bar') }
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'BioDSL::Pipeline::PlotHeatmap with invalid terminal raises' do
|
116
|
+
assert_raise(BioDSL::OptionError) { @p.plot_heatmap(terminal: 'foo') }
|
117
|
+
end
|
118
|
+
|
119
|
+
test 'BioDSL::Pipeline::PlotHeatmap with valid terminal don\'t raise' do
|
120
|
+
%w(dumb post svg x11 aqua png pdf).each do |terminal|
|
121
|
+
assert_nothing_raised { @p.plot_heatmap(terminal: terminal.to_sym) }
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
test 'BioDSL::Pipeline::PlotHeatmap to file outputs correctly' do
|
126
|
+
result = capture_stderr do
|
127
|
+
@p.plot_heatmap(output: @file, test: true).
|
128
|
+
run(input: @input, output: @output2)
|
129
|
+
end
|
130
|
+
|
131
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
132
|
+
assert_equal(@expected, result)
|
133
|
+
end
|
134
|
+
|
135
|
+
test 'BioDSL::Pipeline::PlotHeatmap to file with logscale outputs OK' do
|
136
|
+
result = capture_stderr do
|
137
|
+
@p.plot_heatmap(output: @file, logscale: true, test: true).
|
138
|
+
run(input: @input, output: @output2)
|
139
|
+
end
|
140
|
+
|
141
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
142
|
+
assert_equal(@expected2, result)
|
143
|
+
end
|
144
|
+
|
145
|
+
test 'BioDSL::Pipeline::PlotHeatmap to existing file raises' do
|
146
|
+
`touch #{@file}`
|
147
|
+
assert_raise(BioDSL::OptionError) { @p.plot_heatmap(output: @file) }
|
148
|
+
end
|
149
|
+
|
150
|
+
test 'BioDSL::Pipeline::PlotHeatmap to existing file with :force' \
|
151
|
+
'outputs correctly' do
|
152
|
+
`touch #{@file}`
|
153
|
+
result = capture_stderr do
|
154
|
+
@p.plot_heatmap(output: @file, force: true, test: true).
|
155
|
+
run(input: @input)
|
156
|
+
end
|
157
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
158
|
+
assert_equal(@expected, result)
|
159
|
+
end
|
160
|
+
|
161
|
+
test 'BioDSL::Pipeline::PlotHeatmap with flux outputs correctly' do
|
162
|
+
result = capture_stderr do
|
163
|
+
@p.plot_heatmap(output: @file, force: true, test: true).
|
164
|
+
run(input: @input, output: @output2)
|
165
|
+
end
|
166
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
167
|
+
assert_equal(@expected, result)
|
168
|
+
|
169
|
+
stream_expected = <<-EXP.gsub(/^\s+\|/, '')
|
170
|
+
|{:V0=>1, :V1=>2, :V2=>3, :V3=>4}
|
171
|
+
|{:V0=>5, :V1=>6, :V2=>7, :V3=>8}
|
172
|
+
|{:V0=>9, :V1=>10, :V2=>11, :V3=>12}
|
173
|
+
EXP
|
174
|
+
|
175
|
+
assert_equal(stream_expected, collect_result)
|
176
|
+
end
|
177
|
+
|
178
|
+
test 'BioDSL::Pipeline::PlotHeatmap status outputs correctly' do
|
179
|
+
@p.plot_heatmap(output: @file, force: true).
|
180
|
+
run(input: @input, output: @output2)
|
181
|
+
|
182
|
+
assert_equal(3, @p.status.first[:records_in])
|
183
|
+
assert_equal(3, @p.status.first[:records_out])
|
184
|
+
end
|
185
|
+
end
|
@@ -0,0 +1,194 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
|
3
|
+
|
4
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2007-2015 Martin Asser Hansen (mail@maasha.dk). #
|
7
|
+
# #
|
8
|
+
# This program is free software; you can redistribute it and/or #
|
9
|
+
# modify it under the terms of the GNU General Public License #
|
10
|
+
# as published by the Free Software Foundation; either version 2 #
|
11
|
+
# of the License, or (at your option) any later version. #
|
12
|
+
# #
|
13
|
+
# This program is distributed in the hope that it will be useful, #
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
16
|
+
# GNU General Public License for more details. #
|
17
|
+
# #
|
18
|
+
# You should have received a copy of the GNU General Public License #
|
19
|
+
# along with this program; if not, write to the Free Software #
|
20
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, #
|
21
|
+
# USA. #
|
22
|
+
# #
|
23
|
+
# http://www.gnu.org/copyleft/gpl.html #
|
24
|
+
# #
|
25
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
26
|
+
# #
|
27
|
+
# This software is part of BioDSL (www.github.com/maasha/BioDSL). #
|
28
|
+
# #
|
29
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
30
|
+
|
31
|
+
require 'test/helper'
|
32
|
+
|
33
|
+
# Test class for PlotHistogram.
|
34
|
+
# rubocop:disable ClassLength
|
35
|
+
class TestPlotHistogram < Test::Unit::TestCase
|
36
|
+
def setup
|
37
|
+
omit('gnuplot not found') unless BioDSL::Filesys.which('gnuplot')
|
38
|
+
|
39
|
+
@tmpdir = Dir.mktmpdir('BioDSL')
|
40
|
+
@file = File.join(@tmpdir, 'test.plot')
|
41
|
+
|
42
|
+
@input, @output = BioDSL::Stream.pipe
|
43
|
+
@input2, @output2 = BioDSL::Stream.pipe
|
44
|
+
|
45
|
+
setup_stream
|
46
|
+
setup_expected1
|
47
|
+
setup_expected2
|
48
|
+
|
49
|
+
@p = BioDSL::Pipeline.new
|
50
|
+
end
|
51
|
+
|
52
|
+
def setup_stream
|
53
|
+
@output.write(ID: 'x', LEN: 1)
|
54
|
+
@output.write(ID: 'x', LEN: 2)
|
55
|
+
@output.write(ID: 'x', LEN: 2)
|
56
|
+
@output.write(ID: 'x', LEN: 3)
|
57
|
+
@output.write(ID: 'y', LEN: 3)
|
58
|
+
@output.write(ID: 'y', LEN: 3)
|
59
|
+
@output.close
|
60
|
+
end
|
61
|
+
|
62
|
+
# rubocop:disable MethodLength
|
63
|
+
def setup_expected1
|
64
|
+
@expected1 = <<-EOF.gsub(/^\s+\|/, '')
|
65
|
+
|set terminal dumb
|
66
|
+
|set title \"Histogram\"
|
67
|
+
|set xlabel \"LEN\"
|
68
|
+
|set ylabel \"n\"
|
69
|
+
|set autoscale xfix
|
70
|
+
|set style fill solid 0.5 border
|
71
|
+
|set xtics out
|
72
|
+
|set ytics out
|
73
|
+
|set yrange [0:*]
|
74
|
+
|set output \"\"
|
75
|
+
|plot \"-\" using 1:2 with boxes notitle
|
76
|
+
|0 0
|
77
|
+
|1 1
|
78
|
+
|2 2
|
79
|
+
|3 3
|
80
|
+
|e
|
81
|
+
EOF
|
82
|
+
end
|
83
|
+
|
84
|
+
def setup_expected2
|
85
|
+
@expected2 = <<-EOF.gsub(/^\s+\|/, '')
|
86
|
+
|set terminal dumb
|
87
|
+
|set title \"Histogram\"
|
88
|
+
|set xlabel \"ID\"
|
89
|
+
|set ylabel \"n\"
|
90
|
+
|set autoscale xfix
|
91
|
+
|set style fill solid 0.5 border
|
92
|
+
|set xtics out
|
93
|
+
|set ytics out
|
94
|
+
|set yrange [0:*]
|
95
|
+
|set output \"\"
|
96
|
+
|plot \"-\" using 2:xticlabels(1) with boxes notitle lc rgb \"red\"
|
97
|
+
|x 4
|
98
|
+
|y 2
|
99
|
+
|e
|
100
|
+
EOF
|
101
|
+
end
|
102
|
+
|
103
|
+
# rubocop:enable MethodLength
|
104
|
+
def teardown
|
105
|
+
FileUtils.rm_r @tmpdir
|
106
|
+
end
|
107
|
+
|
108
|
+
test 'BioDSL::Pipeline::PlotHistogram with invalid options raises' do
|
109
|
+
assert_raise(BioDSL::OptionError) do
|
110
|
+
@p.plot_histogram(key: :LEN, foo: 'bar')
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
test 'BioDSL::Pipeline::PlotHistogram with invalid terminal raises' do
|
115
|
+
assert_raise(BioDSL::OptionError) do
|
116
|
+
@p.plot_histogram(key: :LEN, terminal: 'foo')
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'BioDSL::Pipeline::PlotHistogram with valid terminal don\'t raise' do
|
121
|
+
%w(dumb post svg x11 aqua png pdf).each do |terminal|
|
122
|
+
assert_nothing_raised do
|
123
|
+
@p.plot_histogram(key: :LEN, terminal: terminal.to_sym)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
test 'BioDSL::Pipeline::PlotHistogram to file with numeric outputs OK' do
|
129
|
+
result = capture_stderr do
|
130
|
+
@p.plot_histogram(key: :LEN, output: @file, test: true).
|
131
|
+
run(input: @input, output: @output2)
|
132
|
+
end
|
133
|
+
|
134
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
135
|
+
assert_equal(@expected1, result)
|
136
|
+
end
|
137
|
+
|
138
|
+
test 'BioDSL::Pipeline::PlotHistogram to file with non-numeric outputs ' \
|
139
|
+
'correctly' do
|
140
|
+
result = capture_stderr do
|
141
|
+
@p.plot_histogram(key: :ID, output: @file, test: true).
|
142
|
+
run(input: @input, output: @output2)
|
143
|
+
end
|
144
|
+
|
145
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
146
|
+
assert_equal(@expected2, result)
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'BioDSL::Pipeline::PlotHistogram to existing file raises' do
|
150
|
+
`touch #{@file}`
|
151
|
+
assert_raise(BioDSL::OptionError) { @p.plot_histogram(output: @file) }
|
152
|
+
end
|
153
|
+
|
154
|
+
test 'BioDSL::Pipeline::PlotHistogram to existing file with :force ' \
|
155
|
+
'outputs correctly' do
|
156
|
+
`touch #{@file}`
|
157
|
+
result = capture_stderr do
|
158
|
+
@p.plot_histogram(key: :LEN, output: @file, force: true, test: true).
|
159
|
+
run(input: @input)
|
160
|
+
end
|
161
|
+
|
162
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
163
|
+
assert_equal(@expected1, result)
|
164
|
+
end
|
165
|
+
|
166
|
+
test 'BioDSL::Pipeline::PlotHistogram with flux outputs correctly' do
|
167
|
+
result = capture_stderr do
|
168
|
+
@p.plot_histogram(key: :LEN, output: @file, force: true, test: true).
|
169
|
+
run(input: @input, output: @output2)
|
170
|
+
end
|
171
|
+
|
172
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
173
|
+
assert_equal(@expected1, result)
|
174
|
+
|
175
|
+
expected = <<-EXP.gsub(/^\s+\|/, '')
|
176
|
+
|{:ID=>"x", :LEN=>1}
|
177
|
+
|{:ID=>"x", :LEN=>2}
|
178
|
+
|{:ID=>"x", :LEN=>2}
|
179
|
+
|{:ID=>"x", :LEN=>3}
|
180
|
+
|{:ID=>"y", :LEN=>3}
|
181
|
+
|{:ID=>"y", :LEN=>3}
|
182
|
+
EXP
|
183
|
+
|
184
|
+
assert_equal(expected, collect_result)
|
185
|
+
end
|
186
|
+
|
187
|
+
test 'BioDSL::Pipeline::PlotHistogram status outputs correctly' do
|
188
|
+
@p.plot_histogram(key: :LEN, output: @file, force: true).
|
189
|
+
run(input: @input, output: @output2)
|
190
|
+
|
191
|
+
assert_equal(6, @p.status.first[:records_in])
|
192
|
+
assert_equal(6, @p.status.first[:records_out])
|
193
|
+
end
|
194
|
+
end
|
@@ -0,0 +1,157 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', '..', '..')
|
3
|
+
|
4
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
5
|
+
# #
|
6
|
+
# Copyright (C) 2007-2015 Martin Asser Hansen (mail@maasha.dk). #
|
7
|
+
# #
|
8
|
+
# This program is free software; you can redistribute it and/or #
|
9
|
+
# modify it under the terms of the GNU General Public License #
|
10
|
+
# as published by the Free Software Foundation; either version 2 #
|
11
|
+
# of the License, or (at your option) any later version. #
|
12
|
+
# #
|
13
|
+
# This program is distributed in the hope that it will be useful, #
|
14
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
|
15
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
|
16
|
+
# GNU General Public License for more details. #
|
17
|
+
# #
|
18
|
+
# You should have received a copy of the GNU General Public License #
|
19
|
+
# along with this program; if not, write to the Free Software #
|
20
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, #
|
21
|
+
# USA. #
|
22
|
+
# #
|
23
|
+
# http://www.gnu.org/copyleft/gpl.html #
|
24
|
+
# #
|
25
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
26
|
+
# #
|
27
|
+
# This software is part of BioDSL (www.github.com/maasha/BioDSL). #
|
28
|
+
# #
|
29
|
+
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
|
30
|
+
|
31
|
+
require 'test/helper'
|
32
|
+
|
33
|
+
# Test class for PlotMatches
|
34
|
+
class TestPlotMatches < Test::Unit::TestCase
|
35
|
+
def setup
|
36
|
+
omit('gnuplot not found') unless BioDSL::Filesys.which('gnuplot')
|
37
|
+
|
38
|
+
@tmpdir = Dir.mktmpdir('BioDSL')
|
39
|
+
@file = File.join(@tmpdir, 'test.plot')
|
40
|
+
|
41
|
+
@input, @output = BioDSL::Stream.pipe
|
42
|
+
@input2, @output2 = BioDSL::Stream.pipe
|
43
|
+
|
44
|
+
setup_data
|
45
|
+
setup_expected
|
46
|
+
|
47
|
+
@p = BioDSL::Pipeline.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def setup_data
|
51
|
+
@output.write(Q_BEG: 0, S_BEG: 0, Q_END: 10, S_END: 10, STRAND: '+')
|
52
|
+
@output.write(Q_BEG: 0, S_BEG: 0, Q_END: 10, S_END: 10, STRAND: '-')
|
53
|
+
@output.write(Q_BEG: 3, S_BEG: 3, Q_END: 6, S_END: 6, DIRECTION: 'forward')
|
54
|
+
@output.write(Q_BEG: 3, S_BEG: 3, Q_END: 6, S_END: 6, DIRECTION: 'reverse')
|
55
|
+
@output.close
|
56
|
+
end
|
57
|
+
|
58
|
+
# rubocop:disable MethodLength
|
59
|
+
def setup_expected
|
60
|
+
@expected = <<-EOF.gsub(/^\s+\|/, '').delete("\n")
|
61
|
+
|set terminal dumb
|
62
|
+
|set title "Matches"
|
63
|
+
|set xlabel "x"
|
64
|
+
|set ylabel "y"
|
65
|
+
|set autoscale xfix
|
66
|
+
|set autoscale yfix
|
67
|
+
|set style fill solid 0.5 border
|
68
|
+
|set style line 1 linetype 1 linecolor rgb "green" linewidth 2 pointtype
|
69
|
+
| 6 pointsize default
|
70
|
+
|set style line 2 linetype 1 linecolor rgb "red" linewidth 2 pointtype
|
71
|
+
| 6 pointsize default
|
72
|
+
|set xtics border out
|
73
|
+
|set ytics border out
|
74
|
+
|set grid
|
75
|
+
|set nokey
|
76
|
+
|set output ""
|
77
|
+
|plot "-" using 1:2:3:4 with vectors nohead ls 1, "-" using 1:2:3:4 with
|
78
|
+
| vectors nohead ls 2
|
79
|
+
|0 0 10 10
|
80
|
+
|3 3 3 3
|
81
|
+
|e
|
82
|
+
|10 0 -10 10
|
83
|
+
|6 3 -3 3
|
84
|
+
|e
|
85
|
+
EOF
|
86
|
+
end
|
87
|
+
|
88
|
+
def teardown
|
89
|
+
FileUtils.rm_r @tmpdir
|
90
|
+
end
|
91
|
+
|
92
|
+
test 'BioDSL::Pipeline::PlotMatches with invalid options raises' do
|
93
|
+
assert_raise(BioDSL::OptionError) { @p.plot_matches(foo: 'bar') }
|
94
|
+
end
|
95
|
+
|
96
|
+
test 'BioDSL::Pipeline::PlotMatches with invalid terminal raises' do
|
97
|
+
assert_raise(BioDSL::OptionError) { @p.plot_matches(terminal: 'foo') }
|
98
|
+
end
|
99
|
+
|
100
|
+
test 'BioDSL::Pipeline::PlotMatches with valid terminal don\'t raise' do
|
101
|
+
%w(dumb post svg x11 aqua png pdf).each do |terminal|
|
102
|
+
assert_nothing_raised { @p.plot_matches(terminal: terminal.to_sym) }
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
test 'BioDSL::Pipeline::PlotMatches to file outputs correctly' do
|
107
|
+
result = capture_stderr do
|
108
|
+
@p.plot_matches(output: @file, test: true).
|
109
|
+
run(input: @input, output: @output2)
|
110
|
+
end
|
111
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
112
|
+
assert_equal(@expected, result.delete("\n"))
|
113
|
+
end
|
114
|
+
|
115
|
+
test 'BioDSL::Pipeline::PlotMatches to existing file raises' do
|
116
|
+
`touch #{@file}`
|
117
|
+
assert_raise(BioDSL::OptionError) { @p.plot_matches(output: @file) }
|
118
|
+
end
|
119
|
+
|
120
|
+
test 'BioDSL::Pipeline::PlotMatches to existing file with :force ' \
|
121
|
+
'outputs correctly' do
|
122
|
+
`touch #{@file}`
|
123
|
+
result = capture_stderr do
|
124
|
+
@p.plot_matches(output: @file, force: true, test: true).run(input: @input)
|
125
|
+
end
|
126
|
+
|
127
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
128
|
+
assert_equal(@expected, result.delete("\n"))
|
129
|
+
end
|
130
|
+
|
131
|
+
test 'BioDSL::Pipeline::PlotMatches with flux outputs correctly' do
|
132
|
+
result = capture_stderr do
|
133
|
+
@p.plot_matches(output: @file, force: true, test: true).
|
134
|
+
run(input: @input, output: @output2)
|
135
|
+
end
|
136
|
+
result.sub!(/set output "[^"]+"/, 'set output ""')
|
137
|
+
|
138
|
+
assert_equal(@expected, result.delete("\n"))
|
139
|
+
|
140
|
+
expected = <<-EXP.gsub(/^\s+\|/, '')
|
141
|
+
|{:Q_BEG=>0, :S_BEG=>0, :Q_END=>10, :S_END=>10, :STRAND=>"+"}
|
142
|
+
|{:Q_BEG=>0, :S_BEG=>0, :Q_END=>10, :S_END=>10, :STRAND=>"-"}
|
143
|
+
|{:Q_BEG=>3, :S_BEG=>3, :Q_END=>6, :S_END=>6, :DIRECTION=>"forward"}
|
144
|
+
|{:Q_BEG=>3, :S_BEG=>3, :Q_END=>6, :S_END=>6, :DIRECTION=>"reverse"}
|
145
|
+
EXP
|
146
|
+
assert_equal(expected, collect_result)
|
147
|
+
end
|
148
|
+
|
149
|
+
test 'BioDSL::Pipeline::PlotMatches status outputs correctly' do
|
150
|
+
@p.plot_matches(output: @file, force: true).
|
151
|
+
run(input: @input, output: @output2)
|
152
|
+
|
153
|
+
assert_equal(4, @p.status.first[:records_in])
|
154
|
+
assert_equal(4, @p.status.first[:records_out])
|
155
|
+
assert_equal(4, @p.status.first[:matches_in])
|
156
|
+
end
|
157
|
+
end
|