Class: GeneValidator::Output
- Inherits:
-
Object
- Object
- GeneValidator::Output
- Extended by:
- Forwardable
- Defined in:
- lib/genevalidator/output.rb
Instance Attribute Summary collapse
-
#fails ⇒ Object
Returns the value of attribute fails.
-
#idx ⇒ Object
Returns the value of attribute idx.
-
#nr_hits ⇒ Object
Returns the value of attribute nr_hits.
-
#overall_score ⇒ Object
Returns the value of attribute overall_score.
-
#prediction_def ⇒ Object
Returns the value of attribute prediction_def.
-
#successes ⇒ Object
Returns the value of attribute successes.
-
#validations ⇒ Object
list of
ValidationReport
objects.
Class Method Summary collapse
-
.calculate_no_quries_with_no_evidence(json_data) ⇒ Object
calculate number of queries that had warnings for all validations.
- .calculate_run_time(json_data) ⇒ Object
- .count_internet_errors(json_data) ⇒ Object
- .count_mafft_errors(json_data) ⇒ Object
-
.generate_evaluation_text(overview) ⇒ Object
Calculates an overall evaluation of the output Params:
all_query_outputs
: Array ofValidationTest
objects Output Array of Strigs with the reports. - .generate_overview(json_data, min_blast_hits) ⇒ Object
- .map_errors(json_data) ⇒ Object
- .overview_hash(scores_from_json, quartiles, nee, no_mafft, no_internet, map_errors, run_time, insufficient_BLAST_hits) ⇒ Object
- .print_console_footer(overall_evaluation, opt) ⇒ Object
Instance Method Summary collapse
- #generate_json ⇒ Object
-
#initialize(current_idx, no_of_hits, definition) ⇒ Output
constructor
Initilizes the object Params:
current_idx
: index of the current query. - #print_output_console ⇒ Object
Constructor Details
#initialize(current_idx, no_of_hits, definition) ⇒ Output
Initilizes the object Params: current_idx
: index of the current query
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/genevalidator/output.rb', line 24 def initialize(current_idx, no_of_hits, definition) @opt = opt @dirs = dirs @config = config @config[:run_no] += 1 output_dir = @dirs[:output_dir] @output_filename = File.join(output_dir, "#{@dirs[:filename]}_results") @prediction_def = definition @nr_hits = no_of_hits @idx = current_idx end |
Instance Attribute Details
#fails ⇒ Object
Returns the value of attribute fails.
17 18 19 |
# File 'lib/genevalidator/output.rb', line 17 def fails @fails end |
#idx ⇒ Object
Returns the value of attribute idx.
14 15 16 |
# File 'lib/genevalidator/output.rb', line 14 def idx @idx end |
#nr_hits ⇒ Object
Returns the value of attribute nr_hits.
9 10 11 |
# File 'lib/genevalidator/output.rb', line 9 def nr_hits @nr_hits end |
#overall_score ⇒ Object
Returns the value of attribute overall_score.
16 17 18 |
# File 'lib/genevalidator/output.rb', line 16 def overall_score @overall_score end |
#prediction_def ⇒ Object
Returns the value of attribute prediction_def.
8 9 10 |
# File 'lib/genevalidator/output.rb', line 8 def prediction_def @prediction_def end |
#successes ⇒ Object
Returns the value of attribute successes.
18 19 20 |
# File 'lib/genevalidator/output.rb', line 18 def successes @successes end |
#validations ⇒ Object
list of ValidationReport
objects
12 13 14 |
# File 'lib/genevalidator/output.rb', line 12 def validations @validations end |
Class Method Details
.calculate_no_quries_with_no_evidence(json_data) ⇒ Object
calculate number of queries that had warnings for all validations.
141 142 143 144 145 146 147 148 149 150 |
# File 'lib/genevalidator/output.rb', line 141 def calculate_no_quries_with_no_evidence(json_data) all_warnings = 0 json_data.each do |row| status = row[:validations].map { |_, h| h[:status] } if status.count { |r| r == 'warning' } == status.length all_warnings += 1 end end all_warnings end |
.calculate_run_time(json_data) ⇒ Object
175 176 177 178 179 180 181 182 183 184 185 186 187 |
# File 'lib/genevalidator/output.rb', line 175 def calculate_run_time(json_data) run_time = Hash.new(Pair1.new(0, 0)) json_data.map do |row| row[:validations].each do |short_header, v| next if v[:run_time].nil? || v[:run_time].zero? next if v[:validation] == 'unapplicable' || v[:validation] == 'error' p = Pair1.new(run_time[short_header.to_s].x + v[:run_time], run_time[short_header.to_s].y + 1) run_time[short_header.to_s] = p end end run_time end |
.count_internet_errors(json_data) ⇒ Object
159 160 161 162 163 164 |
# File 'lib/genevalidator/output.rb', line 159 def count_internet_errors(json_data) json_data.count do |row| num = row[:validations].count { |_, h| h[:print] == 'Internet error' } num.zero? ? false : true end end |
.count_mafft_errors(json_data) ⇒ Object
152 153 154 155 156 157 |
# File 'lib/genevalidator/output.rb', line 152 def count_mafft_errors(json_data) json_data.count do |row| num = row[:validations].count { |_, h| h[:print] == 'Mafft error' } num.zero? ? false : true end end |
.generate_evaluation_text(overview) ⇒ Object
Calculates an overall evaluation of the output Params: all_query_outputs
: Array of ValidationTest
objects Output Array of Strigs with the reports
195 196 197 198 199 200 201 |
# File 'lib/genevalidator/output.rb', line 195 def generate_evaluation_text(overview) eval = general_overview(overview) error_eval = errors_overview(overview) time_eval = time_overview(overview) [eval, error_eval, time_eval].reject(&:empty?) end |
.generate_overview(json_data, min_blast_hits) ⇒ Object
111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/genevalidator/output.rb', line 111 def generate_overview(json_data, min_blast_hits) scores_from_json = json_data.map { |e| e[:overall_score] } quartiles = scores_from_json.all_quartiles nee = calculate_no_quries_with_no_evidence(json_data) no_mafft = count_mafft_errors(json_data) no_internet = count_internet_errors(json_data) map_errors = map_errors(json_data) run_time = calculate_run_time(json_data) min_hits = json_data.count { |e| e[:no_hits] < min_blast_hits } overview_hash(scores_from_json, quartiles, nee, no_mafft, no_internet, map_errors, run_time, min_hits) end |
.map_errors(json_data) ⇒ Object
166 167 168 169 170 171 172 173 |
# File 'lib/genevalidator/output.rb', line 166 def map_errors(json_data) errors = Hash.new(0) json_data.each do |row| e = row[:validations].map { |s, h| s if h[:validation] == 'error' } e.compact.each { |err| errors[err] += 1 } end errors end |
.overview_hash(scores_from_json, quartiles, nee, no_mafft, no_internet, map_errors, run_time, insufficient_BLAST_hits) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 |
# File 'lib/genevalidator/output.rb', line 124 def overview_hash(scores_from_json, quartiles, nee, no_mafft, no_internet, map_errors, run_time, insufficient_BLAST_hits) { scores: scores_from_json, no_queries: scores_from_json.length, good_scores: scores_from_json.count { |s| s >= 75 }, bad_scores: scores_from_json.count { |s| s < 75 }, nee: nee, no_mafft: no_mafft, no_internet: no_internet, map_errors: map_errors, run_time: run_time, first_quartile_of_scores: quartiles[0], second_quartile_of_scores: quartiles[1], third_quartile_of_scores: quartiles[2], insufficient_BLAST_hits: insufficient_BLAST_hits } end |
.print_console_footer(overall_evaluation, opt) ⇒ Object
103 104 105 106 107 108 109 |
# File 'lib/genevalidator/output.rb', line 103 def (overall_evaluation, opt) return unless (opt[:output_formats].include? 'stdout') || opt[:hide_summary] warn '' warn "==> #{overall_evaluation.join("\n")}" warn '' end |
Instance Method Details
#generate_json ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/genevalidator/output.rb', line 48 def generate_json fname = File.join(@dirs[:json_dir], "#{@dirs[:filename]}_#{@idx}.json") row_data = { idx: @idx, overall_score: @overall_score, definition: @prediction_def, no_hits: @nr_hits } row = create_validation_hash(row_data) arr_idx = @idx - 1 @config[:json_output][arr_idx] = row File.open(fname, 'w') { |f| f.write(row.to_json) } end |
#print_output_console ⇒ Object
37 38 39 40 41 42 43 44 45 46 |
# File 'lib/genevalidator/output.rb', line 37 def print_output_console return unless @opt[:output_formats].include? 'stdout' c_fmt = "%3s\t%5s\t%20s\t%7s\t" mutex.synchronize do print_console_header(c_fmt) short_def = @prediction_def.split(' ')[0] print format(c_fmt, @idx, @overall_score, short_def, @nr_hits) puts validations.map(&:print).join("\t").gsub(' ', ' ') end end |