From de03020a09cdc6438d27916207cab1de554a70f2 Mon Sep 17 00:00:00 2001 From: gebele Date: Wed, 27 Mar 2013 17:11:59 +0100 Subject: error handling compound names;smiles validation --- application.rb | 111 ++++++++++++++++++++++++++--------------- public/stylesheets/screen.css | 2 +- public/stylesheets/screen.sass | 15 ++++++ views/details.haml | 6 +-- views/error.haml | 8 +++ views/predict.haml | 5 +- 6 files changed, 102 insertions(+), 45 deletions(-) create mode 100644 views/error.haml 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 diff --git a/public/stylesheets/screen.css b/public/stylesheets/screen.css index 10ab093..d522e1d 100644 --- a/public/stylesheets/screen.css +++ b/public/stylesheets/screen.css @@ -1 +1 @@ -body{background-image:url("/images/gray_jean.png");background-color:#ccf;overflow:scroll;font-family:sans-serif;min-width:800px;min-heigth:600px}body a{text-decoration:none;font-weight:bold;color:#000}.logo img{float:left}.logo h1{margin-top:-2px;position:relative;top:-4px;left:20px}.content{background-image:url("/images/gray_jean.png")}.content h1{margin:0.3em;text-shadow:#fff 1px 1px 0;font-size:x-large;font-family:Verdana;display:inline}.content h2{text-shadow:#fff 1px 1px 0;font-size:x-large;color:#f55}.content .arrow{margin:5px 0px 5px 20px}.content .back{display:inline}.content .close{text-align:right}.content fieldset#top{border:0;margin-top:5em;padding:10px;background-color:#dbc87b;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset}.content fieldset#top draw{display:block}.content fieldset#middle{border:0;padding:10px;background-color:#dbc87b;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset}.content fieldset#middle #model a{font-weight:normal}.content fieldset#bottom{border:0;background-color:#dbc87b;padding:10px;margin-bottom:5em;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content fieldset#bottom input#predict{margin-left:1em}.content .predictions{margin-top:5em;background-color:#dbc87b;padding:10px;text-align:justify;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content .overview{background-image:url("/images/gray_jean.png");padding:12px;margin-top:1em;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content .overview caption{text-align:left}.content .overview #overview tr td{background-color:#fff;border:1px solid #dad9c7;padding-left:1em}.content .overview #overview tr td#compound{width:150px}.details{margin-bottom:2em;height:400px;scroll:auto;background-image:url("/images/gray_jean.png");-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.results{background-image:url("/images/gray_jean.png");overflow:auto;margin-top:2em;margin-bottom:2em;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset}.results .tablesorter{width:100%}.results .tablesorter thead{background-color:#fcfaf3}.results .tablesorter thead tr th.header{background-image:url("/images/bg.gif");background-repeat:no-repeat;background-position:center left;cursor:pointer;padding-left:20px;border:1px solid #dad9c7;margin-left:-1px}.results .tablesorter thead tr th.headerSortDown{background-image:url("/images/desc.gif");background-color:#e2d397}.results .tablesorter thead tr th.headerSortUp{background-image:url("/images/asc.gif");background-color:#e2d397}.results .tablesorter tbody tr.odd td{background-color:#f0f0f0}.results .tablesorter tbody tr.even td{background-color:ivory}input#predict{border:0px;background-color:#dbc87b;margin:0;padding:0}.footer{margin:20px 0 20px 0} +body{background-image:url("/images/gray_jean.png");background-color:#ccf;overflow:scroll;font-family:sans-serif;min-width:800px;min-heigth:600px}body a{text-decoration:none;font-weight:bold;color:#000}.logo img{float:left}.logo h1{margin-top:-2px;position:relative;top:-4px;left:20px}.content{background-image:url("/images/gray_jean.png")}.content h1{margin:0.3em;text-shadow:#fff 1px 1px 0;font-size:x-large;font-family:Verdana;display:inline}.content h2{text-shadow:#fff 1px 1px 0;font-size:x-large;color:#f55}.content .arrow{margin:5px 0px 5px 20px}.content .back{display:inline}.content .close{text-align:right}.content fieldset#top{border:0;margin-top:5em;padding:10px;background-color:#dbc87b;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset}.content fieldset#top draw{display:block}.content fieldset#middle{border:0;padding:10px;background-color:#dbc87b;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset}.content fieldset#middle #model a{font-weight:normal}.content fieldset#bottom{border:0;background-color:#dbc87b;padding:10px;margin-bottom:5em;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content fieldset#bottom input#predict{margin-left:1em}.content .predictions{margin-top:5em;background-color:#dbc87b;padding:10px;text-align:justify;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content .overview{background-image:url("/images/gray_jean.png");padding:12px;margin-top:1em;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content .overview caption{text-align:left}.content .overview #overview tr td{background-color:#fff;border:1px solid #dad9c7;padding-left:1em}.content .overview #overview tr td#compound{width:150px}.content .error{margin-top:5em;background-color:#dbc87b;padding:10px;text-align:justify;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-border-radius-topleft:25px;-webkit-border-top-left-radius:25px;border-top-left-radius:25px;-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-topright:25px;-webkit-border-top-right-radius:25px;border-top-right-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.content .error error{border:2px solid #f55;background-color:#fff;color:#f55}.details{margin-bottom:2em;height:400px;scroll:auto;background-image:url("/images/gray_jean.png");-moz-border-radius-bottomleft:25px;-webkit-border-bottom-left-radius:25px;border-bottom-left-radius:25px;-moz-border-radius-bottomright:25px;-webkit-border-bottom-right-radius:25px;border-bottom-right-radius:25px;-webkit-background-clip:border;-moz-background-clip:border;background-clip:border-box}.results{background-image:url("/images/gray_jean.png");overflow:auto;margin-top:2em;margin-bottom:2em;-webkit-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;-moz-box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset;box-shadow:1px 1px 1px #fff inset,-1px -1px 5px rgba(0,0,0,0.3) inset}.results .tablesorter{width:100%}.results .tablesorter thead{background-color:#fcfaf3}.results .tablesorter thead tr th.header{background-image:url("/images/bg.gif");background-repeat:no-repeat;background-position:center left;cursor:pointer;padding-left:20px;border:1px solid #dad9c7;margin-left:-1px}.results .tablesorter thead tr th.headerSortDown{background-image:url("/images/desc.gif");background-color:#e2d397}.results .tablesorter thead tr th.headerSortUp{background-image:url("/images/asc.gif");background-color:#e2d397}.results .tablesorter tbody tr.odd td{background-color:#f0f0f0}.results .tablesorter tbody tr.even td{background-color:ivory}input#predict{border:0px;background-color:#dbc87b;margin:0;padding:0}.footer{margin:20px 0 20px 0} diff --git a/public/stylesheets/screen.sass b/public/stylesheets/screen.sass index d521eb8..db6395d 100644 --- a/public/stylesheets/screen.sass +++ b/public/stylesheets/screen.sass @@ -121,6 +121,21 @@ body padding-left: 1em #overview tr td#compound width: 150px + + .error + margin-top: 5em + background-color: $ist-color + padding: 10px + text-align: justify + +box-shadow(1px 1px 1px rgba(white, 1) inset, -1px -1px 5px rgba(black, 0.3) inset) + +border-left-radius(25px) + +border-right-radius(25px) + +background-clip(border-box) + + error + border: 2px solid #FF5555 + background-color: #FFFFFF + color: #FF5555 .details margin-bottom: 2em diff --git a/views/details.haml b/views/details.haml index 448e8a8..38d97fe 100644 --- a/views/details.haml +++ b/views/details.haml @@ -7,12 +7,12 @@ %img{:src=>"#{@compound_uri.uri}/image", :alt=>@compound_uri.uri, :width=>"100px"} %p SMILES: - = @compound_uri.smiles if @compound_uri.smiles + = @smiles %p // TODO handle OpenTox::ResourceNotFoundError Names: - = @compound_uri.names if @compound_uri.names + = @names %p - = @compound_uri.inchi.gsub("InChI=", "InChI: ") if @compound_uri.inchi + = @inchi diff --git a/views/error.haml b/views/error.haml new file mode 100644 index 0000000..9aced43 --- /dev/null +++ b/views/error.haml @@ -0,0 +1,8 @@ +.error + .back + %h1 + %img{:src=>"/images/arrow_left_float.png", :alt=>"arrow"} + %a{:href => to('/predict')} New Prediction + %error + = @error_report.to_s + diff --git a/views/predict.haml b/views/predict.haml index dbfab50..b53acb6 100644 --- a/views/predict.haml +++ b/views/predict.haml @@ -6,7 +6,7 @@ }; function checksmiles () { if (document.form.identifier.value == "") { - alert("Please insert a compound.") + alert("Please insert a compound."); document.form.identifier.focus(); return false; }; @@ -20,7 +20,8 @@ }; return true; }; - + +/ whole site content needs to be in one form. Input and checkboxes are checked by js functions. %form{:name => "form", :action => to('/predict'), :method => "post", :enctype => "multipart/form-data", :onsubmit => "return !!(checksmiles() & checkboxes())" } %fieldset#top %a{:href => "#insert", :id => "linkInsert"} -- cgit v1.2.3