From f86c084311282036ffa7b4588c0fa0d5b59af95b Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 24 Nov 2016 16:03:09 +0000 Subject: several fixes; works with lazar tree e111369ce5564f159b3f5f85c92afdd22352eaa1 --- views/details.haml | 2 +- views/layout.haml | 18 ++++--- views/license.haml | 1 + views/model_details.haml | 134 +++++++++++++++++++++++++++-------------------- views/neighbors.haml | 13 +++-- views/predict.haml | 1 + views/prediction.haml | 35 ++++++++----- views/style.scss | 14 +++-- views/validation.haml | 16 ------ 9 files changed, 127 insertions(+), 107 deletions(-) create mode 100644 views/license.haml delete mode 100644 views/validation.haml (limited to 'views') diff --git a/views/details.haml b/views/details.haml index 8a57440..bb8250d 100644 --- a/views/details.haml +++ b/views/details.haml @@ -19,6 +19,6 @@ %hr %p{:style=>"padding-left:0.5em;"} / pubchem link - %a.btn.btn-primary{:href=>"http://aop.in-silico.ch/", :title=>"Link opens in new window.", :alt=>"pubchem read across", :target=>"_blank"} PubChem read across + %a.btn.btn-primary{:href=>"http://aop.in-silico.ch/", :title=>"Link opens in new window.", :alt=>"pubchem read across", :rel=>"external"} PubChem read across %i (experimental) %br diff --git a/views/layout.haml b/views/layout.haml index a40b68c..dddf854 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -15,7 +15,7 @@ %script{:src=>"/javascripts/bootstrap.min.js"} %script{:src=>"/javascripts/jquery.tablesorter.min.js"} %script{:src=>"/javascripts/jquery.tablesorter.widgets.js"} - %script{ :src=>"/javascripts/lazar-gui.js"} + %script{:src=>"/javascripts/lazar-gui.js"} %body %noscript %div{ :style=>"width: 22em; position: absolute; left: 50%; margin-left: -11em; color: red; background-color: white; border: 1px solid red; padding: 4px; font-family: sans-serif"} @@ -26,7 +26,7 @@ %a{:href=> to("/predict")} %img.media-object{:src=>"/images/IST_logo_s.png", :alt=>"logo", :width=>"150px", :heigth=>"150px", :style=>"margin:0 3em 0 2em;"} %div.col-md-8 - %h1.media-heading{:style=>"margin: 0 0 0 2em;"} + %h1.media-heading lazar toxicity predictions %div.col-md-2 %h1.media-heading @@ -55,7 +55,7 @@ %img.share{:src=>"/images/Facebook.png"} %div.row Previous version: - %a{:href=>"http://lazar-old.in-silico.ch"} lazar-old + %a{:href=>"http://lazar-old.in-silico.ch", :rel => "external"} lazar-old :javascript $(document).ready(function(){ $("#back-top").hide(); @@ -79,15 +79,17 @@ %p.text-muted © %a{:href => 'http://www.in-silico.ch', :rel => "external"} in silico toxicology gmbh 2004 - #{Time.now.year.to_s} + | + %a{:href => to("/license"), :rel => "external"} GPL3 License %supporters.col-md-12 - %p Financial support: - %a{:href=>"http://www.bfr.bund.de/de/start.html", :target=>"_blank"} + %p Financial support by + %a{:href=>"http://www.bfr.bund.de/de/start.html", :rel=>"external"} %img{:src=>"/images/bfr_logo.gif"} - %a{:href=>"http://www.opentox.org/", :target=>"_blank"} + %a{:href=>"http://www.opentox.org/", :rel=>"external"} %img{:src=>"/images/ot_logo.png"} - %a{:href=>"https://enanomapper.net/", :target=>"_blank"} + %a{:href=>"https://enanomapper.net/", :rel=>"external"} %img{:src=>"/images/enm_logo.png"} - %a{:href=>"https://www.researchgate.net/institution/Nestle_SA/department/Nestle_Research_Center", :target=>"_blank"} + %a{:href=>"https://www.researchgate.net/institution/Nestle_SA/department/Nestle_Research_Center", :rel=>"external"} %img{:src=>"/images/nestec.jpg"} diff --git a/views/license.haml b/views/license.haml new file mode 100644 index 0000000..2813220 --- /dev/null +++ b/views/license.haml @@ -0,0 +1 @@ += @license diff --git a/views/model_details.haml b/views/model_details.haml index 1be75e7..7646471 100644 --- a/views/model_details.haml +++ b/views/model_details.haml @@ -1,26 +1,39 @@ %b Model: %br Source: -%a{:href=>model.source, :target=>"external"} +%a{:href=>model.source, :rel=>"external"} = model.source %br - model.classification? ? type = "Classification" : type = "Regression" = "Type:\t" = type %br -- training_dataset = OpenTox::Dataset.find model.training_dataset.id +- training_dataset = OpenTox::Dataset.find model.model.training_dataset_id = "Training compounds:\t" = training_dataset.compounds.size - +%br +%b Algorithms: +%br +Similarity: +%a{:href=> "http://www.rubydoc.info/gems/lazar/OpenTox%2F#{model.model.algorithms["similarity"]["method"].sub("::", "%2F")}", :rel=>"external"} + = model.model.algorithms["similarity"]["method"] += ", min: #{model.model.algorithms["similarity"]["min"]}" +%br +Prediction: +%a{:href=>"http://www.rubydoc.info/gems/lazar/OpenTox%2F#{model.model.algorithms["prediction"]["method"].sub("::","%2f")}", :rel=>"external"} + = model.model.algorithms["prediction"]["method"] +%br +Descriptors: += model.model.algorithms["descriptors"]["method"]+"," += model.model.algorithms["descriptors"]["type"] %p - if type == "Classification" %b Independent crossvalidations: - else %b Independent crossvalidations (-log10 transformed): %div.row{:id=>"validations#{model.id}", :style=>"background-color:#f5f5f5;"} - - model.crossvalidations.each do |crossvalidation| + - crossvalidations.each do |cv| %span.col-xs-4.col-sm-4.col-md-4.col-lg-4 - - cv = OpenTox::CrossValidation.find crossvalidation.id = "Num folds:\t" = cv.folds %br @@ -34,76 +47,81 @@ 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"] + = cv.true_rate["active"].round(3) if cv.true_rate %br = "True negative rate:\t" - = cv.true_rate["inactive"].round(3) if cv.true_rate["inactive"] + = cv.true_rate["inactive"].round(3) if cv.true_rate %br = "Positive predictive value:\t" - = cv.predictivity["active"].round(3) if cv.predictivity["active"] + = cv.predictivity["active"].round(3) if cv.predictivity %br = "Negative predictive value:\t" - = cv.predictivity["inactive"].round(3) if cv.predictivity["inactive"] + = cv.predictivity["inactive"].round(3) if cv.predictivity %p - %b Confusion Matrix: - %table.table.table-condensed.table-borderless{:style=>"width:20%;"} - %tbody - %tr - %td - %td - %td - %b actual - %td - %td - %tr - %td - %td - %td active - %td inactive - -#%td total - %tr - %td - %b predicted - %td active - %td - =cv.confusion_matrix[0][0] - %td - =cv.confusion_matrix[0][1] - -#%td - =cv.confusion_matrix[0][0]+cv.confusion_matrix[0][1] - %tr - %td - %td inactive - %td - =cv.confusion_matrix[1][0] - %td - =cv.confusion_matrix[1][1] - -#%td - =cv.confusion_matrix[1][0]+cv.confusion_matrix[1][1] - -#%tr - %td - %td total - %td - =cv.confusion_matrix[0][0]+cv.confusion_matrix[1][0] - %td - =cv.confusion_matrix[0][1]+cv.confusion_matrix[1][1] - %td - -#= "Confusion Matrix:\t" - -#= cv.confusion_matrix + - ["confusion_matrix", "weighted_confusion_matrix"].each_with_index do |matrix,idx| + %b= (idx == 0 ? "Confusion Matrix" : "Weighted Confusion Matrix") + %table.table.table-condensed.table-borderless{:style=>"width:20%;"} + %tbody + %tr + %td + %td + %td + %b actual + %td + %td + %tr + %td + %td + %td active + %td inactive + -#%td total + %tr + %td + %b predicted + %td active + %td + =( idx == 1 ? cv.send(matrix)[0][0].round(3) : cv.send(matrix)[0][0]) + %td + =( idx == 1 ? cv.send(matrix)[0][1].round(3) : cv.send(matrix)[0][1]) + -#%td + =cv.confusion_matrix[0][0]+cv.confusion_matrix[0][1] + %tr + %td + %td inactive + %td + =( idx == 1 ? cv.send(matrix)[1][0].round(3) : cv.send(matrix)[1][0]) + %td + =( idx == 1 ? cv.send(matrix)[1][1].round(3) : cv.send(matrix)[1][1]) + -#%td + =cv.confusion_matrix[1][0]+cv.confusion_matrix[1][1] + -#%tr + %td + %td total + %td + =cv.confusion_matrix[0][0]+cv.confusion_matrix[1][0] + %td + =cv.confusion_matrix[0][1]+cv.confusion_matrix[1][1] + %td + -#= "Confusion Matrix:\t" + -#= cv.confusion_matrix + %br %br /= "Confidence plot:" /%p.plot / %img{:src=>"confp#{cv.id}.svg"} - if model.regression? %br - = "Root mean squared error:\t" + %a.ht5{:href=>"https://en.wikipedia.org/wiki/Root-mean-square_deviation", :rel=>"external"} RMSE: = cv.rmse.round(3) if cv.rmse %br - = "Mean absolute error:\t" + %a.ht5{:href=>"https://en.wikipedia.org/wiki/Mean_absolute_error", :rel=>"external"} MAE: = cv.mae.round(3) if cv.mae %br - = "R square:\t" + %a.ht5{:href=>"https://en.wikipedia.org/wiki/Coefficient_of_determination", :rel=>"external"}= "R"+"2"+":" = cv.r_squared.round(3) if cv.r_squared %br /= "Confidence plot:" @@ -113,5 +131,5 @@ Source: /= "Correlation plot" /%p.plot / %img{:src=>"/corrp#{cv.id}.svg"} - + %br diff --git a/views/neighbors.haml b/views/neighbors.haml index 096e432..d9f2796 100644 --- a/views/neighbors.haml +++ b/views/neighbors.haml @@ -79,20 +79,19 @@ - prediction[:neighbors].uniq.each_with_index do |neighbor,count| %tr / Compound - - c = Compound.find(neighbor["_id"]) + - c = Compound.find(neighbor) %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["_id"])}/details"), :id=>"link#{j+1}#{count}"}} %p= c.svg %p= c.smiles - - mw = c.molecular_weight - / Measured Activity = compound.features + / Measured Activity %td{:style =>"vertical-align:middle;padding-left:1em;width:20%;white-space:nowrap;"} - - 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} #{(unit == "mmol/L") ? "(mg/L)" : "(mg/kg_bw/day)"}"}.join("
") : features.join("
") + = (type == "Regression" ? "#{neighbor[:measurement].delog10}" + " (#{unit})" : neighbor[:measurement]) + %br + = "#{c.mmol_to_mg(neighbor[:measurement].delog10)}" + " (#{(unit =~ /\b(mol\/L)\b/) ? "mg/L" : "mg/kg_bw/day"})" if type == "Regression" / 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[:tanimoto] != nil ? neighbor[:tanimoto].to_f.round(3) : "Not enough similar compounds
in training dataset." + = neighbor[:similarity].round(3) - else %span.btn.btn-default.disabled diff --git a/views/predict.haml b/views/predict.haml index 010ed12..8ae5684 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -162,6 +162,7 @@ document.getElementById("details#{model.id}").appendChild(details); $(button).show(); $(image).hide(); + addExternalLinks(); }); } } diff --git a/views/prediction.haml b/views/prediction.haml index 0f3d57b..1aefe06 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -18,7 +18,6 @@ %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| @@ -29,17 +28,20 @@ %b{:class => "title"} = "#{@models[i].endpoint.gsub('_', ' ')} (#{@models[i].species})" %p - - if prediction[:confidence] == "measured" + - if prediction[:warning] =~ /\b(identical)\b/i - @dbhit[i] = true %p + /TODO combine with regular view, if prediction value is present %b Measured activity: - 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 + " (#{unit})"+", #{'%.2e' % weight} #{unit == "mmol/L" ? "(mg/L)" : "(mg/kg_bw/day)"}"}.join("
") : prediction[:value].join(", ") + = (type == "Regression") ? prediction[:value].collect{|value| "#{value} (#{unit}) , #{@compound.mmol_to_mg(value.delog10)} #{unit =~ /mmol\/L/ ? "(mg/L)" : "(mg/kg_bw/day)"}"}.join("
") : prediction[:value].join(", ") - else - = (type == "Regression") ? "#{"%.2e" % prediction[:value]} (#{unit}), #{'%.2e' % @compound.mmol_to_mg(prediction[:value])} #{(unit == "mmol/L") ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:value] + = (type == "Regression") ? "#{prediction[:value]} (#{unit}), #{@compound.mmol_to_mg(prediction[:value].delog10)} #{(unit =~ /\b(mol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:value] %p %b Compound is part of the training dataset + / warning popover + %a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Warnings", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"left", html:"true", content:"#{prediction[:warning]}"}} - elsif prediction[:neighbors].size > 0 %p / model type (classification|regression) @@ -47,23 +49,30 @@ = type %br %b Prediction: - = (type == "Regression") ? "#{'%.2e' % prediction[:value]} (#{unit}) , #{'%.2e' % @compound.mmol_to_mg(prediction[:value])} #{(unit == "mmol/L") ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:value] - / tabindex=0 seems the best fix for FF|S browsers on OSX better than trigger="click focus" which ends up in double click for FF. / prediction popover %a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Prediction", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"left", html:"true", content:"

lazar searches the training dataset for similar compounds (neighbors) and calculates the prediction from their experimental activities.

Classification:
Majority vote of neighbor activities weighted by similarity.

Regression:
Prediction from a local partial least squares regression model with neighbor activities weighted by similarity.

Original publication."}} %br + = (type == "Regression") ? "#{prediction[:value].delog10} (#{unit})
#{@compound.mmol_to_mg(prediction[:value].delog10)} #{(unit =~ /\b(mol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:value] + / tabindex=0 seems the best fix for FF|S browsers on OSX better than trigger="click focus" which ends up in double click for FF. + %br - if type == "Regression" %b 95% Prediction interval: - - interval = prediction[:prediction_interval].nil? ? " - - " : prediction[:prediction_interval].collect{|i| i.round(2)} - %br - = "#{interval[0]} - #{interval[1]} (#{unit}), #{'%.2e' % @compound.mmol_to_mg(interval[0])} - #{'%.2e' % @compound.mmol_to_mg(interval[1])} #{(unit == "mmol/L") ? "(mg/L)" : "(mg/kg_bw/day)"}" + - interval = (prediction[:prediction_interval].nil? ? ["- -","- -"] : prediction[:prediction_interval]) / prediction intervall popover %a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Prediction intervall", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"left", html:"true", content:"An estimate of prediction uncertainty. The \"real\" value should be with 95% probability within the prediction interval."}} + %br + = "#{interval[0].delog10} - #{interval[1].delog10} (#{unit})" + %br + = "#{@compound.mmol_to_mg(interval[0].delog10)} - #{@compound.mmol_to_mg(interval[1].delog10)} #{(unit =~ /\b(mol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" if !prediction[:prediction_interval].nil? - else - %b Confidence: - = prediction[:confidence].round(2) unless prediction[:confidence].nil? - / confidence popover - %a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Confidence", :tabindex=>"0", data: {trigger:"focus", 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."}} + %b Probability: + - unless prediction[:probabilities].nil? + %br + = "#{prediction[:probabilities].keys[0]}: #{prediction[:probabilities].values[0]}" + %br + = "#{prediction[:probabilities].keys[1]}: #{prediction[:probabilities].values[1]}" + / probability popover + -#%a.btn.glyphicon.glyphicon-info-sign{:href=>"#", :title=>"Confidence", :tabindex=>"0", data: {trigger:"focus", 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 / - if @model_type[i] =~ /classification/i && (p.data_entries[0][1] != nil && p.data_entries[0][1] != 0.0) diff --git a/views/style.scss b/views/style.scss index 49e03ab..2c84781 100644 --- a/views/style.scss +++ b/views/style.scss @@ -51,10 +51,12 @@ ul.share-buttons{ padding: 0 2px 1px 2px !important; } .page-header{ - margin:20px 0 20px; - text-align:justify; + background-color: #fff; + padding:20px 0 20px 0; + margin: 0; + text-align:center; display:inline-block; - width:98.5%; + width:100%; } .share{ width: 30px; @@ -62,9 +64,13 @@ ul.share-buttons{ } supporters{ background-color: white; - + text-align:center; img{ width: 200px; margin-right: 1em; } } + +.footer{ + margin-top:3em; +} diff --git a/views/validation.haml b/views/validation.haml deleted file mode 100644 index fd63ea6..0000000 --- a/views/validation.haml +++ /dev/null @@ -1,16 +0,0 @@ -- case @model_type -- when "classification" - - prediction = @cv.metadata["http://www.opentox.org/api/1.2#classificationStatistics"]["http://www.opentox.org/api/1.2#numCorrect"] + @cv.metadata["http://www.opentox.org/api/1.2#classificationStatistics"]["http://www.opentox.org/api/1.2#numIncorrect"] - %p= "Number of predictions: #{prediction}" - - percent = @cv.metadata["http://www.opentox.org/api/1.2#classificationStatistics"]["http://www.opentox.org/api/1.2#percentCorrect"] - %p= "Correct predictions: #{percent.round(2)} %" -- when "regression" - - prediction = @cv.metadata["http://www.opentox.org/api/1.2#numInstances"].to_i - @cv.metadata["http://www.opentox.org/api/1.2#numUnpredicted"].to_i - %p= "Number of predictions: #{prediction}" - - rSquare = @cv.metadata["http://www.opentox.org/api/1.2#regressionStatistics"]["http://www.opentox.org/api/1.2#rSquare"] - %p= "R-squared: #{rSquare.round(2)} %" - - rootMeanSquaredError = @cv.metadata["http://www.opentox.org/api/1.2#regressionStatistics"]["http://www.opentox.org/api/1.2#rootMeanSquaredError"] - %p= "Root Mean Square Error: #{rootMeanSquaredError.round(2)} %" - - meanAbsoluteError = @cv.metadata["http://www.opentox.org/api/1.2#regressionStatistics"]["http://www.opentox.org/api/1.2#meanAbsoluteError"] - %p= "Mean Absolute Error: #{meanAbsoluteError.round(2)} %" - -- cgit v1.2.3