summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Helma <helma@in-silico.de>2010-02-04 19:41:23 +0100
committerChristoph Helma <helma@in-silico.de>2010-02-04 19:41:23 +0100
commit6171a5a7879c0465f0eaea8f2451554882af4b92 (patch)
tree5119817ebb7540eaa8b229fe66618ce9564e23cb
parente769f0d2c2b5eb866b039f0b7857955d9e436e78 (diff)
tasks as trees, prediction of database structures, improved error checking
-rw-r--r--application.rb33
-rw-r--r--config.ru2
-rw-r--r--views/create.haml28
-rw-r--r--views/predict.haml37
-rw-r--r--views/prediction.haml26
-rw-r--r--views/style.sass22
6 files changed, 88 insertions, 60 deletions
diff --git a/application.rb b/application.rb
index ff9b964..a649b82 100644
--- a/application.rb
+++ b/application.rb
@@ -2,7 +2,6 @@
require lib
end
require 'rack-flash'
-#require 'benchmark'
gem 'opentox-ruby-api-wrapper', '= 1.2.7'
require 'opentox-ruby-api-wrapper'
gem 'sinatra-static-assets'
@@ -11,6 +10,20 @@ require 'sinatra/static_assets'
use Rack::Flash
set :sessions, true
+helpers do
+ def activity(a)
+ case a.to_s
+ when "true"
+ act = "active"
+ when "false"
+ act = "inactive"
+ else
+ act = "not available"
+ end
+ act
+ end
+end
+
get '/?' do
redirect url_for('/create')
end
@@ -75,14 +88,15 @@ post '/predict/?' do # post chemical name to model
@compound = OpenTox::Compound.new(:name => params[:identifier])
rescue
flash[:notice] = "Could not find a structure for #{@identifier}. Please try again."
- redirect '/predict'
+ redirect url_for('/predict')
end
@predictions = []
params[:selection].keys.each do |uri|
prediction = nil
confidence = nil
title = nil
- prediction = RestClient.post uri, :compound_uri => @compound.uri, :accept => "application/x-yaml"
+ db_activities = []
+ prediction = RestClient.post uri, :compound_uri => @compound.uri#, :accept => "application/x-yaml"
model = Redland::Model.new Redland::MemoryStore.new
parser = Redland::Parser.new
parser.parse_string_into_model(model,prediction,'/')
@@ -93,18 +107,13 @@ post '/predict/?' do # post chemical name to model
feature_name = model.object(feature,DC['title']).to_s
prediction = model.object(v,OT['value']).to_s if feature_name.match(/classification/)
confidence = model.object(v,OT['value']).to_s if feature_name.match(/confidence/)
+ db_activities << model.object(v,OT['value']).to_s if feature_name.match(/#{title}/)
end
- case prediction.to_s
- when "true"
- prediction = "active"
- when "false"
- prediction = "inactive"
- else
- prediction = "not available"
- end
- @predictions << {:title => title, :prediction => prediction, :confidence => confidence}
+ @predictions << {:title => title, :prediction => prediction, :confidence => confidence, :measured_activities => db_activities}
+ LOGGER.debug db_activities.to_yaml
end
+ LOGGER.debug @predictions.to_yaml
haml :prediction
#@predictions.to_yaml
end
diff --git a/config.ru b/config.ru
index efe0004..78b1144 100644
--- a/config.ru
+++ b/config.ru
@@ -1,5 +1,5 @@
require 'rubygems'
require 'opentox-ruby-api-wrapper'
-require 'tasks/config'
+require 'config/config_ru'
set :app_file, __FILE__ # to get the view path right
run Sinatra::Application
diff --git a/views/create.haml b/views/create.haml
index 9477210..5527d70 100644
--- a/views/create.haml
+++ b/views/create.haml
@@ -1,17 +1,15 @@
-.upload
+.input
%form{ :action => url_for('/upload'), :method => "post", :enctype => "multipart/form-data" }
- %ol
- %li
- %label{:for => 'endpoint'}Enter endpoint name:
- %input{:type => 'text', :name => 'endpoint', :id => 'endpoint'}
- %li
- %label{:for => 'file'}
- Upload training data in CSV format:
- %input{:type => 'file', :name => 'file', :id => 'file'}
- (
- = link_to "formatting instructions ", 'csv_format'
- )
- %li
- %input{ :type => "submit", :value => "Create model"}
- = link_to "Cancel", 'create'
+ %fieldset
+ %legend Upload training data and create a prediction model
+ %label{:for => 'endpoint'} 1. Enter endpoint name:
+ %input{:type => 'text', :name => 'endpoint', :id => 'endpoint'}
+ %br
+ %label{:for => 'file'} 2. Select training data in CSV format:
+ %input{:type => 'file', :name => 'file', :id => 'file'}
+ (
+ = link_to "formatting instructions ", 'csv_format'
+ )
+ %input{ :type => "submit", :value => "Create model"}
+ = link_to "Cancel", 'create'
diff --git a/views/predict.haml b/views/predict.haml
index 7c4b980..f6ed6a3 100644
--- a/views/predict.haml
+++ b/views/predict.haml
@@ -1,25 +1,20 @@
-.upload
+.input
- unless @models.nil?
%form{ :action => url_for('/predict'), :method => "post", :enctype => "multipart/form-data" }
- %ol
- %li
- %label{:for => 'identifier'}Enter a compound identifier:
- %input{:type => 'text', :name => 'identifier', :id => 'identifier'}
- (Name, InChI, Smiles, CAS, ...)
- %li
- %label{:for => 'model'}Choose one or more prediction models:
- %ul
- - @models.each do |model|
- - yaml = RestClient.get model, :accept => 'application/x-yaml'
- - yaml = YAML.load yaml
- %br
- -# %input{:type => 'checkbox', :name => 'model_uri', :value => model}
- -# %input{:type => 'checkbox', :name => "selection[#{model}]", :value => true}
- %input{:type => 'checkbox', :name => "selection[#{model}]", :value => true, :id => 'model'}
- = yaml[:endpoint].split(/#/).last
+ %fieldset
+ %legend Enter a compound identifier
+ %label{:for => 'identifier'} Name, InChI, Smiles, CAS, ...
+ %input{:type => 'text', :name => 'identifier', :id => 'identifier'}
+ %fieldset
+ %legend Choose one or more prediction models
+ - @models.each do |model|
+ - yaml = RestClient.get model, :accept => 'application/x-yaml'
+ - yaml = YAML.load yaml
+ %label{:for => model}
+ = yaml[:endpoint].split(/#/).last.gsub(/_/,' ')
+ %input{:type => 'checkbox', :name => "selection[#{model}]", :value => true, :id => model}
+ %br
- %li
- %p
- %input{ :type => "submit", :value => "Predict"}
- = link_to 'Cancel', '/'
+ %input{ :type => "submit", :value => "Predict"}
+ = link_to 'Cancel', '/'
diff --git a/views/prediction.haml b/views/prediction.haml
index aa84fee..74e0956 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -9,8 +9,24 @@
- @predictions.each do |p|
%td
%b
- = p[:title] + ":"
- = p[:prediction]
- %br
- Confidence:
- = p[:confidence]
+ = p[:title].gsub(/_/,' ') + ":"
+ - if p[:measured_activities].size > 0
+ %br
+ - p[:measured_activities].each do |a|
+ - if activity(a) == 'active'
+ .active
+ = activity(a)
+ - elsif activity(a) == 'inactive'
+ .inactive
+ = activity(a)
+ %br (training data)
+ - else
+ - if activity(p[:prediction]) == 'active'
+ .active
+ = activity(p[:prediction])
+ - elsif activity(p[:prediction]) == 'inactive'
+ .inactive
+ = activity(p[:prediction])
+ - if p[:confidence]
+ %br
+ = "(confidence: #{sprintf('%.03f', p[:confidence].to_f.abs)})"
diff --git a/views/style.sass b/views/style.sass
index 4d29ddd..c509c3b 100644
--- a/views/style.sass
+++ b/views/style.sass
@@ -62,16 +62,20 @@ body
padding: 1%
border: 1px solid red
- .upload
+ .input
text-align: left
form
- li
- clear: left
+ fieldset
+ border: 0
+ legend
+ font-weight: bold
+ color = !fg_color
label
- width: 20em
- float: left
- margin-right: 0.5em
+ width: 25em
display: block
+ float: left
+ br
+ clear: both
.predictions
:text-align center
@@ -89,4 +93,10 @@ body
:border 1px solid
:padding 2%
+.active
+ color: red
+
+.inactive
+ color: green
+
.footer