aboutsummaryrefslogtreecommitdiff
path: root/wqflask/wqflask/templates/correlation_page.html
blob: c5b4477b77134acce907fb496e97916ed64aeb40 (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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
{% extends "base.html" %}
{% block css %}
    <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/css/jquery.dataTables.css" />
    <link rel="stylesheet" type="text/css" href="/static/packages/DT_bootstrap/DT_bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="/static/packages/TableTools/media/css/TableTools.css" />
    <link rel="stylesheet" type="text/css" href="/static/new/packages/DataTables/extensions/buttons.bootstrap.css" />
{% endblock %}
{% block content %}
    
    {{ header("Correlation", 'Trait: {} Dataset: {}'.format(this_trait.name, dataset.name)) }}

    <div class="container">
        <div class="page-header">
            <h1>Correlation Table</h1>
        </div>

        <p>Values of record {{ this_trait.name }} in the <a href="/static/dbdoc/{{dataset.fullname}}">{{ dataset.fullname }}</a>
        dataset were compared to all records in the <a href="/static/dbdoc/{{target_dataset.fullname}}">{{ target_dataset.fullname }}</a>
        dataset. The top {{ return_number }} correlations ranked by the {{ formatted_corr_type }} are displayed.
        You can resort this list by clicking the headers. Select the Record ID to open the trait data
        and analysis page.
        </p>    

        <br />
        <button class="btn btn-default" id="select_all"><span class="glyphicon glyphicon-ok"></span> Select All</button>
        <button class="btn btn-default" id="deselect_all"><span class="glyphicon glyphicon-remove"></span> Deselect All</button>
        <button class="btn btn-default" id="invert"><span class="glyphicon glyphicon-resize-vertical"></span> Invert</button>
        <button class="btn btn-default" id="add" disabled><span class="glyphicon glyphicon-plus-sign"></span> Add</button>
        <button id="redraw" class="btn btn-default">Reset Columns</button>
        <input type="text" id="searchbox" class="form-control" style="width: 200px; display: inline;" placeholder="Search This Table For ...">
        <input type="text" id="select_top" class="form-control" style="width: 200px; display: inline;" placeholder="Select Top ...">
        <br />
        <br />

        <div style="width: {% if target_dataset.type == "ProbeSet" %}1600px{% elif target_dataset.type == "Publish" %}1200px{% else %}800px{% endif %}; background-color: #eeeeee; border: 1px solid black;">
            <table width="1600px" id="trait_table" class="table table-hover table-striped">
                <thead>
                    <tr>
                        <th style="width: 30px; background-color: #eeeeee;"></th>
                    {% for header in target_dataset.header_fields %}
                        {% if header == 'Year' %}
                        <th style="text-align: right; background-color: #eeeeee;">{{header}}</th>
                        {% elif header == 'Max LRS' %}
                        <th style="text-align: right; background-color: #eeeeee;">Max&nbsp;&nbsp;<br>LRS<a href="http://genenetwork.org//glossary.html#L" target="_blank"><sup style="color:#f00"> ?</sup></a></th>
                        {% elif header == 'Max LRS Location' %}
                        <th style="text-align: right; background-color: #eeeeee;">{{header}}</th>
                        {% elif header == 'Location' %}
                        <th style="text-align: right; background-color: #eeeeee;">{{header}}</th>
                        {% elif header == 'Mean' %}
                        <th style="text-align: right; background-color: #eeeeee;">{{header}}</th>
                        {% elif header == 'Additive Effect' %}
                        <th style="text-align: right; background-color: #eeeeee;">Add&nbsp;&nbsp;<br>Effect<a href="http://genenetwork.org//glossary.html#A" target="_blank"><sup style="color:#f00"> ?</sup></a></th>
                        {% elif header == 'Index' %}
                        <th style="text-align: right; background-color: #eeeeee; padding-left: 0px; margin-left: 0px;">{{header}}</th>
                        {% elif header == 'N' %}
                        <th style="text-align: right; background-color: #eeeeee;">{{header}}</th>
                        {% else %}
                        <th style="background-color: #eeeeee;">{{header}}</th>
                        {% endif %}
                    {% endfor %}
                    {% if target_dataset.type == "ProbeSet" %}
                        {% if corr_method == 'pearson' %}
                        <th style="text-align: right; background-color: #eeeeee;">Sample r</th>
                        <th style="text-align: right; background-color: #eeeeee;">&nbsp;&nbsp;N</th>
                        <th style="text-align: right; background-color: #eeeeee;">Sample p(r)</th>
                        <th style="text-align: right; background-color: #eeeeee;">Lit r</th>
                        <th style="text-align: right; background-color: #eeeeee;">Tissue r</th>
                        {% else %}
                        <th style="text-align: right; background-color: #eeeeee;">Sample rho</th>
                        <th style="text-align: right; background-color: #eeeeee;">N</th>
                        <th style="text-align: right; background-color: #eeeeee;">Sample p(rho)</th>
                        <th style="text-align: right; background-color: #eeeeee;">Lit r</th>
                        <th style="text-align: right; background-color: #eeeeee;">Tissue rho</th>
                        {% endif %}
                    {% elif target_dataset.type == "Publish" %}
                        {% if corr_method == 'pearson' %}
                        <th style="text-align: right; background-color: #eeeeee;">Sample r</th>
                        <th style="text-align: right; background-color: #eeeeee;">&nbsp;&nbsp;N</th>
                        <th style="text-align: right; background-color: #eeeeee;">Sample p(r)</th>
                        {% else %}
                        <th style="text-align: right; background-color: #eeeeee;">Sample rho</th>
                        <th style="text-align: right; background-color: #eeeeee;">&nbsp;&nbsp;N</th>
                        <th style="text-align: right; background-color: #eeeeee;">Sample p(rho)</th>
                        {% endif %}
                    {% elif target_dataset.type == "Geno" %}
                        {% if corr_method == 'pearson' %}
                        <th style="text-align: right; background-color: #eeeeee;">Sample r</th>
                        <th style="text-align: right; background-color: #eeeeee;">N</th>
                        <th style="text-align: right; background-color: #eeeeee;">Sample p(r)</th>
                        {% else %}
                        <th style="text-align: right; background-color: #eeeeee;">Sample rho</th>
                        <th style="text-align: right; background-color: #eeeeee;">N</th>
                        <th style="text-align: right; background-color: #eeeeee;">Sample p(rho)</th>
                        {% endif %}
                    {% endif %}
                    </tr>
                </thead>

                <tbody>
                {% for trait in correlation_results %}
                    <tr>
                        <td>&nbsp;<INPUT TYPE="checkbox" NAME="searchResult" class="checkbox trait_checkbox" style="transform: scale(1.5);" VALUE="{{ data_hmac('{}:{}'.format(trait.name, trait.dataset.name)) }}"></td>
                        <td align="right">{{ loop.index }}</td>
                        <td>
                            <a href="{{ url_for('show_trait_page',
                                    trait_id = trait.name,
                                    dataset = dataset.name
                                    )}}">
                                {{ trait.name }}
                            </a>
                        </td>
                      {% if target_dataset.type == 'ProbeSet' %}
                        <td>{{ trait.symbol }}</td>
                        <td>{{ trait.description_display }}</TD>
                        <td align="right"style="white-space: nowrap;">{{ trait.location_repr }}</td>
                        <td align="right">{{ '%0.3f' % trait.mean|float }}</td>
                        <td align="right" style="padding-right: 15px;">{% if trait.LRS_score_repr != "N/A" %}{{ '%0.1f' % trait.LRS_score_repr|float }}{% else %}N/A{% endif %}</td>
                        <td align="right" style="padding-right: 15px;">{{ trait.LRS_location_repr }}</td>
                        <td align="right" style="padding-right: 15px;">{% if trait.additive != "" %}{{ '%0.3f' % trait.additive|float }}{% else %}N/A{% endif %}</td>
                        <td align="right" style="padding-right: 15px;"><a target="_blank" href="corr_scatter_plot?dataset_1={{dataset.name}}&dataset_2={{trait.dataset.name}}&trait_1={{this_trait.name}}&trait_2={{trait.name}}">{{'%0.3f'|format(trait.sample_r)}}</a></td>
                        <td align="right" style="padding-right: 15px;">{{ trait.num_overlap }}</td>
                        <td align="right" style="padding-right: 15px;">{{'%0.3e'|format(trait.sample_p)}}</td>
                        {% if trait.lit_corr == "" or trait.lit_corr == 0.000 %}
                        <td align="right" style="padding-right: 15px;">--</td>
                        {% else %}
                        <td align="right" style="padding-right: 15px;">{{'%0.3f'|format(trait.lit_corr)}}</td>
                        {% endif %}
                        {% if trait.tissue_corr == "" or trait.tissue_corr == 0.000 %}
                        <td align="right" style="padding-right: 15px;">--</td>
                        {% else %}
                        <td align="right" style="padding-right: 15px;">{{'%0.3f'|format(trait.tissue_corr)}}</td>
                        {% endif %}
                      {% elif target_dataset.type == "Publish" %}
                        <td>{{ trait.description_display }}</td>
                        <td>{{ trait.authors }}</td>
                        <td>
                            <a href="{{ trait.pubmed_link }}">
                                {{ trait.pubmed_text }}
                            </a>
                        </td>
                        <td align="right" style="padding-right: 15px;">{{ trait.LRS_score_repr }}</td>
                        <td align="right" style="padding-right: 15px;">{{ trait.LRS_location_repr }}</td>
                        <td align="right" style="padding-right: 15px;">{% if trait.additive != "" %}{{ '%0.3f' % trait.additive|float }}{% else %}N/A{% endif %}</td>
                        <td align="right" style="padding-right: 15px;"><a target="_blank" href="corr_scatter_plot?dataset_1={{dataset.name}}&dataset_2={{trait.dataset.name}}&trait_1={{this_trait.name}}&trait_2={{trait.name}}">{{'%0.3f'|format(trait.sample_r)}}</a></td>
                        <td align="right" style="padding-right: 15px;">{{ trait.num_overlap }}</td>
                        <td align="right" style="padding-right: 15px;">{{'%0.3e'|format(trait.sample_p)}}</td>
                      {% elif target_dataset.type == "Geno" %}
                        <td align="right" style="padding-right: 15px;">{{ trait.location_repr }}</TD>
                        <td align="right" style="padding-right: 15px;"><a target="_blank" href="corr_scatter_plot?dataset_1={{dataset.name}}&dataset_2={{trait.dataset.name}}&trait_1={{this_trait.name}}&trait_2={{trait.name}}">{{'%0.3f'|format(trait.sample_r)}}</a></td>
                        <td align="right" style="padding-right: 15px;">{{ trait.num_overlap }}</td>
                        <td align="right" style="padding-right: 15px;">{{'%0.3e'|format(trait.sample_p)}}</td>
                      {% endif %}
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}

{% block js %}  
    <script type="text/javascript" src="/static/new/javascript/search_results.js"></script>

    <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/jquery.dataTables.js"></script>
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/dataTables.buttons.min.js"></script>
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.html5.min.js"></script>
    <script language="javascript" type="text/javascript" src="https://cdn.datatables.net/buttons/1.0.0/js/buttons.bootstrap.min.js"></script>
    <script language="javascript" type="text/javascript" src="/static/new/js_external/jszip.min.js"></script>
    <script language="javascript" type="text/javascript" src="/static/new/packages/DataTables/js/dataTables.naturalSort.js"></script>
    <script language="javascript" type="text/javascript" src="/static/packages/DT_bootstrap/DT_bootstrap.js"></script>
    <script language="javascript" type="text/javascript" src="/static/packages/TableTools/media/js/TableTools.min.js"></script>
    <script language="javascript" type="text/javascript" src="/static/packages/underscore/underscore-min.js"></script>
    <script type="text/javascript" charset="utf-8">
        function getValue(x) {
            if (x.indexOf('input') >= 0) {
                if ($(x).val() == 'x') {
                    return 0;
                }
                else {
                   return parseFloat($(x).val());
                }
            }
            else if (isNaN(x)) {
                return x;
            }
            return parseFloat(x);
        }
            
        jQuery.fn.dataTableExt.oSort['numeric-html-asc']  = function(a,b) {
            a = Math.abs(parseFloat($(a).text()));
            b = Math.abs(parseFloat($(b).text()));
            return ((a < b) ? -1 : ((a > b) ?  1 : 0));
        };

        jQuery.fn.dataTableExt.oSort['numeric-html-desc']  = function(a,b) {
            a = Math.abs(parseFloat($(a).text()));
            b = Math.abs(parseFloat($(b).text()));
            return ((a < b) ? 1 : ((a > b) ?  -1 : 0));
        };

        jQuery.fn.dataTableExt.oSort['cust-txt-asc'] = function (a, b) {
            var x = getValue(a);
            var y = getValue(b); 
            
            if (x == 'N/A' || x == '') {
                return 1;
            }
            else if (y == 'N/A' || y == '') {
                return -1;
            }
            else {
                return ((x < y) ? -1 : ((x > y) ? 1 : 0));
            }
        };
            
        jQuery.fn.dataTableExt.oSort['cust-txt-desc'] = function (a, b) {
            var x = getValue(a);
            var y = getValue(b);
            return ((x < y) ? 1 : ((x > y) ? -1 : 0));
        };


        $(document).ready( function () {
            
            $('#trait_table tr').click(function(event) {
                if (event.target.type !== 'checkbox') {
                    $(':checkbox', this).trigger('click');
                }
            });

            console.time("Creating table");

            {% if target_dataset.type == "ProbeSet" %}
            $('#trait_table').dataTable( {
                "paging": false,
                "buttons": [
                    {
                       extend: 'csvHtml5',
                       text: 'Download CSV',
                       title: 'correlation_results',
                       fieldBoundary: '"',
                       exportOptions: {
                           columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
                       }
                    }
                ],
                "columnDefs": [ 
                    { "targets": 0, "orderable": false }
                ],  
                "columns": [
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural", "width": "20%" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "numeric-html" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" }
                ],
                "order": [[10, "desc" ]],
                "sDom": "Btir",
                "autoWidth": false,
                "bDeferRender": true,
                "scrollY": "800px",
                "scrollCollapse": false
            } );

            var table = $('#trait_table').DataTable();
            new $.fn.dataTable.FixedHeader( table );

            {% elif target_dataset.type == "Publish" %}
            $('#trait_table').dataTable( {
                "paging": false,
                "buttons": [
                    {
                       extend: 'csvHtml5',
                       text: 'Download CSV',
                       title: 'correlation_results',
                       fieldBoundary: '"',
                       exportOptions: {
                           columns: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
                       }
                    }
                ],
                "columnDefs": [ 
                    { "targets": 0, "orderable": false }
                ],  
                "columns": [
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural", "width": "25%" },
                    { "type": "natural", "width": "10%" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "numeric-html" },
                    { "type": "natural" },
                    { "type": "natural" }
                ],
                "order": [[9, "desc" ]],
                "sDom": "Btir",
                "autoWidth": false,
                "bDeferRender": true,
                "scrollY": "800px",
                "scrollCollapse": false
            } );
            {% elif target_dataset.type == "Geno" %}
            $('#trait_table').dataTable( {
                "paging": false,
                "buttons": [
                    {
                       extend: 'csvHtml5',
                       text: 'Download CSV',
                       title: 'correlation_results',
                       fieldBoundary: '"',
                       exportOptions: {
                           columns: [1, 2, 3, 4, 5, 6]
                       }
                    }
                ],
                "columnDefs": [ 
                    { "targets": 0, "orderable": false }
                ],  
                "columns": [
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "natural" },
                    { "type": "numeric-html" },
                    { "type": "natural" },
                    { "type": "natural" }
                ],
                "order": [[4, "desc" ]],
                "sDom": "Btir",
                "autoWidth": false,
                "bDeferRender": true,
                "scrollY": "800px",
                "scrollCollapse": false
            } );
            {% endif %}
            console.timeEnd("Creating table");


        });
    </script>
{% endblock %}