scbi_fasta 0.1.8 → 0.1.9

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.
@@ -1,3 +1,7 @@
1
+ === 0.1.9 2011-10-28
2
+
3
+ Also parses and returns comment lines in each and nextseq
4
+
1
5
  === 0.1.8 2011-06-13
2
6
 
3
7
  first rubygems published
@@ -8,5 +8,5 @@ require 'fasta_file'
8
8
 
9
9
 
10
10
  module ScbiFasta
11
- VERSION = '0.1.8'
11
+ VERSION = '0.1.9'
12
12
  end
@@ -34,11 +34,12 @@ attr_accessor :num_seqs, :end_fasta
34
34
  @with_qual = false
35
35
  #raise "File #{qual_file_name} doesn't exists"
36
36
  end
37
-
37
+ # puts "With_qual #{fasta_file_name}?: #{@with_qual}"
38
38
 
39
39
  @num_seqs = 0 ;
40
40
 
41
41
  @seq_name = '';
42
+ @seq_comment='';
42
43
  @file_fasta = File.open(fasta_file_name) ;
43
44
  @end_fasta=false;
44
45
 
@@ -67,16 +68,17 @@ attr_accessor :num_seqs, :end_fasta
67
68
 
68
69
  rewind
69
70
 
70
- n,f,q=next_seq
71
+ n,f,q,c = next_seq
71
72
  while (!n.nil?)
72
73
 
73
74
  if @with_qual
74
- yield(n,f,q)
75
+
76
+ yield(n,f,q,c)
75
77
  else
76
- yield(n,f)
78
+ yield(n,f,q)
77
79
  end
78
80
 
79
- n,f,q=next_seq
81
+ n,f,q,c=next_seq
80
82
  end
81
83
 
82
84
  rewind
@@ -89,6 +91,7 @@ attr_accessor :num_seqs, :end_fasta
89
91
  @num_seqs = 0 ;
90
92
 
91
93
  @seq_name = '';
94
+ @seq_comment= '';
92
95
  @file_fasta.pos=0
93
96
  @end_fasta=false;
94
97
 
@@ -111,7 +114,7 @@ attr_accessor :num_seqs, :end_fasta
111
114
  # envia on_process_sequence
112
115
  if ((!@end_fasta) && (!@with_qual or !@end_qual))
113
116
 
114
- name_f,fasta=read_fasta
117
+ name_f,fasta,comment=read_fasta
115
118
 
116
119
  if @with_qual
117
120
 
@@ -129,9 +132,9 @@ attr_accessor :num_seqs, :end_fasta
129
132
  if fasta.length == qual.count(' ') + 1
130
133
  if @qual_to_array
131
134
  a_qual = qual.strip.split(/\s/).map{|e| e.to_i}
132
- res =[name_f,fasta,a_qual]
135
+ res =[name_f,fasta,a_qual,comment]
133
136
  else
134
- res =[name_f,fasta,qual]
137
+ res =[name_f,fasta,qual,comment]
135
138
  end
136
139
 
137
140
  else #if (!a_qual.empty?)
@@ -141,7 +144,7 @@ attr_accessor :num_seqs, :end_fasta
141
144
  end
142
145
 
143
146
  else # without qual
144
- res =[name_f,fasta]
147
+ res =[name_f,fasta,comment]
145
148
  end
146
149
  end
147
150
 
@@ -179,17 +182,19 @@ attr_accessor :num_seqs, :end_fasta
179
182
  if !@seq_name.empty?
180
183
  # ya había leido una
181
184
  #puts "leida #{@seq_name} + #{@seq_fasta}"
182
- res = [@seq_name,seq_fasta]
185
+ res = [@seq_name,seq_fasta, @seq_comment]
183
186
  end
184
187
 
185
188
 
186
189
  #get only name
187
190
  line_fasta.gsub!(/^>\s*/,'');
188
191
 
189
- line_fasta =~ /(^[^\s]+)/
192
+ # line_fasta =~ /(^[^\s]+)/
193
+ line_fasta =~ /(^[^\s]+)\s*(.*)$/
190
194
  # remove comments
191
195
 
192
196
  @seq_name = $1
197
+ @seq_comment = $2
193
198
 
194
199
  seq_fasta='';
195
200
 
@@ -211,7 +216,7 @@ attr_accessor :num_seqs, :end_fasta
211
216
 
212
217
  #si no hay más secuencias hay que devolver la última, CASO EOF
213
218
  if res.nil? and !@seq_name.empty?
214
- res= [@seq_name,seq_fasta]
219
+ res= [@seq_name,seq_fasta, @seq_comment]
215
220
  end
216
221
 
217
222
  return res
@@ -4,7 +4,7 @@ class TestFastaQualFile < Test::Unit::TestCase
4
4
 
5
5
 
6
6
  def setup
7
- @test_file='/tmp/fbinfile';
7
+ @test_file='/tmp/scbi_fasta';
8
8
 
9
9
  @seq_fasta='ACTG'
10
10
  @seq_qual=[25]
@@ -19,7 +19,7 @@ class TestFastaQualFile < Test::Unit::TestCase
19
19
 
20
20
  n.times do |c|
21
21
  i = c+1
22
- name = ">#{@seq_name+i.to_s} comments"
22
+ name = ">#{@seq_name+i.to_s} comments#{i}"
23
23
 
24
24
  f.puts(name)
25
25
  f.puts(@seq_fasta*i)
@@ -46,13 +46,13 @@ class TestFastaQualFile < Test::Unit::TestCase
46
46
 
47
47
  100.times do |c|
48
48
  i = c+1
49
- n,s,q = fqr.next_seq
49
+ n,s,q,c = fqr.next_seq
50
50
 
51
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
-
52
+ assert_equal(@seq_name+i.to_s,n)
53
+ assert_equal(@seq_fasta*i,s)
54
+ assert_equal((@seq_qual*i*@seq_fasta.length).join(' '),q)
55
+ assert_equal('comments'+i.to_s,c)
56
56
  end
57
57
 
58
58
  fqr.close
@@ -74,13 +74,13 @@ class TestFastaQualFile < Test::Unit::TestCase
74
74
 
75
75
  i=1
76
76
 
77
- fqr.each do |n,s,q|
77
+ fqr.each do |n,s,q,c|
78
78
 
79
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
-
80
+ assert_equal(@seq_name+i.to_s,n)
81
+ assert_equal(@seq_fasta*i,s)
82
+ assert_equal((@seq_qual*i*@seq_fasta.length).join(' '),q)
83
+ assert_equal('comments'+i.to_s,c)
84
84
  i+=1
85
85
  end
86
86
 
@@ -105,11 +105,12 @@ class TestFastaQualFile < Test::Unit::TestCase
105
105
 
106
106
  100.times do |c|
107
107
  i = c+1
108
- n,s,q = fqr.next_seq
108
+ n,s,c,q = fqr.next_seq
109
109
 
110
- #puts n,s.length,q.split(' ').length
111
- assert(@seq_name+i.to_s==n)
112
- assert(@seq_fasta*i==s)
110
+ # puts n,s.length,q.split(' ').length
111
+ assert_equal(@seq_name+i.to_s,n)
112
+ assert_equal(@seq_fasta*i,s)
113
+ assert_equal('comments'+i.to_s,c)
113
114
  assert(q.nil?)
114
115
 
115
116
  end
@@ -135,12 +136,12 @@ class TestFastaQualFile < Test::Unit::TestCase
135
136
 
136
137
  i=1
137
138
 
138
- fqr.each do |n,s,q|
139
-
139
+ fqr.each do |n,s,c,q|
140
+ # puts n,s,q
140
141
  #puts n,s.length,q.split(' ').length
141
- assert(@seq_name+i.to_s==n)
142
- assert(@seq_fasta*i==s)
143
-
142
+ assert_equal(@seq_name+i.to_s,n)
143
+ assert_equal(@seq_fasta*i,s)
144
+ assert_equal('comments'+i.to_s,c)
144
145
  assert(q.nil?)
145
146
 
146
147
  i+=1
@@ -150,10 +151,10 @@ class TestFastaQualFile < Test::Unit::TestCase
150
151
 
151
152
  fqr.close
152
153
 
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
154
+ # rescue Exception => e
155
+ # puts "failed in #{n} , #{s}"
156
+ # puts "expected #{@seq_name+i.to_s} , #{@seq_fasta*i==s}"
157
+ # puts e.message, e.backtrace
157
158
 
158
159
  end
159
160
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: scbi_fasta
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.8
5
+ version: 0.1.9
6
6
  platform: ruby
7
7
  authors:
8
8
  - Almudena Bocinos
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-13 00:00:00 Z
13
+ date: 2011-10-28 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hoe