Skip to content

Commit

Permalink
Bug fix: fixed ScanError when bit score is in exponential notation
Browse files Browse the repository at this point in the history
* Bug fix: fixed ScanError when bit score is in exponential notation
  such as 1.234e+5.
* Regular expressions for numerics including exponential notations
  are changed to get correct values.
  • Loading branch information
ngoto committed Jul 29, 2008
1 parent 88b2fb2 commit 9256ce8
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions lib/bio/appl/blast/format0.rb
Expand Up @@ -345,7 +345,7 @@ def parse_colon_separated_params(hash, ary)
sc = StringScanner.new(str) sc = StringScanner.new(str)
sc.skip(/\s*/) sc.skip(/\s*/)
while sc.rest? while sc.rest?
if sc.match?(/Number of sequences better than +([e\-\.\d]+) *\: *(.+)/) then if sc.match?(/Number of sequences better than +([e\+\-\.\d]+) *\: *(.+)/) then
ev = sc[1] ev = sc[1]
ev = '1' + ev if ev[0] == ?e ev = '1' + ev if ev[0] == ?e
@expect = ev.to_f @expect = ev.to_f
Expand All @@ -369,7 +369,7 @@ def parse_params
parse_colon_separated_params(@hash, @f0params) parse_colon_separated_params(@hash, @f0params)
#p @hash #p @hash
if val = @hash['Matrix'] then if val = @hash['Matrix'] then
if /blastn *matrix *\: *([e\-\.\d]+) +([e\-\.\d]+)/ =~ val then if /blastn *matrix *\: *([e\+\-\.\d]+) +([e\+\-\.\d]+)/ =~ val then
@matrix = 'blastn' @matrix = 'blastn'
@sc_match = $1.to_i @sc_match = $1.to_i
@sc_mismatch = $2.to_i @sc_mismatch = $2.to_i
Expand All @@ -378,10 +378,10 @@ def parse_params
end end
end end
if val = @hash['Gap Penalties'] then if val = @hash['Gap Penalties'] then
if /Existence\: *([e\-\.\d]+)/ =~ val then if /Existence\: *([e\+\-\.\d]+)/ =~ val then
@gap_open = $1.to_i @gap_open = $1.to_i
end end
if /Extension\: *([e\-\.\d]+)/ =~ val then if /Extension\: *([e\+\-\.\d]+)/ =~ val then
@gap_extend = $1.to_i @gap_extend = $1.to_i
end end
end end
Expand Down Expand Up @@ -716,7 +716,7 @@ def parse_stat
sc.skip(/ */) sc.skip(/ */)
end end
sc.skip(/\s*/) sc.skip(/\s*/)
while r = sc.scan(/[e\.\-\d]+/) while r = sc.scan(/[e\+\-\.\d]+/)
#p r #p r
h[s0.shift] = r h[s0.shift] = r
sc.skip(/ */) sc.skip(/ */)
Expand Down Expand Up @@ -973,11 +973,11 @@ def parse_score
sc = StringScanner.new(@f0score) sc = StringScanner.new(@f0score)
while sc.rest? while sc.rest?
sc.skip(/\s*/) sc.skip(/\s*/)
if sc.skip(/Expect(?:\(\d+\))? *\= *([e\-\.\d]+)/) then if sc.skip(/Expect(?:\(\d+\))? *\= *([e\+\-\.\d]+)/) then
ev = sc[1].to_s ev = sc[1].to_s
ev = '1' + ev if ev[0] == ?e ev = '1' + ev if ev[0] == ?e
@evalue = ev.to_f @evalue = ev.to_f
elsif sc.skip(/Score *\= *([e\-\.\d]+) *bits *\( *([e\-\.\d]+) *\)/) then elsif sc.skip(/Score *\= *([e\+\-\.\d]+) *bits *\( *([e\+\-\.\d]+) *\)/) then
bs = sc[1] bs = sc[1]
bs = '1' + bs if bs[0] == ?e bs = '1' + bs if bs[0] == ?e
@bit_score = bs.to_f @bit_score = bs.to_f
Expand Down Expand Up @@ -1021,19 +1021,19 @@ def parse_score
if sc[2] then if sc[2] then
@hit_frame = sc[3].to_i @hit_frame = sc[3].to_i
end end
elsif sc.skip(/Score *\= *([e\-\.\d]+) +\(([e\-\.\d]+) *bits *\)/) then elsif sc.skip(/Score *\= *([e\+\-\.\d]+) +\(([e\+\-\.\d]+) *bits *\)/) then
#WU-BLAST #WU-BLAST
@score = sc[1].to_i @score = sc[1].to_i
bs = sc[2] bs = sc[2]
bs = '1' + bs if bs[0] == ?e bs = '1' + bs if bs[0] == ?e
@bit_score = bs.to_f @bit_score = bs.to_f
elsif sc.skip(/P *\= * ([e\-\.\d]+)/) then elsif sc.skip(/P *\= * ([e\+\-\.\d]+)/) then
#WU-BLAST #WU-BLAST
@p_sum_n = nil @p_sum_n = nil
pv = sc[1] pv = sc[1]
pv = '1' + pv if pv[0] == ?e pv = '1' + pv if pv[0] == ?e
@pvalue = pv.to_f @pvalue = pv.to_f
elsif sc.skip(/Sum +P *\( *(\d+) *\) *\= *([e\-\.\d]+)/) then elsif sc.skip(/Sum +P *\( *(\d+) *\) *\= *([e\+\-\.\d]+)/) then
#WU-BLAST #WU-BLAST
@p_sum_n = sc[1].to_i @p_sum_n = sc[1].to_i
pv = sc[2] pv = sc[2]
Expand Down

0 comments on commit 9256ce8

Please sign in to comment.