spec/dummy/quorum/lib/search_tools/blast.rb in quorum-0.3.3 vs spec/dummy/quorum/lib/search_tools/blast.rb in quorum-0.4.0
- old
+ new
@@ -124,10 +124,13 @@
#
def create_hash(sequence)
Digest::MD5.hexdigest(sequence).to_s + "-" + Time.now.to_f.to_s
end
+ #
+ # Blastn command
+ #
def generate_blastn_cmd
blastn = "blastn " <<
"-db \"#{@db}\" " <<
"-query #{@na_fasta} " <<
"-outfmt 5 " <<
@@ -143,10 +146,13 @@
end
blastn << "-dust yes " if @filter
blastn
end
+ #
+ # Blastx command
+ #
def generate_blastx_cmd
blastx = "blastx " <<
"-db \"#{@db}\" " <<
"-query #{@na_fasta} " <<
"-outfmt 5 " <<
@@ -162,10 +168,13 @@
end
blastx << "-seg yes " if @filter
blastx
end
+ #
+ # Tblastn command
+ #
def generate_tblastn_cmd
tblastn = "tblastn " <<
"-db \"#{@db}\" " <<
"-query #{@aa_fasta} " <<
"-outfmt 5 " <<
@@ -183,10 +192,13 @@
end
tblastn << "-seg yes " if @filter
tblastn
end
+ #
+ # Blastp command
+ #
def generate_blastp_cmd
blastp = "blastp " <<
"-db \"#{@db}\" " <<
"-query #{@aa_fasta} " <<
"-outfmt 5 " <<
@@ -254,16 +266,69 @@
return hit_display_id, hit_def
end
#
- # Parse and save Blast results using bio-blastxmlparser.
- # Only save Blast results if results.bit_score > @min_score.
+ # Save Blast Job Report
#
+ # Hsps are only reported if a query hit against the Blast db.
+ # Only save the @data if bit_score exists and it's > the user
+ # defined minimum score.
+ #
+ # Set the attribute results to true for downstream processes.
+ #
+ def save_hsp_results
+ if @data[:bit_score] && (@data[:bit_score].to_i > @min_score.to_i)
+ @data[:results] = true
+ @data["#{@algorithm}_job_id".to_sym] = @job.method(@job_association).call.job_id
+
+ job_report = @job.method(@job_report_association).call.build(@data)
+
+ unless job_report.save!
+ @logger.log(
+ "ActiveRecord",
+ "Unable to save #{@algorithm} results to database.",
+ 1,
+ @tmp_files
+ )
+ end
+ end
+ end
+
+ #
+ # Save empty Blast Job Report
+ #
+ # Set the attribute results to false for downstream processes.
+ #
+ def save_empty_results
+ job_report = @job.method(@job_report_association).call.build(
+ "#{@algorithm}_job_id" => @job.method(@job_association).call.job_id,
+ "results" => false
+ )
+ unless job_report.save!
+ @logger.log(
+ "ActiveRecord",
+ "Unable to save #{@algorithm} results to database.",
+ 1,
+ @tmp_files
+ )
+ end
+ @logger.log(
+ "NCBI Blast",
+ "#{@algorithm} report empty.",
+ 0,
+ @tmp_files
+ )
+ end
+
+ #
+ # Parse and save Blast results.
+ #
+ # Parse the Blast XML output and save results.
+ #
def parse_and_save_results
- # Helper to avoid having to perform a query.
- saved = false
+ @results = false # Did the xml contain results?
if File.size(@out) > 0
report = Bio::Blast::XmlIterator.new(@out)
report.to_enum.each do |iteration|
@@ -290,60 +355,28 @@
@data[:hit_to] = hsp.hit_to
@data[:query_frame] = hsp.query_frame
@data[:hit_frame] = hsp.hit_frame
@data[:identity] = hsp.identity
@data[:positive] = hsp.positive
+ @data[:gaps] = hsp.gaps
@data[:align_len] = hsp.align_len
@data[:qseq] = hsp.qseq
@data[:hseq] = hsp.hseq
@data[:midline] = hsp.midline
- # Hsps are only reported if a query hit against the Blast db.
- # Only save the @data if bit_score exists.
if @data[:bit_score] &&
(@data[:bit_score].to_i > @min_score.to_i)
- @data[:results] = true
- @data["#{@algorithm}_job_id".to_sym] = @job.method(@job_association).call.job_id
- saved = true
- # Build a new report for each Hsp.
- job_report = @job.method(@job_report_association).call.build(@data)
- unless job_report.save!
- @logger.log(
- "ActiveRecord",
- "Unable to save #{@algorithm} results to database.",
- 1,
- @tmp_files
- )
- end
+ @results = true
+ save_hsp_results
end
end
end
end
end
- # Save the record and set results to false.
- unless saved
- job_report = @job.method(@job_report_association).call.build(
- "#{@algorithm}_job_id" => @job.method(@job_association).call.job_id,
- "results" => false
- )
- unless job_report.save!
- @logger.log(
- "ActiveRecord",
- "Unable to save #{@algorithm} results to database.",
- 1,
- @tmp_files
- )
- end
- @logger.log(
- "NCBI Blast",
- "#{@algorithm} report empty.",
- 0,
- @tmp_files
- )
- end
+ save_empty_results unless @results
end
#
# Group record ids of hsps belonging to the same query and hit_accession.
#
@@ -386,9 +419,12 @@
end
end
end
end
+ #
+ # Remove tmp files.
+ #
def remove_tmp_files
`rm #{@tmp_files}` if @tmp_files
end
public