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
ValidationReportobjects.
Class Method Summary collapse
-
.create_plot_json(scores, plot_dir) ⇒ Object
make the historgram with the resulted scores.
- .errors_overview(o) ⇒ Object
- .general_overview(o) ⇒ Object
-
.overview(o) ⇒ Object
Calculates an overall evaluation of the output Params:
all_query_outputs: Array ofValidationTestobjects Output Array of Strigs with the reports. -
.print_footer(overview, config) ⇒ Object
Method that closes the gas in the html file and writes the overall evaluation Param:
all_query_outputs: array withValidationTestobjectshtml_path: path of the html folderfilemane: name of the fasta input file. - .print_summary_to_console(overall_evaluation, summary) ⇒ Object
- .time_overview(o) ⇒ Object
- .turn_off_sorting(html_path) ⇒ Object
- .write_json_file(array, json_file) ⇒ Object
Instance Method Summary collapse
- #create_graphs_hash(item) ⇒ Object
- #create_validation_hashes(row) ⇒ Object
- #generate_html ⇒ Object
- #generate_json ⇒ Object
-
#initialize(current_idx, no_of_hits, definition) ⇒ Output
constructor
Initilizes the object Params:
current_idx: index of the current query. - #output_filename ⇒ Object
- #print_console_header ⇒ Object
- #print_output_console ⇒ Object
- #set_up_html(erb_file, output_file) ⇒ Object
- #write_html_header(output_html) ⇒ Object
- #write_row_json(row) ⇒ Object
Constructor Details
#initialize(current_idx, no_of_hits, definition) ⇒ Output
Initilizes the object Params: current_idx: index of the current query
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/genevalidator/output.rb', line 29 def initialize(current_idx, no_of_hits, definition) @opt = opt @config = config @config[:run_no] += 1 @prediction_def = definition @nr_hits = no_of_hits @idx = current_idx @app_html = File.join(@config[:html_path], 'files/table.html') end |
Instance Attribute Details
#fails ⇒ Object
Returns the value of attribute fails.
22 23 24 |
# File 'lib/genevalidator/output.rb', line 22 def fails @fails end |
#idx ⇒ Object
Returns the value of attribute idx.
19 20 21 |
# File 'lib/genevalidator/output.rb', line 19 def idx @idx end |
#nr_hits ⇒ Object
Returns the value of attribute nr_hits.
14 15 16 |
# File 'lib/genevalidator/output.rb', line 14 def nr_hits @nr_hits end |
#overall_score ⇒ Object
Returns the value of attribute overall_score.
21 22 23 |
# File 'lib/genevalidator/output.rb', line 21 def overall_score @overall_score end |
#prediction_def ⇒ Object
Returns the value of attribute prediction_def.
13 14 15 |
# File 'lib/genevalidator/output.rb', line 13 def prediction_def @prediction_def end |
#successes ⇒ Object
Returns the value of attribute successes.
23 24 25 |
# File 'lib/genevalidator/output.rb', line 23 def successes @successes end |
#validations ⇒ Object
list of ValidationReport objects
17 18 19 |
# File 'lib/genevalidator/output.rb', line 17 def validations @validations end |
Class Method Details
.create_plot_json(scores, plot_dir) ⇒ Object
make the historgram with the resulted scores
195 196 197 198 199 200 201 202 |
# File 'lib/genevalidator/output.rb', line 195 def self.create_plot_json(scores, plot_dir) plot_file = File.join(plot_dir, 'overview.json') data = [scores.group_by { |a| a }.map { |k, vs| { 'key' => k, 'value' => vs.length, 'main' => false } }] hash = { data: data, type: :simplebars, title: 'Overall Evaluation', footer: '', xtitle: 'Validation Score', ytitle: 'Number of Queries', aux1: 10, aux2: '' } File.open(plot_file, 'w') { |f| f.write hash.to_json } end |
.errors_overview(o) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 |
# File 'lib/genevalidator/output.rb', line 236 def self.errors_overview(o) # errors per validation error_eval = '' o[:map_errors].each do |k, v| error_eval << "\nWe couldn't run #{k} Validation for #{v} queries" end if o[:no_mafft] >= (o[:no_queries] - o[:nee]) error_eval << "\nWe couldn't run MAFFT multiple alignment" end if o[:no_internet] >= (o[:no_queries] - o[:nee]) error_eval << "\nWe couldn't make use of your internet connection" end error_eval end |
.general_overview(o) ⇒ Object
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/genevalidator/output.rb', line 219 def self.general_overview(o) good_pred = (o[:good_scores] == 1) ? 'One' : "#{o[:good_scores]} are" bad_pred = (o[:bad_scores] == 1) ? 'One' : "#{o[:bad_scores]} are" eval = "Overall Query Score Evaluation:\n" \ "#{o[:no_queries]} predictions were validated, from which there" \ " were:\n" \ "#{good_pred} good prediction(s),\n" \ "#{bad_pred} possibly weak prediction(s).\n" if o[:nee] != 0 # nee = no evidence eval << "#{o[:nee]} could not be evaluated due to the lack of" \ ' evidence.' end eval end |
.overview(o) ⇒ Object
Calculates an overall evaluation of the output Params: all_query_outputs: Array of ValidationTest objects Output Array of Strigs with the reports
210 211 212 213 214 215 216 217 |
# File 'lib/genevalidator/output.rb', line 210 def self.overview(o) eval = general_overview(o) error_eval = errors_overview(o) time_eval = time_overview(o) overall_evaluation = [eval, error_eval, time_eval] overall_evaluation.select { |e| e != '' } end |
.print_footer(overview, config) ⇒ Object
Method that closes the gas in the html file and writes the overall evaluation Param: all_query_outputs: array with ValidationTest objects html_path: path of the html folder filemane: name of the fasta input file
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
# File 'lib/genevalidator/output.rb', line 142 def self.(overview, config) overall_evaluation = overview(overview) create_plot_json(overview[:scores], config[:plot_dir]) less = overall_evaluation[0].gsub("\n", '<br>').gsub("'", %q(\\\')) eval = print_summary_to_console(overall_evaluation, config[:summary]) evaluation = eval.gsub("\n", '<br>').gsub("'", %q(\\\')) = File.join(config[:aux], 'template_footer.erb') no_of_results_files = (config[:run_no].to_f / config[:output_max]).ceil template_file = File.open(, 'r').read erb = ERB.new(template_file, 0, '>') output_files = [] (1..no_of_results_files).each { |i| output_files << "results#{i}.html" } (1..no_of_results_files).each do |i| results_html = File.join(config[:html_path], "results#{i}.html") File.open(results_html, 'a+') { |f| f.write(erb.result(binding)) } end turn_off_sorting(config[:html_path]) if no_of_results_files > 1 # write footer for the app = File.join(config[:aux], 'app_template_footer.erb') table_html = File.join(config[:html_path], 'files/table.html') = File.open(, 'r').read table_erb = ERB.new(, 0, '>') File.open(table_html, 'a+') { |f| f.write(table_erb.result(binding)) } end |
.print_summary_to_console(overall_evaluation, summary) ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'lib/genevalidator/output.rb', line 185 def self.print_summary_to_console(overall_evaluation, summary) # print to console eval = '' overall_evaluation.each { |e| eval << "\n#{e}" } $stderr.puts eval if summary $stderr.puts '' eval end |
.time_overview(o) ⇒ Object
251 252 253 254 255 256 257 258 259 |
# File 'lib/genevalidator/output.rb', line 251 def self.time_overview(o) time_eval = '' o[:run_time].each do |key, value| average_time = value.x / (value.y).to_f time_eval << "\nAverage running time for #{key} Validation:" \ " #{average_time.round(3)}s per validation" end time_eval end |
.turn_off_sorting(html_path) ⇒ Object
176 177 178 179 180 181 182 183 |
# File 'lib/genevalidator/output.rb', line 176 def self.turn_off_sorting(html_path) script_file = File.join(html_path, 'files/js/script.js') temp_file = File.join(html_path, 'files/js/script.temp.js') File.open(temp_file, 'w') do |out_file| out_file.puts File.readlines(script_file)[30..-1].join end FileUtils.mv(temp_file, script_file) end |
.write_json_file(array, json_file) ⇒ Object
131 132 133 |
# File 'lib/genevalidator/output.rb', line 131 def self.write_json_file(array, json_file) File.open(json_file, 'w') { |f| f.write(array.to_json) } end |
Instance Method Details
#create_graphs_hash(item) ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/genevalidator/output.rb', line 115 def create_graphs_hash(item) graphs = [] item.plot_files.each do |g| graphs << { data: g.data, type: g.type, title: g.title, footer: g., xtitle: g.xtitle, ytitle: g.ytitle, aux1: g.aux1, aux2: g.aux2 } end graphs end |
#create_validation_hashes(row) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/genevalidator/output.rb', line 99 def create_validation_hashes(row) row[:validations] = {} @validations.each do |item| val = { header: item.header, description: item.description, status: item.color, print: item.print.gsub(' ', ' ') } if item.color != 'warning' explain = { approach: item.approach, explanation: item.explanation, conclusion: item.conclusion } val.merge!(explain) end val[:graphs] = create_graphs_hash(item) unless item.plot_files.nil? row[:validations][item.short_header] = val end row end |
#generate_html ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/genevalidator/output.rb', line 57 def generate_html mutex_html.synchronize do output_html = output_filename query_erb = File.join(@config[:aux], 'template_query.erb') template_file = File.open(query_erb, 'r').read erb = ERB.new(template_file, 0, '>') File.open(output_html, 'a') { |f| f.write(erb.result(binding)) } File.open(@app_html, 'a') { |f| f.write(erb.result(binding)) } end end |
#generate_json ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/genevalidator/output.rb', line 89 def generate_json mutex_json.synchronize do row = { idx: @idx, overall_score: @overall_score, definition: @prediction_def, no_hits: @nr_hits } row = create_validation_hashes(row) write_row_json(row) @config[:json_output] << row end end |
#output_filename ⇒ Object
68 69 70 71 72 73 |
# File 'lib/genevalidator/output.rb', line 68 def output_filename i = (@config[:run_no].to_f / @config[:output_max]).ceil output_html = File.join(@config[:html_path], "results#{i}.html") write_html_header(output_html) output_html end |
#print_console_header ⇒ Object
51 52 53 54 55 |
# File 'lib/genevalidator/output.rb', line 51 def print_console_header @config[:console_header_printed] = true print format("%3s\t%5s\t%20s\t%7s\t", 'No', 'Score', 'Identifier', 'No_Hits') puts validations.map(&:short_header).join("\t") end |
#print_output_console ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'lib/genevalidator/output.rb', line 41 def print_output_console mutex.synchronize do print_console_header unless @config[:console_header_printed] short_def = @prediction_def.scan(/([^ ]+)/)[0][0] print format("%3s\t%5s\t%20s\t%7s\t", @idx, @overall_score, short_def, @nr_hits) puts validations.map(&:print).join("\t").gsub(' ', ' ') end end |
#set_up_html(erb_file, output_file) ⇒ Object
82 83 84 85 86 87 |
# File 'lib/genevalidator/output.rb', line 82 def set_up_html(erb_file, output_file) return if File.exist?(output_file) template_contents = File.open(erb_file, 'r').read erb = ERB.new(template_contents, 0, '>') File.open(output_file, 'w+') { |f| f.write(erb.result(binding)) } end |
#write_html_header(output_html) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/genevalidator/output.rb', line 75 def write_html_header(output_html) head_erb = File.join(@config[:aux], 'template_header.erb') head_table_erb = File.join(@config[:aux], 'app_template_header.erb') set_up_html(head_erb, output_html) unless File.exist?(output_html) set_up_html(head_table_erb, @app_html) unless File.exist?(@app_html) end |
#write_row_json(row) ⇒ Object
125 126 127 128 129 |
# File 'lib/genevalidator/output.rb', line 125 def write_row_json(row) row_json = File.join(@config[:plot_dir], "#{@config[:filename]}_#{@idx}.json") File.open(row_json, 'w') { |f| f.write(row.to_json) } end |