From 510822b13d48344ffe4e047a4415ebdb218dadc0 Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 24 Mar 2016 19:41:37 +0000 Subject: updated for latest lazar changes; introduced 95% prediction interval --- application.rb | 20 ++++++++++---------- views/model_details.haml | 29 ++++++++++------------------- views/neighbors.haml | 31 +++++++++++++++++++++---------- views/prediction.haml | 11 ++++++++--- 4 files changed, 49 insertions(+), 42 deletions(-) diff --git a/application.rb b/application.rb index a4dc7c4..6c6a73f 100644 --- a/application.rb +++ b/application.rb @@ -32,16 +32,16 @@ end get '/predict/modeldetails/:model' do model = OpenTox::Model::Prediction.find params[:model] crossvalidations = model.crossvalidations - confidence_plots = crossvalidations.collect{|cv| [cv.id, cv.confidence_plot]} - confidence_plots.each do |confp| - File.open(File.join('public', "confp#{confp[0]}.png"), 'w'){|file| file.write(confp[1])} unless File.exists? File.join('public', "confp#{confp[0]}.png") - end - if model.regression? - correlation_plots = crossvalidations.collect{|cv| [cv.id, cv.correlation_plot]} - correlation_plots.each do |corrp| - File.open(File.join('public', "corrp#{corrp[0]}.png"), 'w'){|file| file.write(corrp[1])} unless File.exists? File.join('public', "corrp#{corrp[0]}.png") - end - end + #confidence_plots = crossvalidations.collect{|cv| [cv.id, cv.confidence_plot]} + #confidence_plots.each do |confp| + # File.open(File.join('public', "confp#{confp[0]}.svg"), 'w'){|file| file.write(confp[1])} unless File.exists? File.join('public', "confp#{confp[0]}.svg") + #end + #if model.regression? + # correlation_plots = crossvalidations.collect{|cv| [cv.id, cv.correlation_plot]} + # correlation_plots.each do |corrp| + # File.open(File.join('public', "corrp#{corrp[0]}.svg"), 'w'){|file| file.write(corrp[1])} unless File.exists? File.join('public', "corrp#{corrp[0]}.svg") + # end + #end return haml :model_details, :layout=> false, :locals => {:model => model} end diff --git a/views/model_details.haml b/views/model_details.haml index 04cc0f0..34e86ac 100644 --- a/views/model_details.haml +++ b/views/model_details.haml @@ -36,9 +36,6 @@ Source: = "Accuracy:\t" = cv.accuracy.round(3) if cv.accuracy %br - = "Weighted Accuracy:\t" - = cv.weighted_accuracy.round(3) if cv.weighted_accuracy - %br = "True positive rate:\t" = cv.true_rate["active"].round(3) if cv.true_rate["active"] %br @@ -97,32 +94,26 @@ Source: -#= "Confusion Matrix:\t" -#= cv.confusion_matrix %br - = "Confidence plot:" - %p.plot - %img{:src=>"confp#{cv.id}.png"} + /= "Confidence plot:" + /%p.plot + / %img{:src=>"confp#{cv.id}.svg"} - if model.regression? %br = "Root mean squared error:\t" = cv.rmse.round(3) if cv.rmse %br - = "Weighted root mean squared error:\t" - = cv.weighted_rmse.round(3) if cv.weighted_rmse - %br = "Mean absolute error:\t" = cv.mae.round(3) if cv.mae - %br - = "Weighted mean absolute error:\t" - = cv.weighted_mae.round(3) if cv.weighted_mae %br = "R square:\t" = cv.r_squared.round(3) if cv.r_squared %br - = "Confidence plot:" - %p.plot - %img{:src=>"/confp#{cv.id}.png"} - %br - = "Correlation plot" - %p.plot - %img{:src=>"/corrp#{cv.id}.png"} + /= "Confidence plot:" + /%p.plot + / %img{:src=>"/confp#{cv.id}.svg"} + /%br + /= "Correlation plot" + /%p.plot + / %img{:src=>"/corrp#{cv.id}.svg"} %br diff --git a/views/neighbors.haml b/views/neighbors.haml index 6001605..6011a6d 100644 --- a/views/neighbors.haml +++ b/views/neighbors.haml @@ -9,7 +9,17 @@ #tabs %ul.nav.nav-tabs.nav-justified{:id=>"neighborTabs", :role=>"tablist"} / each model a tab head ; + / hash for predictionFeature + - predictionFeature = {} - @models.each_with_index do |model,i| + / get predictionFeature type + - m = Model::Lazar.find model.model_id.to_s + - predFeature = Feature.find m.prediction_feature_id.to_s + / define feature type (numeric : nominal) + - predFeatureType = (predFeature.numeric? ? "numeric" : "nominal") + / use prediction feature id for neighbor compound features + - predFeatureId = m.prediction_feature_id.to_s + - predictionFeature[i] = {"id" => predFeatureId, "type" => predFeatureType} %li{:class => ("active" if i == 0)} %a{:href => "#results_#{i+1}", :id => "linkTab#{i+1}", data: {toggle:"tab"}} = "#{model.endpoint} (#{model.species})" @@ -29,7 +39,7 @@ debug: false, theme: "bootstrap", headerTemplate: '{content} {icon}', - widgets: ['zebra', 'columns', 'uitheme', 'stickyHeaders'], + widgets: ['columns', 'uitheme', 'stickyHeaders'], widgetOptions: { stickyHeaders_attachTo : '.tab-content', stickyHeaders : '', @@ -74,19 +84,20 @@ - prediction[:neighbors].uniq.each_with_index do |neighbor,count| %tr / Compound + - c = Compound.find(neighbor["_id"]) %td{:style =>"vertical-align:middle;padding-left:1em;width:50%;"} - /%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 + /%a.btn.btn-link{:href => "#details#{j+1}", data: { toggle: "modal", remote: to("/prediction/#{CGI.escape(neighbor["_id"])}/details"), :id=>"link#{j+1}#{count}"}} + %p= c.svg + %p= c.smiles + - mw = c.molecular_weight + / Measured Activity = compound.features %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 + - features = c.features.collect{|k,v| v if k == predictionFeature[j]["id"] }.compact.flatten + = (predictionFeature[j]["type"] == "numeric") ? features.collect{|v| weight = c.mmol_to_mg(v); '%.2e' % v + " (#{@models[j].unit})"+" | #{'%.2e' % weight} (mg/kg_bw/day)"}.join("
") : features.join("
") + / Similarity = tanimoto %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? - = neighbor[1] != nil ? neighbor[1].round(2) : "Not enough similar compounds
in training dataset." + = neighbor[:tanimoto] != nil ? neighbor[:tanimoto].to_f.round(3) : "Not enough similar compounds
in training dataset." - else %span.btn.btn-default.disabled diff --git a/views/prediction.haml b/views/prediction.haml index 33e9ec5..aeaafdc 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -18,7 +18,7 @@ %td{:id=>"compound", :style=>"vertical-align:top;"} %p= @compound.svg %p= @compound.smiles - -#- mw = @compound.molecular_weight + - mw = @compound.molecular_weight - @model_types = {} - @dbhit = {} - @predictions.each_with_index do |prediction,i| @@ -51,8 +51,13 @@ / %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 / TODO probability - %b Confidence: - = prediction[:confidence].round(2) + - if type == "Regression" + %b 95% Prediction interval: + - interval = prediction[:prediction_interval].collect{|i| i.round(2)} + = interval + - else + %b Confidence: + = prediction[:confidence].round(2) unless prediction[:confidence].nil? / %a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Confidence", data: {toggle:"popover", placement:"left", html:"true", content:"Indicates the applicability domain of a model. Predictions with a high confidence can be expected to be more reliable than predictions with low confidence. Confidence values may take any value between 0 and 1. For most models confidence > 0.025 is a sensible (hard) cutoff to distinguish between reliable and unreliable predictions."}} %p /TODO add tooltip for significant ftagments and descriptors -- cgit v1.2.3