BioDSL 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (197) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/BioDSL.gemspec +64 -0
  4. data/LICENSE +339 -0
  5. data/README.md +205 -0
  6. data/Rakefile +94 -0
  7. data/examples/fastq_to_fasta.rb +8 -0
  8. data/lib/BioDSL/cary.rb +242 -0
  9. data/lib/BioDSL/command.rb +133 -0
  10. data/lib/BioDSL/commands/add_key.rb +110 -0
  11. data/lib/BioDSL/commands/align_seq_mothur.rb +194 -0
  12. data/lib/BioDSL/commands/analyze_residue_distribution.rb +222 -0
  13. data/lib/BioDSL/commands/assemble_pairs.rb +336 -0
  14. data/lib/BioDSL/commands/assemble_seq_idba.rb +230 -0
  15. data/lib/BioDSL/commands/assemble_seq_ray.rb +345 -0
  16. data/lib/BioDSL/commands/assemble_seq_spades.rb +252 -0
  17. data/lib/BioDSL/commands/classify_seq.rb +217 -0
  18. data/lib/BioDSL/commands/classify_seq_mothur.rb +226 -0
  19. data/lib/BioDSL/commands/clip_primer.rb +318 -0
  20. data/lib/BioDSL/commands/cluster_otus.rb +181 -0
  21. data/lib/BioDSL/commands/collapse_otus.rb +170 -0
  22. data/lib/BioDSL/commands/collect_otus.rb +150 -0
  23. data/lib/BioDSL/commands/complement_seq.rb +117 -0
  24. data/lib/BioDSL/commands/count.rb +135 -0
  25. data/lib/BioDSL/commands/count_values.rb +149 -0
  26. data/lib/BioDSL/commands/degap_seq.rb +253 -0
  27. data/lib/BioDSL/commands/dereplicate_seq.rb +168 -0
  28. data/lib/BioDSL/commands/dump.rb +157 -0
  29. data/lib/BioDSL/commands/filter_rrna.rb +239 -0
  30. data/lib/BioDSL/commands/genecall.rb +237 -0
  31. data/lib/BioDSL/commands/grab.rb +535 -0
  32. data/lib/BioDSL/commands/index_taxonomy.rb +226 -0
  33. data/lib/BioDSL/commands/mask_seq.rb +175 -0
  34. data/lib/BioDSL/commands/mean_scores.rb +168 -0
  35. data/lib/BioDSL/commands/merge_pair_seq.rb +175 -0
  36. data/lib/BioDSL/commands/merge_table.rb +225 -0
  37. data/lib/BioDSL/commands/merge_values.rb +113 -0
  38. data/lib/BioDSL/commands/plot_heatmap.rb +233 -0
  39. data/lib/BioDSL/commands/plot_histogram.rb +306 -0
  40. data/lib/BioDSL/commands/plot_matches.rb +282 -0
  41. data/lib/BioDSL/commands/plot_residue_distribution.rb +278 -0
  42. data/lib/BioDSL/commands/plot_scores.rb +285 -0
  43. data/lib/BioDSL/commands/random.rb +153 -0
  44. data/lib/BioDSL/commands/read_fasta.rb +222 -0
  45. data/lib/BioDSL/commands/read_fastq.rb +414 -0
  46. data/lib/BioDSL/commands/read_table.rb +329 -0
  47. data/lib/BioDSL/commands/reverse_seq.rb +113 -0
  48. data/lib/BioDSL/commands/slice_align.rb +400 -0
  49. data/lib/BioDSL/commands/slice_seq.rb +151 -0
  50. data/lib/BioDSL/commands/sort.rb +223 -0
  51. data/lib/BioDSL/commands/split_pair_seq.rb +220 -0
  52. data/lib/BioDSL/commands/split_values.rb +165 -0
  53. data/lib/BioDSL/commands/trim_primer.rb +314 -0
  54. data/lib/BioDSL/commands/trim_seq.rb +192 -0
  55. data/lib/BioDSL/commands/uchime_ref.rb +170 -0
  56. data/lib/BioDSL/commands/uclust.rb +286 -0
  57. data/lib/BioDSL/commands/unique_values.rb +145 -0
  58. data/lib/BioDSL/commands/usearch_global.rb +171 -0
  59. data/lib/BioDSL/commands/usearch_local.rb +171 -0
  60. data/lib/BioDSL/commands/write_fasta.rb +207 -0
  61. data/lib/BioDSL/commands/write_fastq.rb +191 -0
  62. data/lib/BioDSL/commands/write_table.rb +419 -0
  63. data/lib/BioDSL/commands/write_tree.rb +167 -0
  64. data/lib/BioDSL/commands.rb +31 -0
  65. data/lib/BioDSL/config.rb +55 -0
  66. data/lib/BioDSL/csv.rb +307 -0
  67. data/lib/BioDSL/debug.rb +42 -0
  68. data/lib/BioDSL/fasta.rb +133 -0
  69. data/lib/BioDSL/fastq.rb +77 -0
  70. data/lib/BioDSL/filesys.rb +137 -0
  71. data/lib/BioDSL/fork.rb +145 -0
  72. data/lib/BioDSL/hamming.rb +128 -0
  73. data/lib/BioDSL/helpers/aux_helper.rb +44 -0
  74. data/lib/BioDSL/helpers/email_helper.rb +66 -0
  75. data/lib/BioDSL/helpers/history_helper.rb +40 -0
  76. data/lib/BioDSL/helpers/log_helper.rb +55 -0
  77. data/lib/BioDSL/helpers/options_helper.rb +405 -0
  78. data/lib/BioDSL/helpers/status_helper.rb +132 -0
  79. data/lib/BioDSL/helpers.rb +35 -0
  80. data/lib/BioDSL/html_report.rb +200 -0
  81. data/lib/BioDSL/math.rb +55 -0
  82. data/lib/BioDSL/mummer.rb +216 -0
  83. data/lib/BioDSL/pipeline.rb +354 -0
  84. data/lib/BioDSL/seq/ambiguity.rb +66 -0
  85. data/lib/BioDSL/seq/assemble.rb +240 -0
  86. data/lib/BioDSL/seq/backtrack.rb +252 -0
  87. data/lib/BioDSL/seq/digest.rb +99 -0
  88. data/lib/BioDSL/seq/dynamic.rb +263 -0
  89. data/lib/BioDSL/seq/homopolymer.rb +59 -0
  90. data/lib/BioDSL/seq/kmer.rb +293 -0
  91. data/lib/BioDSL/seq/levenshtein.rb +113 -0
  92. data/lib/BioDSL/seq/translate.rb +109 -0
  93. data/lib/BioDSL/seq/trim.rb +188 -0
  94. data/lib/BioDSL/seq.rb +742 -0
  95. data/lib/BioDSL/serializer.rb +98 -0
  96. data/lib/BioDSL/stream.rb +113 -0
  97. data/lib/BioDSL/taxonomy.rb +691 -0
  98. data/lib/BioDSL/test.rb +42 -0
  99. data/lib/BioDSL/tmp_dir.rb +68 -0
  100. data/lib/BioDSL/usearch.rb +301 -0
  101. data/lib/BioDSL/verbose.rb +42 -0
  102. data/lib/BioDSL/version.rb +31 -0
  103. data/lib/BioDSL.rb +81 -0
  104. data/test/BioDSL/commands/test_add_key.rb +105 -0
  105. data/test/BioDSL/commands/test_align_seq_mothur.rb +99 -0
  106. data/test/BioDSL/commands/test_analyze_residue_distribution.rb +134 -0
  107. data/test/BioDSL/commands/test_assemble_pairs.rb +459 -0
  108. data/test/BioDSL/commands/test_assemble_seq_idba.rb +50 -0
  109. data/test/BioDSL/commands/test_assemble_seq_ray.rb +51 -0
  110. data/test/BioDSL/commands/test_assemble_seq_spades.rb +50 -0
  111. data/test/BioDSL/commands/test_classify_seq.rb +50 -0
  112. data/test/BioDSL/commands/test_classify_seq_mothur.rb +59 -0
  113. data/test/BioDSL/commands/test_clip_primer.rb +377 -0
  114. data/test/BioDSL/commands/test_cluster_otus.rb +128 -0
  115. data/test/BioDSL/commands/test_collapse_otus.rb +81 -0
  116. data/test/BioDSL/commands/test_collect_otus.rb +82 -0
  117. data/test/BioDSL/commands/test_complement_seq.rb +78 -0
  118. data/test/BioDSL/commands/test_count.rb +103 -0
  119. data/test/BioDSL/commands/test_count_values.rb +85 -0
  120. data/test/BioDSL/commands/test_degap_seq.rb +96 -0
  121. data/test/BioDSL/commands/test_dereplicate_seq.rb +92 -0
  122. data/test/BioDSL/commands/test_dump.rb +109 -0
  123. data/test/BioDSL/commands/test_filter_rrna.rb +128 -0
  124. data/test/BioDSL/commands/test_genecall.rb +50 -0
  125. data/test/BioDSL/commands/test_grab.rb +398 -0
  126. data/test/BioDSL/commands/test_index_taxonomy.rb +62 -0
  127. data/test/BioDSL/commands/test_mask_seq.rb +98 -0
  128. data/test/BioDSL/commands/test_mean_scores.rb +111 -0
  129. data/test/BioDSL/commands/test_merge_pair_seq.rb +115 -0
  130. data/test/BioDSL/commands/test_merge_table.rb +131 -0
  131. data/test/BioDSL/commands/test_merge_values.rb +83 -0
  132. data/test/BioDSL/commands/test_plot_heatmap.rb +185 -0
  133. data/test/BioDSL/commands/test_plot_histogram.rb +194 -0
  134. data/test/BioDSL/commands/test_plot_matches.rb +157 -0
  135. data/test/BioDSL/commands/test_plot_residue_distribution.rb +309 -0
  136. data/test/BioDSL/commands/test_plot_scores.rb +308 -0
  137. data/test/BioDSL/commands/test_random.rb +88 -0
  138. data/test/BioDSL/commands/test_read_fasta.rb +229 -0
  139. data/test/BioDSL/commands/test_read_fastq.rb +552 -0
  140. data/test/BioDSL/commands/test_read_table.rb +327 -0
  141. data/test/BioDSL/commands/test_reverse_seq.rb +79 -0
  142. data/test/BioDSL/commands/test_slice_align.rb +218 -0
  143. data/test/BioDSL/commands/test_slice_seq.rb +131 -0
  144. data/test/BioDSL/commands/test_sort.rb +128 -0
  145. data/test/BioDSL/commands/test_split_pair_seq.rb +164 -0
  146. data/test/BioDSL/commands/test_split_values.rb +95 -0
  147. data/test/BioDSL/commands/test_trim_primer.rb +329 -0
  148. data/test/BioDSL/commands/test_trim_seq.rb +150 -0
  149. data/test/BioDSL/commands/test_uchime_ref.rb +113 -0
  150. data/test/BioDSL/commands/test_uclust.rb +139 -0
  151. data/test/BioDSL/commands/test_unique_values.rb +98 -0
  152. data/test/BioDSL/commands/test_usearch_global.rb +123 -0
  153. data/test/BioDSL/commands/test_usearch_local.rb +125 -0
  154. data/test/BioDSL/commands/test_write_fasta.rb +159 -0
  155. data/test/BioDSL/commands/test_write_fastq.rb +166 -0
  156. data/test/BioDSL/commands/test_write_table.rb +411 -0
  157. data/test/BioDSL/commands/test_write_tree.rb +122 -0
  158. data/test/BioDSL/helpers/test_options_helper.rb +272 -0
  159. data/test/BioDSL/seq/test_assemble.rb +98 -0
  160. data/test/BioDSL/seq/test_backtrack.rb +176 -0
  161. data/test/BioDSL/seq/test_digest.rb +71 -0
  162. data/test/BioDSL/seq/test_dynamic.rb +133 -0
  163. data/test/BioDSL/seq/test_homopolymer.rb +58 -0
  164. data/test/BioDSL/seq/test_kmer.rb +134 -0
  165. data/test/BioDSL/seq/test_translate.rb +75 -0
  166. data/test/BioDSL/seq/test_trim.rb +101 -0
  167. data/test/BioDSL/test_cary.rb +176 -0
  168. data/test/BioDSL/test_command.rb +45 -0
  169. data/test/BioDSL/test_csv.rb +514 -0
  170. data/test/BioDSL/test_debug.rb +42 -0
  171. data/test/BioDSL/test_fasta.rb +154 -0
  172. data/test/BioDSL/test_fastq.rb +46 -0
  173. data/test/BioDSL/test_filesys.rb +145 -0
  174. data/test/BioDSL/test_fork.rb +85 -0
  175. data/test/BioDSL/test_math.rb +41 -0
  176. data/test/BioDSL/test_mummer.rb +79 -0
  177. data/test/BioDSL/test_pipeline.rb +187 -0
  178. data/test/BioDSL/test_seq.rb +790 -0
  179. data/test/BioDSL/test_serializer.rb +72 -0
  180. data/test/BioDSL/test_stream.rb +55 -0
  181. data/test/BioDSL/test_taxonomy.rb +336 -0
  182. data/test/BioDSL/test_test.rb +42 -0
  183. data/test/BioDSL/test_tmp_dir.rb +58 -0
  184. data/test/BioDSL/test_usearch.rb +33 -0
  185. data/test/BioDSL/test_verbose.rb +42 -0
  186. data/test/helper.rb +82 -0
  187. data/www/command.html.haml +14 -0
  188. data/www/css.html.haml +55 -0
  189. data/www/input_files.html.haml +3 -0
  190. data/www/layout.html.haml +12 -0
  191. data/www/output_files.html.haml +3 -0
  192. data/www/overview.html.haml +15 -0
  193. data/www/pipeline.html.haml +4 -0
  194. data/www/png.html.haml +2 -0
  195. data/www/status.html.haml +9 -0
  196. data/www/time.html.haml +11 -0
  197. metadata +503 -0
@@ -0,0 +1,309 @@
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 PlotResidueDistribution.
34
+ #
35
+ # rubocop: disable ClassLength
36
+ class TestPlotResidueDistribution < 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
+ [{SEQ: 'AN'},
55
+ {SEQ: 'T'},
56
+ {SEQ: 'C'},
57
+ {SEQ: 'G'},
58
+ {FOO: 'BAR'}].each do |record|
59
+ @output.write(record)
60
+ end
61
+
62
+ @output.close
63
+ end
64
+
65
+ # rubocop: disable MethodLength
66
+ def setup_expected1
67
+ @expected1 = <<-EOF.gsub(/^\s+\|/, '').delete("\n")
68
+ |set terminal dumb
69
+ |set title \"Residue Distribution\"
70
+ |set xlabel \"Sequence position\"
71
+ |set ylabel \"%\"
72
+ |set output \"\"
73
+ |set xtics out
74
+ |set ytics out
75
+ |set yrange [0:100]
76
+ |set xrange [0:2]
77
+ |set auto fix
78
+ |set offsets \"1\"
79
+ |set key outside right top vertical Left reverse noenhanced autotitles
80
+ | columnhead nobox
81
+ |set key invert samplen 4 spacing 1 width 0 height 0
82
+ |set style fill solid 0.5 border
83
+ |set style histogram rowstacked
84
+ |set style data histograms
85
+ |set boxwidth 0.75 absolute
86
+ |set linetype 1 lc rgb \"#FF0010\"
87
+ |set linetype 2 lc rgb \"#191919\"
88
+ |set linetype 3 lc rgb \"#0075DC\"
89
+ |set linetype 4 lc rgb \"#2BCE48\"
90
+ |set linetype 5 lc rgb \"#FFFF00\"
91
+ |set linetype 6 lc rgb \"#4C005C\"
92
+ |set linetype 7 lc rgb \"#993F00\"
93
+ |set linetype 8 lc rgb \"#FFCC99\"
94
+ |set linetype 9 lc rgb \"#808080\"
95
+ |set linetype 10 lc rgb \"#94FFB5\"
96
+ |set linetype 11 lc rgb \"#8F7C00\"
97
+ |set linetype 12 lc rgb \"#9DCC00\"
98
+ |set linetype 13 lc rgb \"#C20088\"
99
+ |set linetype 14 lc rgb \"#003380\"
100
+ |set linetype 15 lc rgb \"#FFA405\"
101
+ |set linetype 16 lc rgb \"#FFA8BB\"
102
+ |set linetype 17 lc rgb \"#426600\"
103
+ |set linetype 18 lc rgb \"#F0A3FF\"
104
+ |set linetype 19 lc rgb \"#5EF1F2\"
105
+ |set linetype 20 lc rgb \"#00998F\"
106
+ |set linetype 21 lc rgb \"#E0FF66\"
107
+ |set linetype 22 lc rgb \"#740AFF\"
108
+ |set linetype 23 lc rgb \"#990000\"
109
+ |set linetype 24 lc rgb \"#FFFF80\"
110
+ |set linetype 25 lc rgb \"#005C31\"
111
+ |set linetype 26 lc rgb \"#FF5005\"
112
+ |set linetype cycle 26
113
+ |plot \"-\" using 1 with histogram lt 1 title \"T\", \"-\" using 1 with
114
+ | histogram lt 2 title \"N\", \"-\" using 1 with histogram lt 3
115
+ | title \"G\", \"-\" using 1 with histogram lt 4
116
+ | title \"C\", \"-\" using 1 with histogram lt 5
117
+ | title \"A\"
118
+ |0.0
119
+ |25.0
120
+ |0.0
121
+ |e
122
+ |0.0
123
+ |0.0
124
+ |100.0
125
+ |e
126
+ |0.0
127
+ |25.0
128
+ |0.0
129
+ |e
130
+ |0.0
131
+ |25.0
132
+ |0.0
133
+ |e
134
+ |0.0
135
+ |25.0
136
+ |0.0
137
+ |e
138
+ EOF
139
+ end
140
+
141
+ def setup_expected2
142
+ @expected2 = <<-EOF.gsub(/^\s+\|/, '').delete("\n")
143
+ |set terminal dumb
144
+ |set title \"Residue Distribution\"
145
+ |set xlabel \"Sequence position\"
146
+ |set ylabel \"%\"
147
+ |set output \"\"
148
+ |set xtics out
149
+ |set ytics out
150
+ |set yrange [0:100]
151
+ |set xrange [0:2]
152
+ |set auto fix
153
+ |set offsets \"1\"
154
+ |set key outside right top vertical Left reverse noenhanced autotitles
155
+ | columnhead nobox
156
+ |set key invert samplen 4 spacing 1 width 0 height 0
157
+ |set style fill solid 0.5 border
158
+ |set style histogram rowstacked
159
+ |set style data histograms
160
+ |set boxwidth 0.75 absolute
161
+ |set linetype 1 lc rgb \"#FF0010\"
162
+ |set linetype 2 lc rgb \"#191919\"
163
+ |set linetype 3 lc rgb \"#0075DC\"
164
+ |set linetype 4 lc rgb \"#2BCE48\"
165
+ |set linetype 5 lc rgb \"#FFFF00\"
166
+ |set linetype 6 lc rgb \"#4C005C\"
167
+ |set linetype 7 lc rgb \"#993F00\"
168
+ |set linetype 8 lc rgb \"#FFCC99\"
169
+ |set linetype 9 lc rgb \"#808080\"
170
+ |set linetype 10 lc rgb \"#94FFB5\"
171
+ |set linetype 11 lc rgb \"#8F7C00\"
172
+ |set linetype 12 lc rgb \"#9DCC00\"
173
+ |set linetype 13 lc rgb \"#C20088\"
174
+ |set linetype 14 lc rgb \"#003380\"
175
+ |set linetype 15 lc rgb \"#FFA405\"
176
+ |set linetype 16 lc rgb \"#FFA8BB\"
177
+ |set linetype 17 lc rgb \"#426600\"
178
+ |set linetype 18 lc rgb \"#F0A3FF\"
179
+ |set linetype 19 lc rgb \"#5EF1F2\"
180
+ |set linetype 20 lc rgb \"#00998F\"
181
+ |set linetype 21 lc rgb \"#E0FF66\"
182
+ |set linetype 22 lc rgb \"#740AFF\"
183
+ |set linetype 23 lc rgb \"#990000\"
184
+ |set linetype 24 lc rgb \"#FFFF80\"
185
+ |set linetype 25 lc rgb \"#005C31\"
186
+ |set linetype 26 lc rgb \"#FF5005\"
187
+ |set linetype cycle 26
188
+ |plot \"-\" using 1 with histogram lt 1 title \"T\", \"-\" using 1 with
189
+ | histogram lt 2 title \"N\", \"-\" using 1 with histogram lt 3
190
+ | title \"G\", \"-\" using 1 with histogram lt 4
191
+ | title \"C\", \"-\" using 1 with histogram lt 5
192
+ | title \"A\", \"-\" using 1:2 with lines lw 2 lt
193
+ | rgb \"black\" title \"count\"
194
+ |0.0
195
+ |25.0
196
+ |0.0
197
+ |e
198
+ |0.0
199
+ |0.0
200
+ |100.0
201
+ |e
202
+ |0.0
203
+ |25.0
204
+ |0.0
205
+ |e
206
+ |0.0
207
+ |25.0
208
+ |0.0
209
+ |e
210
+ |0.0
211
+ |25.0
212
+ |0.0
213
+ |e
214
+ |0 0.0
215
+ |0 100.0
216
+ |1 25.0
217
+ |e
218
+ EOF
219
+ end
220
+
221
+ # rubocop: enable MethodLength
222
+ def teardown
223
+ FileUtils.rm_r @tmpdir
224
+ end
225
+
226
+ test 'BioDSL::Pipeline::PlotResidueDistribution with invalid options ' \
227
+ 'raises' do
228
+ assert_raise(BioDSL::OptionError) do
229
+ @p.plot_residue_distribution(foo: 'bar')
230
+ end
231
+ end
232
+
233
+ test 'BioDSL::Pipeline::PlotResidueDistribution with invalid terminal ' \
234
+ 'raises' do
235
+ assert_raise(BioDSL::OptionError) do
236
+ @p.plot_residue_distribution(terminal: 'foo')
237
+ end
238
+ end
239
+
240
+ test 'BioDSL::Pipeline::PlotResidueDistribution with valid terminal ' \
241
+ 'don\'t raise' do
242
+ %w(dumb post svg x11 aqua png pdf).each do |terminal|
243
+ assert_nothing_raised do
244
+ @p.plot_residue_distribution(terminal: terminal.to_sym)
245
+ end
246
+ end
247
+ end
248
+
249
+ test 'BioDSL::Pipeline::PlotResidueDistribution to file outputs OK' do
250
+ result = capture_stderr do
251
+ @p.plot_residue_distribution(output: @file, test: true).
252
+ run(input: @input, output: @output2)
253
+ end
254
+ result.sub!(/set output "[^"]+"/, 'set output ""')
255
+ assert_equal(@expected1, result.delete("\n"))
256
+ end
257
+
258
+ test 'BioDSL::Pipeline::PlotResidueDistribution to file with :count ' \
259
+ 'outputs correctly' do
260
+ result = capture_stderr do
261
+ @p.plot_residue_distribution(output: @file, count: true, test: true).
262
+ run(input: @input, output: @output2)
263
+ end
264
+ result.sub!(/set output "[^"]+"/, 'set output ""')
265
+ assert_equal(@expected2, result.delete("\n"))
266
+ end
267
+
268
+ test 'BioDSL::Pipeline::PlotResidueDistribution to existing file raises' do
269
+ `touch #{@file}`
270
+ assert_raise(BioDSL::OptionError) do
271
+ @p.plot_residue_distribution(output: @file)
272
+ end
273
+ end
274
+
275
+ test 'BioDSL::Pipeline::PlotResidueDistribution to existing file with ' \
276
+ ':force outputs correctly' do
277
+ `touch #{@file}`
278
+ result = capture_stderr do
279
+ @p.plot_residue_distribution(output: @file, force: true, test: true).
280
+ run(input: @input)
281
+ end
282
+ result.sub!(/set output "[^"]+"/, 'set output ""')
283
+ assert_equal(@expected1, result.delete("\n"))
284
+ end
285
+
286
+ test 'BioDSL::Pipeline::PlotResidueDistribution with flux outputs OK' do
287
+ result = capture_stderr do
288
+ @p.plot_residue_distribution(output: @file, force: true, test: true).
289
+ run(input: @input, output: @output2)
290
+ end
291
+ result.sub!(/set output "[^"]+"/, 'set output ""')
292
+ assert_equal(@expected1, result.delete("\n"))
293
+
294
+ expected = '{:SEQ=>"AN"}{:SEQ=>"T"}{:SEQ=>"C"}{:SEQ=>"G"}{:FOO=>"BAR"}'
295
+ assert_equal(expected, collect_result.delete("\n"))
296
+ end
297
+
298
+ test 'BioDSL::Pipeline::PlotResidueDistribution status outputs OK' do
299
+ @p.plot_residue_distribution(output: @file, force: true).
300
+ run(input: @input, output: @output2)
301
+
302
+ assert_equal(5, @p.status.first[:records_in])
303
+ assert_equal(5, @p.status.first[:records_out])
304
+ assert_equal(4, @p.status.first[:sequences_in])
305
+ assert_equal(4, @p.status.first[:sequences_out])
306
+ assert_equal(5, @p.status.first[:residues_in])
307
+ assert_equal(5, @p.status.first[:residues_out])
308
+ end
309
+ end
@@ -0,0 +1,308 @@
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 PlotScores.
34
+ #
35
+ # rubocop: disable ClassLength
36
+ class TestPlotScores < 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(SCORES: %q(!"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI))
55
+ @output.write(SCORES: %q("#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI))
56
+ @output.write(SCORES: %(#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI))
57
+ @output.write(SCORES: %($%&'()*+,-./0123456789:;<=>?@ABCDEFGHI))
58
+ @output.write(SCORES: %(%&'()*+,-./0123456789:;<=>?@ABCDEFGHI))
59
+ @output.write(SCORES: %(&'()*+,-./0123456789:;<=>?@ABCDEFGHI))
60
+ @output.close
61
+ end
62
+
63
+ # rubocop: disable MethodLength
64
+ def setup_expected1
65
+ @expected = <<-EOF.gsub(/^\s+\|/, '')
66
+ |set terminal dumb
67
+ |set title "Mean Quality Scores"
68
+ |set xlabel "Sequence Position"
69
+ |set ylabel "Mean Score"
70
+ |set output ""
71
+ |set xrange [0:42]
72
+ |set yrange [0:40]
73
+ |set style fill solid 0.5 border
74
+ |set xtics out
75
+ |set ytics out
76
+ |plot "-" with boxes lc rgb "red" title "mean score"
77
+ |1 2.5
78
+ |2 3.5
79
+ |3 4.5
80
+ |4 5.5
81
+ |5 6.5
82
+ |6 7.5
83
+ |7 8.5
84
+ |8 9.5
85
+ |9 10.5
86
+ |10 11.5
87
+ |11 12.5
88
+ |12 13.5
89
+ |13 14.5
90
+ |14 15.5
91
+ |15 16.5
92
+ |16 17.5
93
+ |17 18.5
94
+ |18 19.5
95
+ |19 20.5
96
+ |20 21.5
97
+ |21 22.5
98
+ |22 23.5
99
+ |23 24.5
100
+ |24 25.5
101
+ |25 26.5
102
+ |26 27.5
103
+ |27 28.5
104
+ |28 29.5
105
+ |29 30.5
106
+ |30 31.5
107
+ |31 32.5
108
+ |32 33.5
109
+ |33 34.5
110
+ |34 35.5
111
+ |35 36.5
112
+ |36 37.5
113
+ |37 38.0
114
+ |38 38.5
115
+ |39 39.0
116
+ |40 39.5
117
+ |41 40.0
118
+ |e
119
+ EOF
120
+ end
121
+
122
+ # rubocop: disable LineLength
123
+ def setup_expected2
124
+ @expected2 = <<-EOF.gsub(/^\s+\|/, '')
125
+ |set terminal dumb
126
+ |set title \"Mean Quality Scores\"
127
+ |set xlabel \"Sequence Position\"
128
+ |set ylabel \"Mean Score\"
129
+ |set output \"\"
130
+ |set xrange [0:42]
131
+ |set yrange [0:40]
132
+ |set style fill solid 0.5 border
133
+ |set xtics out
134
+ |set ytics out
135
+ |plot \"-\" with boxes lc rgb \"red\" title \"mean score\", \"-\" with lines lt rgb \"black\" title \"relative count\"
136
+ |1 2.5
137
+ |2 3.5
138
+ |3 4.5
139
+ |4 5.5
140
+ |5 6.5
141
+ |6 7.5
142
+ |7 8.5
143
+ |8 9.5
144
+ |9 10.5
145
+ |10 11.5
146
+ |11 12.5
147
+ |12 13.5
148
+ |13 14.5
149
+ |14 15.5
150
+ |15 16.5
151
+ |16 17.5
152
+ |17 18.5
153
+ |18 19.5
154
+ |19 20.5
155
+ |20 21.5
156
+ |21 22.5
157
+ |22 23.5
158
+ |23 24.5
159
+ |24 25.5
160
+ |25 26.5
161
+ |26 27.5
162
+ |27 28.5
163
+ |28 29.5
164
+ |29 30.5
165
+ |30 31.5
166
+ |31 32.5
167
+ |32 33.5
168
+ |33 34.5
169
+ |34 35.5
170
+ |35 36.5
171
+ |36 37.5
172
+ |37 38.0
173
+ |38 38.5
174
+ |39 39.0
175
+ |40 39.5
176
+ |41 40.0
177
+ |e
178
+ |1 40.0
179
+ |2 40.0
180
+ |3 40.0
181
+ |4 40.0
182
+ |5 40.0
183
+ |6 40.0
184
+ |7 40.0
185
+ |8 40.0
186
+ |9 40.0
187
+ |10 40.0
188
+ |11 40.0
189
+ |12 40.0
190
+ |13 40.0
191
+ |14 40.0
192
+ |15 40.0
193
+ |16 40.0
194
+ |17 40.0
195
+ |18 40.0
196
+ |19 40.0
197
+ |20 40.0
198
+ |21 40.0
199
+ |22 40.0
200
+ |23 40.0
201
+ |24 40.0
202
+ |25 40.0
203
+ |26 40.0
204
+ |27 40.0
205
+ |28 40.0
206
+ |29 40.0
207
+ |30 40.0
208
+ |31 40.0
209
+ |32 40.0
210
+ |33 40.0
211
+ |34 40.0
212
+ |35 40.0
213
+ |36 40.0
214
+ |37 33.33333206176758
215
+ |38 26.66666603088379
216
+ |39 20.0
217
+ |40 13.333333015441895
218
+ |41 6.666666507720947
219
+ |e
220
+ EOF
221
+ end
222
+
223
+ # rubocop: enable MethodLength
224
+ # rubocop: enable LineLength
225
+ def teardown
226
+ FileUtils.rm_r @tmpdir
227
+ end
228
+
229
+ test 'BioDSL::Pipeline::PlotScores with invalid options raises' do
230
+ assert_raise(BioDSL::OptionError) { @p.plot_scores(foo: 'bar') }
231
+ end
232
+
233
+ test 'BioDSL::Pipeline::PlotScores with invalid terminal raises' do
234
+ assert_raise(BioDSL::OptionError) { @p.plot_scores(terminal: 'foo') }
235
+ end
236
+
237
+ test 'BioDSL::Pipeline::PlotScores with valid terminal don\'t raise' do
238
+ %w(dumb post svg x11 aqua png pdf).each do |terminal|
239
+ assert_nothing_raised { @p.plot_scores(terminal: terminal.to_sym) }
240
+ end
241
+ end
242
+
243
+ test 'BioDSL::Pipeline::PlotScores to file outputs correctly' do
244
+ result = capture_stderr do
245
+ @p.plot_scores(output: @file, test: true).
246
+ run(input: @input, output: @output2)
247
+ end
248
+ result.sub!(/set output "[^"]+"/, 'set output ""')
249
+ assert_equal(@expected, result)
250
+ end
251
+
252
+ test 'BioDSL::Pipeline::PlotScores status outputs correctly' do
253
+ @p.plot_scores(output: @file).
254
+ run(input: @input, output: @output2)
255
+
256
+ assert_equal(6, @p.status.first[:records_in])
257
+ assert_equal(6, @p.status.first[:records_out])
258
+ assert_equal(0, @p.status.first[:sequences_in])
259
+ assert_equal(0, @p.status.first[:sequences_out])
260
+ assert_equal(0, @p.status.first[:residues_in])
261
+ assert_equal(0, @p.status.first[:residues_out])
262
+ end
263
+
264
+ test 'BioDSL::Pipeline::PlotScores to file with count: true outputs OK' do
265
+ result = capture_stderr do
266
+ @p.plot_scores(count: true, output: @file, test: true).
267
+ run(input: @input, output: @output2)
268
+ end
269
+ result.sub!(/set output "[^"]+"/, 'set output ""')
270
+ assert_equal(@expected2, result)
271
+ end
272
+
273
+ test 'BioDSL::Pipeline::PlotScores to existing file raises' do
274
+ `touch #{@file}`
275
+ assert_raise(BioDSL::OptionError) { @p.plot_scores(output: @file) }
276
+ end
277
+
278
+ test 'BioDSL::Pipeline::PlotScores to existing file with :force outputs ' \
279
+ 'correctly' do
280
+ `touch #{@file}`
281
+ result = capture_stderr do
282
+ @p.plot_scores(output: @file, force: true, test: true).run(input: @input)
283
+ end
284
+ result.sub!(/set output "[^"]+"/, 'set output ""')
285
+ assert_equal(@expected, result)
286
+ end
287
+
288
+ test 'BioDSL::Pipeline::PlotScores with flux outputs correctly' do
289
+ result = capture_stderr do
290
+ @p.plot_scores(output: @file, force: true, test: true).
291
+ run(input: @input, output: @output2)
292
+ end
293
+
294
+ result.sub!(/set output "[^"]+"/, 'set output ""')
295
+ assert_equal(@expected, result)
296
+
297
+ expected = <<-EXP.gsub(/^\s+\|/, '')
298
+ |{:SCORES=>"!\\"\\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI"}
299
+ |{:SCORES=>"\\"\\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI"}
300
+ |{:SCORES=>"\\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI"}
301
+ |{:SCORES=>"$%&'()*+,-./0123456789:;<=>?@ABCDEFGHI"}
302
+ |{:SCORES=>"%&'()*+,-./0123456789:;<=>?@ABCDEFGHI"}
303
+ |{:SCORES=>"&'()*+,-./0123456789:;<=>?@ABCDEFGHI"}
304
+ EXP
305
+
306
+ assert_equal(expected, collect_result)
307
+ end
308
+ end
@@ -0,0 +1,88 @@
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 Random.
34
+ class TestRandom < Test::Unit::TestCase
35
+ def setup
36
+ @input, @output = BioDSL::Stream.pipe
37
+ @input2, @output2 = BioDSL::Stream.pipe
38
+
39
+ [{TEST: 1},
40
+ {TEST: 2},
41
+ {TEST: 3},
42
+ {TEST: 4},
43
+ {TEST: 5},
44
+ {TEST: 6}].each do |record|
45
+ @output.write record
46
+ end
47
+
48
+ @output.close
49
+
50
+ @p = BioDSL::Pipeline.new
51
+ end
52
+
53
+ test 'BioDSL::Pipeline#random with disallowed option raises' do
54
+ assert_raise(BioDSL::OptionError) { @p.random(foo: 'bar') }
55
+ end
56
+
57
+ test 'BioDSL::Pipeline#random with allowed options don\'t raise' do
58
+ assert_nothing_raised { @p.random(number: 2) }
59
+ end
60
+
61
+ test 'BioDSL::Pipeline#random returns correctly' do
62
+ @p.random(number: 3).run(input: @input, output: @output2)
63
+ size = 0
64
+ @input2.map { size += 1 }
65
+
66
+ assert_equal(3, size)
67
+ end
68
+
69
+ test 'BioDSL::Pipeline#random status returns correctly' do
70
+ @p.random(number: 3).run(input: @input, output: @output2)
71
+
72
+ assert_equal(6, @p.status.first[:records_in])
73
+ assert_equal(3, @p.status.first[:records_out])
74
+ end
75
+
76
+ test 'BioDSL::Pipeline#random with pairs: true returns correctly' do
77
+ @p.random(number: 4, pairs: true).run(input: @input, output: @output2)
78
+
79
+ size = 0
80
+
81
+ @input2.each_slice(2) do |record1, record2|
82
+ assert_equal(record1[:TEST].to_i, record2[:TEST].to_i - 1)
83
+ size += 2
84
+ end
85
+
86
+ assert_equal(4, size)
87
+ end
88
+ end