lib/genevalidator/validation_duplication.rb in genevalidator-1.6.1 vs lib/genevalidator/validation_duplication.rb in genevalidator-1.6.2

- old
+ new

@@ -1,8 +1,14 @@ -require 'genevalidator/validation_report' +require 'bio' +require 'forwardable' +require 'statsample' + require 'genevalidator/exceptions' require 'genevalidator/ext/array' +require 'genevalidator/validation_report' +require 'genevalidator/validation_test' + module GeneValidator ## # Class that stores the validation output information class DuplicationValidationOutput < ValidationReport attr_reader :pvalue @@ -69,28 +75,31 @@ ## # This class contains the methods necessary for # finding duplicated subsequences in the predicted gene class DuplicationValidation < ValidationTest + extend Forwardable + def_delegators GeneValidator, :opt, :config + attr_reader :raw_seq_file attr_reader :index_file_name attr_reader :raw_seq_file_load - def initialize(type, prediction, hits, raw_seq_file, index_file_name, - raw_seq_file_load, db, num_threads) + def initialize(prediction, hits) super @short_header = 'Duplication' @header = 'Duplication' @description = 'Check whether there is a duplicated subsequence' \ ' in the predicted gene by counting the hsp' \ ' residue coverage of the prediction, for each hit.' @cli_name = 'dup' - @raw_seq_file = raw_seq_file - @index_file_name = index_file_name - @raw_seq_file_load = raw_seq_file_load - @db = db - @num_threads = num_threads + @raw_seq_file = opt[:raw_sequences] + @index_file_name = config[:raw_seq_file_index] + @raw_seq_file_load = config[:raw_seq_file_load] + @db = opt[:db] + @num_threads = opt[:num_threads] + @type = config[:type] end def in_range?(ranges, idx) ranges.each do |range| return (range.member?(idx)) ? true : false @@ -212,52 +221,47 @@ if averages.reject { |x| x == 1 } == [] @validation_report = DuplicationValidationOutput.new(@short_header, @header, @description, 1, averages) - @validation_report.running_time = Time.now - start + @validation_report.run_time = Time.now - start return @validation_report end pval = wilcox_test(averages) @validation_report = DuplicationValidationOutput.new(@short_header, @header, @description, pval, averages) - @running_time = Time.now - start + @run_time = Time.now - start @validation_report rescue NotEnoughHitsError @validation_report = ValidationReport.new('Not enough evidence', :warning, @short_header, @header, - @description, @explanation, - @conclusion) + @description) rescue NoMafftInstallationError @validation_report = ValidationReport.new('Mafft error', :error, @short_header, @header, - @description, @explanation, - @conclusion) + @description) @validation_report.errors.push NoMafftInstallationError rescue NoInternetError @validation_report = ValidationReport.new('Internet error', :error, @short_header, @header, - @description, @explanation, - @conclusion) + @description) @validation_report.errors.push NoInternetError rescue Exception @validation_report = ValidationReport.new('Unexpected error', :error, @short_header, @header, - @description, @explanation, - @conclusion) + @description) @validation_report.errors.push 'Unexpected Error' end ## # wilcox test implementation from statsample ruby gem # many thanks to Claudio for helping us with the implementation! def wilcox_test(averages) - require 'statsample' wilcox = Statsample::Test.wilcoxon_signed_rank(averages.to_scale, Array.new(averages.length, 1).to_scale) (averages.length < 15) ? wilcox.probability_exact : wilcox.probability_z