PageSourceSearch

https://www.cancerhotspots.org/src/js/controller/CancerHotspots.js

js cancerhotspots.org collected 2026-10-03 21:19:11 UTC 14,214 bytes, 395 lines download raw bytes

1/*
2 * Copyright (c) 2016 Memorial Sloan-Kettering Cancer Center.
3 *
4 * This library is distributed in the hope that it will be useful, but WITHOUT
5 * ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY OR FITNESS
6 * FOR A PARTICULAR PURPOSE. The software and documentation provided hereunder
7 * is on an "as is" basis, and Memorial Sloan-Kettering Cancer Center has no
8 * obligations to provide maintenance, support, updates, enhancements or
9 * modifications. In no event shall Memorial Sloan-Kettering Cancer Center be
10 * liable to any party for direct, indirect, special, incidental or
11 * consequential damages, including lost profits, arising out of the use of this
12 * software and its documentation, even if Memorial Sloan-Kettering Cancer
13 * Center has been advised of the possibility of such damage.
14 */
15
16/*
17 * This file is part of cBioPortal Cancer Hotspots.
18 *
19 * cBioPortal is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU Affero General Public License as
21 * published by the Free Software Foundation, either version 3 of the
22 * License.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27 * GNU Affero General Public License for more details.
28 *
29 * You should have received a copy of the GNU Affero General Public License
30 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
31 */
32
33/**
34 * @author Selcuk Onur Sumer
35 */
36function CancerHotspots(options)
37{
38    var _hotspotProxy = null;
39    var _clusterProxy = null;
40    var _metadataProxy = null;
41
42    var _defaultOpts = {
43        pageLoaderDelay: 50,
44        tableLoaderDelay: 500,
45        appContent: "#app_content",
46        appTemplateId: "main_page",
47        pageContent: "#page_content",
48        pageLoader: "#page_loader",
49        mainView: "#main_view",
50        mainContent: "#main_content",
51        homePage: "#home",
52        homeTemplateId: "home_page",
53        aboutPage: "#about",
54        downloadPage: "#download",
55        downloadTemplateId: "download_page",
56        aboutTemplateId: "about_page",
57        residuePage: "#residue",
58        residueTemplateId: "residue_page",
59        content: {
60            app: {
61                tagline: "A resource for statistically significant mutations in cancer",
62                title: "Cancer Hotspots",
63                logoStyle: "hotspot-fire"
64            },
65            home: {
66                mutationInfo: _.template($("#v2_mutation_info").html())()
67            },
68            download: {
69                content:[{
70                    links: [
71                        {href: 'href="files/hotspots_v3.xlsx"',
72                            text: "V3 New Hotspots (Table S5)"}
73                    ],
74                    info: _.template($("#hotspots_v3_info").html())()
75                }, {
76                    links: [
77                        {href: 'href="files/hotspots_v2.xls"',
78                            text: "Hotspot Results V2"},
79                        {href: 'href="https://cbioportal-download.s3.amazonaws.com/cancerhotspots.v2.maf.gz"',
80                            text: "V2 Mutational Data (MAF)"}
81                    ],
82                    info: _.template($("#hotspots_v2_info").html())()
83                }, {
84                    links: [
85                        {href: 'href="files/hotspots.xls"',
86                            text: "Hotspot Results V1"},
87                        {href: 'href="https://github.com/taylor-lab/hotspots/blob/master/LINK_TO_MUTATIONAL_DATA"',
88                            text: "V1 Mutational Data (MAF)"}
89                    ],
90                    info: _.template($("#hotspots_v1_info").html())()
91                }]
92            }
93        },
94        // TODO view & render options...
95        view: {
96            hotspotTable: {}
97        }
98    };
99
100    // merge options with default options to use defaults for missing values
101    var _options = jQuery.extend(true, {}, _defaultOpts, options);
102
103    function switchContent(routeFn, params)
104    {
105        // hide everything first
106        $(_options.pageContent).children().hide();
107
108        // show the loader image before starting the transition
109        $(_options.pageLoader).show();
110
111        setTimeout(function() {
112            routeFn(params);
113
114            // hide the loader image after transition completed
115            $(_options.pageLoader).hide();
116        }, _options.pageLoaderDelay);
117    }
118
119    function home(params)
120    {
121        function initWithData(metadata)
122        {
123            var proxy = new HotspotDataProxy();
124
125            // get all hotspot data
126            proxy.getAllHotspots(function(data) {
127                var mainTemplateFn = _.template($(_options.mainView).html());
128                $(_options.mainContent).html(mainTemplateFn());
129
130                var options = jQuery.extend(true, {}, _options.view.hotspotTable, {
131                    metadata: metadata,
132                    data: data
133                });
134
135                // init the table view with the hotspot data
136                var tableView = new HotspotTableView(options);
137
138                // render the table
139                tableView.render();
140            });
141        }
142
143        function initWithAjax(metadata)
144        {
145            var mainTemplateFn = _.template($(_options.mainView).html());
146            $(_options.mainContent).html(mainTemplateFn());
147
148            // init the table view with the hotspot data retrieval function
149            var options = jQuery.extend(true, {}, _options.view.hotspotTable, {
150                metadata: metadata,
151                "ajax": function (data, callback, settings) {
152                    _hotspotProxy.getAllHotspots(function(hotspotData) {
153                        // defer rendering of the table a few miliseconds
154                        // for a smoother rendering of the loader
155                        setTimeout(function(){
156                            callback({data: hotspotData});
157                        }, _options.tableLoaderDelay);
158                    });
159                }
160            });
161
162            var tableView = new HotspotTableView(options);
163
164            // render the table
165            tableView.render();
166        }
167
168        // init section if not initialized yet
169        if (!$(_options.homePage).length)
170        {
171            var templateFn = _.template($("#" + _options.homeTemplateId).html());
172            $(_options.pageContent).append(templateFn(params));
173
174            // initial AJAX call to determine which profile is active
175            _metadataProxy.getMetadata(function(data) {
176                //initWithData(data);
177                initWithAjax(data);
178            });
179        }
180
181        $(_options.homePage).show();
182    }
183
184    function download(params)
185    {
186        // init section if not initialized yet
187        if (!$(_options.downloadPage).length)
188        {
189            var templateFn = _.template($("#" + _options.downloadTemplateId).html());
190            $(_options.pageContent).append(templateFn(downloadTemplateVars(params)));
191        }
192
193        $(_options.downloadPage).show();
194    }
195
196    function downloadTemplateVars(params)
197    {
198        var linkTemplateFn = _.template($("#download_link_basic_template").html());
199        var contentTemplateFn = _.template($("#download_basic_content").html());
200        var content = [];
201
202        _.each(params.content, function(item) {
203            var links = [];
204
205            links.push("<ul>");
206
207            _.each(item.links, function(link) {
208                links.push(linkTemplateFn(link));
209            });
210
211            links.push("</ul>");
212
213            content.push(contentTemplateFn({
214                links: links.join("\n"),
215                info: item.info
216            }))
217        });
218
219        return {
220            content: content.join("\n")
221        };
222    }
223
224    function about(params)
225    {
226        // init section if not initialized yet
227        if (!$(_options.aboutPage).length)
228        {
229            var templateFn = _.template($("#" + _options.aboutTemplateId).html());
230            $(_options.pageContent).append(templateFn());
231        }
232
233        $(_options.aboutPage).show();
234    }
235
236    function cluster(params)
237    {
238        // init section if not initialized yet
239        if (!$(_options.residuePage).length)
240        {
241            var templateFn = _.template($("#" + _options.residueTemplateId).html());
242            $(_options.pageContent).append(templateFn());
243        }
244
245        $(_options.residuePage).show();
246
247        var dataManager = new ClusterDataManager();
248        dataManager.updateData({
249            gene: params.hugoSymbol,
250            residue: params.residue
251        });
252
253        var viewOpts = {
254            dataManager: dataManager,
255            ajax: function (data, callback, settings) {
256                _clusterProxy.getCluster(params.hugoSymbol, params.residue, function(clusterData) {
257                    _hotspotProxy.getHotspotsByGene([params.hugoSymbol], function(hotspotData) {
258                        dataManager.updateData({
259                            clusters: clusterData,
260                            mutations: hotspotData
261                        });
262                        // defer rendering of the table a few miliseconds
263                        // for a smoother rendering of the loader
264                        setTimeout(function(){
265                            callback({data: clusterData});
266                        }, _options.tableLoaderDelay);
267                    });
268                });
269            }
270            //TODO pValueThreshold: _options.pValueThreshold
271        };
272
273        if (params.residue == null)
274        {
275            viewOpts.templateId = "gene_view";
276        }
277
278        var residueView = new ResidueView(viewOpts);
279
280        var residueController = new ResidueController(residueView, dataManager);
281        residueController.init();
282        residueView.render();
283    }
284
285    function init()
286    {
287        // init router
288        var router = new Router({
289            '/home': function() {
290                switchContent(home, _options.content.home);
291            },
292            '/about': function() {
293                switchContent(about);
294            },
295            '/download': function() {
296                switchContent(download, _options.content.download);
297            },
298            '/residue/:hugoSymbol/:residue': function(hugoSymbol, residue) {
299                switchContent(cluster, {hugoSymbol: hugoSymbol, residue: residue});
300            },
301            '/gene/:hugoSymbol/': function(hugoSymbol) {
302                switchContent(cluster, {hugoSymbol: hugoSymbol});
303            }
304        });
305
306        router.configure({notfound: function() {
307            // TODO switch to the not found page! (a static error page)
308            //switchContent(unknown);
309            $(_options.pageContent).children().hide();
310        }});
311
312        // init data proxies
313        _metadataProxy = new MetadataProxy();
314
315        _metadataProxy.getMetadata(function(metadata) {
316            var hotspotProxyOptions = {};
317
318            if (metadata.profile.toLowerCase().indexOf("3d") != -1)
319            {
320                hotspotProxyOptions.serviceUrl = "api/hotspots/3d";
321                _options.content = {
322                    app: {
323                        tagline: "A resource for statistically significant mutations clustering " +
324                                 "in 3D protein structures in cancer",
325                        title: "3D Hotspots",
326                        logoStyle: "hotspot-fire hotspot-3d-fire"
327                    },
328                    home: {
329                        mutationInfo:  _.template($("#3d_mutation_info").html())()
330                    },
331                    download: {
332                        content: [{
333                            links: [
334                                {href: 'href="files/3d_hotspots.xls"', text: "3D Hotspot Results"}
335                            ],
336                            info: "Resources for mutations in 3D protein structures:"
337                        }]
338                    }
339                };
340
341                // update page title as well
342                document.title = "3D Hotspots";
343            }
344            else
345            {
346                // TODO update options in a safer way...
347
348                _options.view.hotspotTable.renderer = {
349                    residue: {
350                        templateId: "residue_column_single"
351                    },
352                    gene: {
353                        templateId: "gene_column_single"
354                    }
355                };
356
357                if (metadata.profile.toLowerCase().indexOf("internal") != -1)
358                {
359                    _options.content.home.mutationInfo =
360                        _.template($("#internal_mutation_info").html())();
361
362                    // // 2 more internal links in addition to the public ones
363                    // _options.content.download.content.unshift({
364                    //     links: [
365                    //         {href: 'href="files/internal_hotspots.xls"',
366                    //             text: "Hotspot Results V3"},
367                    //         {href: "",
368                    //             text: "V3 Mutational Data (MAF) will be available upon publication"}
369                    //     ],
370                    //     info: _.template($("#hotspots_v3_info").html())()
371                    // });
372                }
373            }
374
375            _hotspotProxy = new HotspotDataProxy(hotspotProxyOptions);
376            _clusterProxy = new ClusterDataProxy();
377
378            // init static content
379            var templateFn = _.template($("#" + _options.appTemplateId).html());
380            $(_options.appContent).append(templateFn(_options.content.app));
381
382            // TODO temporarily hiding about page link for now
383            if (metadata.profile.toLowerCase() === "3d")
384            {
385                $(_options.appContent).find(".about-nav").hide();
386                $(".footer .footer-about-link").hide();
387            }
388
389            // load home page content initially
390            router.init("/home");
391        });
392    }
393
394    this.init = init;
395}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.