summaryrefslogtreecommitdiff
path: root/application.rb
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2013-03-27 17:11:59 +0100
committergebele <gebele@in-silico.ch>2013-03-27 17:11:59 +0100
commitde03020a09cdc6438d27916207cab1de554a70f2 (patch)
tree65192a060f7793d7741cb1c5f5d91f124ba9e0b6 /application.rb
parent2b02d8fdafe4ea4d4027d5aa18d56fc77ec5ef9a (diff)
error handling compound names;smiles validation
Diffstat (limited to 'application.rb')
-rw-r--r--application.rb111
1 files changed, 72 insertions, 39 deletions
diff --git a/application.rb b/application.rb
index 69cf031..54b2d10 100644
--- a/application.rb
+++ b/application.rb
@@ -8,10 +8,6 @@ require File.join(File.dirname(__FILE__),'helper.rb')
require File.join(ENV["HOME"],".opentox","config","lazar-gui.rb")
helpers do
- def compound_uri(uri)
- $logger.debug "\ncompound_uri: #{uri}\n"
- @compound_uri = OpenTox::Compound.new uri
- end
end
get '/?' do
@@ -20,50 +16,87 @@ end
get '/predict/?' do
@models = OpenTox::Model.all $model[:uri]
-
haml :predict
end
-post '/predict/?' do
- # transfered input
- @identifier = params[:identifier]
- # get compound from SMILES
- @compound = OpenTox::Compound.from_smiles $compound[:uri], @identifier.to_s
- # init
- @@prediction_models = []
- @@predictions = []
- # init lazar algorithm
- lazar = OpenTox::Algorithm.new File.join($algorithm[:uri],"lazar")
- # gather models from service and compare if selected
- params[:selection].each do |model|
- @mselected = model[0]
- @mall = OpenTox::Model.all $model[:uri]
- @mall.each do |m|
- m.get
- @@prediction_models << m if m.title =~ /#{@mselected}/
- end
- $logger.debug "@prediction_models: #{@@prediction_models.inspect}"
- end
+get '/jme_help/?' do
+ File.read(File.join('views','jme_help.html'))
+end
- # predict with selected models
- # results in prediction variable
- # store prediction in array for better handling
- @@prediction_models.each do |m|
- @prediction_uri = m.run :compound_uri => "#{@compound.uri}"
- prediction = OpenTox::Dataset.new @prediction_uri
- pa = []
- pa << prediction
- @@predictions << pa
+# best way to get individual compound uri for details
+get '/prediction/:neighbour/details/?' do
+ @compound_uri = OpenTox::Compound.new params[:neighbour]
+ @smiles = @compound_uri.smiles
+ task = OpenTox::Task.create($task[:uri], @subjectid, RDF::DC.description => "look for names.") do
+ names = @compound_uri.names
end
-
- haml :prediction
+ sleep 1
+ task.get
+ case task[RDF::OT.hasStatus]
+ when "Error"
+ @names = "There are no names for this compound available."
+ when "Completed"
+ @names = @compound_uri.names
+ end
+ @inchi = @compound_uri.inchi.gsub("InChI=", "InChI: ")
+ haml :details, :layout => false
end
+post '/predict/?' do
+ # validate identifier input
+ task = OpenTox::Task.create($task[:uri], @subjectid, RDF::DC.description => "#{params[:identifier] ? params[:identifier] : "no valid SMILES string."}: Validate SMILES string.") do
+ # transfered input
+ @identifier = params[:identifier]
+ # get compound from SMILES
+ @compound = OpenTox::Compound.from_smiles $compound[:uri], @identifier.to_s
+ # validate SMILES by converting to INCHI
+ inchi = @compound.inchi
+ end
+ # necessary to wait for task
+ sleep 1
+ task.get
+ $logger.debug "task uri: #{task.uri}"
+ $logger.debug "task status: #{task[RDF::OT.hasStatus]}"
+ # case task fails return message smiles invalid
+ # case task completed go ahead
+ case task[RDF::OT.hasStatus]
+ when "Error"
+ @error_report = "Not a valid SMILES string."
+ haml :error
+ when "Completed"
+ @identifier = params[:identifier]
+ @compound = OpenTox::Compound.from_smiles $compound[:uri], @identifier.to_s
+ # init
+ @@prediction_models = []
+ @@predictions = []
+ # init lazar algorithm
+ lazar = OpenTox::Algorithm.new File.join($algorithm[:uri],"lazar")
+ # gather models from service and compare if selected
+ params[:selection].each do |model|
+ @mselected = model[0]
+ @mall = OpenTox::Model.all $model[:uri]
+ @mall.each do |m|
+ m.get
+ @@prediction_models << m if m.title =~ /#{@mselected}/
+ end
+ $logger.debug "@prediction_models: #{@@prediction_models.inspect}"
+ end
-get '/prediction/:neighbour/details/?' do
- @compound_uri = OpenTox::Compound.new params[:neighbour]
+ # predict with selected models
+ # results in prediction variable
+ # store prediction in array for better handling
+ @@prediction_models.each do |m|
+ @prediction_uri = m.run :compound_uri => "#{@compound.uri}"
+ prediction = OpenTox::Dataset.new @prediction_uri
+ pa = []
+ pa << prediction
+ @@predictions << pa
+ end
+
+ haml :prediction
+ end
+
- haml :details, :layout => false
end
get '/stylesheets/:name.css' do