From 11dd9bce948364283654b2f056fefb933afc3e6e Mon Sep 17 00:00:00 2001 From: gebele Date: Thu, 4 Dec 2014 17:38:55 +0100 Subject: several updates in code; validation integrated, probability for classification; updated call for more details for smarts view --- application.rb | 9 +++++---- views/neighbors.haml | 1 - views/predict.haml | 27 +++++++++++++-------------- views/prediction.haml | 20 ++++++++++++++++---- views/significant_fragments.haml | 6 +++--- views/style.scss | 2 +- views/validation.haml | 16 ++++++++++++++++ 7 files changed, 54 insertions(+), 27 deletions(-) create mode 100644 views/validation.haml diff --git a/application.rb b/application.rb index 2cb16bb..e566211 100644 --- a/application.rb +++ b/application.rb @@ -10,8 +10,9 @@ helpers do @@models = [] models = `curl -k GET -H accept:text/uri-list #{$model[:uri]}`.split("\n") .collect{|m| model = OpenTox::Model::Lazar.find m; @@models << model if model.type.flatten.to_s =~ /PredictionModel/} - @@cv = [] - `curl -k GET -H accept:text/uri-list #{$validation[:uri]}/crossvalidation`.split("\n").each{|cv| x = OpenTox::Validation.find cv; @@cv << x} + #@@cv = [] + #`curl -k GET -H accept:text/uri-list #{$validation[:uri]}/crossvalidation`.split("\n").each{|cv| x = OpenTox::Validation.find cv+"/statistics" if cv =~ /7/; @@cv << x} + #@@cv = OpenTox::Validation.find "https://dg.in-silico.ch/validation/crossvalidation/7/statistics" end get '/?' do @@ -22,7 +23,7 @@ get '/predict/?' do # sort models by endpoint alphabetically $size = 0 @models = @@models.sort!{|a, b| a.type.select{|e| e =~ /endpoint/i} <=> b.type.select{|e| e =~ /endpoint/i}} - @cv = @@cv.collect{|cv| cv.metadata.select{|x| x =~ /predictionFeature/}} + #@cv = @@cv#.collect{|cv| cv.metadata.select{|x| x =~ /predictionFeature/}} @models.size <= 0 ? (haml :info) : (haml :predict) end @@ -200,7 +201,7 @@ post '/predict/?' do @predictions = [] @model_type = [] # get selected models - #TODO compare if model is selected by uri not title + # compare selected model by uri params[:selection].each do |model| # selected model = model[0] # compare selected with all models diff --git a/views/neighbors.haml b/views/neighbors.haml index 32554d6..603f920 100644 --- a/views/neighbors.haml +++ b/views/neighbors.haml @@ -108,7 +108,6 @@ %td = p.data_entries[count][3] != nil ? p.data_entries[count][3].round(3) : "Not enough similar compounds in training dataset." %td - %br - if @type =~ /classification/i - if p.data_entries[count][3] != nil %a{:href => to("/prediction/#{CGI.escape(@model_uri)}/#{@type}/#{CGI.escape(neighbor_compound.uri)}/significant_fragments"), :id=>"link#{count_rs}#{count}sf", :target=>"details"} Significant fragments diff --git a/views/predict.haml b/views/predict.haml index 62fe93c..e9d222f 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -112,6 +112,7 @@ %p{:style=>"display:inline;"} Algorithm: %code{:style=>"font-size:x-large;"} lazar - model.type.to_s =~ /regression/i ? type = "regression" : type = "classification" + - @model_type = type %p= "Type: "+type - training_dataset = OpenTox::Dataset.new "#{model[RDF::OT.trainingDataset]}" - training_compounds = training_dataset.compounds.size.to_s @@ -123,26 +124,24 @@ %a{:href=>"http://www.maunz.de/libfminer2-bbrc-doc/", :title=>"link opens in new window.", :target=>"_blank"} Fminer backbone refinement classes %br %br - %p{:style=>"display:inline"}= "Training Dataset: " - %a{:href=>"#{to("/predict/#{CGI.escape(model[RDF::OT.trainingDataset])}")}", :title=>"link opens in new window."} download rdf + %p{:style=>"display:inline"}= "Model: " + %a{:href=>"#{to("/predict/#{CGI.escape(model.uri)}")}", :title=>"download"} rdf %br %br %p{:style=>"display:inline"}= "Feature Dataset: " - %a{:href=>"#{to("/predict/#{CGI.escape(model[RDF::OT.featureDataset])}")}", :title=>"download"} download rdf + %a{:href=>"#{to("/predict/#{CGI.escape(model[RDF::OT.featureDataset])}")}", :title=>"download"} rdf %br %br - %p{:style=>"display:inline"}= "Model: " - %a{:href=>"#{to("/predict/#{CGI.escape(model.uri)}")}", :title=>"download"} download rdf + %p{:style=>"display:inline"}= "Training Dataset: " + %a{:href=>"#{to("/predict/#{CGI.escape(model[RDF::OT.trainingDataset])}")}", :title=>"link opens in new window."} rdf %br - %h3 Validation: - -#%p= @cv.inspect - %a{:href => "#"} - Detailed report link - %p Number of predictions: integer - %p Correct predictions: % - - - //%br + - unless model.metadata[RDF::OT.crossValidation].nil? + %h3 Validation: + %a{:href => "#{model.metadata[RDF::OT.crossValidation][0]}", :title=>"link opens in new window.", :target=>"_blank"} + Detailed report link + %br + - @cv = OpenTox::Validation.find "#{model.metadata[RDF::OT.crossValidation][0]+"/statistics"}" + = haml :validation, :layout => false, :validation => @cv, :model_type => @model_type .arrow %img{:src=>"/images/arrow_down_float.png", :alt=>"v", :class=> "arrow"} diff --git a/views/prediction.haml b/views/prediction.haml index 3cd2f3f..dfc7009 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -14,7 +14,7 @@ %tbody %tr - %td{:id=>"compound", :style=>"width: 200px;padding:0.2em;"} + %td{:id=>"compound", :style=>"width: 200px;vertical-align:top;"} %a{:href => to("/prediction/#{CGI.escape(@compound.uri)}/details"), :id=>"linkCompound", :target=>"details_overview"} Names and synonyms %img{:src=>"#{@compound.uri}/image", :alt=>"Compound image not available", :title=>"#{@compound.smiles}", :width=>"150", :height=>"150"} @@ -57,9 +57,13 @@ %b Result: %b - if c.class == String - = (c != '' ? c : "No prediction result.") + - result = (c != '' ? c : "No prediction result.") + = result - else - = (c != '' ? c.round(3) : "No prediction result.") + - result = (c != '' ? c.round(3) : "No prediction result.") + = result + - confidence = (p.data_entries[0][1] != nil && p.data_entries[0][1] != 0.0) ? p.data_entries[0][1].round(2) : "--" + / title must be empty for tooltip %a{:href=>"#result", :title=>"", :id=>"result"} %img{:src=>"/images/info_white.png"} @@ -84,10 +88,16 @@ %a{:href=>"http://www.frontiersin.org/Journal/10.3389/fphar.2013.00038/abstract", :target=>"_blank"} original publication ) Please keep in mind that predictions are based on the measured activities of neighbors. + - @cv = OpenTox::Validation.find @prediction_models[count].metadata[RDF::OT.crossValidation][0]+"/statistics" unless @prediction_models[count].title.include?("Mutagenicity") + - unless @model_type[count] == "regression" + %b + = "Probalitity: " + - unless result == "No prediction result." or confidence == "--" + = "#{@cv.probabilities( confidence, result )[:probs][result].round(3)*100} %" %p .confidence %b Confidence: - = (p.data_entries[0][1] != nil && p.data_entries[0][1] != 0.0) ? p.data_entries[0][1].round(3) : "--" + = confidence / title must be empty for tooltip %a{:href=>"#confidence", :title=>"", :id=>"confidence"} %img{:src=>"/images/info_white.png"} @@ -101,6 +111,8 @@ 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[count] =~ /classification/i && (p.data_entries[0][1] != nil && p.data_entries[0][1] != 0.0) diff --git a/views/significant_fragments.haml b/views/significant_fragments.haml index 3004c89..b039804 100644 --- a/views/significant_fragments.haml +++ b/views/significant_fragments.haml @@ -1,7 +1,7 @@ %link{ :href=>"/style.css", :media=>"screen, projection", :rel=>"stylesheet", :type=>"text/css"} .content{:style=>"margin-top:0;"} - if @type =~ /classification/i - .significant_fragments{:style=>"padding:0.7em;padding-bottom:5em;"} + .significant_fragments{:style=>"padding:0.7em;padding-bottom:10em;"} %button{:id=>"closebutton", :onclick=>"parent.$('#iframe_details').bPopup().close();parent.$('#iframe_overview').bPopup().close();"} X %h2{:style=>"margin-left:8px;"} @@ -25,7 +25,7 @@ %td / fragments[1] = smarts = fragments[1] - %img{:src => "http://smartsview.de/smartsview/auto/png/2/none/#{CGI.escape(fragments[1])}", :class => "smarts"} + %img{:src => "http://smartsview.de/smartsview/auto/png/1/both/#{CGI.escape(fragments[1])}", :class => "smarts"} %td /fragments[2] = pValue = fragments[2] @@ -42,7 +42,7 @@ - if fragments[0] == @value_map.index("active") %tr %td - %img{:src => "http://smartsview.de/smartsview/auto/png/2/none/#{CGI.escape(fragments[1])}", :class => "smarts"} + %img{:src => "http://smartsview.de/smartsview/auto/png/1/both/#{CGI.escape(fragments[1])}", :class => "smarts"} = fragments[1] %td = fragments[2] diff --git a/views/style.scss b/views/style.scss index caeef49..a068ab1 100644 --- a/views/style.scss +++ b/views/style.scss @@ -157,7 +157,7 @@ body { //float: left; } img.smarts:hover{ - transform: scale(5); + transform: scale(4); border: solid 1px black; } diff --git a/views/validation.haml b/views/validation.haml new file mode 100644 index 0000000..fd63ea6 --- /dev/null +++ b/views/validation.haml @@ -0,0 +1,16 @@ +- 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