summaryrefslogtreecommitdiff
path: root/views/prediction.haml
blob: bde23972613476b8762e10a65bb7e9ebafb9b05a (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
:javascript
  $(document).ready(function(){
    $('[data-toggle="popover"]').popover();
    $('.modal').on('hidden.bs.modal', function () {
      $(this).removeData('bs.modal');
    });
    $('.modal').on('show.bs.modal', function(e){
      var button = $(e.relatedTarget);
      var modal = $(this);
      modal.find('.modal-content').load(button.data("remote"));
    });
  });
%div.card
  %a.btn.btn-outline-info{:href => to('/predict')}
    %span.fa.fa-caret-left
    New Prediction
%div.card.bg-light
  %div.card-body
    %h3.card-title Prediction:
    %div.table-responsive
      %table.table.table-bordered{:id=>"overview"}
        %tbody
          %tr
            %td.align-items-center{:id=>"compound"}
              %a.btn.btn-link{:href => "#details0", data: { toggle: "modal", remote: to("/prediction/#{@compound.id}/details"), :id=>"link01"}}
                = embedded_svg(@compound.svg, :title=>"click for details")
              %p= @compound.smiles
              %p
                %a{:href=>PUBCHEM_CID_URI+@compound.cid, :rel => "external"}
                  PubChem
                  %span.fa.fa-xs.fa-external-link
            - @model_types = {}
            - @dbhit = {}
            - @predictions.each_with_index do |prediction,i|
              - type = @models[i].model.class.to_s.match("Classification") ? "Classification" : "Regression"
              - @model_types[i] = type
              - unit = @models[i].unit
              %td
                %b{:class => "title"}
                  = "#{@models[i].endpoint.gsub('_', ' ')} (#{@models[i].species})"
                
                / check for prediction
                - if prediction[:neighbors] and !prediction[:value].nil?
                  %p
                  / show model type (classification|regression)
                  %b Type:
                  = type
                  %p 
                  / check for database hit
                  - if prediction[:info] =~ /\b(identical)\b/i
                    - @dbhit[i] = true
                    
                    / show message about dbhit and measurements
                    %p
                      :plain
                        This compound was part of the training dataset. <i>All</i> information </br>
                        from this compound was removed from the training data before the </br>
                        prediction, to obtain unbiased results.
                      %p
                      %b Measured activity:
                      %br
                      - if prediction[:measurements].is_a?(Array)
                        = (type == "Regression") ? prediction[:measurements].collect{|value| "#{value.delog10.signif(3)} (#{unit})</br>#{@compound.mmol_to_mg(value.delog10).signif(3)} #{unit =~ /mmol\/L/ ? "(mg/L)" : "(mg/kg_bw/day)"}"}.join("</br>") : prediction[:measurements].join(", ")
                      - else
                        = (type == "Regression") ? "#{prediction[:measurements].delog10.signif(3)} (#{unit})</br>#{@compound.mmol_to_mg(prediction[:measurements].delog10).signif(3)} #{(unit =~ /\b(mmol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:measurements]
                  
                  - else
                    - @dbhit[i] = false
                  
                  / show prediction
                  %p
                    %b Prediction:
                    / prediction popover
                    %a.btn.fa.fa-info-circle{:href=>"javascript:void(0)", :title=>"Prediction", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"left", html:"true", content:"<p>lazar searches the training dataset for similar compounds (neighbors) and calculates the prediction from their experimental activities.<p><b>Classification:</b></br>Majority vote of neighbor activities weighted by similarity.<p><b>Regression:</b></br>Prediction from a local partial least squares regression model with neighbor activities weighted by similarity.<p><a href=\"http://www.frontiersin.org/Journal/10.3389/fphar.2013.00038/abstract\", target=\"_blank\"> Original publication</a>.<hr></hr><a href=\"https://doi.org/10.3389/fphar.2013.00038\", target=\"_blank\"><img src=\"https://zenodo.org/badge/DOI/10.3389/zenodo.10.3389.svg\" alt=\"DOI\"></a>"}}
                    %br
                    = (type == "Regression") ? "#{prediction[:value].delog10.signif(3)} (#{unit})</br>#{@compound.mmol_to_mg(prediction[:value].delog10).signif(3)} #{(unit =~ /\b(mmol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" : prediction[:value]
                    
                  / show prediction interval or probability
                  - if type == "Regression"
                    %p
                      %b 95% Prediction interval:
                      - interval = (prediction[:prediction_interval].nil? ? nil : prediction[:prediction_interval])
                      / prediction interval popover
                      %a.btn.fa.fa-info-circle{:href=>"javascript:void(0)", :title=>"Prediction intervall", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"left", html:"true", content:"An estimate of prediction uncertainty. The \"real\" value should be with 95% probability within the prediction interval."}}
                      %br
                      = interval.nil? ? "--" : "#{interval[1].delog10.signif(3)} - #{interval[0].delog10.signif(3)} (#{unit})"
                      %br
                      = "#{@compound.mmol_to_mg(interval[1].delog10).signif(3)} - #{@compound.mmol_to_mg(interval[0].delog10).signif(3)} #{(unit =~ /\b(mmol\/L)\b/) ? "(mg/L)" : "(mg/kg_bw/day)"}" if !interval.nil?
                    %p
                      %b Confidence:
                      %br
                      = prediction[:confidence]
                  - else
                    %p
                      %b Probability:
                      / probability popover
                      %a.btn.fa.fa-info-circle{:href=>"javascript:void(0)", :title=>"Pobability", :tabindex=>"0", data: {trigger:"focus", toggle:"popover", placement:"left", html:"true", content:"Probability that the prediction belongs to one of the given classes."}}
                      - unless prediction[:probabilities].nil?
                        %br
                        = "#{prediction[:probabilities].keys[0]}: #{prediction[:probabilities].values[0].signif(3)}"
                        - if prediction[:probabilities].size == 2
                          %br
                          = "#{prediction[:probabilities].keys[1]}: #{prediction[:probabilities].values[1].signif(3)}"
                    %p
                      %b Confidence:
                      %br
                      = prediction[:confidence]
                  
                  / show warnings and info
                  %p
                    - if !prediction[:info].blank?
                      %b Info:
                      %br
                      %p=prediction[:info].sub(/\'.*\'/,"").sub(/,/, ",<br>")
                    - if !prediction[:warnings].blank?
                      - warning = prediction[:warnings].last
                      %b Warnings:
                      %br
                      %p=warning#.sub(/,/, ",<br>")
                - else
                  %br
                  - if !prediction[:info].blank?
                    %b Info:
                    %br
                    %p=prediction[:info].sub(/\'.*\'/,"").sub(/,/, ",<br>")
                  - if !prediction[:warnings].blank?
                    - warning = prediction[:warnings].last
                    %b Warnings:
                    %br
                    %p=warning#.sub(/,/, ",<br>")

/ always show the neighbors table, message is given there  
= haml :neighbors, :layout => false, :model_type => @model_types, :dbhit => @dbhit
    
%div.modal.fade{:id=>"details0", :tabindex=>"-1", :role=>"dialog"}
  %div.modal-dialog.modal-lg{:role=>"document"}
    %div.modal-content