summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgebele <gebele@in-silico.ch>2015-09-23 12:29:46 +0200
committergebele <gebele@in-silico.ch>2015-09-23 12:29:46 +0200
commit06a2f447ac99a37a60c71bb1c7b988beaa213e56 (patch)
tree3ff32e29aaa6a287ba4e7df28167e91c71639e1a
parent205a34e25b280fe2cffc2223730fffd2637661bf (diff)
enable csv download
-rw-r--r--application.rb41
-rw-r--r--views/batch.haml12
-rw-r--r--views/error.haml4
-rw-r--r--views/layout.haml2
-rw-r--r--views/predict.haml74
-rw-r--r--views/prediction.haml5
6 files changed, 73 insertions, 65 deletions
diff --git a/application.rb b/application.rb
index 1e9cf35..8168c52 100644
--- a/application.rb
+++ b/application.rb
@@ -189,13 +189,32 @@ get '/prediction/:model_uri/:type/:neighbor/significant_fragments/?' do
haml :significant_fragments, :layout => false
end
-get '/predict/:dataset/?' do
- t = Tempfile.new("tempfile.rdf")
- t << `curl -k -H accept:application/rdf+xml #{params[:dataset]}`
- send_file t.path,
- :filename => params[:dataset].split("/").last+".rdf"
- t.close
- t.unlink
+get '/predict/?:csv?' do
+ response['Content-Type'] = "text/csv"
+ @csv = "\"Compound\",\"Endpoint\",\"Type\",\"Prediction\",\"Confidence\"\n"
+ @@batch.each do |key, values|
+ values.each do |array|
+ model = array[0]
+ prediction = array[1]
+ compound = key.smiles
+ endpoint = "#{model.endpoint.gsub('_', ' ')} (#{model.species})"
+ if prediction[:confidence] == "measured"
+ type = ""
+ pred = prediction[:value].numeric? ? "#{prediction[:value].round(3)} (#{model.unit})" : prediction[:value]
+ confidence = "measured activity"
+ elsif prediction[:neighbors].size > 0
+ type = model.model.class.to_s.match("Classification") ? "Classification" : "Regression"
+ pred = prediction[:value].numeric? ? "#{'%.2e' % prediction[:value]} #{model.unit}" : prediction[:value]
+ confidence = prediction[:confidence]
+ else
+ type = ""
+ pred = "Not enough similar compounds in training dataset."
+ confidence = ""
+ end
+ @csv += "\"#{compound}\",\"#{endpoint}\",\"#{type}\",\"#{pred}\",\"#{confidence}\"\n"
+ end
+ end
+ @csv
end
post '/predict/?' do
@@ -213,6 +232,11 @@ post '/predict/?' do
input = OpenTox::Dataset.from_csv_file File.join "tmp", params[:fileselect][:filename]
dataset = OpenTox::Dataset.find input.id
@compounds = dataset.compounds
+ if @compounds.size == 0
+ @error_report = "No valid SMILES submitted."
+ dataset.delete
+ return haml :error
+ end
@batch = {}
@compounds.each do |compound|
@batch[compound] = []
@@ -222,7 +246,8 @@ post '/predict/?' do
@batch[compound] << [model, prediction]
end
end
- input.delete
+ @@batch = @batch
+ dataset.delete
return haml :batch
end
diff --git a/views/batch.haml b/views/batch.haml
index 7cf1d77..44d22f1 100644
--- a/views/batch.haml
+++ b/views/batch.haml
@@ -1,13 +1,19 @@
%div.well
- %a.btn.btn-warning{:href => to('/predict')} Make New Prediction
+ %a.btn.btn-warning{:href => to('/predict')}
+ %span.glyphicon.glyphicon-menu-left{:aria=>{:hidden=>"true"}}
+ Make New Prediction
/ displays all prediction result in first table
%div.table-responsive
%table.table.table-bordered{:id=>"batch", :style=>"background-color:white;"}
%thead
%tr
- %h3.col-md-4 Batch Prediction Results:
+ %h3.col-md-4{:style=>"padding-left:0;"} Batch Prediction Results:
%h3.col-md-8= @filename
-
+ %tr
+ %span.btn.btn-default
+ %a{:href=>"#{to("/predict/#{@filename}")}", :title=>"download"}
+ %span.glyphicon.glyphicon-download-alt{:aria=>{:hidden=>"true"}}
+ CSV
%tbody
/ key = compound, values = array of arrays with model, prediction
- @batch.each do |key, values|
diff --git a/views/error.haml b/views/error.haml
index c1c1f16..555982b 100644
--- a/views/error.haml
+++ b/views/error.haml
@@ -1,5 +1,7 @@
%div.well
- %a.btn.btn-warning{:href => to('/predict')} Back
+ %a.btn.btn-warning{:href => to('/predict')}
+ %i.glyphicon.glyphicon-menu-left
+ Back
%hr
%div.well{:style=>"width:100%;margin-bottom:2em;"}
= @error_report
diff --git a/views/layout.haml b/views/layout.haml
index 94a24e9..60f2bb3 100644
--- a/views/layout.haml
+++ b/views/layout.haml
@@ -24,7 +24,7 @@
%div.row
%div.col-md-2
%a{:href=> to("/predict")}
- %img.media-object{:src=>"/images/ist_logo.png", :alt=>"logo", :style=>"margin:0 3em 1em 2em;"}
+ %img.media-object{:src=>"/images/ist_logo.png", :alt=>"logo", :style=>"margin:0 3em 0 2em;"}
%div.col-md-8
%h1.media-heading{:style=>"margin: 0 0 0 1em;"} Lazar Toxicity Predictions
diff --git a/views/predict.haml b/views/predict.haml
index 273e567..de92c15 100644
--- a/views/predict.haml
+++ b/views/predict.haml
@@ -103,53 +103,24 @@
// whole site content needs to be in one form. Input and checkboxes are proofed by js functions.
%form{:name => "form", :action => to('/predict'), :method => "post", :enctype => "multipart/form-data", :onsubmit => "return !!(showcircle())" }
%fieldset#top.well
- %div.row
- %h2.col-md-6 1. Draw a chemical structure
- %h2.col-md-6 Select csv file
- %div.row
- %div.col-md-6
- #insert
- %label &nbsp;
- #appletContainer
- %br
- %label{:for => 'identifier'}
- or enter the
- %a{:href => "http://en.wikipedia.org/wiki/Simplified_molecular_input_line_entry_specification", :rel => "external"} SMILES
- string:
- %br
- %input{:type => 'text', :name => 'identifier', :id => 'identifier', :size => '60'}
- %div.col-md-6{:style=>"padding-top:3em;"}
- #batch
- Browse file (csv) for batch prediction:
- %br
- %span.btn.btn-default.btn-file
- %input{:type=>"file", :name=> "fileselect", :id=>"fileselect", :accept=>".csv"}
- %p
- Example structure:
- %table.table.table-bordered{:style=>"border-bottom:0;"}
- %thead
- %tr
- %th
- SMILES
- %th
- notes
- %tbody
- %tr
- %td
- compound
- %td
- %tr
- %td
- compound
- %td
- %tr
- %td
- compound
- %td
- %tr
- %td{:style=>"border-bottom:0;"}
- = "...."
- %td{:style=>"border-bottom:0;"}
+ %h2 1. Draw a chemical structure
+ #insert
+ %label &nbsp;
+ #appletContainer
+ %br
+ %label{:for => 'identifier'}
+ or enter the
+ %a{:href => "http://en.wikipedia.org/wiki/Simplified_molecular_input_line_entry_specification", :rel => "external"} SMILES
+ string:
+ %br
+ %input{:type => 'text', :name => 'identifier', :id => 'identifier', :size => '60'}
+ %p
+ %label{:for=>"fileselect"}
+ or upload a CSV file for batch predictions
+ %br
+ %span.btn.btn-default.btn-file
+ -#%input{:type=>"file", :name=> "fileselect", :id=>"fileselect", :accept=>".csv", :disabled=>"disabled"}
+ %input{:type=>"file", :name=> "fileselect", :id=>"fileselect", :accept=>"text/csv"}
%fieldset#middle.well
%h2 2. Select one or more endpoints
@@ -168,7 +139,10 @@
Details | Validation
%div.panel-collapse.collapse{:id=>"details#{model.id}", :style=>"margin-left:1em;"}
%b Model:
- = model.id
+ %br
+ Source:
+ %a{:href=>model.source, :rel=>"external"}
+ = model.source
%br
= "Algorithm:\tLAZAR"
%br
@@ -259,8 +233,8 @@
%td
=cv.confusion_matrix[0][1]+cv.confusion_matrix[1][1]
%td
- -#= "Confusion Matrix:\t"
- -#= cv.confusion_matrix
+ -#= "Confusion Matrix:\t"
+ -#= cv.confusion_matrix
- if model.regression?
%br
= "Root mean squared error:\t"
diff --git a/views/prediction.haml b/views/prediction.haml
index 87f8511..a03b509 100644
--- a/views/prediction.haml
+++ b/views/prediction.haml
@@ -6,8 +6,9 @@
});
});
%div.well
- %a.btn.btn-warning{:href => to('/predict')} Make New Prediction
-
+ %a.btn.btn-warning{:href => to('/predict')}
+ %i.glyphicon.glyphicon-menu-left
+ Make New Prediction
/ displays all prediction result in first table
%div.table-responsive
%table.table.table-bordered{:id=>"overview", :style=>"background-color:white;"}