Class: GeneValidator::Output
- Inherits:
-
Object
- Object
- GeneValidator::Output
- Defined in:
- lib/genevalidator/output.rb
Instance Attribute Summary collapse
-
#fails ⇒ Object
Returns the value of attribute fails.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#html_path ⇒ Object
Returns the value of attribute html_path.
-
#idx ⇒ Object
Returns the value of attribute idx.
-
#mutex ⇒ Object
Returns the value of attribute mutex.
-
#mutex_html ⇒ Object
Returns the value of attribute mutex_html.
-
#mutex_yaml ⇒ Object
Returns the value of attribute mutex_yaml.
-
#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.
-
#prediction_len ⇒ Object
Returns the value of attribute prediction_len.
-
#start_idx ⇒ Object
Returns the value of attribute start_idx.
-
#successes ⇒ Object
Returns the value of attribute successes.
-
#validations ⇒ Object
list of
ValidationReportobjects. -
#yaml_path ⇒ Object
Returns the value of attribute yaml_path.
Class Method Summary collapse
-
.overall_evaluation(no_queries, good_scores, bad_scores, no_evidence, no_mafft, no_internet, map_errors, running_times) ⇒ Object
Calculates an overall evaluation of the output Params:
all_query_outputs: Array ofValidationTestobjects Output Array of Strigs with the reports. -
.print_footer(no_queries, scores, good_predictions, bad_predictions, nee, no_mafft, no_internet, map_errors, running_times, html_path, filename) ⇒ 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 def self.print_footer(all_query_outputs, html_path, filename).
Instance Method Summary collapse
- #generate_html ⇒ Object
-
#initialize(mutex, mutex_yaml, mutex_html, filename, html_path, yaml_path, idx = 0, start_idx = 0) ⇒ Output
constructor
Initilizes the object Params:
mutex:Mutexfor exclusive access to the consolemutex_yaml:Mutexfor exclusive access to the YAML filemutex_html:Mutexfor exclusive access to the HTML filefilename: name of the fasta input filehtml_path: path of the html folderyaml_path: path where the yaml output wil be savedidx: idnex of the current querystart_idx: number of the sequence from the file to start with. - #print_output_console ⇒ Object
- #print_output_file_yaml ⇒ Object
Constructor Details
#initialize(mutex, mutex_yaml, mutex_html, filename, html_path, yaml_path, idx = 0, start_idx = 0) ⇒ Output
Initilizes the object Params: mutex: Mutex for exclusive access to the console mutex_yaml: Mutex for exclusive access to the YAML file mutex_html: Mutex for exclusive access to the HTML file filename: name of the fasta input file html_path: path of the html folder yaml_path: path where the yaml output wil be saved idx: idnex of the current query start_idx: number of the sequence from the file to start with
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/genevalidator/output.rb', line 40 def initialize(mutex, mutex_yaml, mutex_html, filename, html_path, yaml_path, idx = 0, start_idx = 0) @prediction_len = 0 @prediction_def = 'no_definition' @nr_hits = 0 @filename = filename @html_path = html_path @yaml_path = yaml_path @idx = idx @start_idx = start_idx @mutex = mutex @mutex_yaml = mutex_yaml @mutex_html = mutex_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 |
#filename ⇒ Object
Returns the value of attribute filename.
15 16 17 |
# File 'lib/genevalidator/output.rb', line 15 def filename @filename end |
#html_path ⇒ Object
Returns the value of attribute html_path.
16 17 18 |
# File 'lib/genevalidator/output.rb', line 16 def html_path @html_path end |
#idx ⇒ Object
Returns the value of attribute idx.
18 19 20 |
# File 'lib/genevalidator/output.rb', line 18 def idx @idx end |
#mutex ⇒ Object
Returns the value of attribute mutex.
25 26 27 |
# File 'lib/genevalidator/output.rb', line 25 def mutex @mutex end |
#mutex_html ⇒ Object
Returns the value of attribute mutex_html.
27 28 29 |
# File 'lib/genevalidator/output.rb', line 27 def mutex_html @mutex_html end |
#mutex_yaml ⇒ Object
Returns the value of attribute mutex_yaml.
26 27 28 |
# File 'lib/genevalidator/output.rb', line 26 def mutex_yaml @mutex_yaml end |
#nr_hits ⇒ Object
Returns the value of attribute nr_hits.
10 11 12 |
# File 'lib/genevalidator/output.rb', line 10 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.
9 10 11 |
# File 'lib/genevalidator/output.rb', line 9 def prediction_def @prediction_def end |
#prediction_len ⇒ Object
Returns the value of attribute prediction_len.
8 9 10 |
# File 'lib/genevalidator/output.rb', line 8 def prediction_len @prediction_len end |
#start_idx ⇒ Object
Returns the value of attribute start_idx.
19 20 21 |
# File 'lib/genevalidator/output.rb', line 19 def start_idx @start_idx 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
13 14 15 |
# File 'lib/genevalidator/output.rb', line 13 def validations @validations end |
#yaml_path ⇒ Object
Returns the value of attribute yaml_path.
17 18 19 |
# File 'lib/genevalidator/output.rb', line 17 def yaml_path @yaml_path end |
Class Method Details
.overall_evaluation(no_queries, good_scores, bad_scores, no_evidence, no_mafft, no_internet, map_errors, running_times) ⇒ Object
Calculates an overall evaluation of the output Params: all_query_outputs: Array of ValidationTest objects Output Array of Strigs with the reports
228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
# File 'lib/genevalidator/output.rb', line 228 def self.overall_evaluation(no_queries, good_scores, bad_scores, no_evidence, no_mafft, no_internet, map_errors, running_times) good_pred = (good_scores == 1) ? 'One' : "#{good_scores} are" bad_pred = (bad_scores == 1) ? 'One' : "#{bad_scores} are" eval = "Overall Query Score Evaluation:\n" \ "#{no_queries} predictions were validated, from which there" \ " were:\n" \ "#{good_pred} good prediction(s),\n" \ "#{bad_pred} possibly weak prediction(s).\n" if no_evidence != 0 eval << "#{no_evidence} could not be evaluated due to the lack of" \ ' evidence.' end # errors per validation error_eval = '' map_errors.each do |k, v| error_eval << "\nWe couldn't run #{k} Validation for #{v} queries" end if no_mafft >= (no_queries - no_evidence) error_eval << "\nWe couldn't run MAFFT multiple alignment" end if no_internet >= (no_queries - no_evidence) error_eval << "\nWe couldn't make use of your internet connection" end time_eval = '' running_times.each do |key, value| average_time = value.x / (value.y + 0.0) time_eval << "\nAverage running time for #{key} Validation:" \ " #{average_time.round(3)}s per validation" end overall_evaluation = [eval, error_eval, time_eval] overall_evaluation.select { |e| e != '' } end |
.print_footer(no_queries, scores, good_predictions, bad_predictions, nee, no_mafft, no_internet, map_errors, running_times, html_path, filename) ⇒ 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 def self.print_footer(all_query_outputs, html_path, filename)
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/genevalidator/output.rb', line 162 def self.(no_queries, scores, good_predictions, bad_predictions, nee, no_mafft, no_internet, map_errors, running_times, html_path, filename) # compute the statistics # overall_evaluation = overall_evaluation(all_query_outputs, filename) overall_evaluation = overall_evaluation(no_queries, good_predictions, bad_predictions, nee, no_mafft, no_internet, map_errors, running_times) less = overall_evaluation[0] less = less.gsub("\n", '<br>').gsub("'", %q(\\\')) # print to console evaluation = '' overall_evaluation.each { |e| evaluation << "\n#{e}" } puts evaluation puts '' # print to html # make the historgram with the resulted scores statistics_filename = "#{html_path}/files/json/#{filename}_statistics.json" f = File.open(statistics_filename, 'w') f.write( [scores.group_by { |a| a }.map { |k, vs| { 'key' => k, 'value' => vs.length, 'main' => false } }].to_json) f.close plot_statistics = Plot.new("files/json/#{filename}_statistics.json", :simplebars, 'Overall evaluation', '', 'validation score', 'number of queries', 10) evaluation = evaluation.gsub("\n", '<br>').gsub("'", %q(\\\')) index_file = "#{html_path}/results.html" table_file = "#{html_path}/files/table.html" aux_dir = File.join(File.dirname(File.(__FILE__)), '../../aux') = File.join(aux_dir, 'template_footer.erb') = File.join(aux_dir, 'app_template_footer.erb') template_file = File.open(, 'r').read erb = ERB.new(template_file, 0, '>') File.open(index_file, 'a+') do |file| file.write(erb.result(binding)) end = File.open(, 'r').read table_erb = ERB.new(, 0, '>') File.open(table_file, 'a+') do |file| file.write(table_erb.result(binding)) end end |
Instance Method Details
#generate_html ⇒ Object
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 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/genevalidator/output.rb', line 103 def generate_html if @fails == 0 bg_icon = 'success' else bg_icon = 'danger' end index_file = "#{@html_path}/results.html" table_file = "#{@html_path}/files/table.html" aux_dir = File.join(File.dirname(File.(__FILE__)), '../../aux') # if it's the first time I write in the html file if @idx == @start_idx @mutex_html.synchronize do template_header = File.join(aux_dir, 'template_header.erb') template_file = File.open(template_header, 'r').read erb = ERB.new(template_file, 0, '>') # Creating a Separate output file for the web app app_template_header = File.join(aux_dir, 'app_template_header.erb') table_template_file = File.open(app_template_header, 'r').read erb_table = ERB.new(table_template_file, 0, '>') File.open(index_file, 'w+') do |file| file.write(erb.result(binding)) end File.open(table_file, 'w+') do |file| file.write(erb_table.result(binding)) end end end toggle = "toggle#{@idx}" @mutex_yaml.synchronize do template_query = File.join(aux_dir, 'template_query.erb') template_file = File.open(template_query, 'r').read erb = ERB.new(template_file, 0, '>') File.open(index_file, 'a') do |file| file.write(erb.result(binding)) end File.open(table_file, 'a') do |file| file.write(erb.result(binding)) end end end |
#print_output_console ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/genevalidator/output.rb', line 57 def print_output_console if @idx == @start_idx header = sprintf('%3s|%s|%20s|%5s', 'No', 'Score', 'Identifier', 'No_Hits') validations.map do |v| header << "|#{v.short_header}" end puts header end short_def = @prediction_def.scan(/([^ ]+)/)[0][0] validation_outputs = validations.map(&:print) output = sprintf('%3s|%d|%20s|%5s|', @idx, @overall_score, short_def, @nr_hits) validation_outputs.each do |item| output << item output << '|' end @mutex.synchronize do puts output.gsub(' ', ' ') end end |
#print_output_file_yaml ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/genevalidator/output.rb', line 82 def print_output_file_yaml file_yaml = "#{@yaml_path}/#{@filename}.yaml" report = validations if @idx == @start_idx @mutex_yaml.synchronize do File.open(file_yaml, 'w') do |f| YAML.dump({ @prediction_def.scan(/([^ ]+)/)[0][0] => report }, f) end end else @mutex_yaml.synchronize do hash = {} # YAML.load_file(file_yaml) hash[@prediction_def.scan(/([^ ]+)/)[0][0]] = report File.open(file_yaml, 'a') do |f| new_report = hash.to_yaml f.write(new_report[4..new_report.length - 1]) end end end end |