class Bio::Blast::Default::Report::Iteration
Bio::Blast::Default::Report::Iteration stores information about a iteration. It may contain some Bio::Blast::Default::Report::Hit objects. Note that a PSI-BLAST (blastpgp command) result usually contain multiple iterations in it, and a normal BLAST (blastall command) result usually contain one iteration in it.
Attributes
name (title or filename) of the database
number of sequences in database
number of letters in database
effective length of the database
entropy of the database
e-value threshold specified when BLAST was executed
gapped entropy of the database
gapped kappa of the database
gapped lambda of the database
kappa of the database
lambda of the database
(PSI-BLAST) Messages of the iteration.
(PSI-BLAST) Iteration round number.
(PHI-BLAST) Number of occurrences of pattern in the database.
posted date of the database
Public Class Methods
Creates a new Iteration object. It is designed to be called only internally from the Bio::Blast::Default::Report class. Users shall not use the method directly.
# File lib/bio/appl/blast/format0.rb, line 485 def initialize(data) @f0stat = [] @f0dbstat = AlwaysNil.instance @f0hitlist = [] @hits = [] @num = 1 r = data.shift @f0message = [ r ] r.gsub!(/^Results from round (\d+).*\z/) { |x| @num = $1.to_i @f0message << x '' } r = data.shift while /^Number of occurrences of pattern in the database is +(\d+)/ =~ r # PHI-BLAST @pattern_in_database = $1.to_i @f0message << r r = data.shift end if /^Results from round (\d+)/ =~ r then @num = $1.to_i @f0message << r r = data.shift end if r and !(/\*{5} No hits found \*{5}/ =~ r) then @f0hitlist << r begin @f0hitlist << data.shift end until r = data[0] and /^\>/ =~ r if r and /^CONVERGED\!/ =~ r then r.sub!(/(.*\n)*^CONVERGED\!.*\n/) { |x| @f0hitlist << x; '' } end if defined?(@pattern_in_database) and r = data.first then #PHI-BLAST while /^\>/ =~ r @hits << Hit.new(data) r = data.first break unless r while /^Significant alignments for pattern/ =~ r data.shift r = data.first end end else #not PHI-BLAST while r = data[0] and /^\>/ =~ r @hits << Hit.new(data) end end end if /^CONVERGED\!\s*$/ =~ @f0hitlist[-1].to_s then @message = 'CONVERGED!' @flag_converged = true end end
Private Class Methods
Defines attributes which delegate to @f0dbstat objects.
# File lib/bio/appl/blast/format0.rb, line 755 def self.delegate_to_f0dbstat(*names) names.each do |x| module_eval("def #{x}; @f0dbstat.#{x}; end") end end
Defines attributes which call parse_stat
before accessing.
# File lib/bio/appl/blast/format0.rb, line 727 def self.method_after_parse_stat(*names) names.each do |x| module_eval("def #{x}; parse_stat; @#{x}; end") end end
Public Instance Methods
(PSI-BLAST) Returns true if the iteration is converged. Otherwise, returns false.
# File lib/bio/appl/blast/format0.rb, line 566 def converged? @flag_converged end
Iterates over each hit of the iteration. Yields a Bio::Blast::Default::Report::Hit object.
# File lib/bio/appl/blast/format0.rb, line 558 def each hits.each do |x| yield x end end
Returns the hits of the iteration. It returns an array of Bio::Blast::Default::Report::Hit objects.
# File lib/bio/appl/blast/format0.rb, line 551 def hits parse_hitlist @hits end
(PHI-BLAST) Returns hits for pattern. ????
# File lib/bio/appl/blast/format0.rb, line 614 def hits_for_pattern parse_hitlist @hits_for_pattern end
(PSI-BLAST) Returns hits which have been found again in the iteration. It returns an array of Bio::Blast::Default::Report::Hit objects.
# File lib/bio/appl/blast/format0.rb, line 600 def hits_found_again parse_hitlist @hits_found_again end
(PSI-BLAST) Returns hits which have been newly found in the iteration. It returns an array of Bio::Blast::Default::Report::Hit objects.
# File lib/bio/appl/blast/format0.rb, line 608 def hits_newly_found parse_hitlist @hits_newly_found end
(PHI-BLAST) Returns pattern string. Returns nil if it is not a PHI-BLAST result.
# File lib/bio/appl/blast/format0.rb, line 572 def pattern #PHI-BLAST if !defined?(@pattern) and defined?(@pattern_in_database) then @pattern = nil @pattern_positions = [] @f0message.each do |r| sc = StringScanner.new(r) if sc.skip_until(/^ *pattern +([^\s]+)/) then @pattern = sc[1] unless @pattern sc.skip_until(/(?:^ *| +)at position +(\d+) +of +query +sequence/) @pattern_positions << sc[1].to_i end end end @pattern end
(PHI-BLAST) Returns pattern positions. Returns nil if it is not a PHI-BLAST result.
# File lib/bio/appl/blast/format0.rb, line 591 def pattern_positions #PHI-BLAST pattern @pattern_positions end
Private Instance Methods
Parses list of hits.
# File lib/bio/appl/blast/format0.rb, line 620 def parse_hitlist unless defined?(@parse_hitlist) @hits_found_again = [] @hits_newly_found = [] @hits_unknown_state = [] i = 0 a = @hits_newly_found flag = true @f0hitlist.each do |x| sc = StringScanner.new(x) if flag then if sc.skip_until(/^Sequences used in model and found again\:\s*$/) a = @hits_found_again end flag = nil next end next if sc.skip(/^CONVERGED\!$/) if sc.skip(/^Sequences not found previously or not previously below threshold\:\s*$/) then a = @hits_newly_found next elsif sc.skip(/^Sequences.+\:\s*$/) then #possibly a bug or unknown format? a = @hits_unknown_state next elsif sc.skip(/^Significant (matches|alignments) for pattern/) then # PHI-BLAST # do nothing when 'alignments' if sc[1] == 'matches' then unless defined?(@hits_for_pattern) @hits_for_pattern = [] end a = [] @hits_for_pattern << a end next end b = x.split(/^/) b.collect! { |y| y.empty? ? nil : y } b.compact! if i + b.size > @hits.size then ((@hits.size - i)...(b.size)).each do |j| y = b[j]; y.strip! y.reverse! z = y.split(/\s+/, 3) z.each { |y| y.reverse! } h = Hit.new([ z.pop.to_s.sub(/\.+\z/, '') ]) bs = z.pop.to_s bs = '1' + bs if bs[0] == ?e bs = (bs.empty? ? nil : bs.to_f) ev = z.pop.to_s ev = '1' + ev if ev[0] == ?e ev = (ev.empty? ? (1.0/0.0) : ev.to_f) h.instance_eval { @bit_score = bs; @evalue = ev } @hits << h end end a.concat(@hits[i, b.size]) i += b.size end #each @hits_found_again.each do |x| x.instance_eval { @again = true } end @parse_hitlist = true end #unless end
Parses statistics for the iteration.
# File lib/bio/appl/blast/format0.rb, line 689 def parse_stat unless defined?(@parse_stat) @f0stat.each do |x| gapped = nil sc = StringScanner.new(x) sc.skip(/\s*/) if sc.skip(/Gapped\s*/) then gapped = true end s0 = [] h = {} while r = sc.scan(/\w+/) #p r s0 << r sc.skip(/ */) end sc.skip(/\s*/) while r = sc.scan(/[e\+\-\.\d]+/) #p r h[s0.shift] = r sc.skip(/ */) end if gapped then @gapped_lambda = (v = h['Lambda']) ? v.to_f : nil @gapped_kappa = (v = h['K']) ? v.to_f : nil @gapped_entropy = (v = h['H']) ? v.to_f : nil else @lambda = (v = h['Lambda']) ? v.to_f : nil @kappa = (v = h['K']) ? v.to_f : nil @entropy = (v = h['H']) ? v.to_f : nil end end #each @parse_stat = true end #unless end