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,122 @@
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 WriteTree.
34
+ class TestWriteTree < Test::Unit::TestCase
35
+ def setup
36
+ @tmpdir = Dir.mktmpdir('BioDSL')
37
+
38
+ omit('FastTree not found') unless BioDSL::Filesys.which('FastTree')
39
+
40
+ setup_data
41
+
42
+ @file = File.join(@tmpdir, 'test.tree')
43
+ @p = BioDSL::Pipeline.new
44
+ end
45
+
46
+ def setup_data
47
+ @input, @output = BioDSL::Stream.pipe
48
+ @input2, @output2 = BioDSL::Stream.pipe
49
+
50
+ @output.write(SEQ: 'attgactgacg--')
51
+ @output.write(SEQ: 'attgactaagacg')
52
+ @output.write(SEQ: 'a---actgacg--')
53
+ @output.write(SEQ: 'a---actaagacg')
54
+ @output.write(SEQ: 'a---actaagacg')
55
+ @output.write(FOO: 'BAR')
56
+ @output.close
57
+ end
58
+
59
+ def teardown
60
+ FileUtils.rm_r @tmpdir if @tmpdir
61
+ end
62
+
63
+ test 'BioDSL::Pipeline::WriteTree with invalid options raises' do
64
+ assert_raise(BioDSL::OptionError) { @p.write_tree(foo: 'bar') }
65
+ end
66
+
67
+ test 'BioDSL::Pipeline::WriteTree to stdout outputs correctly' do
68
+ result = capture_stdout { @p.write_tree.run(input: @input) }
69
+ expected = '(1:0.00055,(3:0.0,4:0.0):0.00054,' \
70
+ '(0:0.00055,2:0.00054)0.996:0.34079);'
71
+ assert_equal(expected, result.chomp)
72
+ end
73
+
74
+ test 'BioDSL::Pipeline::WriteTree to file outputs correctly' do
75
+ @p.write_tree(output: @file).run(input: @input, output: @output2)
76
+ result = File.read(@file)
77
+ expected = '(1:0.00055,(3:0.0,4:0.0):0.00054,' \
78
+ '(0:0.00055,2:0.00054)0.996:0.34079);'
79
+ assert_equal(expected, result.chomp)
80
+ end
81
+
82
+ test 'BioDSL::Pipeline::WriteTree to existing file raises' do
83
+ `touch #{@file}`
84
+ assert_raise(BioDSL::OptionError) { @p.write_tree(output: @file) }
85
+ end
86
+
87
+ test 'BioDSL::Pipeline::WriteTree to existing file w. :force outputs OK' do
88
+ `touch #{@file}`
89
+ @p.write_tree(output: @file, force: true).run(input: @input)
90
+ result = File.open(@file).read
91
+ expected = '(1:0.00055,(3:0.0,4:0.0):0.00054,' \
92
+ '(0:0.00055,2:0.00054)0.996:0.34079);'
93
+ assert_equal(expected, result.chomp)
94
+ end
95
+
96
+ test 'BioDSL::Pipeline::WriteTree with flux outputs correctly' do
97
+ @p.write_tree(output: @file).run(input: @input, output: @output2)
98
+ result = File.open(@file).read
99
+ expected = '(1:0.00055,(3:0.0,4:0.0):0.00054,' \
100
+ '(0:0.00055,2:0.00054)0.996:0.34079);'
101
+ assert_equal(expected, result.chomp)
102
+
103
+ expected = <<-EXP.gsub(/^\s+\|/, '')
104
+ |{:SEQ=>"attgactgacg--"}
105
+ |{:SEQ=>"attgactaagacg"}
106
+ |{:SEQ=>"a---actgacg--"}
107
+ |{:SEQ=>"a---actaagacg"}
108
+ |{:SEQ=>"a---actaagacg"}
109
+ |{:FOO=>"BAR"}
110
+ EXP
111
+
112
+ assert_equal(expected, collect_result)
113
+ end
114
+
115
+ test 'BioDSL::Pipeline::WriteTree status outputs correctly' do
116
+ @p.write_tree(output: @file).run(input: @input, output: @output2)
117
+ assert_equal(6, @p.status.first[:records_in])
118
+ assert_equal(6, @p.status.first[:records_out])
119
+ assert_equal(5, @p.status.first[:sequences_in])
120
+ assert_equal(65, @p.status.first[:residues_in])
121
+ end
122
+ end
@@ -0,0 +1,272 @@
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 OptionHelper.
34
+ # rubocop:disable Metrics/ClassLength,
35
+ class TestOptionsHelper < Test::Unit::TestCase
36
+ include BioDSL::OptionsHelper
37
+
38
+ def setup
39
+ @err = BioDSL::OptionError
40
+ end
41
+
42
+ test '#options_allowed with disallowed option raises' do
43
+ options = {bar: 'foo'}
44
+ assert_raise(@err) { options_allowed(options, :foo) }
45
+ end
46
+
47
+ test '#options_allowed with allowed option dont raise' do
48
+ options = {foo: 'bar'}
49
+ assert_nothing_raised { options_allowed(options, :foo) }
50
+ end
51
+
52
+ test '#options_allowed with no options dont raise' do
53
+ options = {}
54
+ assert_nothing_raised { options_allowed(options, :foo) }
55
+ end
56
+
57
+ test '#options_allowed_values with disallowed value raises' do
58
+ options = {bar: 'foo'}
59
+ assert_raise(@err) { options_allowed_values(options, bar: [1]) }
60
+ end
61
+
62
+ test '#options_allowed_values with allowed value dont raise' do
63
+ options = {bar: 'foo'}
64
+ assert_nothing_raised { options_allowed_values(options, bar: ['foo']) }
65
+ end
66
+
67
+ test '#options_required w/o required options raises' do
68
+ options = {bar: 'foo'}
69
+ assert_raise(@err) { options_required(options, :foo) }
70
+ end
71
+
72
+ test '#options_required with required options dont raise' do
73
+ options = {bar: 'foo', one: 'two'}
74
+ assert_nothing_raised { options_required(options, :bar, :one) }
75
+ end
76
+
77
+ test '#options_required_unique with non-unique required options raises' do
78
+ options = {bar: 'foo', one: 'two'}
79
+ assert_raise(@err) { options_required_unique(options, :bar, :one) }
80
+ end
81
+
82
+ test '#options_required_unique with unique required options dont raise' do
83
+ options = {bar: 'foo', one: 'two'}
84
+ assert_nothing_raised { options_required_unique(options, :one) }
85
+ end
86
+
87
+ test '#options_unique with non-unique options raises' do
88
+ options = {bar: 'foo', one: 'two'}
89
+ assert_raise(@err) { options_unique(options, :bar, :one) }
90
+ end
91
+
92
+ test '#options_unique with unique options dont raise' do
93
+ options = {bar: 'foo', one: 'two'}
94
+ assert_nothing_raised { options_unique(options, :one) }
95
+ end
96
+
97
+ test '#options_unique with no options dont raise' do
98
+ options = {}
99
+ assert_nothing_raised { options_unique(options, :one) }
100
+ end
101
+
102
+ test '#options_list_unique with duplicate elements raise' do
103
+ options = {foo: [0, 0]}
104
+
105
+ assert_raise(@err) { options_list_unique(options, :foo) }
106
+ end
107
+
108
+ test '#options_list_unique with unique elements dont raise' do
109
+ options = {foo: [0, 1]}
110
+ assert_nothing_raised { options_list_unique(options, :foo) }
111
+ end
112
+
113
+ test '#options_tie w/o tie option raises' do
114
+ options = {gzip: true}
115
+
116
+ assert_raise(@err) { options_tie(options, gzip: :output) }
117
+ end
118
+
119
+ test '#options_tie with tie option dont raise' do
120
+ options = {gzip: true, output: 'foo'}
121
+ assert_nothing_raised { options_tie(options, gzip: :output) }
122
+ end
123
+
124
+ test '#options_tie with reverse tie option dont raise' do
125
+ options = {gzip: true, output: 'foo'}
126
+ assert_nothing_raised { options_tie(options, output: :gzip) }
127
+ end
128
+
129
+ test '#options_conflict with conflicting options raise' do
130
+ options = {select: true, reject: true}
131
+ assert_raise(@err) { options_conflict(options, select: :reject) }
132
+ end
133
+
134
+ test '#options_conflict with non-conflicting options dont raise' do
135
+ options = {select: true}
136
+ assert_nothing_raised { options_conflict(options, select: :reject) }
137
+ end
138
+
139
+ test '#options_files_exist w/o options dont raise' do
140
+ options = {}
141
+ assert_nothing_raised { options_files_exist(options, :foo) }
142
+ end
143
+
144
+ test '#options_files_exist with file dont raise' do
145
+ options = {input: __FILE__}
146
+ assert_nothing_raised { options_files_exist(options, :input) }
147
+ end
148
+
149
+ test '#options_files_exist with non-existing file raise' do
150
+ options = {input: 'ljg34gj324'}
151
+ assert_raise(@err) { options_files_exist(options, :input) }
152
+ end
153
+
154
+ test '#options_files_exist with one non-existing file raise' do
155
+ options = {input: __FILE__, input2: '32g4g24g23'}
156
+ assert_raise(@err) { options_files_exist(options, :input, :input2) }
157
+ end
158
+
159
+ test '#options_files_exist with Array of non-existing files raise' do
160
+ options = {input: %w(__FILE__ h23j42h34)}
161
+ assert_raise(@err) { options_files_exist(options, :input) }
162
+ end
163
+
164
+ test '#options_files_exist with Arrays of non-existing files raise' do
165
+ options = {input: [__FILE__], input2: ['h23j42h34']}
166
+ assert_raise(@err) { options_files_exist(options, :input, :input2) }
167
+ end
168
+
169
+ test '#options_files_exist with existing file and glob don\'t raise' do
170
+ glob = __FILE__.sub(/\.rb$/, '*')
171
+ options = {input: glob}
172
+ assert_nothing_raised { options_files_exist(options, :input) }
173
+ end
174
+
175
+ test '#options_files_exist with non-matching glob raises' do
176
+ options = {input: 'f234rs*d32'}
177
+ assert_raise(@err) { options_files_exist(options, :input) }
178
+ end
179
+
180
+ test '#options_files_exist_force w/o options dont raise' do
181
+ options = {}
182
+ assert_nothing_raised { options_files_exist_force(options, :input) }
183
+ end
184
+
185
+ test '#options_files_exist_force with force dont raise' do
186
+ options = {input: __FILE__, force: true}
187
+ assert_nothing_raised { options_files_exist_force(options, :input) }
188
+ end
189
+
190
+ test '#options_files_exist_force w/o force raise' do
191
+ options = {input: __FILE__}
192
+ assert_raise(@err) { options_files_exist_force(options, :input) }
193
+ end
194
+
195
+ test '#options_dirs_exist w/o options dont raise' do
196
+ options = {}
197
+ assert_nothing_raised { options_dirs_exist(options, :foo) }
198
+ end
199
+
200
+ test '#options_dirs_exist with dir dont raise' do
201
+ options = {input: __dir__}
202
+ assert_nothing_raised { options_dirs_exist(options, :input) }
203
+ end
204
+
205
+ test '#options_dirs_exist with non-existing dir raise' do
206
+ options = {input: 'ljg34gj324'}
207
+ assert_raise(@err) { options_dirs_exist(options, :input) }
208
+ end
209
+
210
+ test '#options_dirs_exist with one non-existing dir raise' do
211
+ options = {input: __dir__, input2: '32g4g24g23'}
212
+ assert_raise(@err) { options_dirs_exist(options, :input, :input2) }
213
+ end
214
+
215
+ test '#options_dirs_exist with Array of non-existing dirs raise' do
216
+ options = {input: [__dir__, 'h23j42h34']}
217
+ assert_raise(@err) { options_dirs_exist(options, :input) }
218
+ end
219
+
220
+ test '#options_dirs_exist with Arrays of non-existing dirs raise' do
221
+ options = {input: [__dir__], input2: ['h23j42h34']}
222
+ assert_raise(@err) { options_dirs_exist(options, :input, :input2) }
223
+ end
224
+
225
+ test '#options_assert with false statement raise' do
226
+ options = {min: 0}
227
+ assert_raise(@err) { options_assert(options, ':min > 0') }
228
+ end
229
+
230
+ test '#options_assert with true statement dont raise' do
231
+ options = {min: 0}
232
+ assert_nothing_raised { options_assert(options, ':min == 0') }
233
+ end
234
+
235
+ test '#options_glob returns correctly' do
236
+ glob = __FILE__[0..-3] + '*'
237
+ assert_equal([__FILE__], options_glob(glob))
238
+ end
239
+
240
+ test '#options_glob with Array returns correctly' do
241
+ glob = __FILE__[0..-3] + '*'
242
+ assert_equal([__FILE__, __FILE__], options_glob([glob, glob]))
243
+ end
244
+
245
+ test 'options_load_rc with existing option returns correctly' do
246
+ file = Tempfile.new('rc_file')
247
+
248
+ begin
249
+ File.write(file, 'test foo bar')
250
+ options = {foo: 123}
251
+ options_load_rc(options, :test, file.path)
252
+ assert_equal({foo: 123}, options)
253
+ ensure
254
+ file.unlink
255
+ file.close
256
+ end
257
+ end
258
+
259
+ test 'options_load_rc w/o existing option returns correctly' do
260
+ file = Tempfile.new('rc_file')
261
+
262
+ begin
263
+ File.write(file, 'test foo bar')
264
+ options = {}
265
+ options_load_rc(options, :test, file.path)
266
+ assert_equal({foo: 'bar'}, options)
267
+ ensure
268
+ file.unlink
269
+ file.close
270
+ end
271
+ end
272
+ end
@@ -0,0 +1,98 @@
1
+ #!/usr/bin/env ruby
2
+ $:.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, USA. #
21
+ # #
22
+ # http://www.gnu.org/copyleft/gpl.html #
23
+ # #
24
+ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
25
+ # #
26
+ # This software is part of BioDSL (www.BioDSL.org). #
27
+ # #
28
+ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
29
+
30
+ require 'test/helper'
31
+
32
+ class TestAssemble < Test::Unit::TestCase
33
+ def setup
34
+ @entry1 = BioDSL::Seq.new(seq: "ttttttttttATCTCGC")
35
+ @entry2 = BioDSL::Seq.new(seq: "naTCTCGgaaaaaaaaa")
36
+ end
37
+
38
+ test "#assemble with bad mismatches_max raises" do
39
+ assert_raise(BioDSL::AssembleError) { BioDSL::Assemble.pair(@entry1, @entry2, mismatches_max: -1) }
40
+ end
41
+
42
+ test "#assemble with bad overlap_max raises" do
43
+ assert_raise(BioDSL::AssembleError) { BioDSL::Assemble.pair(@entry1, @entry2, overlap_max: 0) }
44
+ end
45
+
46
+ test "#assemble with bad overlap_min raises" do
47
+ assert_raise(BioDSL::AssembleError) { BioDSL::Assemble.pair(@entry1, @entry2, overlap_min: 0) }
48
+ end
49
+
50
+ test "#assemble returns correctly" do
51
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2)
52
+ assert_equal("ttttttttttatctcgCatctcggaaaaaaaaa", assembly.seq)
53
+ end
54
+
55
+ test "#assemble with uneven sequence length returns correctly" do
56
+ @entry1.seq = "tttttttttATCTCGC"
57
+ @entry2.seq = "naTCTCGgaaaaa"
58
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2)
59
+ assert_equal("tttttttttatctcgCatctcggaaaaa", assembly.seq)
60
+ end
61
+
62
+ test "#assemble with subsequence returns correctly" do
63
+ @entry1.seq = "tttttttttATCTCGC"
64
+ @entry2.seq = "naTCTCG"
65
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2)
66
+ assert_equal("ttttttttTATCTCGc", assembly.seq)
67
+ end
68
+
69
+ test "#assemble with seq_name returns correctly" do
70
+ @entry1.seq_name = "foo"
71
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2)
72
+ assert_equal("foo:overlap=1:hamming=0", assembly.seq_name)
73
+ assert_equal("ttttttttttatctcgCatctcggaaaaaaaaa", assembly.seq)
74
+ end
75
+
76
+ test "#assemble with qual returns correctly" do
77
+ @entry1.qual = "00000000000000000"
78
+ @entry2.qual = "@@@@@@@@@@@@@@@@@"
79
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2)
80
+ assert_equal("ttttttttttatctcgNatctcggaaaaaaaaa", assembly.seq)
81
+ assert_equal("00000000000000008@@@@@@@@@@@@@@@@", assembly.qual)
82
+ end
83
+
84
+ test "#assemble with mismatches_max returns correctly" do
85
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2, mismatches_max: 10)
86
+ assert_equal("tttttttttTATCTCGCaaaaaaaaa", assembly.seq)
87
+ end
88
+
89
+ test "#assemble with overlap_max returns correctly" do
90
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2, mismatches_max: 10, overlap_max: 7)
91
+ assert_equal("ttttttttttatctcgCatctcggaaaaaaaaa", assembly.seq)
92
+ end
93
+
94
+ test "#assemble with overlap_min returns correctly" do
95
+ assembly = BioDSL::Assemble.pair(@entry1, @entry2, mismatches_max: 10, overlap_min: 9)
96
+ assert_nil(assembly)
97
+ end
98
+ end
@@ -0,0 +1,176 @@
1
+ #!/usr/bin/env ruby
2
+ $:.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, USA. #
21
+ # #
22
+ # http://www.gnu.org/copyleft/gpl.html #
23
+ # #
24
+ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
25
+ # #
26
+ # This software is part of BioDSL (www.BioDSL.org). #
27
+ # #
28
+ # >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #
29
+
30
+ require 'test/helper'
31
+
32
+ class BackTrackTest < Test::Unit::TestCase
33
+ def setup
34
+ # 0 1
35
+ # 01234567890123456789
36
+ @seq = BioDSL::Seq.new(seq: "tacgatgctagcatgcacgg")
37
+ @seq.extend(BioDSL::BackTrack)
38
+ end
39
+
40
+ test "#patscan with bad pattern raises" do
41
+ ["", "X", "1"].each { |pattern|
42
+ assert_raise(BioDSL::BackTrackError) { @seq.patscan(pattern) }
43
+ }
44
+ end
45
+
46
+ test "#patscan with OK pattern dont raise" do
47
+ ["N", "atcg"].each { |pattern|
48
+ assert_nothing_raised { @seq.patscan(pattern) }
49
+ }
50
+ end
51
+
52
+ test "#patscan with bad start raises" do
53
+ [-1, 20].each { |start|
54
+ assert_raise(BioDSL::BackTrackError) { @seq.patscan("N", start: start) }
55
+ }
56
+ end
57
+
58
+ test "#patscan with OK start dont raise" do
59
+ [0, 19].each { |start|
60
+ assert_nothing_raised { @seq.patscan("N", start: start) }
61
+ }
62
+ end
63
+
64
+ test "#patscan with bad stop raises" do
65
+ [-1, 20].each { |stop|
66
+ assert_raise(BioDSL::BackTrackError) { @seq.patscan("N", stop: stop) }
67
+ }
68
+ end
69
+
70
+ test "#patscan with OK stop dont raise" do
71
+ [0, 19].each { |stop|
72
+ assert_nothing_raised { @seq.patscan("N", stop: stop) }
73
+ }
74
+ end
75
+
76
+ test "#patscan with stop returns correctly" do
77
+ assert_nil(@seq.patmatch("G", start: 0, stop: 2))
78
+ assert_equal("3:1:g", @seq.patmatch("G", start: 0, stop: 3).to_s)
79
+ end
80
+
81
+ test "#patscan with bad mis raises" do
82
+ [-1, 6].each { |mis|
83
+ assert_raise(BioDSL::BackTrackError) { @seq.patscan("N", max_mismatches: mis) }
84
+ }
85
+ end
86
+
87
+ test "#patscan with OK mis dont raise" do
88
+ [0, 5].each { |mis|
89
+ assert_nothing_raised { @seq.patscan("N", max_mismatches: mis) }
90
+ }
91
+ end
92
+
93
+ test "#patscan with bad ins raises" do
94
+ [-1, 6].each { |ins|
95
+ assert_raise(BioDSL::BackTrackError) { @seq.patscan("N", max_insertions: ins) }
96
+ }
97
+ end
98
+
99
+ test "#patscan with OK ins dont raise" do
100
+ [0, 5].each { |ins|
101
+ assert_nothing_raised { @seq.patscan("N", max_insertions: ins) }
102
+ }
103
+ end
104
+
105
+ test "#patscan with bad del raises" do
106
+ [-1, 6].each { |del|
107
+ assert_raise(BioDSL::BackTrackError) { @seq.patscan("N", max_deletions: del) }
108
+ }
109
+ end
110
+
111
+ test "#patscan with OK del dont raise" do
112
+ [0, 5].each { |del|
113
+ assert_nothing_raised { @seq.patscan("N", max_deletions: del) }
114
+ }
115
+ end
116
+
117
+ test "#patscan perfect left is ok" do
118
+ assert_equal("0:7:tacgatg", @seq.patscan("TACGATG").first.to_s)
119
+ end
120
+
121
+ test "#patscan perfect right is ok" do
122
+ assert_equal("13:7:tgcacgg", @seq.patscan("TGCACGG").first.to_s)
123
+ end
124
+
125
+ test "#patscan ambiguity is ok" do
126
+ assert_equal("13:7:tgcacgg", @seq.patscan("TGCACNN").first.to_s)
127
+ end
128
+
129
+ test "#patscan start is ok" do
130
+ assert_equal("10:1:g", @seq.patscan("N", start: 10).first.to_s)
131
+ assert_equal("19:1:g", @seq.patscan("N", start: 10).last.to_s)
132
+ end
133
+
134
+ test "#patscan mis left is ok" do
135
+ assert_equal("0:7:tacgatg", @seq.patscan("Aacgatg", max_mismatches: 1).first.to_s)
136
+ end
137
+
138
+ test "#patscan mis right is ok" do
139
+ assert_equal("13:7:tgcacgg", @seq.patscan("tgcacgA", max_mismatches: 1).first.to_s)
140
+ end
141
+
142
+ test "#patscan ins left is ok" do
143
+ assert_equal("0:7:tacgatg", @seq.patscan("Atacgatg", max_insertions: 1).first.to_s)
144
+ end
145
+
146
+ test "#patscan ins right is ok" do
147
+ assert_equal("13:7:tgcacgg", @seq.patscan("tgcacggA", max_insertions: 1).first.to_s)
148
+ end
149
+
150
+ test "#patscan del left is ok" do
151
+ assert_equal("0:7:tacgatg", @seq.patscan("acgatg", max_deletions: 1).first.to_s)
152
+ end
153
+
154
+ test "#patscan del right is ok" do
155
+ assert_equal("12:8:atgcacgg", @seq.patscan("tgcacgg", max_deletions: 1).first.to_s)
156
+ end
157
+
158
+ test "#patscan ambiguity mis ins del all ok" do
159
+ assert_equal("0:20:tacgatgctagcatgcacgg", @seq.patscan("tacatgcNagGatgcCacgg",
160
+ max_mismatches: 1,
161
+ max_insertions: 1,
162
+ max_deletions: 1).first.to_s)
163
+ end
164
+
165
+ test "#patmatch in block context returns correctly" do
166
+ @seq.patmatch("tacatgcNagGatgcCacgg",
167
+ max_mismatches: 1,
168
+ max_insertions: 1,
169
+ max_deletions: 1) do |hit|
170
+ assert_equal("tacgatgctagcatgcacgg", hit.match)
171
+ assert_equal(0, hit.pos)
172
+ assert_equal(20, hit.length)
173
+ break
174
+ end
175
+ end
176
+ end