genfrag 0.0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. data/.bnsignore +16 -0
  2. data/History.txt +4 -0
  3. data/LICENSE.txt +58 -0
  4. data/README.rdoc +40 -0
  5. data/Rakefile +53 -0
  6. data/bin/genfrag +8 -0
  7. data/lib/genfrag.rb +129 -0
  8. data/lib/genfrag/app.rb +105 -0
  9. data/lib/genfrag/app/command.rb +145 -0
  10. data/lib/genfrag/app/index_command.rb +227 -0
  11. data/lib/genfrag/app/index_command/db.rb +105 -0
  12. data/lib/genfrag/app/search_command.rb +298 -0
  13. data/lib/genfrag/app/search_command/match.rb +165 -0
  14. data/lib/genfrag/app/search_command/process_file.rb +125 -0
  15. data/lib/genfrag/app/search_command/trim.rb +121 -0
  16. data/lib/genfrag/debug.rb +0 -0
  17. data/spec/data/index_command/in/a.fasta +109 -0
  18. data/spec/data/index_command/out/1-a_lookup.tdf +4 -0
  19. data/spec/data/index_command/out/2-a_lookup.db +0 -0
  20. data/spec/data/index_command/out/3-a_lookup.tdf +2 -0
  21. data/spec/data/index_command/out/4-a_lookup.db +0 -0
  22. data/spec/data/index_command/out/5-a_lookup.tdf +4 -0
  23. data/spec/data/index_command/out/6-a_lookup.db +0 -0
  24. data/spec/data/index_command/out/a.fasta.db +0 -0
  25. data/spec/data/index_command/out/a.fasta.tdf +6 -0
  26. data/spec/genfrag/app/command_spec.rb +55 -0
  27. data/spec/genfrag/app/index_command_spec.rb +258 -0
  28. data/spec/genfrag/app/search_command/match_spec.rb +77 -0
  29. data/spec/genfrag/app/search_command/process_file_spec.rb +185 -0
  30. data/spec/genfrag/app/search_command/trim_spec.rb +75 -0
  31. data/spec/genfrag/app/search_command_spec.rb +260 -0
  32. data/spec/genfrag/app_spec.rb +77 -0
  33. data/spec/genfrag_spec.rb +87 -0
  34. data/spec/spec_helper.rb +56 -0
  35. data/tasks/ann.rake +80 -0
  36. data/tasks/bones.rake +20 -0
  37. data/tasks/gem.rake +201 -0
  38. data/tasks/git.rake +40 -0
  39. data/tasks/notes.rake +27 -0
  40. data/tasks/post_load.rake +34 -0
  41. data/tasks/rdoc.rake +50 -0
  42. data/tasks/rubyforge.rake +55 -0
  43. data/tasks/setup.rb +300 -0
  44. data/tasks/spec.rake +54 -0
  45. data/tasks/svn.rake +47 -0
  46. data/tasks/test.rake +40 -0
  47. metadata +136 -0
@@ -0,0 +1,75 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. .. .. spec_helper]))
4
+
5
+ # --------------------------------------------------------------------------
6
+ describe Genfrag::App::SearchCommand do
7
+
8
+ before :all do
9
+ @out = StringIO.new
10
+ @err = StringIO.new
11
+ @input_dir = File.join(GENFRAG_SPEC_DATA_DIR, 'index_command', 'out')
12
+ @frozen_output_dir = File.join(GENFRAG_SPEC_DATA_DIR, 'search_command', 'out')
13
+ @working_output_dir = File.join(GENFRAG_SPEC_TMP_DIR, %w[search_command])
14
+ FileUtils.mkdir_p(@working_output_dir) unless File.directory? @working_output_dir
15
+ end
16
+
17
+ before :each do
18
+ @app = Genfrag::App::SearchCommand.new(@out, @err)
19
+ end
20
+
21
+ after :each do
22
+ @out.clear
23
+ @err.clear
24
+ end
25
+
26
+ describe 'test calculate_trim_for_nucleotides' do
27
+ it 'should work for BstYI' do
28
+ re5_ds = Bio::RestrictionEnzyme::DoubleStranded.new('BstYI')
29
+ re3_ds = Bio::RestrictionEnzyme::DoubleStranded.new('BstYI')
30
+
31
+ @app.calculate_trim_for_nucleotides(re5_ds, re3_ds).should == {:from_left_primary=>1, :from_right_primary=>5, :from_right_complement=>1, :from_left_complement=>5}
32
+ end
33
+
34
+ it 'should work for PpiI' do
35
+ re5_ds = Bio::RestrictionEnzyme::DoubleStranded.new('PpiI')
36
+ re3_ds = Bio::RestrictionEnzyme::DoubleStranded.new('PpiI')
37
+
38
+ @app.calculate_trim_for_nucleotides(re5_ds, re3_ds).should == {:from_right_primary=>33, :from_left_primary=>38, :from_right_complement=>38, :from_left_complement=>33}
39
+ end
40
+ end
41
+
42
+ describe 'test calculate_left_and_right_trims' do
43
+ it 'should work for BstYI / PpiI' do
44
+ re5_ds = Bio::RestrictionEnzyme::DoubleStranded.new('BstYI')
45
+ re3_ds = Bio::RestrictionEnzyme::DoubleStranded.new('PpiI')
46
+
47
+ trim = @app.calculate_trim_for_nucleotides(re5_ds, re3_ds)
48
+ @app.calculate_left_and_right_trims(trim).should == [{:trim_from_both=>1, :dot_out_from_primary=>false}, {:trim_from_both=>33, :dot_out_from_primary=>false}]
49
+ end
50
+
51
+ it 'should work for PpiI / BstYI' do
52
+ re5_ds = Bio::RestrictionEnzyme::DoubleStranded.new('PpiI')
53
+ re3_ds = Bio::RestrictionEnzyme::DoubleStranded.new('BstYI')
54
+
55
+ trim = @app.calculate_trim_for_nucleotides(re5_ds, re3_ds)
56
+ @app.calculate_left_and_right_trims(trim).should == [{:trim_from_both=>33, :dot_out_from_primary=>true}, {:trim_from_both=>1, :dot_out_from_primary=>true}]
57
+ end
58
+ end
59
+
60
+ describe 'test trim_sequences' do
61
+ it 'test' do
62
+ p = "agatccttattgagaacggtgagtcttcttcatctttacctcttcctattgttgcgaatgcagctgcaccagtcggatttgatggtcctatgtttcaatatcataatcaaaatcagcaaaagccggttcaattccaatatcaggctctttatgatttttatgatcagattccaaagaaaattcatggttttaa"
63
+ c = "tctaggaataactcttgccactcagaagaagtagaaatggagaaggataacaacgcttacgtcgacgtggtcagcctaaactaccaggatacaaagttatagtattagttttagtcgttttcggccaagttaaggttatagtccgagaaatactaaaaatactagtctaaggtttcttttaagtaccaaaatt"
64
+ l = {:trim_from_both=>1, :dot_out_from_primary=>false}
65
+ r = {:trim_from_both=>1, :dot_out_from_primary=>true}
66
+ t = {:from_right_primary=>3, :from_left_primary=>1, :from_right_complement=>1, :from_left_complement=>5}
67
+ @app.trim_sequences(p,c,l,r,t).should ==
68
+ ["gatccttattgagaacggtgagtcttcttcatctttacctcttcctattgttgcgaatgcagctgcaccagtcggatttgatggtcctatgtttcaatatcataatcaaaatcagcaaaagccggttcaattccaatatcaggctctttatgatttttatgatcagattccaaagaaaattcatggttt..",
69
+ "....gaataactcttgccactcagaagaagtagaaatggagaaggataacaacgcttacgtcgacgtggtcagcctaaactaccaggatacaaagttatagtattagttttagtcgttttcggccaagttaaggttatagtccgagaaatactaaaaatactagtctaaggtttcttttaagtaccaaaat"]
70
+ end
71
+ end
72
+
73
+ end
74
+
75
+ # EOF
@@ -0,0 +1,260 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. .. spec_helper]))
4
+
5
+ # --------------------------------------------------------------------------
6
+ describe Genfrag::App::SearchCommand do
7
+
8
+ =begin
9
+ before :all do
10
+ @out = StringIO.new
11
+ @err = StringIO.new
12
+ @input_dir = File.join(GENFRAG_SPEC_DATA_DIR, 'index_command', 'in')
13
+ @frozen_output_dir = File.join(GENFRAG_SPEC_DATA_DIR, 'index_command', 'out')
14
+ @working_output_dir = File.join(GENFRAG_SPEC_TMP_DIR, %w[index_command])
15
+ FileUtils.mkdir_p(@working_output_dir) unless File.directory? @working_output_dir
16
+ end
17
+
18
+ before :each do
19
+ @app = Genfrag::App::IndexCommand.new(@out, @err)
20
+ end
21
+
22
+ after :each do
23
+ @out.clear
24
+ @err.clear
25
+ end
26
+
27
+ describe 'when used from the command-line' do
28
+ it 'should provide a help command and exit' do
29
+ lambda {@app.cli_run %w[--help]}.should raise_error(SystemExit)
30
+ @out.readline.should match(%r/Usage: genfrag index \[options\]/)
31
+ @out.clear
32
+
33
+ lambda {@app.cli_run %w[--help]}.should raise_error(SystemExit)
34
+ @out.readline.should match(%r/Usage: genfrag index \[options\]/)
35
+ end
36
+
37
+ it 'should default to the help message and exit if no command is given' do
38
+ lambda {@app.cli_run %w[]}.should raise_error(SystemExit)
39
+ @out.readline.should match(%r/Usage: genfrag index \[options\]/)
40
+ end
41
+
42
+ it 'should stop on unrecognized options' do
43
+ lambda {@app.cli_run %w[--bad]}.should raise_error(OptionParser::InvalidOption)
44
+ end
45
+
46
+ it 'should recognize a fasta file passed as an argument' do
47
+ pending 'feature'
48
+ end
49
+
50
+ it 'should recognize multiple fasta files passed as arguments' do
51
+ pending 'feature'
52
+ end
53
+
54
+ it 'should stop on missing --fasta' do
55
+ lambda {@app.cli_run %w[-v --re5 BstYI --re3 BstYI]}.should raise_error(SystemExit)
56
+ end
57
+
58
+ it 'should stop on missing --re5' do
59
+ lambda {@app.cli_run %w[-v --fasta a --re3 BstYI]}.should raise_error(SystemExit)
60
+ end
61
+
62
+ it 'should stop on missing --re3' do
63
+ lambda {@app.cli_run %w[-v --fasta a --re5 BstYI]}.should raise_error(SystemExit)
64
+ end
65
+
66
+ it "should stop when --re3 is passed something it can't recognize" do
67
+ lambda {@app.cli_run %w[-v --fasta a --re5 BstYI --re3 notanenzyme]}.should raise_error
68
+ end
69
+
70
+ it "should stop when --re5 is passed something it can't recognize" do
71
+ lambda {@app.cli_run %w[-v --fasta a --re3 BstYI --re5 notanenzyme]}.should raise_error
72
+ end
73
+ end
74
+
75
+ describe 'command-line option parser' do
76
+ it 'should stop on unrecognized options' do
77
+ lambda {@app.parse %w[--bad]}.should raise_error(OptionParser::InvalidOption)
78
+ end
79
+
80
+ it 'should recognize verbose' do
81
+ @app.parse(%w[--verbose])
82
+ @app.parse(%w[-v])
83
+ end
84
+
85
+ it 'should recognize tracktime' do
86
+ @app.parse(%w[--tracktime])
87
+ @app.parse(%w[-m])
88
+ end
89
+
90
+ it 'should recognize quiet' do
91
+ @app.parse(%w[--quiet])
92
+ @app.parse(%w[-q])
93
+ end
94
+
95
+ it 'should recognize re5 with string' do
96
+ @app.parse(%w[--re5 a])
97
+ @app.parse(%w[-5 a])
98
+ end
99
+
100
+ it 'should recognize re3 with string' do
101
+ @app.parse(%w[--re3 a])
102
+ @app.parse(%w[-3 a])
103
+ end
104
+
105
+ it 'should recognize sqlite' do
106
+ @app.parse(%w[--sqlite])
107
+ @app.parse(%w[-t])
108
+ end
109
+
110
+ it 'should recognize lookup with string' do
111
+ @app.parse(%w[--lookup a])
112
+ @app.parse(%w[-l a])
113
+ end
114
+
115
+ it 'should recognize fasta with string' do
116
+ @app.parse(%w[--fasta a])
117
+ @app.parse(%w[-f a])
118
+ end
119
+
120
+ it 'should recognize a combination of arguments' do
121
+ @app.parse(%w[-v --re5 a --re3 a])
122
+ @app.parse(%w[--verbose -5 a -3 a])
123
+ end
124
+ end
125
+
126
+ describe 'with working example,' do
127
+
128
+ after :all do
129
+ #FileUtils.rm Dir.glob(File.join(@working_output_dir,'*'))
130
+ end
131
+
132
+ describe 'a.fasta' do
133
+
134
+ before :each do
135
+ @fasta = 'a.fasta'
136
+ @app = Genfrag::App::IndexCommand.new(@out, @err)
137
+ @app.ops.indir = @input_dir
138
+ @app.ops.outdir = @working_output_dir
139
+ @app.ops.filefasta = @fasta
140
+ end
141
+
142
+ ############################################################
143
+ describe 'using re5 = BstYI and re3 = MseI' do
144
+
145
+ before :each do
146
+ @app.ops.re5 = 'BstYI'
147
+ @app.ops.re3 = 'MseI'
148
+ end
149
+
150
+ describe 'without sqlite' do
151
+ it 'should execute' do
152
+ @app.ops.filelookup = '1-a_lookup'
153
+ @app.ops.sqlite = false
154
+ @app.run
155
+ end
156
+ it 'lookup should be the same' do
157
+ compare('1-a_lookup', '.tdf')
158
+ end
159
+ it 'fasta should be the same' do
160
+ compare(@fasta, '.tdf')
161
+ end
162
+ end
163
+
164
+ describe 'with sqlite' do
165
+ it 'should execute' do
166
+ @app.ops.filelookup = '2-a_lookup'
167
+ @app.ops.sqlite = true
168
+ @app.run
169
+ end
170
+ it 'lookup should be the same' do
171
+ compare('2-a_lookup', '.db')
172
+ end
173
+ it 'fasta should be the same' do
174
+ compare(@fasta, '.tdf')
175
+ end
176
+ end
177
+ end
178
+
179
+ ############################################################
180
+ describe 'using re5 = MseI and re3 = BstYI' do
181
+
182
+ before :each do
183
+ @app.ops.re5 = 'MseI'
184
+ @app.ops.re3 = 'BstYI'
185
+ end
186
+
187
+ describe 'without sqlite' do
188
+ it 'should execute' do
189
+ @app.ops.filelookup = '3-a_lookup'
190
+ @app.ops.sqlite = false
191
+ @app.run
192
+ end
193
+ it 'lookup should be the same' do
194
+ compare('3-a_lookup', '.tdf')
195
+ end
196
+ it 'fasta should be the same' do
197
+ compare(@fasta, '.tdf')
198
+ end
199
+ end
200
+
201
+ describe 'with sqlite' do
202
+ it 'should execute' do
203
+ @app.ops.filelookup = '4-a_lookup'
204
+ @app.ops.sqlite = true
205
+ @app.run
206
+ end
207
+ it 'lookup should be the same' do
208
+ compare('4-a_lookup', '.db')
209
+ end
210
+ it 'fasta should be the same' do
211
+ compare(@fasta, '.tdf')
212
+ end
213
+ end
214
+ end
215
+
216
+ ############################################################
217
+ describe 'using re5 = TaqI and re3 = AluI' do
218
+
219
+ before :each do
220
+ @app.ops.re5 = 'TaqI'
221
+ @app.ops.re3 = 'AluI'
222
+ end
223
+
224
+ describe 'without sqlite' do
225
+ it 'should execute' do
226
+ @app.ops.filelookup = '5-a_lookup'
227
+ @app.ops.sqlite = false
228
+ @app.run
229
+ end
230
+ it 'lookup should be the same' do
231
+ compare('5-a_lookup', '.tdf')
232
+ end
233
+ it 'fasta should be the same' do
234
+ compare(@fasta, '.tdf')
235
+ end
236
+ end
237
+
238
+ describe 'with sqlite' do
239
+ it 'should execute' do
240
+ @app.ops.filelookup = '6-a_lookup'
241
+ @app.ops.sqlite = true
242
+ @app.run
243
+ end
244
+ it 'lookup should be the same' do
245
+ compare('6-a_lookup', '.db')
246
+ end
247
+ it 'fasta should be the same' do
248
+ compare(@fasta, '.tdf')
249
+ end
250
+ end
251
+ end
252
+
253
+ end # a.fasta
254
+
255
+ end # with working example
256
+ =end
257
+
258
+ end
259
+
260
+ # EOF
@@ -0,0 +1,77 @@
1
+
2
+ require File.expand_path(
3
+ File.join(File.dirname(__FILE__), %w[.. spec_helper]))
4
+
5
+ #class Runner
6
+ # attr_accessor :name
7
+ # def run(*a, &b) nil; end
8
+ #end
9
+
10
+ describe Genfrag::App do
11
+
12
+ before :all do
13
+ @out = StringIO.new
14
+ @err = StringIO.new
15
+ end
16
+
17
+ before :each do
18
+ # @runner = ::Runner.new
19
+ @app = Genfrag::App.new(@out, @err)
20
+
21
+ Genfrag::App::IndexCommand.stub!(:new)
22
+ Genfrag::App::SearchCommand.stub!(:new)
23
+ end
24
+
25
+ after :each do
26
+ @out.clear
27
+ @err.clear
28
+ end
29
+
30
+ it 'should provide an index command' do
31
+ @app.cli_run %w[index]
32
+ end
33
+
34
+ it 'should provide a search command' do
35
+ @app.cli_run %w[search]
36
+ end
37
+
38
+ it 'should provide an info command' do
39
+ pending "feature"
40
+ @app.cli_run %w[info]
41
+ end
42
+
43
+ it 'should provide a help command' do
44
+ @app.cli_run %w[--help]
45
+ @out.readline
46
+ @out.readline.should match(%r/GenFrag allows/)
47
+ @out.clear
48
+
49
+ @app.cli_run %w[-h]
50
+ @out.readline
51
+ @out.readline.should match(%r/GenFrag allows/)
52
+ end
53
+
54
+ it 'should default to the help message if no command is given' do
55
+ @app.cli_run []
56
+ @out.readline
57
+ @out.readline.should match(%r/GenFrag allows/)
58
+ end
59
+
60
+ it 'should report an error for unrecognized commands' do
61
+ lambda {@app.cli_run %w[bad_func]}.should raise_error(SystemExit)
62
+ @err.readline.should == 'ERROR: While executing genfrag ... (RuntimeError)'
63
+ @err.readline.should == ' Unknown command "bad_func"'
64
+ end
65
+
66
+ it 'should report a version number' do
67
+ @app.cli_run %w[--version]
68
+ @out.readline.should == "Genfrag #{Genfrag::VERSION}"
69
+ @out.clear
70
+
71
+ @app.cli_run %w[-V]
72
+ @out.readline.should == "Genfrag #{Genfrag::VERSION}"
73
+ end
74
+
75
+ end # describe Genfrag::App
76
+
77
+ # EOF
@@ -0,0 +1,87 @@
1
+
2
+ require File.join(File.dirname(__FILE__), %w[spec_helper])
3
+
4
+ describe Genfrag do
5
+
6
+ before :all do
7
+ @root_dir = File.expand_path(File.join(File.dirname(__FILE__), '..'))
8
+ @app = Genfrag
9
+ end
10
+
11
+ it "finds things releative to 'root'" do
12
+ Genfrag.path(%w[lib genfrag debug]).
13
+ should == File.join(@root_dir, %w[lib genfrag debug])
14
+ end
15
+
16
+ describe 'filename function' do
17
+ describe 'name_adapters' do
18
+ it 'should format correctly' do
19
+ @app.name_adapters('abc.db').should == 'abc'
20
+ @app.name_adapters('abc.tdf').should == 'abc'
21
+ @app.name_adapters('abc.x').should == 'abc.x'
22
+ @app.name_adapters.should be_nil
23
+ end
24
+ end
25
+
26
+ describe 'name_normalized_fasta' do
27
+ it 'should format correctly using filefasta option' do
28
+ @app.name_normalized_fasta(nil,'abc.db').should == 'abc'
29
+ @app.name_normalized_fasta(nil,'abc.tdf').should == 'abc'
30
+ @app.name_normalized_fasta(nil,'abc.x').should == 'abc.x'
31
+ end
32
+
33
+ it 'should format correctly using multiple input files' do
34
+ files = ['zxy', 'abc', 'def']
35
+ @app.name_normalized_fasta(files).should == 'abc_def_zxy_normalized'
36
+
37
+ files = ['zxy', 'foo/abc', 'foo/def']
38
+ @app.name_normalized_fasta(files).should == 'fooxabc_fooxdef_zxy_normalized'
39
+ end
40
+
41
+ it 'should raise an error without any filename source' do
42
+ lambda {@app.name_normalized_fasta}.should raise_error
43
+ end
44
+ end
45
+
46
+ describe 'name_freq_lookup' do
47
+ # def name_freq_lookup(input_filenames=[],filefasta=nil,filelookup=nil,re5=nil,re3=nil)
48
+
49
+ it 'should format correctly using filelookup option' do
50
+ @app.name_freq_lookup(nil,nil,'abc.db').should == 'abc'
51
+ @app.name_freq_lookup(nil,nil,'abc.tdf').should == 'abc'
52
+ @app.name_freq_lookup(nil,nil,'abc.x').should == 'abc.x'
53
+ end
54
+
55
+ it 'should format correctly without filelookup option and with filefasta and enzymes' do
56
+ re5 = 'MyRe5'
57
+ re3 = 'MyRe3'
58
+ @app.name_freq_lookup(nil,'abc.db',nil,re5,re3).should == 'abc_myre5_myre3_index'
59
+ @app.name_freq_lookup(nil,'abc.tdf',nil,re5,re3).should == 'abc_myre5_myre3_index'
60
+ @app.name_freq_lookup(nil,'abc.x',nil,re5,re3).should == 'abc.x_myre5_myre3_index'
61
+ end
62
+
63
+ it 'should format correctly using multiple input files and enzymes' do
64
+ re5 = 'MyRe5'
65
+ re3 = 'MyRe3'
66
+
67
+ files = ['zxy', 'abc', 'def']
68
+ @app.name_freq_lookup(files,nil,nil,re5,re3).should == 'abc_def_zxy_myre5_myre3_index'
69
+
70
+ files = ['zxy', 'foo/abc', 'foo/def']
71
+ @app.name_freq_lookup(files,nil,nil,re5,re3).should == 'fooxabc_fooxdef_zxy_myre5_myre3_index'
72
+ end
73
+
74
+ it 'should raise an error using multiple input files without enzymes' do
75
+ files = ['zxy', 'abc', 'def']
76
+ lambda {@app.name_freq_lookup(files)}.should raise_error
77
+ end
78
+
79
+ it 'should raise an error without any filename source' do
80
+ lambda {@app.name_freq_lookup}.should raise_error
81
+ end
82
+ end
83
+ end
84
+
85
+ end
86
+
87
+ # EOF