From 1d6588b35b4ffff16717e24b42a0d396d5347f95 Mon Sep 17 00:00:00 2001 From: gebele Date: Tue, 26 Jan 2016 12:53:40 +0000 Subject: batch merge --- application.rb | 23 ++++++++++++++++++----- views/batch.haml | 15 +++++++++------ views/neighbors.haml | 21 ++++++++++++++++++--- views/predict.haml | 1 - views/prediction.haml | 14 +++++++++----- 5 files changed, 54 insertions(+), 20 deletions(-) diff --git a/application.rb b/application.rb index 229f3a1..fc7e415 100644 --- a/application.rb +++ b/application.rb @@ -202,21 +202,34 @@ get '/predict/?:csv?' do model = array[0] prediction = array[1] compound = key.smiles + mw = key.molecular_weight endpoint = "#{model.endpoint.gsub('_', ' ')} (#{model.species})" if prediction[:confidence] == "measured" - type = "" - pred = prediction[:value].numeric? ? "#{prediction[:value].round(3)} (#{model.unit})" : prediction[:value] - confidence = "measured activity" + if prediction[:value].is_a?(Array) + prediction[:value].each do |value| + type = "" + weight = Compound.from_smiles(compound).mmol_to_mg(value, mw) + pred = value.numeric? ? "#{'%.2e' % value} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : value + confidence = "measured activity" + @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n" + end + else + type = "" + weight = Compound.from_smiles(compound).mmol_to_mg(prediction[:value], mw) + pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : prediction[:value] + confidence = "measured activity" + end elsif prediction[:neighbors].size > 0 + weight = Compound.from_smiles(compound).mmol_to_mg(prediction[:value], mw) type = model.model.class.to_s.match("Classification") ? "Classification" : "Regression" - pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} #{model.unit}" : prediction[:value] + pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % weight} (mg/kg_bw/day)" : prediction[:value] confidence = prediction[:confidence] else type = "" pred = "Not enough similar compounds in training dataset." confidence = "" end - @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n" + @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n" unless prediction[:value].is_a?(Array) end end @csv diff --git a/views/batch.haml b/views/batch.haml index ec987c4..9bfa67e 100644 --- a/views/batch.haml +++ b/views/batch.haml @@ -18,6 +18,7 @@ / key = compound, values = array of arrays with model, prediction - @batch.each do |key, values| - compound = key + - mw = compound.molecular_weight %tr %td{:style=>"vertical-align:top;"} %p= compound.svg @@ -32,10 +33,13 @@ %p - if prediction[:confidence] == "measured" %p - / TODO fix scientific notation from database - %b Measured activity: - = prediction[:value].numeric? ? "#{prediction[:value].round(3)} (#{model.unit})" : prediction[:value] - %p Compound is part of the training dataset + %b Measured activity: + - if prediction[:value].is_a?(Array) + = prediction[:value][0].numeric? ? prediction[:value].collect{|v| weight = compound.mmol_to_mg(v, mw); '%.2e' % v + " (#{model.unit})"+" | #{'%.2e' % weight} (mg/kg_bw/day)"}.join("
") : prediction[:value].join(", ") + - else + = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value] + %p + %b Compound is part of the training dataset - elsif prediction[:neighbors].size > 0 %p / model type (classification|regression) @@ -43,8 +47,7 @@ = model.model.class.to_s.match("Classification") ? "Classification" : "Regression" %br %b Prediction: - / TODO scientific notation - = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit})" : prediction[:value] + = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} (#{model.unit}) | #{'%.2e' % compound.mmol_to_mg(prediction[:value], mw)} (mg/kg_bw/day)" : prediction[:value] %br / TODO probability %b Confidence: diff --git a/views/neighbors.haml b/views/neighbors.haml index a741b45..6001605 100644 --- a/views/neighbors.haml +++ b/views/neighbors.haml @@ -29,7 +29,20 @@ debug: false, theme: "bootstrap", headerTemplate: '{content} {icon}', - widgets: ['zebra', 'columns', 'uitheme'], + widgets: ['zebra', 'columns', 'uitheme', 'stickyHeaders'], + widgetOptions: { + stickyHeaders_attachTo : '.tab-content', + stickyHeaders : '', + stickyHeaders_offset : 0, + stickyHeaders_cloneId : '-sticky', + stickyHeaders_addResizeEvent : true, + stickyHeaders_includeCaption : true, + stickyHeaders_zIndex : 2, + stickyHeaders_attachTo : null, + stickyHeaders_xScroll : null, + stickyHeaders_yScroll : null, + stickyHeaders_filteredToTop: true + }, headers: {0: {sorter: false}, 3: {sorter: false}}, sortList: [[2,1]], widthFixed: false @@ -65,9 +78,11 @@ /%a.btn.btn-link{:href => "#details#{j+1}", data: { toggle: "modal", remote: to("/prediction/#{CGI.escape(neighbor[0].to_s)}/details"), :id=>"link#{j+1}#{count}"}} %p= Compound.find(neighbor[0]).svg %p= Compound.find(neighbor[0]).smiles + - c = Compound.find(neighbor[0]) + //- mw = c.molecular_weight / Measured Activity - %td{:style =>"vertical-align:middle;padding-left:1em;width:20%;"} - = (type == "Regression") ? neighbor[2].collect{|n| '%.2e' % n + " (#{@models[j].unit})"}.join("
") : neighbor[2].join(", ") + %td{:style =>"vertical-align:middle;padding-left:1em;width:20%;white-space:nowrap;"} + = (type == "Regression") ? neighbor[2].collect{|n| weight = c.mmol_to_mg(n); '%.2e' % n + " (#{@models[j].unit})"+"|#{'%.2e' % weight} (mg/kg_bw/day)"}.join("
") : neighbor[2].join(", ") / Similarity %td{:style =>"vertical-align:middle;padding-left:1em;width:20%;"} / TODO differentiate between no neighbors found and compound found in dataset, display neighbors for compounds in dataset? diff --git a/views/predict.haml b/views/predict.haml index 8ab9ee0..010ed12 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -125,7 +125,6 @@ %br %input{:type => 'text', :name => 'identifier', :id => 'identifier', :size => '60'} %p - // disable for public version %label{:for=>"fileselect"} or upload a CSV file for batch predictions (disabled in public version) %br diff --git a/views/prediction.haml b/views/prediction.haml index ef0c5db..33e9ec5 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -18,6 +18,7 @@ %td{:id=>"compound", :style=>"vertical-align:top;"} %p= @compound.svg %p= @compound.smiles + -#- mw = @compound.molecular_weight - @model_types = {} - @dbhit = {} - @predictions.each_with_index do |prediction,i| @@ -30,10 +31,14 @@ - if prediction[:confidence] == "measured" - @dbhit[i] = true %p - / TODO fix scientific notation from database %b Measured activity: - = (type == "Regression") ? "#{"%.2e" % prediction[:value]} (#{@models[i].unit})" : prediction[:value] - %p Compound is part of the training dataset + - p prediction[:value] + - if prediction[:value].is_a?(Array) + = (type == "Regression") ? prediction[:value].collect{|v| weight = Compound.from_smiles(@compound.smiles).mmol_to_mg(v); '%.2e' % v + " (#{@models[i].unit})"+"|#{'%.2e' % weight} (mg/kg_bw/day)"}.join("
") : prediction[:value].join(", ") + - else + = (type == "Regression") ? "#{"%.2e" % prediction[:value]} (#{@models[i].unit}) | #{'%.2e' % @compound.mmol_to_mg(prediction[:value])} (mg/kg_bw/day)" : prediction[:value] + %p + %b Compound is part of the training dataset - elsif prediction[:neighbors].size > 0 %p / model type (classification|regression) @@ -41,8 +46,7 @@ = type %br %b Prediction: - / TODO scientific notation - = (type == "Regression") ? "#{'%.2e' % prediction[:value]} (#{@models[i].unit})" : prediction[:value] + = (type == "Regression") ? "#{'%.2e' % prediction[:value]} (#{@models[i].unit}) | #{'%.2e' % @compound.mmol_to_mg(prediction[:value])} (mg/kg_bw/day)" : prediction[:value] / TODO update description / %a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Prediction", data: {toggle:"popover", placement:"left", html:"true", content:"LAZAR calculates searches the training dataset for similar compounds (neighbors) and calculates the prediction from their measured activities. LAZAR calculates predictions using Please keep in mind that predictions are based on the measured activities of neighbors."}} %br -- cgit v1.2.3