lib/genevalidator/output.rb in genevalidator-1.6.2 vs lib/genevalidator/output.rb in genevalidator-1.6.3
- old
+ new
@@ -32,12 +32,10 @@
@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
def print_output_console
mutex.synchronize do
print_console_header unless @config[:console_header_printed]
@@ -48,37 +46,35 @@
end
end
def print_console_header
@config[:console_header_printed] = true
- print format("%3s\t%5s\t%20s\t%7s\t", 'No', 'Score', 'Identifier', 'No_Hits')
+ print format("%3s\t%5s\t%20s\t%7s\t", 'No', 'Score', 'Identifier',
+ 'No_Hits')
puts validations.map(&:short_header).join("\t")
end
def generate_html
mutex_html.synchronize do
- output_html = output_filename
+ 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
def output_filename
- i = (@config[:run_no].to_f / @config[:output_max]).ceil
- output_html = File.join(@config[:html_path], "results#{i}.html")
+ idx = (@config[:run_no].to_f / @config[:output_max]).ceil
+ output_html = File.join(@config[:html_path], "results#{idx}.html")
write_html_header(output_html)
output_html
end
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
def set_up_html(erb_file, output_file)
return if File.exist?(output_file)
template_contents = File.open(erb_file, 'r').read
@@ -97,29 +93,35 @@
end
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 = add_basic_validation_info(item)
+ explain = add_explanation_data(item) if item.color != 'warning'
+ val.merge!(explain) if explain
val[:graphs] = create_graphs_hash(item) unless item.plot_files.nil?
row[:validations][item.short_header] = val
end
row
end
+ def add_basic_validation_info(item)
+ { header: item.header, description: item.description, status: item.color,
+ print: item.print.gsub(' ', ' ') }
+ end
+
+ def add_explanation_data(item)
+ { approach: item.approach, explanation: item.explanation,
+ conclusion: item.conclusion }
+ end
+
def create_graphs_hash(item)
graphs = []
item.plot_files.each do |g|
graphs << { data: g.data, type: g.type, title: g.title,
- footer: g.footer, xtitle: g.xtitle,
- ytitle: g.ytitle, aux1: g.aux1, aux2: g.aux2 }
+ footer: g.footer, xtitle: g.xtitle, ytitle: g.ytitle,
+ aux1: g.aux1, aux2: g.aux2 }
end
graphs
end
def write_row_json(row)
@@ -138,21 +140,14 @@
# 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(overview, config)
- overall_evaluation = overview(overview)
+ set_overall_evaluation(overview, config)
- create_plot_json(overview[:scores], config[:plot_dir])
+ footer_erb = File.join(config[:aux], 'template_footer.erb')
- 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(\\\'))
-
- footer_erb = File.join(config[:aux], 'template_footer.erb')
-
no_of_results_files = (config[:run_no].to_f / config[:output_max]).ceil
template_file = File.open(footer_erb, 'r').read
erb = ERB.new(template_file, 0, '>')
output_files = []
@@ -162,44 +157,48 @@
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
+ end
- # write footer for the app
- app_footer_erb = File.join(config[:aux], 'app_template_footer.erb')
- table_html = File.join(config[:html_path], 'files/table.html')
- table_footer_template = File.open(app_footer_erb, 'r').read
- table_erb = ERB.new(table_footer_template, 0, '>')
- File.open(table_html, 'a+') { |f| f.write(table_erb.result(binding)) }
+ def self.set_overall_evaluation(overview, config)
+ overall_evaluation = overview(overview)
+ 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(\\\'))
+
+ create_overview_json(overview[:scores], config[:plot_dir], less,
+ evaluation)
end
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
+ File.open("#{script_file}.tmp", 'w') do |f|
+ f.puts File.readlines(script_file)[30..-1].join
end
- FileUtils.mv(temp_file, script_file)
+ FileUtils.mv("#{script_file}.tmp", script_file)
end
def self.print_summary_to_console(overall_evaluation, summary)
# print to console
eval = ''
- overall_evaluation.each { |e| eval << "\n#{e}" }
+ overall_evaluation.each { |e| eval << "#{e}\n" }
$stderr.puts eval if summary
$stderr.puts ''
eval
end
# make the historgram with the resulted scores
- def self.create_plot_json(scores, plot_dir)
+ def self.create_overview_json(scores, plot_dir, less, evaluation)
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: '' }
+ ytitle: 'Number of Queries', aux1: 10, aux2: '', less: less,
+ evaluation: evaluation }
File.open(plot_file, 'w') { |f| f.write hash.to_json }
end
##
# Calculates an overall evaluation of the output
@@ -231,11 +230,11 @@
' evidence.'
end
eval
end
+ # errors per validation
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])