Assignment 4/Assignment4.rb
# 4. Doing a BLAST and retrieving the best hit with parameters 
4. Doing a BLAST and retrieving the best hit with parameters
4 . Doing a BLAST and retrieving the best hit with parameters
def blast_best_hit(prog,db,query)
  evalue_threshold = 1e-06 
  coverage_threshold = 0.5
  factory = Bio::Blast.local(prog,"#{File.dirname(db)}/#{File.basename(db,".fa")}") 
  report = factory.query(query)
  if report.hits[0] != nil 
    if prog == "tblastn"
      coverage = report.hits[0].overlap.to_f/query.length.to_f
    elsif prog == "blastx"
      entry_length = query.length/3
      coverage = report.hits[0].overlap.to_f/entry_length.to_f
    end
    evalue = report.hits[0].evalue.to_f
    if coverage >= coverage_threshold && evalue <= evalue_threshold
      return report.hits[0].definition.split("|")[0].strip
    end
  end
end
def blast_best_hit ( prog , db , query ) evalue_threshold = 1e-06 coverage_threshold = 0.5 factory = Bio :: Blast . local ( prog , "#{File.dirname(db)}/#{File.basename(db,".fa")}" ) report = factory . query ( query ) if report . hits [ 0 ] != nil if prog == "tblastn" coverage = report . hits [ 0 ] . overlap . to_f / query . length . to_f elsif prog == "blastx" entry_length = query . length / 3 coverage = report . hits [ 0 ] . overlap . to_f / entry_length . to_f end evalue = report . hits [ 0 ] . evalue . to_f if coverage >= coverage_threshold && evalue <= evalue_threshold return report . hits [ 0 ] . definition . split ( "|" ) [ 0 ] . strip end end end
4.
4 .
# defining parameters: evalue, coverage # 1. create a BLAST factory # local_blast_factory = Bio::Blast.local('blastn','/path/to/db') # 2. run actual BLAST by querying the factory
prog
<not_specific>
db
<not_specific>
query
<not_specific>