scbi_fasta 0.1.8

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,22 @@
1
+ === 0.1.8 2011-06-13
2
+
3
+ first rubygems published
4
+
5
+ === 0.1.3 2010-09-03
6
+
7
+ * 1 minor fix, 3 enhancements:
8
+ * remove comments from sequence names
9
+ * FastaQualFile can be used without qual file
10
+ * added FastaFile
11
+ * added tests
12
+
13
+ === 0.0.2 2010-05-14
14
+
15
+ * 1 improvement:
16
+ * speed improvement in FastaQualFile
17
+
18
+ === 0.0.1 2010-05-14
19
+
20
+ * 1 major enhancement:
21
+ * Initial release of FastaQualFile
22
+
data/Manifest.txt ADDED
@@ -0,0 +1,16 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/scbi_fasta.rb
7
+ lib/scbi_fasta/fasta_qual_file.rb
8
+ lib/scbi_fasta/fasta_file.rb
9
+ script/console
10
+ script/destroy
11
+ script/generate
12
+ test/test_helper.rb
13
+ test/test_fasta_file.rb
14
+ test/test_fasta_qual_file.rb
15
+
16
+
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on scbi_fasta, see http://scbi_fasta.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,93 @@
1
+ = scbi_fasta
2
+
3
+ * http://www.scbi.uma.es/downloads
4
+
5
+ == DESCRIPTION:
6
+
7
+ scbi_fasta is a ruby gem to read FASTA+QUAL files (DNA/RNA sequences).
8
+
9
+
10
+ == FEATURES/PROBLEMS:
11
+
12
+ * Read FASTA files with associated QUAL files
13
+ * Quality values can be automatically splitted
14
+ * Iteration over large files without extra memory usage
15
+
16
+
17
+ == SYNOPSIS:
18
+
19
+ === Reading a FASTA+QUAL with iterator:
20
+
21
+ require 'scbi_fasta'
22
+
23
+ # open file in sanger mode
24
+ fqr=FastaQualFile.new('file1.fasta','file1.fasta.qual')
25
+
26
+
27
+ fqr.each do |name,seq_fasta,qual,comments|
28
+
29
+ puts name
30
+ puts seq_fasta
31
+ puts qual
32
+ puts comments
33
+ end
34
+
35
+ fqr.close
36
+
37
+ === Reading a FASTA one sequence at a time:
38
+
39
+ require 'scbi_fasta'
40
+
41
+ # open file
42
+ fqr=FastaQualFile.new('file1.fasta','file1.fasta.qual')
43
+
44
+
45
+ begin
46
+
47
+ # read one sequence
48
+ name,seq_fasta,qual,comments=fqr.next_seq
49
+
50
+ # name will be nil if there are not more sequences available
51
+ if !name.nil?
52
+ puts name
53
+ puts seq_fasta
54
+ puts qual
55
+ puts comments
56
+ end
57
+ end until name.nil?
58
+
59
+ fqr.close
60
+
61
+
62
+ == REQUIREMENTS:
63
+
64
+ * This is a standalone gem.
65
+
66
+ == INSTALL:
67
+
68
+ * gem install scbi_fasta
69
+
70
+ == LICENSE:
71
+
72
+ (The MIT License)
73
+
74
+ Copyright (c) 2010 Almudena Bocinos, Dario Guerrero
75
+
76
+ Permission is hereby granted, free of charge, to any person obtaining
77
+ a copy of this software and associated documentation files (the
78
+ 'Software'), to deal in the Software without restriction, including
79
+ without limitation the rights to use, copy, modify, merge, publish,
80
+ distribute, sublicense, and/or sell copies of the Software, and to
81
+ permit persons to whom the Software is furnished to do so, subject to
82
+ the following conditions:
83
+
84
+ The above copyright notice and this permission notice shall be
85
+ included in all copies or substantial portions of the Software.
86
+
87
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
88
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
89
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
90
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
91
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
92
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
93
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,26 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/scbi_fasta'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'scbi_fasta' do
14
+ self.developer 'Almudena Bocinos', 'alkoke@gmail.com'
15
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
16
+ self.rubyforge_name = self.name # TODO this is default value
17
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
18
+
19
+ end
20
+
21
+ require 'newgem/tasks'
22
+ Dir['tasks/**/*.rake'].each { |t| load t }
23
+
24
+ # TODO - want other tests/tasks run by default? Add them to the list
25
+ # remove_task :default
26
+ task :default => [:spec, :features, :redocs]
data/lib/scbi_fasta.rb ADDED
@@ -0,0 +1,12 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ $: << File.join(File.dirname(__FILE__),File.basename(__FILE__,File.extname(__FILE__)))
5
+
6
+ require 'fasta_qual_file'
7
+ require 'fasta_file'
8
+
9
+
10
+ module ScbiFasta
11
+ VERSION = '0.1.8'
12
+ end
@@ -0,0 +1,92 @@
1
+ ########################################################
2
+ # Author: Almudena Bocinos Rioboo
3
+ # Use: Deprecated. The class FastaReader has been substituted by FastaQualReader
4
+ # Reads a fasta file and fires events to process it
5
+ #
6
+ ########################################################
7
+
8
+ class FastaFile
9
+
10
+ attr :num_seqs
11
+
12
+
13
+ # Initialize instance
14
+ def initialize(file_name)
15
+ if File.exist?(file_name)
16
+ @num_seqs = 0
17
+
18
+ @file_name = file_name
19
+ @file = File.open(file_name)
20
+ else
21
+ raise "File #{file_name} doesn't exists"
22
+
23
+ end
24
+
25
+ end
26
+
27
+
28
+ # Scans a file, firing events to process content
29
+ def each
30
+
31
+ #init variables
32
+ seq_name = '';
33
+ seq_fasta = '';
34
+ seq_found = false;
35
+
36
+
37
+ # for each line of the file
38
+ @file.each do |line|
39
+
40
+ line.chomp!;
41
+ # if line is name
42
+ if line =~ /^>/
43
+
44
+ #process previous sequence
45
+ if seq_found
46
+ @num_seqs=@num_seqs+1
47
+ yield(seq_name,seq_fasta);
48
+ end
49
+
50
+ #get only name
51
+
52
+ #get only name
53
+ line.gsub!(/^>\s*/,'');
54
+
55
+ line =~ /(^[^\s]+)/
56
+
57
+ # remove comments
58
+ seq_name = $1
59
+
60
+ seq_fasta='';
61
+ seq_found = true;
62
+
63
+ else
64
+
65
+ line.strip! if !line.empty?
66
+
67
+ #add line to fasta of seq
68
+ seq_fasta+=line;
69
+
70
+ seq_fasta.strip! if !seq_fasta.empty?
71
+
72
+ end
73
+
74
+ end
75
+
76
+ # when found EOF, process last sequence
77
+ if seq_found
78
+ @num_seqs=@num_seqs+1
79
+ yield(seq_name,seq_fasta);
80
+ end
81
+ end
82
+
83
+
84
+ def close
85
+ @file.close
86
+ end
87
+
88
+ def with_qual?
89
+ false
90
+ end
91
+
92
+ end
@@ -0,0 +1,288 @@
1
+
2
+ ########################################################
3
+ # Author: Almudena Bocinos Rioboo
4
+ #
5
+ # Reads a fasta file and qual file, and then fires events to process it
6
+ #
7
+ #
8
+ #
9
+ ########################################################
10
+
11
+ class DifferentNamesException < RuntimeError
12
+ end
13
+
14
+ class DifferentSizesException < RuntimeError
15
+ end
16
+
17
+ class FastaQualFile
18
+
19
+ attr_accessor :num_seqs, :end_fasta
20
+
21
+ #------------------------------------
22
+ # Initialize instance
23
+ #------------------------------------
24
+ def initialize(fasta_file_name,qual_file_name='',qual_to_array=false)
25
+
26
+
27
+ if !File.exist?(fasta_file_name)
28
+ raise "File #{fasta_file_name} doesn't exists"
29
+ end
30
+
31
+ @with_qual = true
32
+
33
+ if qual_file_name.nil? or qual_file_name.empty? or !File.exist?(qual_file_name)
34
+ @with_qual = false
35
+ #raise "File #{qual_file_name} doesn't exists"
36
+ end
37
+
38
+
39
+ @num_seqs = 0 ;
40
+
41
+ @seq_name = '';
42
+ @file_fasta = File.open(fasta_file_name) ;
43
+ @end_fasta=false;
44
+
45
+ if @with_qual
46
+
47
+ @qual_to_array = qual_to_array
48
+
49
+ @seq_qual_name='';
50
+ @file_qual = File.open(qual_file_name) ;
51
+ @end_qual=false;
52
+ end
53
+
54
+ end
55
+
56
+ def close
57
+ @file_fasta.close
58
+
59
+ @file_qual.close if @with_qual
60
+ end
61
+
62
+
63
+ #------------------------------------
64
+ # Scans all sequences
65
+ #------------------------------------
66
+ def each
67
+
68
+ rewind
69
+
70
+ n,f,q=next_seq
71
+ while (!n.nil?)
72
+
73
+ if @with_qual
74
+ yield(n,f,q)
75
+ else
76
+ yield(n,f)
77
+ end
78
+
79
+ n,f,q=next_seq
80
+ end
81
+
82
+ rewind
83
+
84
+ end
85
+
86
+
87
+ def rewind
88
+
89
+ @num_seqs = 0 ;
90
+
91
+ @seq_name = '';
92
+ @file_fasta.pos=0
93
+ @end_fasta=false;
94
+
95
+ if @with_qual
96
+ @seq_qual_name='';
97
+ @file_qual.pos=0
98
+ @end_qual=false;
99
+ end
100
+
101
+ end
102
+
103
+ #------------------------------------
104
+ # Scans a file, firing events to process content
105
+ #------------------------------------
106
+ def next_seq
107
+
108
+ #init variables
109
+ res = nil
110
+
111
+ # envia on_process_sequence
112
+ if ((!@end_fasta) && (!@with_qual or !@end_qual))
113
+
114
+ name_f,fasta=read_fasta
115
+
116
+ if @with_qual
117
+
118
+ name_q,qual=read_qual
119
+
120
+ if (name_f!=name_q)
121
+ raise DifferentNamesException.new, "Sequence(<#{name_f}>) and qual(<#{name_q}>) names differs. Sequence will be ignored."
122
+ else
123
+ @num_seqs=@num_seqs+1
124
+
125
+ #storage a string of qualities in an array of qualities
126
+ # a_qual = qual.strip.split(/\s/).map{|e| e.to_i}
127
+ # if ((!a_qual.nil?) && (!a_qual.empty?) && (fasta.size==a_qual.size))
128
+
129
+ if fasta.length == qual.count(' ') + 1
130
+ if @qual_to_array
131
+ a_qual = qual.strip.split(/\s/).map{|e| e.to_i}
132
+ res =[name_f,fasta,a_qual]
133
+ else
134
+ res =[name_f,fasta,qual]
135
+ end
136
+
137
+ else #if (!a_qual.empty?)
138
+ raise DifferentSizesException.new, "Sequence(<#{name_f}>) and qual(<#{name_q}>) sizes differs (#{fasta.length},#{qual.count(' ')} ). Sequence will be ignored."
139
+ end
140
+
141
+ end
142
+
143
+ else # without qual
144
+ res =[name_f,fasta]
145
+ end
146
+ end
147
+
148
+ return res
149
+ end
150
+
151
+ def with_qual?
152
+ @with_qual
153
+ end
154
+
155
+
156
+ private
157
+
158
+ #------------------------------------
159
+ # Read one sequence fasta
160
+ #------------------------------------
161
+
162
+ def read_fasta
163
+ seq_fasta='';
164
+ res = nil
165
+
166
+ # mientras hay lineas en el fichero
167
+ while (!@file_fasta.eof)
168
+ # $LOG.debug "Total fasta #{@seq_fasta} Line fast #{@line_fasta} "
169
+
170
+ # lee una linea
171
+ line_fasta = @file_fasta.readline; line_fasta.chomp!
172
+ # si llega a fin de ficheor, poner eof
173
+ @end_fasta=@file_fasta.eof
174
+
175
+ # si la linea es una nueva secuencia
176
+ if ((line_fasta =~ /^>/))
177
+
178
+ # puede ocurrir que antes ya se hubiese leido una secuencia, entonces devolverla
179
+ if !@seq_name.empty?
180
+ # ya había leido una
181
+ #puts "leida #{@seq_name} + #{@seq_fasta}"
182
+ res = [@seq_name,seq_fasta]
183
+ end
184
+
185
+
186
+ #get only name
187
+ line_fasta.gsub!(/^>\s*/,'');
188
+
189
+ line_fasta =~ /(^[^\s]+)/
190
+ # remove comments
191
+
192
+ @seq_name = $1
193
+
194
+ seq_fasta='';
195
+
196
+ # si hay algo que devolver, romper bucle
197
+ if res
198
+ break
199
+ end
200
+
201
+ else # no es una linea de nombre, añadir al fasta
202
+ line_fasta.strip! if !line_fasta.empty?
203
+ #add line to fasta of seq
204
+ seq_fasta+=line_fasta;
205
+ seq_fasta.strip! if !seq_fasta.empty?
206
+ end
207
+
208
+
209
+ end
210
+
211
+
212
+ #si no hay más secuencias hay que devolver la última, CASO EOF
213
+ if res.nil? and !@seq_name.empty?
214
+ res= [@seq_name,seq_fasta]
215
+ end
216
+
217
+ return res
218
+ end
219
+
220
+ #----
221
+
222
+ #------------------------------------
223
+ # Read one sequence qual
224
+ #------------------------------------
225
+ def read_qual
226
+ seq_qual='';
227
+ res = nil
228
+
229
+ # mientras hay lineas en el fichero
230
+ while (!@file_qual.eof)
231
+ # $LOG.debug "Total fasta #{@seq_qual} Line fast #{@line_qual} "
232
+
233
+ # lee una linea
234
+ line_qual = @file_qual.readline; line_qual.chomp!
235
+ # si llega a fin de ficheor, poner eof
236
+ @end_qual=@file_qual.eof
237
+
238
+ # si la linea es una nueva secuencia
239
+ if ((line_qual =~ /^>/))
240
+
241
+ # puede ocurrir que antes ya se hubiese leido una secuencia, entonces devolverla
242
+ if !@seq_qual_name.empty?
243
+ # ya había leido una
244
+ #puts "leida #{@seq_name} + #{@seq_qual}"
245
+
246
+ seq_qual.gsub!(/\s\s+/,' ')
247
+ res = [@seq_qual_name,seq_qual]
248
+ end
249
+
250
+
251
+ #get only name
252
+ #get only name
253
+ line_qual.gsub!(/^>\s*/,'');
254
+
255
+ line_qual =~ /(^[^\s]+)/
256
+ # remove comments
257
+
258
+ @seq_qual_name = $1
259
+ seq_qual='';
260
+
261
+ # si hay algo que devolver, romper bucle
262
+ if res
263
+ break
264
+ end
265
+
266
+ else # no es una linea de nombre, añadir al fasta
267
+ line_qual.strip! if !line_qual.empty?
268
+ #add line to qual of seq
269
+ seq_qual=seq_qual+' '+line_qual
270
+ seq_qual.strip! if !seq_qual.empty?
271
+ end
272
+
273
+ end
274
+
275
+
276
+ #si no hay más secuencias hay que devolver la última, CASO EOF
277
+ if res.nil? and !@seq_qual_name.empty?
278
+ seq_qual.gsub!(/\s\s+/,' ')
279
+ res= [@seq_qual_name,seq_qual]
280
+ end
281
+
282
+ return res
283
+ end
284
+
285
+
286
+
287
+
288
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/scbi_fasta.rb'}"
9
+ puts "Loading scbi_fasta gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
@@ -0,0 +1,65 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestFastaFile < Test::Unit::TestCase
4
+
5
+ def setup
6
+ @test_file='/tmp/fbinfile';
7
+
8
+ @seq_fasta='ACTG'
9
+ @seq_qual=[25]
10
+ @seq_name='SEQ'
11
+
12
+ end
13
+
14
+
15
+ def fill_file(n)
16
+ f=File.new(@test_file+'.fasta','w')
17
+ q=File.new(@test_file+'.qual','w')
18
+
19
+ n.times do |c|
20
+ i = c+1
21
+ name = ">#{@seq_name+i.to_s} comments"
22
+
23
+ f.puts(name)
24
+ f.puts(@seq_fasta*i)
25
+
26
+ q.puts(name)
27
+ q.puts((@seq_qual*i*@seq_fasta.length).join(' '))
28
+
29
+
30
+ end
31
+
32
+ f.close
33
+ q.close
34
+ end
35
+
36
+ def test_each
37
+
38
+ # make new file and fill with data
39
+ fill_file(100)
40
+
41
+ fqr=FastaFile.new(@test_file+'.fasta')
42
+
43
+ i=1
44
+
45
+
46
+ fqr.each do |n,s|
47
+
48
+ #puts n,s.length,q.split(' ').length
49
+ assert(@seq_name+i.to_s==n)
50
+ assert(@seq_fasta*i==s)
51
+
52
+ i+=1
53
+ end
54
+
55
+ fqr.close
56
+
57
+ rescue Exception => e
58
+ puts "failed in #{n} , #{s}"
59
+ puts "expected #{@seq_name+i.to_s} , #{@seq_fasta*i==s}"
60
+
61
+ puts e.message, e.backtrace
62
+
63
+ end
64
+
65
+ end
@@ -0,0 +1,161 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestFastaQualFile < Test::Unit::TestCase
4
+
5
+
6
+ def setup
7
+ @test_file='/tmp/fbinfile';
8
+
9
+ @seq_fasta='ACTG'
10
+ @seq_qual=[25]
11
+ @seq_name='SEQ'
12
+
13
+ end
14
+
15
+
16
+ def fill_file(n)
17
+ f=File.new(@test_file+'.fasta','w')
18
+ q=File.new(@test_file+'.qual','w')
19
+
20
+ n.times do |c|
21
+ i = c+1
22
+ name = ">#{@seq_name+i.to_s} comments"
23
+
24
+ f.puts(name)
25
+ f.puts(@seq_fasta*i)
26
+
27
+ q.puts(name)
28
+ q.puts((@seq_qual*i*@seq_fasta.length).join(' '))
29
+
30
+
31
+ end
32
+
33
+ f.close
34
+ q.close
35
+ end
36
+
37
+ def test_next_seq
38
+
39
+ # make new file and fill with data
40
+ fill_file(100)
41
+
42
+
43
+ fqr=FastaQualFile.new(@test_file+'.fasta',@test_file+'.qual')
44
+ n,s,q = ['']*3
45
+ i=0
46
+
47
+ 100.times do |c|
48
+ i = c+1
49
+ n,s,q = fqr.next_seq
50
+
51
+ #puts n,s.length,q.split(' ').length
52
+ assert(@seq_name+i.to_s==n)
53
+ assert(@seq_fasta*i==s)
54
+ assert((@seq_qual*i*@seq_fasta.length).join(' ')==q)
55
+
56
+ end
57
+
58
+ fqr.close
59
+
60
+ rescue Exception => e
61
+ puts "failed in #{n} , #{s}, #{q}"
62
+ puts "expected #{@seq_name+i.to_s} , #{@seq_fasta*i==s}, #{(@seq_qual*i*@seq_fasta.length).join(' ')}"
63
+ puts e.message, e.backtrace
64
+
65
+ end
66
+
67
+ def test_each
68
+
69
+ # make new file and fill with data
70
+ fill_file(100)
71
+
72
+
73
+ fqr=FastaQualFile.new(@test_file+'.fasta',@test_file+'.qual')
74
+
75
+ i=1
76
+
77
+ fqr.each do |n,s,q|
78
+
79
+ #puts n,s.length,q.split(' ').length
80
+ assert(@seq_name+i.to_s==n)
81
+ assert(@seq_fasta*i==s)
82
+ assert((@seq_qual*i*@seq_fasta.length).join(' ')==q)
83
+
84
+ i+=1
85
+ end
86
+
87
+ fqr.close
88
+
89
+ rescue Exception => e
90
+ puts "failed in #{n} , #{s}, #{q}"
91
+ puts "expected #{@seq_name+i.to_s} , #{@seq_fasta*i==s}, #{(@seq_qual*i*@seq_fasta.length).join(' ')}"
92
+ puts e.message, e.backtrace
93
+
94
+ end
95
+
96
+ def test_next_seq_only_fasta
97
+
98
+ # make new file and fill with data
99
+ fill_file(100)
100
+
101
+
102
+ fqr=FastaQualFile.new(@test_file+'.fasta')
103
+ n,s = ['']*2
104
+ i=0
105
+
106
+ 100.times do |c|
107
+ i = c+1
108
+ n,s,q = fqr.next_seq
109
+
110
+ #puts n,s.length,q.split(' ').length
111
+ assert(@seq_name+i.to_s==n)
112
+ assert(@seq_fasta*i==s)
113
+ assert(q.nil?)
114
+
115
+ end
116
+
117
+ fqr.close
118
+
119
+ rescue Exception => e
120
+ puts "failed in #{n} , #{s}"
121
+ puts "expected #{@seq_name+i.to_s} , #{@seq_fasta*i==s}"
122
+ puts e.message, e.backtrace
123
+
124
+ end
125
+
126
+
127
+ def test_each_only_fasta
128
+
129
+ count=100
130
+ # make new file and fill with data
131
+ fill_file(count)
132
+
133
+
134
+ fqr=FastaQualFile.new(@test_file+'.fasta')
135
+
136
+ i=1
137
+
138
+ fqr.each do |n,s,q|
139
+
140
+ #puts n,s.length,q.split(' ').length
141
+ assert(@seq_name+i.to_s==n)
142
+ assert(@seq_fasta*i==s)
143
+
144
+ assert(q.nil?)
145
+
146
+ i+=1
147
+ end
148
+
149
+ assert(i==count+1)
150
+
151
+ fqr.close
152
+
153
+ rescue Exception => e
154
+ puts "failed in #{n} , #{s}"
155
+ puts "expected #{@seq_name+i.to_s} , #{@seq_fasta*i==s}"
156
+ puts e.message, e.backtrace
157
+
158
+ end
159
+
160
+
161
+ end
@@ -0,0 +1,4 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/scbi_fasta'
4
+
metadata ADDED
@@ -0,0 +1,83 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scbi_fasta
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.1.8
6
+ platform: ruby
7
+ authors:
8
+ - Almudena Bocinos
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-13 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: 2.8.0
24
+ type: :development
25
+ version_requirements: *id001
26
+ description: scbi_fasta is a ruby gem to read FASTA+QUAL files (DNA/RNA sequences).
27
+ email:
28
+ - alkoke@gmail.com
29
+ executables: []
30
+
31
+ extensions: []
32
+
33
+ extra_rdoc_files:
34
+ - History.txt
35
+ - Manifest.txt
36
+ - PostInstall.txt
37
+ files:
38
+ - History.txt
39
+ - Manifest.txt
40
+ - PostInstall.txt
41
+ - README.rdoc
42
+ - Rakefile
43
+ - lib/scbi_fasta.rb
44
+ - lib/scbi_fasta/fasta_qual_file.rb
45
+ - lib/scbi_fasta/fasta_file.rb
46
+ - script/console
47
+ - script/destroy
48
+ - script/generate
49
+ - test/test_helper.rb
50
+ - test/test_fasta_file.rb
51
+ - test/test_fasta_qual_file.rb
52
+ homepage: http://www.scbi.uma.es/downloads
53
+ licenses: []
54
+
55
+ post_install_message: PostInstall.txt
56
+ rdoc_options:
57
+ - --main
58
+ - README.rdoc
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project: scbi_fasta
76
+ rubygems_version: 1.7.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: scbi_fasta is a ruby gem to read FASTA+QUAL files (DNA/RNA sequences).
80
+ test_files:
81
+ - test/test_fasta_file.rb
82
+ - test/test_fasta_qual_file.rb
83
+ - test/test_helper.rb