class MgNu::Parser::Blast::Format8
Attributes
queries[RW]
Public Class Methods
new(input)
click to toggle source
create a new Format8
parser object
# File lib/mgnu/parser/blast/format8.rb, line 15 def initialize(input) @query = nil @sbjct = nil @queries = [] @input = input end
Public Instance Methods
each() { |query| ... }
click to toggle source
# File lib/mgnu/parser/blast/format8.rb, line 23 def each @input.each do |line| next if line =~ /^#/ # skip comments temp = line.split(/\t/) query_id = temp.shift if @query.nil? @query = Query.new @query.query_id = query_id end if @query.query_id == query_id # already on this query, so just add the sbject extract_sbjct(temp) else # new query_id, save this one and start on new one @query.sbjcts << @sbjct @sbjct = nil yield @query @query = Query.new @query.query_id = query_id extract_sbjct(temp) end end end
extract_hsp(input)
click to toggle source
# File lib/mgnu/parser/blast/format8.rb, line 102 def extract_hsp(input) hsp = Hsp.new hsp.identity = input.shift.to_f hsp.length = input.shift.to_i hsp.mismatches = input.shift.to_i hsp.gap_count = input.shift.to_i hsp.query_from = input.shift.to_i hsp.query_to = input.shift.to_i hsp.sbjct_from = input.shift.to_i hsp.sbjct_to = input.shift.to_i hsp.evalue = input.shift.to_f hsp.bit_score = input.shift.to_f @sbjct.hsps << hsp end
extract_sbjct(input)
click to toggle source
# File lib/mgnu/parser/blast/format8.rb, line 85 def extract_sbjct(input) sbjct_id = input.shift if @sbjct.nil? @sbjct = Sbjct.new @sbjct.sbjct_id = sbjct_id end if @sbjct.sbjct_id == sbjct_id extract_hsp(input) else @query.sbjcts << @sbjct @sbjct = Sbjct.new @sbjct.sbjct_id = sbjct_id extract_hsp(input) end end
parse()
click to toggle source
# File lib/mgnu/parser/blast/format8.rb, line 51 def parse @input.each do |line| next if line =~ /^#/ # skip comments temp = line.split query_id = temp.shift if @query.nil? @query = Query.new @query.query_id = query_id end if @query.query_id == query_id # already on this query, so just add the sbject extract_sbjct(temp) else # new query_id, save this one and start on new one @query.sbjcts << @sbjct @queries << @query @sbjct = nil @query = Query.new @query.query_id = query_id extract_sbjct(temp) end end # end of input.each do |line| #grab the last ones, if present unless @query.nil? @query.sbjcts << @sbjct @queries << @query end end