Class: GeneValidator::BlastReadingFrameValidation

Inherits:
ValidationTest show all
Extended by:
Forwardable
Defined in:
lib/genevalidator/validation_blast_reading_frame.rb

Overview

This class contains the methods necessary for reading frame validation based on BLAST output

Instance Attribute Summary

Attributes inherited from ValidationTest

#cli_name, #description, #header, #hits, #prediction, #run_time, #short_header, #type, #validation_report

Instance Method Summary collapse

Constructor Details

#initialize(type, prediction, hits = nil) ⇒ BlastReadingFrameValidation

Returns a new instance of BlastReadingFrameValidation.



86
87
88
89
90
91
92
93
94
# File 'lib/genevalidator/validation_blast_reading_frame.rb', line 86

def initialize(type, prediction, hits = nil)
  super
  @short_header = 'ReadingFrame'
  @header       = 'Reading Frame'
  @description  = 'Check whether there is a single reading frame among' \
                  ' BLAST hits. Otherwise there might be a reading frame' \
                  ' shift in the query sequence.'
  @cli_name     = 'frame'
end

Instance Method Details

#run(lst = @hits) ⇒ Object

Check reading frame inconsistency Params: lst: vector of Sequence objects Output: BlastRFValidationOutput object



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/genevalidator/validation_blast_reading_frame.rb', line 102

def run(lst = @hits)
  if type.to_s != 'nucleotide'
    @validation_report = ValidationReport.new('', :unapplicable)
    return @validation_report
  end

  raise NotEnoughHitsError if hits.length < opt[:min_blast_hits]
  raise unless prediction.is_a?(Query) && hits[0].is_a?(Query)

  start = Time.now

  rfs =  lst.map { |x| x.hsp_list.map(&:query_reading_frame) }.flatten
  frames = Hash[rfs.group_by { |x| x }.map { |k, vs| [k, vs.length] }]

  # get the main reading frame
  main_rf = frames.map { |_k, v| v }.max
  @prediction.nucleotide_rf = frames.find { |_k, v| v == main_rf }.first

  @validation_report = BlastRFValidationOutput.new(@short_header, @header,
                                                   @description, frames)
  @validation_report.run_time = Time.now - start
  @validation_report
rescue NotEnoughHitsError
  @validation_report = ValidationReport.new('Not enough evidence',
                                            :warning, @short_header,
                                            @header, @description)
rescue StandardError
  @validation_report = ValidationReport.new('Unexpected error', :error,
                                            @short_header, @header,
                                            @description)
  @validation_report.errors.push 'Unexpected Error'
end