summaryrefslogtreecommitdiff
path: root/views/predict.haml
blob: 634054a43704168cd8935d3a2a2e69567a8cc37f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
%link{ :href=>"/jsme/jsa.css", :rel=>"stylesheet"}
%script{:src=>"/jsme/jsme.nocache.js"}
:javascript
  $(function() { 
    $('a[data-toggle="tab"]').on('click', function (e) {
      localStorage.setItem('lastTab', $(e.target).attr('href'));
    });
    var lastTab = localStorage.getItem('lastTab');
    if (lastTab) {
      $('a[href="'+lastTab+'"]').click();
    }
  });  
  
  function getInput(){
    identifier = document.getElementById("identifier").value;
    fileselect = document.getElementById("fileselect").value;
    if (fileselect != ""){
      return 1;
    };
    if (identifier != ""){
      return 2;
    };
    return 0;
  };
  function showcircle() {
    switch (getInput()){
      case 0:
        alert("Please draw or insert a chemical structure.");
        return false;
        break;
      case 1:
        if (checkfile() && checkboxes()){
          button = document.getElementById("submit");
          image = document.getElementById("circle");
          button.parentNode.replaceChild(image, button);
          $("img.circle").show();
          return true;
        };
        return false;
        break;
      case 2:
        if (checksmiles() && checkboxes()){
          button = document.getElementById("submit");
          image = document.getElementById("circle");
          button.parentNode.replaceChild(image, button);
          $("img.circle").show();
          return true;
        };
        return false;
        break;
      default: false;
    };
    return false;
  };
  function checkfile() {
    var fileinput = document.getElementById("fileselect");
    if(fileinput.value != "") {
      //TODO check file type is csv
      return true;
    };
    alert("Please select a file (csv).");
    return false;
  };
  function checksmiles () {
    getsmiles();
    if (document.form.identifier.value == "") {
      alert("Please draw or insert a chemical structure.");
      document.form.identifier.focus();
      $("img.circle").hide();
      return false;
    };
    return true;
  };
  function checkboxes () {
    var checked = false;
    $('input[type="checkbox"]').each(function() {
      if ($(this).is(":checked")) {
        checked = true;
      };
    });
    if (checked == false){
      alert("Please select an endpoint.");
      $("img.circle").hide();
      return false;
    };
    return true;
  };
  function jsmeOnLoad() {
    jsmeApplet = new JSApplet.JSME("appletContainer", "380px", "340px", {
      //optional parameters
      "options" : "polarnitro"
    });
  document.JME = jsmeApplet;
  };
  function getsmiles() {
    if (document.JME.smiles() != '') {
      document.form.identifier.value = document.JME.smiles() ;
    };
  };

// 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
    %h2 1. Draw a chemical structure
    #insert
      %label  
      #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
    #models
      - @endpoints.each do |endpoint|
        %div{:id=>endpoint}
          %h4.head-back=endpoint
          - @models.select{|m| m.endpoint == endpoint}.each do |model|
            %div.row{:id => model.id}
              %span.col-sm-4
                %input{:type => "checkbox", :name => "selection[#{model.id}]", :id => "selection[#{model.species}]", :value => true, :disabled => false}
                %label{:for => "selection[#{model.species}]"}
                  = model.species
              %span.col-sm-8
                %a.btn.btn-default.btn-xs{:data=>{:toggle=>"collapse"}, :href=>"#details#{model.id}", :id => "link#{model.id}", :style=>"font-size:small;"}
                  Details | Validation
            %div.panel-collapse.collapse{:id=>"details#{model.id}", :style=>"margin-left:1em;"}
              %b Model:
              %br
              Source:
              %a{:href=>model.source, :rel=>"external"}
                = model.source
              %br
              = "Algorithm:\tLAZAR"
              %br
              - model.classification? ? type = "Classification" : type = "Regression"
              = "Type:\t"
              = type
              %br
              - training_dataset = OpenTox::Dataset.find model.training_dataset.id
              = "Training dataset:\t"
              = training_dataset.source.split("/").last
              %br
              = "Training compounds:\t"
              = training_dataset.compounds.size

              %p
              %b Validation (repeated):
              %div.row{:style=>"background-color:#f5f5f5;"}
                - model.crossvalidations.each do |crossvalidation|
                  %span.col-xs-4.col-sm-4.col-md-4.col-lg-4
                    - cv = OpenTox::CrossValidation.find crossvalidation.id
                    = "Num folds:\t"
                    = cv.folds
                    %br
                    = "Num instances:\t"
                    = cv.nr_instances
                    %br
                    = "Num unpredicted"
                    = cv.nr_unpredicted
                    - if model.classification? 
                      %br
                      = "Accuracy:\t"
                      = cv.accuracy.round(3) if cv.accuracy
                      %br
                      = "Weighted Accuracy:\t"
                      = cv.weighted_accuracy.round(3) if cv.weighted_accuracy
                      %br
                      = "True positive rate:\t"
                      = cv.true_rate["active"].round(3) if cv.true_rate["active"]
                      %br
                      = "True negative rate:\t"
                      = cv.true_rate["inactive"].round(3) if cv.true_rate["inactive"]
                      %br 
                      = "Positive predictive value:\t"
                      = cv.predictivity["active"].round(3) if cv.predictivity["active"]
                      %br
                      = "Negative predictive value:\t"
                      = cv.predictivity["inactive"].round(3) if cv.predictivity["inactive"]
                      %p
                      %b Confusion Matrix:
                      %table.table.table-condensed.table-borderless{:style=>"width:20%;"}
                        %tbody
                          %tr
                            %td
                            %td
                            %td 
                              %b actual
                            %td
                            %td
                          %tr
                            %td
                            %td
                            %td active
                            %td inactive
                            -#%td total
                          %tr
                            %td 
                              %b predicted
                            %td active
                            %td 
                              =cv.confusion_matrix[0][0]
                            %td 
                              =cv.confusion_matrix[0][1]
                            -#%td 
                              =cv.confusion_matrix[0][0]+cv.confusion_matrix[0][1]
                          %tr
                            %td
                            %td inactive
                            %td 
                              =cv.confusion_matrix[1][0]
                            %td 
                              =cv.confusion_matrix[1][1]
                            -#%td 
                              =cv.confusion_matrix[1][0]+cv.confusion_matrix[1][1]
                          -#%tr
                            %td
                            %td total
                            %td
                              =cv.confusion_matrix[0][0]+cv.confusion_matrix[1][0]
                            %td
                              =cv.confusion_matrix[0][1]+cv.confusion_matrix[1][1]
                            %td
                              -#= "Confusion Matrix:\t"
                              -#= cv.confusion_matrix
                    - if model.regression?
                      %br
                      = "Root mean squared error:\t"
                      = cv.rmse.round(3) if cv.rmse
                      %br
                      = "Weighted root mean squared error:\t"
                      = cv.weighted_rmse.round(3) if cv.weighted_rmse
                      %br
                      = "Mean absolute error:\t"
                      = cv.mae.round(3) if cv.mae
                      %br
                      = "Weighted mean absolute error:\t"
                      = cv.weighted_mae.round(3) if cv.weighted_mae
                      %br 
                      = "R square:\t"
                      = cv.r_squared.round(3) if cv.r_squared
                      /%br
                      /= "Correlation plot"
                      /= cv.correlation_plot
                      /%br
                      /= "Confidence plot:"
                      /= cv.confidence_plot

  
  %fieldset#bottom.well
    %div.row
      %div.col-md-2
        %h2
          3. Predict
      %div.col-md-10
        %input.btn.btn-warning.h2{ :type => "submit", :id => "submit", :value=>">>", :onclick => "getsmiles()"}
        %img.h2{:src=>"/images/wait30trans.gif", :id=>"circle", :class=>"circle", :style=>"display:none;"}