summaryrefslogtreecommitdiff
path: root/views/predict.haml
blob: a438f7f3f7c5e15966da1898bdb2df4db8215333 (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
:javascript

  $(window).bind("pageshow", function(event) {
    $("img.circle").hide();
  });
  
  function showcircle() {
    $("img.circle").show();
  };
  $(document).ready(function(){  
    $('#selCore1').change(function(){
      var selection = $(this).val();
      switch(selection){
        case "Ag":
          $("#physchem1").prop('disabled', false);
          $("#physchem2").prop('disabled', false);
          $("#physchem3").prop('disabled', true);
          $("#physchem4").prop('disabled', true);
          $("#physchem5").prop('disabled', true);
          $("#physchem6").prop('disabled', false);
          $("#physchem7").prop('disabled', true);
          $("#physchem8").prop('disabled', true);
          $("#physchem9").prop('disabled', true);
          $("#physchem10").prop('disabled', true);
          break;
        case "Au":
          $("#physchem1").prop('disabled', false);
          $("#physchem2").prop('disabled', false);
          $("#physchem3").prop('disabled', false);
          $("#physchem4").prop('disabled', false);
          $("#physchem5").prop('disabled', false);
          $("#physchem6").prop('disabled', false);
          $("#physchem7").prop('disabled', false);
          $("#physchem8").prop('disabled', false);
          $("#physchem9").prop('disabled', false);
          $("#physchem10").prop('disabled', false);
          break;
      };
    });
  });

%div.well
  %h3.help-block
    Select an endpoint:
  #tabs
    %ul.nav.nav-tabs{:id=>"modelTab", :role=>"tablist"}
      - @prediction_models.each_with_index do |m, idx|
        %li{:class => ("active" if idx == 0)}
          %a{:href => "#model_#{idx}", :id => "linkTab#{idx}", data: {toggle:"tab"}}
            = "#{idx+1}. #{m["type"].capitalize}"
    %div.tab-content
      - @prediction_models.each_with_index do |m, idx|
        - case m["type"]
        - when "fingerprint"
          - example = @example_fingerprint
          - type = "fingerprint"
          - relevant_features = @fingerprint_relevant_features
        - when "physchem"
          - example = @example_physchem
          - type = "physchem"
          - relevant_features = @physchem_relevant_features
        - when "proteomics"
          - example = @example_proteomics
          - type = "proteomics"
          - relevant_features = @proteomics_relevant_features
        
        #model.tab-pane{:id=>"#{idx}", :class => ("active" if idx == 0)}
          %b Model:
          %br
          Name:
          = m.model.name
          %br
          Type: regression
          %br
          Source:
          %a{:href=>"#{m.source}", :alt=>"source", :rel=>"external"}
            = m.source
          %br
          Species:
          = m.species
          %br
          Training nanoparticles:
          = m.model.training_dataset.nanoparticles.size
          %br
          Endpoint:
          = m.endpoint
          %br
          Unit:
          = m.unit
          %br
          %b Algorithms:
          %br
          Similarity:
          %a{:href=> "http://www.rubydoc.info/gems/lazar/OpenTox%2F#{m.model.algorithms["similarity"]["method"].sub("::", "%2F")}", :rel=>"external"}
            = m.model.algorithms["similarity"]["method"]
          = ", min: #{m.model.algorithms["similarity"]["min"]}"
          %br
          Prediction:
          %a{:href=>"http://www.rubydoc.info/gems/lazar/OpenTox%2F#{m.model.algorithms["prediction"]["method"].sub("::","%2f")}", :rel=>"external"}
            = m.model.algorithms["prediction"]["method"]
          %br
          Feature selection:
          = m.model.algorithms["feature_selection"]["method"].split(".").last if m.model.algorithms["feature_selection"]
          %br
          Descriptors:
          = m.model.algorithms["descriptors"]["method"]+","
          = m.model.algorithms["descriptors"]["categories"]
          %p
          %b Independent crossvalidations (log2 transformed):
          %div.row{:id=>"validations#{m.id}", :style=>"background-color:#f5f5f5;"}
            - m.crossvalidations.each do |cv|
              %span.col-xs-2.col-sm-2.col-md-2.col-lg-2
                = "Num folds:\t"
                = cv.folds
                %br
                = "Num instances:\t"
                = cv.nr_instances
                %br
                = "Num unpredicted"
                = cv.nr_unpredicted
                %br
                %a.ht5{:href=>"https://en.wikipedia.org/wiki/Root-mean-square_deviation", :rel=>"external"} RMSE:
                = cv.rmse.round(3) if cv.rmse
                %br
                %a.ht5{:href=>"https://en.wikipedia.org/wiki/Mean_absolute_error", :rel=>"external"} MAE:
                = cv.mae.round(3) if cv.mae
                %br 
                %a.ht5{:href=>"https://en.wikipedia.org/wiki/Coefficient_of_determination", :rel=>"external"}= "R"+"<sup>2</sup>"+":"
                = cv.r_squared.round(3) if cv.r_squared
          %br
          %b QMRF report
          %p
          %a.btn.btn-default{:href=>to('/qmrf-report/'+m.id), :rel=>"external"} download
          %hr
          %form{:id=>idx, :role=>"form", :action=> to("/predict"), :method=>"post"}
            %h3.help-block
              Please characterise a nanoparticle:
            
            - if type == "fingerprint"
              
              // core
              %div.form-group
                // type = fingerprint
                // send hidden example data to compare
                %input{:id=>"type",:type=>"hidden",:name=>"type",:value=>"#{type}"}
                %input{:id=>"example_core",:type=>"hidden",:name=>"example_core",:value=>"#{example.core["name"]}"}
                %input{:id=>"example_coating",:type=>"hidden",:name=>"example_coating",:value=>"#{example.coating[0]["name"]}"}
                %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.properties}"}
                - size = relevant_features.size
                %input{:id=>"size",:type=>"hidden",:name=>"size",:value=>size}
                %input{:id=>"id",:type=>"hidden",:name=>"example_id",:value=>example.id}
                
              // input form parameters to transfer
              // core
              %div.form-group
                %label{:for=>"selCore#{idx}"} Core
                %select.form-control{:id=>"selCore#{idx}", :autocomplete=>"off", :name=>"input_core",:value=>example.core["name"]}
                  %option{:selected => ("selected" if example.core["name"] == "Ag"), :value => "Ag"} Ag
                  %option{:selected => ("selected" if example.core["name"] == "Au"), :value => "Au"} Au
              
              // coating
              %div.form-group
                %label{:for=>"selCoating#{idx}"} Coating
                %select.form-control{:id=>"selCoating#{idx}", :autocomplete=>"off", :name=>"input_coating",:value=>example.coating[0]["name"]}
                  - coatings = $coating_list.collect{|co| co.coating[0]["name"]}.uniq
                  - coatings.each do |co|
                    %option{:selected => ("selected" if example.coating[0]["name"] == co), :value => co}
                      = co
            
            - if type =~ /physchem/
              %div.form-group
                // type = physchem,proteomics
                // send hidden example data to compare
                %input{:id=>"type",:type=>"hidden",:name=>"type",:value=>"#{type}"}
                %input{:id=>"example_core",:type=>"hidden",:name=>"example_core",:value=>"#{example.core["name"]}"}
                %input{:id=>"example_coating",:type=>"hidden",:name=>"example_coating",:value=>"#{example.coating[0]["name"]}"}
                %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.properties}"}
                - size = relevant_features.size
                %input{:id=>"size",:type=>"hidden",:name=>"size",:value=>size}
                %input{:id=>"id",:type=>"hidden",:name=>"example_id",:value=>example.id}
                
                // input form parameters to transfer
                // core
                %div.form-group
                  %label{:for=>"selCore#{idx}"} Core
                  %select.form-control{:id=>"selCore#{idx}", :autocomplete=>"off", :name=>"input_core",:value=>example.core["name"]}
                    %option{:selected => ("selected" if example.core["name"] == "Ag"), :value => "Ag"} Ag
                    %option{:selected => ("selected" if example.core["name"] == "Au"), :value => "Au"} Au
                
                // coating
                //%h5 Coating
                //%input.input-sm.form-control{:id=>"coating",:type=>"text",:disabled=>"disabled",:name=>"coating",:value=>example.coating[0]["name"]}
                //%input.input-sm.form-control{:id=>"coating",:type=>"hidden",:name=>"input_coating",:value=>example.coating[0]["name"]}
              
                // relevant features
                - relevant_features.sort_by{|f| f.name}.each_with_index do |relf,id|
                  - feature = relf
                  - v = example.properties.find{|id,v| id == feature.id.to_s  }
                  - name = feature.name
                  - if feature[:conditions] && !feature[:conditions]["MEDIUM"].blank?
                    - name = feature.name + " / " + feature[:conditions]["MEDIUM"]
                  - else
                    - name = feature.name
                  - val = !v.nil? ? v[1] : ""
                  - id = id + 1
                  
                  %h5
                    %a.descriptor{:href=>$npo[feature.name], :rel=>"external"}= name + (feature.unit.blank? ? "" : " (#{feature.unit})")

                  // input physchem parameters
                  %input.input-sm.form-control{:id=>"physchem#{id}",:type=>"text",:name=>"input_value_#{id}",:value=>"#{val[0]}", :disabled=>("disabled" if val[0].blank?)}
                  %input{:id=>id,:type=>"hidden",:name=>"input_key_#{id}",:value=>feature.id}
            
            - if type =~ /proteomics/
              %div.form-group
                // type = physchem,proteomics
                // send hidden example data to compare
                %input{:id=>"type",:type=>"hidden",:name=>"type",:value=>"#{type}"}
                %input{:id=>"example_core",:type=>"hidden",:name=>"example_core",:value=>"#{example.core["name"]}"}
                %input{:id=>"example_coating",:type=>"hidden",:name=>"example_coating",:value=>"#{example.coating[0]["name"]}"}
                %input{:id=>"example_pc",:type=>"hidden",:name=>"example_pc",:value=>"#{example.properties}"}
                - size = relevant_features.size
                %input{:id=>"size",:type=>"hidden",:name=>"size",:value=>size}
                %input{:id=>"id",:type=>"hidden",:name=>"example_id",:value=>example.id}
                
                // input form parameters to transfer
                // core
                %div.form-group
                  %label{:for=>"selCore#{idx}"} Core
                  %select.form-control{:id=>"selCore#{idx}", :autocomplete=>"off", :name=>"input_core",:value=>example.core["name"]}
                    %option{:selected => ("selected" if example.core["name"] == "Ag"), :value => "Ag"} Ag
                    %option{:selected => ("selected" if example.core["name"] == "Au"), :value => "Au"} Au
                
                // coating
                //%h5 Coating
                //%input.input-sm.form-control{:id=>"coating",:type=>"text",:disabled=>"disabled",:name=>"coating",:value=>example.coating[0]["name"]}
                //%input.input-sm.form-control{:id=>"coating",:type=>"hidden",:name=>"input_coating",:value=>example.coating[0]["name"]}
              
                // relevant features
                - relevant_features.sort_by{|f| f.name}.each_with_index do |relf,id|
                  - feature = relf
                  - v = example.properties.find{|id,v| id == feature.id.to_s  }
                  - name = feature.name
                  - if feature[:conditions] && !feature[:conditions]["MEDIUM"].blank?
                    - name = feature.name + " / " + feature[:conditions]["MEDIUM"]
                  - else
                    - name = feature.name
                  - val = !v.nil? ? v[1] : ""
                  - id = id + 1
                  
                  %h5
                    %a{:href=>"http://www.uniprot.org/uniprot/#{name}", :rel=>"external"}= name + (feature.unit.blank? ? "" : " (#{feature.unit})")

                  // input physchem parameters
                  %input.input-sm.form-control{:id=>"#{id}",:type=>"text",:name=>"input_value_#{id}",:value=>"#{val[0]}"}
                  %input{:id=>id,:type=>"hidden",:name=>"input_key_#{id}",:value=>feature.id}
            
            // prediction model id 
            %input{:id=>"prediction_model",:type=>"hidden",:name=>"prediction_model",:value=>m.id}
            
            %hr
            #predict
              %button.btn.btn-success{:id=>"submitbutton", :type=>"submit", :onclick=>"showcircle();"} 
                Find similar nano particles
                %span.glyphicon.glyphicon-chevron-right{:id=>"span"}
              %img{:src=>"/images/wait30trans.gif", :id=>"circle", :class=>"circle", :alt=>"wait", :style=>"display:none;"}