summaryrefslogtreecommitdiff
path: root/views/prediction.haml
blob: 076ed648eded685110be9295348d90378f082f98 (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
:javascript
  $(document).ready(function(){
    $('[data-toggle="popover"]').popover();
    $('.modal').on('hidden.bs.modal', function () {
      $(this).removeData('bs.modal');
    });
  });

%div.well
  %a.btn.btn-warning{:href => to('/predict')}
    %i.glyphicon.glyphicon-menu-left
    New Prediction
  / displays all prediction result in first table
  %h3 Prediction Results:
  %div.table-responsive
    %table.table.table-bordered{:id=>"overview"}
      %tbody
        %tr
          %td{:id=>"compound"}
            %b.title Compound
            %p= embedded_svg(@compound.svg, title: @compound.smiles)
            %p= @compound.smiles
          - @model_types = {}
          - @dbhit = {}
          - toxtree = @predictions.pop if @toxtree == true
          - mazzatorta = @predictions.find{|p| p["mazzatorta"]}
          - @predictions.delete(mazzatorta) if mazzatorta
          - unless @predictions.blank?
            - @predictions.each_with_index do |prediction,i|
              - if prediction["Consensus prediction"]
                - sa_prediction = true
              - type = (@models[i].regression? ? "Regression" : "Classification")
              - @model_types[i] = type
              - unit = @models[i].unit
              %td{:style=>"vertical-align:top;white-space:nowrap;"}
                %b.title
                  = (sa_prediction ? "Consensus mutagenicity" : "#{@models[i].endpoint.gsub('_', ' ')} (#{@models[i].species})")
                %p
                / check kazius
                - if sa_prediction
                  - sa_value = prediction["Consensus prediction"]
                  - confidence = prediction["Consensus confidence"]
                  / check for database hit
                  - if prediction[:info] =~ /\b(identical)\b/i
                    - @dbhit[i] = true
                    %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
                      = prediction[:measurements].join("; ")
                  %b Consensus prediction:
                  %br
                  = sa_value
                  %p
                  %b Consensus confidence:
                  %br
                  = confidence
                  %p
                  %b Structural alerts for mutagenicity:
                  %br
                  = prediction["Structural alerts for mutagenicity"].gsub(";","</br>")
                / check for prediction
                - if prediction[:value]
                  %p
                  - if sa_prediction
                    %b.title= ("Lazar #{@models[i].endpoint.gsub('_', ' ').downcase} (#{@models[i].species}):")
                    %p
                  / check for database hit
                  - if prediction[:info] =~ /\b(identical)\b/i
                    - @dbhit[i] = true
                    / show message about dbhit and measurements
                    - unless sa_prediction
                      %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:
                    %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
                    %p
                    - if type == "Regression"
                      %b 95% Prediction interval:
                      - interval = (prediction[:prediction_interval].nil? ? nil : prediction[: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?
                    - else
                      %b Probability:
                      - 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
                    - if !prediction[:warnings].blank?
                      %b Warnings:
                      %br
                      =prediction[:warnings].join("</br>")

                - else
                  - if !prediction[:info].blank?
                    %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]
                  - if !prediction[:warnings].blank?
                    %p
                      %b Warnings:
                      %br
                      =prediction[:warnings].join("</br>")

          / Cramer
          - if @toxtree == true
            %td{:style=>"vertical-align:top;white-space:nowrap;"}
              %b.title Oral toxicity (Cramer rules)
              %p
              %b Cramer rules:
              %br
              =toxtree.first["Cramer rules"]
              %p
              %b Cramer rules, with extensions:
              %br
              =toxtree.last["Cramer rules, with extensions"]

          / Mazzatorta
          - if mazzatorta
            %td{:style=>"vertical-align:top;white-space:nowrap;"}
              %b.title Lowest observed adverse effect level (LOAEL) (Rats) (Mazzatorta)
              %p
              - hash = mazzatorta["mazzatorta"]
              - unless hash.keys.include?("warnings") || hash.key?(:warnings)
                %b Prediction:
                %br
                = "#{hash[:mmol_prediction]} (mmol/kg_bw/day)"
                %br
                = "#{hash[:prediction]} (mg/kg_bw/day)"
              - else
                %b Warnings:
                %br
                = "#{hash[:warnings]}"


  / always show the neighbors table, message is given there. Except only Cramer is selected.
  - unless @predictions.blank?
    = haml :neighbors, :layout => false