class BlastQuery

Object to encapsulate a Blast Query

Attributes

full_query_length[RW]
hits[RW]
query_def[RW]
query_id[RW]

Public Class Methods

new(query_id) click to toggle source

initializes a new Query object

# File lib/scbi_blast/blast_query.rb, line 30
def initialize(query_id)
  @query_id = query_id
  @query_def = query_id
  @full_query_length = 0
  @hits = []
  # inspect
end

Public Instance Methods

add_hit(h) click to toggle source

add a hit to query

# File lib/scbi_blast/blast_query.rb, line 39
def add_hit(h)
  @hits.push h
end
compare?(query) click to toggle source
# File lib/scbi_blast/blast_query.rb, line 78
def compare?(query)
  res=true
  

  # same hits
  res &&=( @hits.count==query.hits.count)
  
  # if !res
  #    puts "Queries not equal:"
  #    puts inspect
  #    puts "="*20
  #    puts query.inspect
  #  end
  
  if res
    @hits.each_with_index do |h,i|
      res &&= h.compare?(query.hits[i])
    end
  end
  
  # if !res
  #    puts "Queries hits not equal:"
  #    puts inspect
  #    puts "="*20
  #    puts query.inspect
  #  end
  
  res &&=( @query_id==query.query_id)
  res &&=( @query_def==query.query_def)
  res &&=( @full_query_length==query.full_query_length)
  
  
  return res
end
inspect() click to toggle source

inspect query values with all hits

# File lib/scbi_blast/blast_query.rb, line 44
def inspect
  res = "\n * Query  #{@query_id}, #{@query_def}, #{@full_query_length} :"
  res += "subject_id ident align_len mismatches gaps q_beg q_end s_beg s_end e_val bit_score reversed\n\n"
  @hits.each{ |h| res+= "=="+h.inspect+"\n" }

  return res
end
merged_hits!(overlap_threshold=0, merged_ids=nil) click to toggle source

merge overlapping hits

# File lib/scbi_blast/blast_query.rb, line 63
def merged_hits!(overlap_threshold=0, merged_ids=nil)
  res = []

  merge_hits(@hits,res,merged_ids)

  begin
    res2=res # iterate until no more overlaps
    res = []
    merge_hits(res2,res,merged_ids)
  end until (res2.count == res.count)


  return res
end
size() click to toggle source

get num of hits

# File lib/scbi_blast/blast_query.rb, line 53
def size
  return @hits.size
end
sort(comand) click to toggle source

sort hits by command

# File lib/scbi_blast/blast_query.rb, line 58
def sort(comand)
  return @hits.sort(comand)
end

Private Instance Methods

merge_hits(hits,merged_hits,merged_ids=nil) click to toggle source

do only one iteration of merge hits

# File lib/scbi_blast/blast_query.rb, line 116
def merge_hits(hits,merged_hits,merged_ids=nil)
  # puts " merging ============"
  hits.each do |hit|

    # save definitions
    merged_ids.push hit.definition if !merged_ids.nil? && (!merged_ids.include?(hit.definition))

    # find overlapping hits
    c=merged_hits.find{|c2| hit.query_overlaps?(c2)}

    if (c.nil?)
      # add new hit
      merged_hits.push(hit.dup)
    else

      # merge with old hit
      c.q_beg=[c.q_beg,hit.q_beg].min
      c.q_end=[c.q_end,hit.q_end].max

      c.subject_id += ' ' + hit.subject_id if (not c.subject_id.include?(hit.subject_id))

    end

  end
end