diff options
author | Christoph Helma <helma@in-silico.ch> | 2010-07-29 19:34:34 +0200 |
---|---|---|
committer | Christoph Helma <helma@in-silico.ch> | 2010-07-29 19:34:34 +0200 |
commit | deb9d2c9a005c152983a70c17c227fc59c917f0b (patch) | |
tree | fde5715579c1e15b6501cc1c6bf18f364d11caa2 | |
parent | 617fee94e1824515dc699a6265260c7b92a0fcea (diff) |
html representation of lazar predictions moved from model service to toxcreate
-rw-r--r-- | application.rb | 48 | ||||
-rw-r--r-- | views/fragment.haml | 9 | ||||
-rwxr-xr-x | views/layout.haml | 8 | ||||
-rw-r--r-- | views/lazar.haml | 163 | ||||
-rw-r--r-- | views/next.haml | 7 | ||||
-rw-r--r-- | views/prediction.haml | 7 | ||||
-rw-r--r-- | views/prev.haml | 8 | ||||
-rw-r--r-- | views/style.sass | 26 |
8 files changed, 265 insertions, 11 deletions
diff --git a/application.rb b/application.rb index 9501b4c..2eca13d 100644 --- a/application.rb +++ b/application.rb @@ -66,7 +66,6 @@ get '/model/:id/:view/?' do end else return "unable to render model: id #{params[:id]}, view #{params[:view]}" - #return "render error" end rescue return "unable to render model: id #{params[:id]}, view #{params[:view]}" @@ -176,8 +175,9 @@ post '/predict/?' do # post chemical name to model confidence = nil title = nil db_activities = [] - LOGGER.debug "curl -X POST -d 'compound_uri=#{@compound.uri}' -H 'Accept:application/x-yaml' #{model.uri}" + #LOGGER.debug "curl -X POST -d 'compound_uri=#{@compound.uri}' -H 'Accept:application/x-yaml' #{model.uri}" prediction = YAML.load(`curl -X POST -d 'compound_uri=#{@compound.uri}' -H 'Accept:application/x-yaml' #{model.uri}`) + #prediction = YAML.load(OpenTox::Model::Lazar.predict(params[:compound_uri],params[:model_uri])) source = prediction.creator if prediction.data[@compound.uri] if source.to_s.match(/model/) # real prediction @@ -185,9 +185,19 @@ post '/predict/?' do # post chemical name to model LOGGER.debug prediction[File.join(@@config[:services]["opentox-model"],"lazar#classification")] LOGGER.debug prediction[File.join(@@config[:services]["opentox-model"],"lazar#confidence")] if !prediction[File.join(@@config[:services]["opentox-model"],"lazar#classification")].nil? - @predictions << {:title => model.name, :prediction => prediction[File.join(@@config[:services]["opentox-model"],"lazar#classification")], :confidence => prediction[File.join(@@config[:services]["opentox-model"],"lazar#confidence")]} + @predictions << { + :title => model.name, + :model_uri => model.uri, + :prediction => prediction[File.join(@@config[:services]["opentox-model"],"lazar#classification")], + :confidence => prediction[File.join(@@config[:services]["opentox-model"],"lazar#confidence")] + } elsif !prediction[File.join(@@config[:services]["opentox-model"],"lazar#regression")].nil? - @predictions << {:title => model.name, :prediction => prediction[File.join(@@config[:services]["opentox-model"],"lazar#regression")], :confidence => prediction[File.join(@@config[:services]["opentox-model"],"lazar#confidence")]} + @predictions << { + :title => model.name, + :model_uri => model.uri, + :prediction => prediction[File.join(@@config[:services]["opentox-model"],"lazar#regression")], + :confidence => prediction[File.join(@@config[:services]["opentox-model"],"lazar#confidence")] + } end else # database value prediction = prediction.data[@compound.uri].first.values @@ -202,6 +212,36 @@ post '/predict/?' do # post chemical name to model haml :prediction end +post "/lazar/?" do + @page = 0 + @page = params[:page].to_i if params[:page] + @highlight = params[:highlight] + @model_uri = params[:model_uri] + @prediction = YAML.load(OpenTox::Model::Lazar.predict(params[:compound_uri],params[:model_uri])) + @compound = OpenTox::Compound.new(:uri => params[:compound_uri]) + @title = @prediction.title + if @prediction.data[@compound.uri] + if @prediction.creator.to_s.match(/model/) # real prediction + p = @prediction.data[@compound.uri].first.values.first + if !p[File.join(@@config[:services]["opentox-model"],"lazar#classification")].nil? + feature = File.join(@@config[:services]["opentox-model"],"lazar#classification") + elsif !p[File.join(@@config[:services]["opentox-model"],"lazar#regression")].nil? + feature = File.join(@@config[:services]["opentox-model"],"lazar#regression") + end + @activity = p[feature] + @confidence = p[File.join(@@config[:services]["opentox-model"],"lazar#confidence")] + @neighbors = p[File.join(@@config[:services]["opentox-model"],"lazar#neighbors")]#.sort{|a,b| b.last[:similarity] <=> a.last[:similarity]} + #@training_activities = p[File.join(@@config[:services]["opentox-model"],"lazar#activities")] + @features = p[File.join(@@config[:services]["opentox-model"],"lazar#features")] + else # database value + @measured_activities = @prediction.data[@compound.uri].first.values + end + else + @activity = "not available (no similar compounds in the training dataset)" + end + haml :lazar +end + delete '/?' do ToxCreateModel.auto_migrate! response['Content-Type'] = 'text/plain' diff --git a/views/fragment.haml b/views/fragment.haml new file mode 100644 index 0000000..fa7495d --- /dev/null +++ b/views/fragment.haml @@ -0,0 +1,9 @@ +%form{:name => "form", :action => url_for('/lazar'), :method => "post", :enctype => "multipart/form-data" } + %input{:type => :hidden, :name => :compound_uri, :value => compound_uri} + %input{:type => :hidden, :name => :model_uri, :value => model_uri} + %input{:type => :hidden, :name => :highlight, :value => smarts} + - if smarts.nil? + %input{ :type => "submit", :value => "Reset"} + - else + %input{ :type => "submit", :value => smarts} + diff --git a/views/layout.haml b/views/layout.haml index 7935b33..61d1650 100755 --- a/views/layout.haml +++ b/views/layout.haml @@ -10,11 +10,7 @@ %body .logo= image_tag "/ToxCreate_rgb_72.png", :alt => 'ToxCreate', :align => "right" - -#.headline - .logo - .span1="Tox" - .span2="Create" - + .index %ul %li{:class => ("selected" if /\/create/ =~ request.path )} @@ -27,7 +23,7 @@ = link_to "Help", "/help" .content - - if `hostname`.match(/ot-test|ot-dev/) + - if `hostname`.match(/ot-test/) .notice This service is for testing purposes only - once a week all models will be deleted. Please send bug reports and feature requests to our %a{:href => 'http://github.com/helma/opentox-toxmodel/issues'} issue tracker. diff --git a/views/lazar.haml b/views/lazar.haml new file mode 100644 index 0000000..057b1cd --- /dev/null +++ b/views/lazar.haml @@ -0,0 +1,163 @@ +.lazar-predictions + %table + %tr + %th= @title.gsub(/_lazar_.*$/,' ').capitalize + %th Prediction + %th + %a{:href => "#", :id => "linkConfidence#{p.object_id}"} Confidence + :javascript + $("a#linkConfidence#{p.object_id}").click(function () { + $("dl#confidence").toggle(); + }); + -#%th + Significant fragments + = haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => nil}, :layout => false + -#%th Additional data + + %tr + %td + %img{:src => @compound.display_smarts_uri(@features[:activating].keys,@features[:deactivating].keys, params[:highlight]), :alt => @compound.smiles} + %td + - if @measured_activities + %br + - @measured_activities.each do |a| + - if activity(a) == 'active' + .active + = activity(a) + - elsif activity(a) == 'inactive' + .inactive + = activity(a) + - else + = a + %br + ( + %a{:href => "#", :id => "linkTrainingData#{p.object_id}"} Training data + :javascript + $("a#linkTrainingData#{p.object_id}").click(function () { + $("dl#training_data").toggle(); + }); + ) + + - else + - if activity(@activity) == 'active' + .active + = activity(@activity) + - elsif activity(@activity) == 'inactive' + .inactive + = activity(@activity) + - elsif @activity.is_a?(Float) + .other + = sprintf('%.03g', @activity) + - else + .other + %em= @activity.to_s + %td= sprintf('%.03g', @confidence.to_f.abs) if @confidence + -#%td + %table + - unless @features[:activating].empty? + %tr + %th activating + %th p value + - if @features[:activating] + - @features[:activating].sort{|a,b| b.last <=> a.last }.each do |f| + %tr + - if @highlight == f[0] + %td.selected= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[0]}, :layout => false + %td.selected= f[1] + - else + %td= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[0]}, :layout => false + %td= f[1] + - unless @features[:deactivating].empty? + %tr + %th deactivating + %th p value + - if @features[:deactivating] + - @features[:deactivating].sort{|a,b| b.last <=> a.last }.each do |f| + %tr + - if @highlight == f[0] + %td.selected= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[0]}, :layout => false + %td.selected= f[1] + - else + %td= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[0]}, :layout => false + %td= f[1] + -#%td + + %tr + %th + Neighbors + = haml :prev, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => @highlight, :page => @page, :size => @neighbors.size}, :layout => false + = "(#{5*@page+1}-#{5*@page+5}/#{@neighbors.size})" + = haml :next, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => @highlight, :page => @page, :size => @neighbors.size}, :layout => false + %th Activity + %th Similarity (activity specific) + -#%th + Significant fragemnts + = haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => nil}, :layout => false + -#%th Additional data + -#%th Exclude + - first = 5*@page + - last = first+4 + - @neighbors.sort{|a,b| b.last[:similarity] <=> a.last[:similarity]}[first..last].each do |uri,data| + - c = OpenTox::Compound.new(:uri => uri) + %tr + %td + -#%br + %a{:href => c.display_smarts_uri(data[:features][:activating].collect{|f| f[:smarts]}, data[:features][:deactivating].collect{|f| f[:smarts]}, params[:highlight])} #{c.smiles} + %br + %img{:src => c.display_smarts_uri(data[:features][:activating].collect{|f| f[:smarts]}, data[:features][:deactivating].collect{|f| f[:smarts]}, params[:highlight]), :alt => c.smiles} + %td + - data[:activities].each do |act| + - if activity(act) == 'active' + .active + = activity(act) + - elsif activity(act) == 'inactive' + .inactive + = activity(act) + - elsif act.is_a?(Float) + .other + = sprintf('%.03g', act) + - else + .other + %em= act.to_s + %td + = sprintf('%.03g', data[:similarity]) + -#%td + %table + - unless data[:features][:activating].empty? + %tr + %th activating + %th p value + - data[:features][:activating].sort{|a,b| b[:p_value] <=> a[:p_value] }.each do |f| + %tr + - if @highlight == f[:smarts] + %td.selected= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[:smarts]}, :layout => false + %td.selected= f[:p_value] + - else + %td= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[:smarts]}, :layout => false + %td= f[:p_value] + - unless data[:features][:deactivating].empty? + %tr + %th deactivating + %th p value + - data[:features][:deactivating].sort{|a,b| b[:p_value] <=> a[:p_value] }.each do |f| + %tr + - if @highlight == f[:smarts] + %td.selected= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[:smarts]}, :layout => false + %td.selected= f[:p_value] + - else + %td= haml :fragment, :locals => {:compound_uri => @compound.uri, :model_uri => @model_uri, :smarts => f[:smarts]}, :layout => false + %td= f[:p_value] + -#%td + -#%td + + +%dl#confidence{ :style => "display: none;" } + %dt Confidence: + %dd 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 distiguish between reliable and unreliable predictions. + + +%dl#training_data{ :style => "display: none;" } + %dt Training data: + %dd Experimental result(s) from the training dataset are displayed here. + + diff --git a/views/next.haml b/views/next.haml new file mode 100644 index 0000000..b7a2b3a --- /dev/null +++ b/views/next.haml @@ -0,0 +1,7 @@ +- unless 5*page.to_i+5 >= size + %form{:name => "form", :action => url_for('/lazar'), :method => "post", :enctype => "multipart/form-data" } + %input{:type => :hidden, :name => :compound_uri, :value => compound_uri} + %input{:type => :hidden, :name => :model_uri, :value => model_uri} + %input{:type => :hidden, :name => :highlight, :value => smarts} + %input{:type => :hidden, :name => :page, :value => page.to_i+1} + %input{ :type => "submit", :value => ">>"} diff --git a/views/prediction.haml b/views/prediction.haml index 1edb2e8..94d7987 100644 --- a/views/prediction.haml +++ b/views/prediction.haml @@ -6,7 +6,7 @@ %th{:colspan => @predictions.size+1} = @identifier %tr - %th + %td %img{:src => @compound.image_uri, :alt => @compound.smiles} - @predictions.each do |p| %td @@ -55,6 +55,11 @@ $("dl#confidence").toggle(); }); ) + %br + %form{:name => "form", :action => url_for('/lazar'), :method => "post", :enctype => "multipart/form-data" } + %input{:type => :hidden, :name => :compound_uri, :value => @compound.uri} + %input{:type => :hidden, :name => :model_uri, :value => p[:model_uri]} + %input{ :type => "submit", :value => "Details"} %dl#confidence{ :style => "display: none;" } %dt Confidence: diff --git a/views/prev.haml b/views/prev.haml new file mode 100644 index 0000000..9a00579 --- /dev/null +++ b/views/prev.haml @@ -0,0 +1,8 @@ +- unless page.to_i == 0 + %form{:name => "form", :action => url_for('/lazar'), :method => "post", :enctype => "multipart/form-data" } + %input{:type => :hidden, :name => :compound_uri, :value => compound_uri} + %input{:type => :hidden, :name => :model_uri, :value => model_uri} + %input{:type => :hidden, :name => :highlight, :value => smarts} + %input{:type => :hidden, :name => :page, :value => page.to_i-1} + %input{ :type => "submit", :value => "<<"} + diff --git a/views/style.sass b/views/style.sass index 1900517..ce579e3 100644 --- a/views/style.sass +++ b/views/style.sass @@ -138,6 +138,32 @@ body img padding: 0 height: 100% + .lazar-predictions + clear: both + margin-top: 2% + table + border-spacing: 0 + border-collapse: collapse + margin: 0 + th + border: 1px solid + color: $body_color + background-color: $fg_color + //border: 1px solid + margin: 0.5em + td + border: 1px solid + background-color: $bg_color2 + padding: 0.5em + table + font-size: x-small + td + border: none + td.selected + background-color: blue + //img + padding: 0 + //height: 100% .model padding: 0em 1em background-color: $bg_color2 |