PageRenderTime 68ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 1ms

/wum/ui-widgets/result-widget-wum.js

https://github.com/wojcieszek-michal/js-common-libs
JavaScript | 988 lines | 738 code | 132 blank | 118 comment | 116 complexity | 5c55bccda75409d03bc2e2e5b2a65daf MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (c) 2012 Francisco Salavert (ICM-CIPF)
  3. * Copyright (c) 2012 Ruben Sanchez (ICM-CIPF)
  4. * Copyright (c) 2012 Ignacio Medina (ICM-CIPF)
  5. *
  6. * This file is part of JS Common Libs.
  7. *
  8. * JS Common Libs is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * JS Common Libs is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with JS Common Libs. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. function ResultWidget(args){
  22. var _this = this;
  23. this.id = "ResultWidget"+ Math.round(Math.random()*10000);
  24. this.targetId = null;
  25. if (args != null){
  26. if (args.targetId!= null){
  27. this.targetId = args.targetId;
  28. }
  29. if (args.application!= null){
  30. this.application = args.application;
  31. }
  32. if (args.app!= null){
  33. this.app = args.app;
  34. }
  35. }
  36. this.adapter = new WumAdapter();
  37. this.adapter.onJobResult.addEventListener(function (sender, data){
  38. // console.log(data);
  39. _this.data = JSON.parse(data);
  40. Ext.getBody().unmask();
  41. _this.panel.setLoading(false);
  42. _this.render();
  43. });
  44. this.panelId=null;
  45. this.networkViewerId = null;
  46. this.genomeMapsId = null;
  47. this.resultTables = new Object();
  48. this.resultHistograms = new Object();
  49. this.resultGCharts = new Object();
  50. this.variantFiles = new Object();
  51. // this.onRendered = new Event();
  52. this.onViewRendered = new Event();
  53. this.onViewRendered.addEventListener(function (sender, targetId){
  54. _this.drawTables();
  55. _this.drawHistograms();
  56. _this.drawGCharts();
  57. _this.drawApplicationItems();
  58. });
  59. };
  60. ResultWidget.prototype.draw = function (sid, record){
  61. // console.log(record.data);
  62. this.record = record;
  63. this.jobId = this.record.data.jobId;
  64. this.id = this.jobId+this.id;
  65. this.panelId = "ResultWidget_"+this.jobId;
  66. this.networkViewerId = this.panelId+"_CellBrowserId";
  67. this.genomeMapsId = this.panelId+"_GenomeMapsId";
  68. this.panel = Ext.getCmp(this.panelId);
  69. if(this.panel==null){
  70. this.panel = Ext.create('Ext.panel.Panel', {
  71. id :this.panelId,
  72. border: 0,
  73. title: this.record.data.name,
  74. closable:true,
  75. autoScroll:true
  76. // html: this.tpl.applyTemplate(outputItems)
  77. });
  78. Ext.getCmp(this.targetId).add(this.panel);
  79. Ext.getCmp(this.targetId).setActiveTab(this.panel);
  80. this.panel.setLoading("Loading job info...");
  81. Ext.getBody().mask();
  82. this.adapter.jobResult(this.jobId, "json", sid);
  83. }else{
  84. // this.panel.setLoading(false);
  85. Ext.getCmp(this.targetId).setActiveTab(this.panel);
  86. }
  87. };
  88. ResultWidget.prototype.render = function (){
  89. var _this=this;
  90. console.log(this.application);
  91. if(this.data.outputItems.length != 0){
  92. var outputItems = this.data.inputItems.concat(this.data.outputItems);
  93. //obtener todos los grupos quitando los repetidos
  94. var obj = {};
  95. for(var i = 0; i < outputItems.length; i++){
  96. var group = outputItems[i].group;
  97. if(group != "" ){ //no meter items con grupo distinto a ""
  98. if(group.indexOf(".")!=-1){//comprobar si alguno tiene un subgrupo
  99. var parent_group = group.split(".")[0];
  100. var sub_group = group.split(".")[1];
  101. if(obj[parent_group]==null) {
  102. obj[parent_group]={};
  103. }
  104. if(obj[parent_group][sub_group]==null){
  105. obj[parent_group][sub_group]=[];
  106. }
  107. //ESTE if quita los resultados para los pvalue = 0.005, 0.01, 0.1, deja solo los 0.05
  108. if(this.checkPValue(outputItems[i].title)){
  109. obj[parent_group][sub_group].push(outputItems[i]);
  110. }
  111. }else {
  112. if(obj[group]==null){
  113. obj[group]={};
  114. obj[group]["items"]=[];
  115. }
  116. //QUITAR la cadena de texto ${pvalue} si existe y la sustituye por 0.05
  117. this.renamePValue(outputItems[i]);
  118. obj[group]["items"].push(outputItems[i]);
  119. }
  120. }
  121. }
  122. obj["Interactive Results"]={items:[]};
  123. console.log(obj);
  124. var topLink = Ext.create('Ext.container.Container', {html:'<a name="'+this.jobId+'top"></a>'});
  125. var info = Ext.create('Ext.container.Container', {
  126. margin: "15 0 5 15",
  127. html:'<p >The job named <span class="info">'+this.record.data.name+' </span>'+
  128. 'was launched on <span class="err">'+this.record.data.creationTime+' </span>'+
  129. 'and has been visited <span class="dis">'+this.record.data.visites+' times</span></p>'+
  130. 'You can download the job results by pressing the <b>download</b> button.'
  131. });
  132. var result = [];
  133. //Solo grupos juntos al principio
  134. var i=1;
  135. for (key in obj){
  136. var groupBox = Ext.create('Ext.container.Container', {
  137. padding:"0 0 2 15",
  138. html:'<p class="s110 emph">'+i+'. <a href="#'+key+'">'+key+'</a></p>'
  139. });
  140. result.push(groupBox);
  141. i++;
  142. }
  143. //Grupos con resultados a continuacion
  144. var i=1;
  145. for (key in obj){
  146. //Grupo
  147. var infoId = (this.jobId+key+"info").replace(/ /gi, "");
  148. var groupBox = Ext.create('Ext.container.Container', {
  149. infoId:infoId,
  150. groupName:key,
  151. padding:"60 15 5 15",
  152. html:'<p class="panel-border-bottom"><span class="s140 emph">'+i+'. <a name="'+key+'" href="#'+this.jobId+'top">'+key+'</a>'+
  153. ' </span><span class="info" id="'+infoId+'"></span></p>',
  154. listeners:{
  155. afterrender:function(){
  156. var text = _this.getInfo(this.groupName);
  157. if(text!=""){
  158. $("#"+this.infoId).html("+info");
  159. var infoTip = Ext.create('Ext.tip.Tip',{
  160. html:text,
  161. listeners:{
  162. show:function(){
  163. var este = this;
  164. this.getEl().on("mouseleave",function(){
  165. este.hide();
  166. });
  167. }
  168. }
  169. });
  170. $("#"+this.infoId).mouseover(function(ev){
  171. $(this).css({cursor:"pointer"});
  172. infoTip.showAt(ev.clientX,ev.clientY);
  173. });
  174. $("#"+this.infoId).click(function(){
  175. infoTip.hide();
  176. });
  177. }
  178. }
  179. }
  180. });
  181. result.push(groupBox);
  182. //Resultados - se le pasa el array de items
  183. result.push(this.getResults(obj[key].items));
  184. //Comprobamos si tiene subgrupos 1 - nivel solo
  185. var c = 1;
  186. for(clave in obj[key]){
  187. if (clave != "items"){
  188. //Grupo
  189. var groupBox = Ext.create('Ext.container.Container', {
  190. padding:"15 15 5 30",
  191. cls:"inlineblock",
  192. html:'<p class="panel-border-bottom s120 emph">'+i+'.'+c+' '+clave+'</p>'
  193. });
  194. //si la clave es Your annotation tratarlo de otra manera... para mas adelante
  195. // console.log(clave)
  196. result.push(groupBox);
  197. // debugger
  198. //Resultados - se le pasa el array de items
  199. result.push(this.getResults(obj[key][clave]));
  200. c++;
  201. }
  202. }//subgrupos
  203. i++;
  204. }
  205. var downloadButton = Ext.create('Ext.button.Button', {
  206. text: 'Download',
  207. margin: "0 0 25 15",
  208. handler: function (){
  209. _this.adapter.download(_this.jobId, $.cookie('bioinfo_sid'));
  210. }
  211. });
  212. var deleteJobButton = Ext.create('Ext.button.Button', {
  213. text: 'Delete',
  214. margin: "0 0 25 30",
  215. handler: function (){
  216. Ext.Msg.confirm("Delete job", "Are you sure you want to delete this job?", function (btnClicked){
  217. // console.log(btnClicked);
  218. if(btnClicked == "yes") {
  219. _this.adapter.onDeleteJob.addEventListener(function (sender, data){
  220. var msg = "";
  221. if(data.response.indexOf("OK") != -1) {
  222. Ext.getCmp(_this.targetId).getActiveTab().close();
  223. msg = "The job has been succesfully deleted.";
  224. }
  225. else {
  226. msg = "ERROR: could not delete job.";
  227. }
  228. Ext.Msg.alert("Delete job", msg);
  229. });
  230. // console.log("Job id: "+_this.jobId+" Cookie: "+$.cookie('bioinfo_sid'));
  231. _this.adapter.deleteJob(_this.jobId, $.cookie('bioinfo_sid'));
  232. }
  233. });
  234. }
  235. });
  236. this.panel.add(topLink);
  237. this.panel.add(info);
  238. this.panel.add(downloadButton);
  239. this.panel.add(deleteJobButton);
  240. this.panel.add(result);
  241. _this.onViewRendered.notify();
  242. }//else
  243. };
  244. ResultWidget.prototype.getResults = function (items){
  245. //Resultados
  246. var boxes = [];
  247. for (var j = 0; j < items.length; j++){
  248. var item = items[j];
  249. //Obtener el container con el resultado
  250. var itemBox = this.showInfo(item);
  251. boxes.push(itemBox);
  252. //A帽adir el container para resultados adicionales segun el type y el tag si procede
  253. var container = this.showTypeInfo(item);
  254. if(container){
  255. boxes.push(container);
  256. }
  257. var container = this.showTagInfo(item);
  258. if(container!=null){
  259. boxes.push(container);
  260. }
  261. }
  262. var itemsBox = Ext.create('Ext.container.Container', {
  263. layout: {type: 'table',columns: 1, tableAttrs: {style: {width: '100%'}}},
  264. items:boxes
  265. });
  266. return itemsBox;
  267. };
  268. ResultWidget.prototype.showInfo = function (item){
  269. var _this=this;
  270. var itemTpl = new Ext.XTemplate(
  271. // '<tpl for="tags">',
  272. // '<span class="ok">{.} </span>:: ',
  273. // '</tpl>',
  274. // '<span class="err">{type} </span>',
  275. '<span class="key">{title} </span>',
  276. '<span class="{[ this.setCSS(values) ]}">{value}</span><br>'
  277. ,
  278. {
  279. // XTemplate configuration:
  280. disableFormats: true,
  281. // member functions:
  282. setCSS: function(item){
  283. switch(item.type){
  284. case 'FILE':
  285. return 'file';
  286. break;
  287. case 'MESSAGE':
  288. //Setting species code
  289. if (item.name == "species"){
  290. _this.species=item.value;
  291. }
  292. return 'message';
  293. break;
  294. }
  295. }
  296. });
  297. //fin template
  298. return itemBox = Ext.create('Ext.container.Container', {
  299. data:item,
  300. datos:item,
  301. margin:"0 10 0 20",
  302. padding:5,
  303. tpl:itemTpl,
  304. cls:"inlineblock",
  305. listeners:{
  306. afterrender:function(){
  307. var datos = this.datos;
  308. if(this.datos.type == 'FILE'){
  309. this.getEl().addClsOnOver("encima");
  310. this.getEl().addCls("whiteborder");
  311. if(_this.application=="variant" && datos.title.toLowerCase().indexOf("filter")!=-1){
  312. _this.filteredVcfFile=datos.value;
  313. }
  314. this.getEl().on("click",function(){
  315. console.log(datos);
  316. var value = datos.value;
  317. _this.adapter.poll(_this.jobId, value, true, $.cookie('bioinfo_sid'));
  318. });
  319. }
  320. }
  321. }
  322. });
  323. };
  324. ResultWidget.prototype.showTypeInfo = function (item){
  325. var _this=this;
  326. var box = Ext.create('Ext.container.Container',{
  327. margin:"0 10 0 10",
  328. padding:5
  329. });
  330. switch(item.type){
  331. case 'IMAGE':
  332. /*width="400" height="200" */
  333. box.html = '<div><img width="900" src="'+_this.adapter.pollurl(_this.jobId,item.value,$.cookie('bioinfo_sid'))+'"></div>';
  334. return box;
  335. break;
  336. default: return null;
  337. }
  338. };
  339. ResultWidget.prototype.showTagInfo = function (item){
  340. var _this=this;
  341. var box = Ext.create('Ext.container.Container',{
  342. margin:"0 10 0 10",
  343. flex:1,
  344. padding:5,
  345. html:""
  346. });
  347. for(var i = 0; i < item.tags.length ; i++){
  348. switch(item.tags[i]){
  349. case 'TABLE':
  350. var id = _this.jobId+item.value+item.tags;
  351. var value = item.value;
  352. _this.resultTables[id] = new ResultTable (_this.jobId, value, item.tags,{targetId:'resultTable_'+id});
  353. // _this.resultTables[id].onRendered.
  354. box.html += '<div id="resultTable_'+id+'" style="padding:5px;"></div>';
  355. return box;
  356. break;
  357. case 'HISTOGRAM':
  358. var id = "histogram_"+_this.jobId+item.value+item.tags;
  359. _this.resultHistograms[id] = item.value;
  360. box.html = '<div id="'+id+'" style="padding:5px;"></div>';
  361. return box;
  362. break;
  363. case 'GCHART':
  364. var id = 'gchart_'+item.name;
  365. _this.resultGCharts[id] = item.value;
  366. box.html = '<div id="'+id+'"></div>';
  367. return box;
  368. break;
  369. case 'CONSEQUENCE_TYPE_VARIANTS':
  370. this.variantFiles[item.name] = item.title;
  371. break;
  372. }
  373. }
  374. return null;
  375. };
  376. ResultWidget.prototype.drawTables = function (){
  377. // console.log(this.resultTables);
  378. for(id in this.resultTables){
  379. this.resultTables[id].draw();
  380. }
  381. };
  382. ResultWidget.prototype.drawHistograms = function (){
  383. //se dibujan todas las tablas
  384. // console.log(this.resultHistograms);
  385. for(id in this.resultHistograms){
  386. var adapterPoll = new WumAdapter();
  387. adapterPoll.onPoll.addEventListener(function(sender,data){
  388. if(data!=""){
  389. var lines = data.split("\n");
  390. var fields=[];
  391. var names=[];
  392. var values=[];
  393. var normValues=[];
  394. var total = 0;
  395. for ( var i = 0; i < lines.length; i++) {
  396. fields.push(lines[i].split("\t"));
  397. if(fields[i][0]!=""){
  398. names.push(fields[i][0]);
  399. }
  400. if(fields[i][1]!=null){
  401. total = total + parseFloat(fields[i][1]);
  402. values.push(fields[i][1]);
  403. }
  404. }
  405. for ( var i = 0; i < values.length; i++) {
  406. normValues.push(Math.round(parseFloat(values[i])/total*100));
  407. }
  408. names = names.toString().replace(/,/gi,"|");
  409. var img = '<img src="https://chart.googleapis.com/chart?cht=p&chs=600x300&chd=t:'+normValues+'&chl='+names+'&chtt=Consequence+types&chts=000000,14.5">';
  410. document.getElementById(id).innerHTML=img;
  411. }
  412. });
  413. adapterPoll.poll(this.jobId,this.resultHistograms[id],false,$.cookie('bioinfo_sid'));
  414. }
  415. };
  416. ResultWidget.prototype.drawGCharts = function (){
  417. for(id in this.resultGCharts){
  418. drawChart(id, this.resultGCharts[id]);
  419. }
  420. };
  421. ResultWidget.prototype.drawApplicationItems = function (){
  422. var _this=this;
  423. var viewerContainer = Ext.create('Ext.container.Container', {
  424. id:this.application+this.id+"Container",
  425. border: true,
  426. margin:"50 50 0 50",
  427. html:'<div class="greyborder" id="'+this.id+'Container"></div><div style="height:40px"></div>'
  428. });
  429. switch (this.application){
  430. case "variant":
  431. viewerContainer.on("afterrender",function(){
  432. _this.createGenomeViewer(_this.id+"Container");
  433. });
  434. break;
  435. case "renato":
  436. //***********bar
  437. var pbar = Ext.create('Ext.ProgressBar', {id:this.id+'pbar',margin:"5 0 0 50",width: 500});
  438. // Wait for 5 seconds, then update the status el (progress bar will auto-reset)
  439. pbar.wait({
  440. interval: 500, //bar will move fast!
  441. duration: 50000,
  442. increment: 15,
  443. text: 'Getting database information and drawing the network, please wait...',
  444. scope: this,
  445. fn: function(){
  446. pbar.updateText('Done!');
  447. }
  448. });
  449. //Add de bar to the main panel
  450. this.panel.add(pbar);
  451. /*************************/
  452. viewerContainer.on("afterrender",function(){
  453. _this.createCellBrowser(_this.id+"Container");
  454. });
  455. break;
  456. default: return null;
  457. }
  458. this.panel.add(viewerContainer);
  459. };
  460. ResultWidget.prototype.createGenomeViewer = function (targetId){
  461. var _this = this;
  462. var width = Ext.getCmp(this.application+targetId).getWidth();
  463. var height = Ext.getCmp(this.application+targetId).getHeight();
  464. //var genomeViewer = new GenomeViewer(targetId, AVAILABLE_SPECIES[0],{
  465. //version:"",
  466. //zoom:75,
  467. //width:width-2,
  468. //height:height-2
  469. //});
  470. //genomeViewer.setMenuBar(this.getGenomeViewerResultBar(genomeViewer));
  471. genomeViewer = new GenomeViewer(targetId, DEFAULT_SPECIES,{
  472. sidePanelCollapsed:true,
  473. width:width-2,
  474. height:700-2
  475. });
  476. genomeViewer.afterRender.addEventListener(function(sender,event){
  477. _this.app.setTracks(genomeViewer);
  478. genomeViewer.addSidePanelItems();
  479. var variantFilterWidget = new VariantFilterWidget(_this.jobId,{
  480. width:width-2,
  481. targetId:_this.application+targetId,
  482. viewer:genomeViewer,
  483. fileNames:_this.variantFiles
  484. });
  485. });
  486. genomeViewer.draw();
  487. var adapter = new WumRestAdapter();
  488. adapter.onPoll.addEventListener(function(sender, data){
  489. var vcfDataAdapter = new VCFDataAdapter(new StringDataSource(data),{async:false,species:genomeViewer.species});
  490. var vcfTrack = new TrackData("VCF file",{
  491. adapter: vcfDataAdapter
  492. });
  493. genomeViewer.addTrack(vcfTrack,{
  494. id:"VCF file",
  495. featuresRender:"MultiFeatureRender",
  496. histogramZoom:50,
  497. height:150,
  498. visibleRange:{start:0,end:100},
  499. featureTypes:FEATURE_TYPES
  500. });
  501. //var feature = vcfDataAdapter.featureCache.getFirstFeature();
  502. //genomeViewer.region.load(feature);
  503. //genomeViewer.setRegion({sender:""});
  504. // genomeViewer.setZoom(75);
  505. });
  506. // console.log(this.filteredVcfFile)
  507. if(this.filteredVcfFile != null){
  508. adapter.poll(_this.jobId, this.filteredVcfFile, false, $.cookie('bioinfo_sid'));
  509. }else{
  510. console.log("No filtered VCF file.");
  511. }
  512. };
  513. var mostSignificativesFeatures = new Array();
  514. ResultWidget.prototype.createCellBrowser = function (targetId){
  515. var _this = this;
  516. record = this.record;
  517. //hide network-viewer, all nodes mut be rendered before show
  518. Ext.getCmp(this.application+targetId).disable();
  519. var width = Ext.getCmp(this.application+targetId).getWidth();
  520. var height = Ext.getCmp(this.application+targetId).getHeight();
  521. //Pako creating cellBrowser
  522. this.networkViewer = new NetworkViewer(targetId,this.getSpeciesItem(this.species),{
  523. width:width-2,
  524. height:height-2
  525. });
  526. // this.networkViewer.setSpeciesMenu(AVAILABLE_SPECIES);
  527. this.networkViewer.draw();
  528. //setting a empty data and format, nodes will be draw later using the interface
  529. var dataset = new GraphDataset();
  530. var layout = new LayoutDataset();
  531. var formatter = new NetworkDataSetFormatter({
  532. "defaultFormat": {"type":"LineEdgeNetworkFormatter","opacity":1, "fill":"#000000", "radius":"5", "strokeWidth":"1", "stroke":"#000000", "size":"2", "title":{"fontSize":10, "fill":"#000000"}},
  533. "selected": {"opacity":0.9, "fill":"#FF0000", "radius":"5", "stroke":"#000000", "size":"2"},
  534. "over": {"opacity":1, "fill":"#DF0101", "radius":"5", "stroke":"#000000", "size":"2", "strokeWidth":"1"}
  535. },
  536. {
  537. "defaultFormat": { "opacity":0.8,"stroke":"#000000", "strokeWidth":"1", "strokeOpacity":0.5, "title":{"fontSize":6, "fontColor":"#000000"}},
  538. "selected": {"stroke":"#DF0101", "fill":"#FF0000"},
  539. "over": { "stroke":"#DF0101","strokeOpacity":1, "strokeWidth":"4"}
  540. },
  541. // { "labeled":false, "height":height,"width":this.width,"right":this.width,"backgroundColor":"#FFFFFF", "balanceNodes":false, "nodesMaxSize":4, "nodesMinSize":2});
  542. { "labeled":false, "backgroundColor":"#FFFFFF", "balanceNodes":false, "nodesMaxSize":4, "nodesMinSize":2});
  543. formatter.dataBind(dataset);
  544. layout.dataBind(dataset);
  545. formatter.setHeight(height - 140);
  546. formatter.setWidth(width-2-13);
  547. this.networkViewer.drawNetwork(dataset, formatter, layout);
  548. //Getting significant_your_annotation_0.05.txt
  549. var adapter2 = new WumRestAdapter();
  550. adapter2.onPoll.addEventListener(function(sender, data){
  551. var lines = data.split("\n");
  552. var significativesFeatures = new Array();
  553. for ( var i = 1; i < lines.length; i++) {
  554. var column = 13;
  555. if(record.data.toolName == "fatiscan"){
  556. if(lines[i].split("\t").length==7){
  557. //we are in the case of logistic model
  558. column = 6;
  559. }
  560. }
  561. var significativeValue = lines[i].split("\t")[column];
  562. if(significativeValue < 1000000){
  563. significativesFeatures.push(lines[i].split("\t")[0]);
  564. }
  565. }
  566. console.log('significativesFeatures.length: '+significativesFeatures.length);
  567. /** TFBS **/
  568. var adapter3 = new WumRestAdapter();
  569. adapter3.onPoll.addEventListener(function(sender, data){
  570. var genes = data.split("\n");
  571. /** Para elminar la linea en blanco: Gorrion Rules! **/
  572. genes.pop();
  573. console.log('genes.length: '+genes.length);
  574. _this.loadNetworkOnCellBrowser(genes, significativesFeatures, targetId);
  575. });
  576. var file = "clean_list1.txt";
  577. if(record.data.toolName == "fatiscan")
  578. file = "id_list.txt";
  579. adapter3.poll(_this.jobId, file, false, $.cookie('bioinfo_sid'));
  580. });
  581. adapter2.poll(this.jobId, "significant_your_annotation_0.05.txt", false, $.cookie('bioinfo_sid'));
  582. //END getting significant_your_annotation_0.05.txt
  583. // By Nacho
  584. // getting 50 most significant genes
  585. console.log('getting ranked_list...');
  586. var cleanListWumAdapater = new WumRestAdapter();
  587. cleanListWumAdapater.onPoll.addEventListener(function(sender, data) {
  588. var lines = data.split("\n");
  589. var numGenes = lines.length;
  590. var cont = 0;
  591. console.log('getting top clean_list...');
  592. for(var i = 0; cont < 50 && i < numGenes; i++) {
  593. if(lines[i].indexOf('#') < 0) {
  594. // console.log('getting top ranked_list... '+lines[i]);
  595. // console.log('getting top ranked_list... '+lines[i].split("\t")[0]);
  596. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  597. cont++;
  598. }
  599. }
  600. cont = 0;
  601. console.log('getting bottom clean_list...');
  602. for(var i = numGenes-1; cont < 50 && i > 0; i--) {
  603. if(lines[i].indexOf('#') < 0) {
  604. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  605. cont++;
  606. }
  607. }
  608. });
  609. cleanListWumAdapater.poll(this.jobId, "clean_list1.txt", false, $.cookie('bioinfo_sid'));
  610. // END getting 50 most significant genes
  611. // getting ranked_list
  612. console.log('getting ranked_list...');
  613. var rankedListWumAdapater = new WumRestAdapter();
  614. rankedListWumAdapater.onPoll.addEventListener(function(sender, data) {
  615. var lines = data.split("\n");
  616. var numGenes = lines.length;
  617. var cont = 0;
  618. console.log('getting top ranked_list...');
  619. for(var i = 0; cont < 50 && i < numGenes; i++) {
  620. if(lines[i].indexOf('#') < 0) {
  621. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  622. cont++;
  623. }
  624. }
  625. cont = 0;
  626. console.log('getting bottom ranked_list...');
  627. for(var i = numGenes-1; cont < 50 && i > 0; i--) {
  628. if(lines[i].indexOf('#') < 0) {
  629. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  630. cont++;
  631. }
  632. }
  633. });
  634. rankedListWumAdapater.poll(this.jobId, "ranked_list.txt", false, $.cookie('bioinfo_sid'));
  635. //END getting ranked_list
  636. };
  637. ResultWidget.prototype.loadNetworkOnCellBrowser = function (genes, tfbs, targetId){
  638. var _this = this;
  639. //tfbs and mirna nodes are rendered
  640. //2 indicates that mirna and tfbs are done
  641. var nodesRendered = 0;
  642. //Getting tfbs by gene
  643. var cellBaseManager = new CellBaseManager(this.networkViewer.species);
  644. cellBaseManager.success.addEventListener(function (evt, response){
  645. var data_tfbs = response.result;
  646. var tfbsByGene = new Object();
  647. for (var i = 0; i < data_tfbs.length; i++){
  648. for ( var j = 0; j < data_tfbs[i].length; j++) {
  649. if(tfbs.toString().indexOf(data_tfbs[i][j].tfName) != -1){
  650. if (tfbsByGene[data_tfbs[i][j].tfName] == null){
  651. tfbsByGene[data_tfbs[i][j].tfName] = new Object();
  652. }
  653. if(tfbsByGene[data_tfbs[i][j].tfName][genes[i]] == null){
  654. tfbsByGene[data_tfbs[i][j].tfName][genes[i]] = true;
  655. }
  656. }
  657. }
  658. }
  659. console.log(tfbsByGene);
  660. console.log(data_tfbs.length);
  661. console.log('contando TFBSs...');
  662. // check the number of elemts to be rendered
  663. // if there are more than 500 then select the most significant
  664. var numElements = 0;
  665. for ( var tf in tfbsByGene) {
  666. if(numElements > 500) {
  667. break;
  668. }
  669. for ( var gene in tfbsByGene[tf]) {
  670. numElements++;
  671. }
  672. }
  673. console.log('menos de 500: '+numElements);
  674. for ( var tf in tfbsByGene) {
  675. _this.networkViewer.networkWidget.getDataset().addNode(tf, {type:"tf"});
  676. var verticeId = _this.networkViewer.networkWidget.getDataset().getVerticesCount() - 1;
  677. _this.networkViewer.networkWidget.getFormatter().getVertexById(verticeId).getDefault().setFill("#DF0101");
  678. // console.log(tfbsByGene[tf]);
  679. // console.log(_this.networkViewer.networkWidget.getFormatter().getVertexById(verticeId));
  680. for ( var gene in tfbsByGene[tf]) {
  681. if(numElements < 500 || mostSignificativesFeatures[gene] == true) {
  682. // console.log(gene);
  683. /** Conecto los tfbs con sus genes **/
  684. if(_this.networkViewer.networkWidget.getDataset().getVertexByName(gene).length == 0){
  685. _this.networkViewer.networkWidget.getDataset().addNode(gene, {type:"gene"});
  686. }
  687. // console.log(_this.networkViewer.networkWidget.getDataset());
  688. // getVertexByName returns an array
  689. var vertexGeneId = _this.networkViewer.networkWidget.getDataset().getVertexByName(gene)[0].id;
  690. var vertexTfbsId = _this.networkViewer.networkWidget.getDataset().getVertexByName(tf)[0].id;
  691. _this.networkViewer.networkWidget.getDataset().addEdge("tfbs_" + vertexGeneId + "_" + vertexTfbsId, vertexTfbsId, vertexGeneId);
  692. _this.networkViewer.networkWidget.getFormatter().getVertexById(vertexGeneId).getDefault().setFill("#0000FF");
  693. }
  694. }
  695. }
  696. _this.networkViewer.networkWidget.getLayout().getLayout("neato");
  697. _this.networkViewer.networkWidget.getLayout().layoutDone.addEventListener(function (evt){
  698. nodesRendered++;
  699. if(nodesRendered==2){
  700. Ext.getCmp(_this.id+'pbar').destroy();
  701. Ext.getCmp(_this.application+targetId).enable();
  702. }
  703. });
  704. });
  705. if(genes.length>0){
  706. cellBaseManager.get("feature", "gene", genes, "tfbs");
  707. }
  708. //getting mirna target by gene
  709. var cellBaseManagerMirna = new CellBaseManager(this.networkViewer.species);
  710. cellBaseManagerMirna.success.addEventListener(function (evt, response){
  711. var data_tfbs = response.result;
  712. var tfbsByGene = new Object();
  713. for (var i = 0; i < data_tfbs.length; i++){
  714. for ( var j = 0; j < data_tfbs[i].length; j++) {
  715. if(tfbs.toString().indexOf(data_tfbs[i][j].mirbaseId) != -1){
  716. if (tfbsByGene[data_tfbs[i][j].mirbaseId] == null){
  717. tfbsByGene[data_tfbs[i][j].mirbaseId] = new Object();
  718. }
  719. if(tfbsByGene[data_tfbs[i][j].mirbaseId][genes[i]] == null){
  720. tfbsByGene[data_tfbs[i][j].mirbaseId][genes[i]] = true;
  721. }
  722. }
  723. }
  724. }
  725. console.log(tfbsByGene);
  726. console.log(data_tfbs.length);
  727. console.log('contando miRNAs...');
  728. // check the number of elemts to be rendered
  729. // if there are more than 500 then select the most significant
  730. var numElements = 0;
  731. for ( var tf in tfbsByGene) {
  732. if(numElements > 500) {
  733. break;
  734. }
  735. for ( var gene in tfbsByGene[tf]) {
  736. numElements++;
  737. }
  738. }
  739. console.log('menos de 500: '+numElements);
  740. for ( var mirna in tfbsByGene) {
  741. _this.networkViewer.networkWidget.getDataset().addNode(mirna, {type:"mirna"});
  742. var verticeId = _this.networkViewer.networkWidget.getDataset().getVerticesCount() - 1;
  743. _this.networkViewer.networkWidget.getFormatter().getVertexById(verticeId).getDefault().setFill("red");
  744. for ( var gene in tfbsByGene[mirna]) {
  745. if(numElements < 500 || mostSignificativesFeatures[gene] == true) {
  746. // console.log(gene);
  747. if(_this.networkViewer.networkWidget.getDataset().getVertexByName(gene).length == 0){
  748. // if(_this.networkViewer.networkWidget.getDataset().getVertexByName(gene) == null) {
  749. _this.networkViewer.networkWidget.getDataset().addNode(gene, {type:"gene"});
  750. }
  751. var vertexGeneId = _this.networkViewer.networkWidget.getDataset().getVertexByName(gene)[0].id;
  752. var vertexTfbsId = _this.networkViewer.networkWidget.getDataset().getVertexByName(mirna)[0].id;
  753. _this.networkViewer.networkWidget.getDataset().addEdge("tfbs_" + vertexGeneId + "_" + vertexTfbsId, vertexTfbsId, vertexGeneId);
  754. _this.networkViewer.networkWidget.getFormatter().getVertexById(vertexGeneId).getDefault().setFill("blue");
  755. var edgeId = _this.networkViewer.networkWidget.getDataset().getEdgesCount() - 1;
  756. _this.networkViewer.networkWidget.getFormatter().changeEdgeType(edgeId, "CutDirectedLineEdgeNetworkFormatter");
  757. }
  758. }
  759. }
  760. _this.networkViewer.networkWidget.getLayout().getLayout("neato");
  761. _this.networkViewer.networkWidget.getLayout().layoutDone.addEventListener(function (evt){
  762. nodesRendered++;
  763. if(nodesRendered==2){
  764. Ext.getCmp(_this.id+'pbar').destroy();
  765. Ext.getCmp(_this.application+targetId).enable();
  766. }
  767. });
  768. });
  769. if(genes.length>0){
  770. cellBaseManagerMirna.get("feature", "gene", genes, "mirna_target");
  771. }else{
  772. Ext.getCmp(_this.id+'pbar').destroy();
  773. Ext.getCmp(_this.application+targetId).enable();
  774. }
  775. };
  776. ResultWidget.prototype.getGenomeViewerResultBar = function(genomeViewer) {
  777. var _this=this;
  778. switch (this.application){
  779. case "variant":
  780. var toolbarMenu = Ext.create('Ext.container.Container', {
  781. cls:'bio-toolbar',
  782. defaults:{margin:'1 0 0 2'},
  783. layout:'vbox',
  784. height:27,
  785. items : [
  786. {xtype:'button',text:'<span class="info">Variant filter tool...</span>',handler:function(){
  787. var variantFilterWidget = new VariantFilterWidget(_this.jobId,{viewer:genomeViewer,fileNames:_this.variantFiles});
  788. // variantFilterWidget.draw();
  789. // variantFilterWidget.parseData(data);
  790. // var wumRestAdapter = new WumRestAdapter();
  791. // wumRestAdapter.onPoll.addEventListener(function(sender, data){
  792. // });
  793. // wumRestAdapter.poll(_this.jobId, "variant.txt", false, $.cookie('bioinfo_sid'));
  794. }
  795. }
  796. ]
  797. });
  798. return toolbarMenu;
  799. break;
  800. default: return null;
  801. }
  802. };
  803. ResultWidget.prototype.getSpeciesItem = function(species) {
  804. //selecciona el objeto AVAILABLE_SPECIES segun el species code
  805. for ( var i = 0; i < AVAILABLE_SPECIES.length; i++) {
  806. if(AVAILABLE_SPECIES[i].species==species){
  807. return AVAILABLE_SPECIES[i];
  808. }
  809. }
  810. };
  811. //Quita los resultados para your annotation
  812. ResultWidget.prototype.checkPValue = function(str) {
  813. //return false si es 0.005, 0.01 贸 0.1
  814. if(str.indexOf("pvalue<0.005")!= -1 ||
  815. str.indexOf("pvalue<0.01")!= -1 ||
  816. str.indexOf("pvalue<0.1")!= -1
  817. ){
  818. return false;
  819. }
  820. return true;
  821. };
  822. //Quita los resultados para your annotation
  823. ResultWidget.prototype.renamePValue = function(item) {
  824. //reemplaza la cadena ${pvalue} por 0.05
  825. if(item.value.indexOf("${pvalue}") != -1){
  826. item.value = item.value.replace(/\$\{pvalue\}/gi, "0.05");
  827. }
  828. };
  829. //XXX no se usa por ahora...Para mas adelante
  830. ResultWidget.prototype.setPValue = function(value) {
  831. console.log(this.id);
  832. var divId="#pvalue"+this.id;
  833. $(divId).html(value);
  834. };
  835. //Quita los resultados para your annotation
  836. ResultWidget.prototype.getInfo = function(groupName) {
  837. switch (this.application){
  838. case "renato":
  839. switch (groupName){
  840. case "Input data": return "This section is a reminder of the parameters or settings you have submitted to run the analysis.";
  841. case "Summary": return "<p>This section shows the number of genes annotated to each database in each list.</p><br><p>Gene list: contains three elements, the number of genes in your gene list annotated in the database over the total number of genes remaining in your gene list after the duplicates management, a percentage of genes in your gene list annotated in the database and the ratio of regulators per gene.<br> Genome: the same structure explained above but applied to the whole genome (TFBS or miRNA) or Your Annotations after the duplicates management.</p>";
  842. case "Significant Results": return "<p>We consider a significant enrichment after correcting the results by a multiple testing correction method. Enrichment p-values are corrected applying the False discovery rate (FDR) method (Benjamini et al., 1995; Storey andTibshirani, 2003). The threshold of signification applied to the correction has been set to 0.05.</p><br><p>The table provided summarizes the information about the enrichment test for each of the significant regulatory elements that have an Adjusted p-value < 0.05. The table is originally sorted by adjusted p-value and can be sorted up and down by clicking in any of the other column headings. When the number of significant results in a table is higher than five, results are split into different pages. You can move forward or backward in the page list using the arrow buttons.</p>";
  843. case "All results": return "This section contains a downloadable individual text file containing all results for all significant and not significant regulators. This file follows the same structure described above.";
  844. case "Annotation files": return "<p>When significant results are obtained, we can suppose that there is one or several regulatory elements behaving different when comparing groups. The list of genes included in the analysis have pointed to a significantly over-represented set of common regulators to these genes. The interpretation of the results will be different in the case of TFs (transcription factors) and miRNAs given that (generally) the first are positive regulators and the latter are negative regulators.</p><br><p>TFs generally bind to the promoter region of their target genes to assist and promote the transcription. miRNAs, on the other hand, bind to transcript products preventing them from being translated. Significant TF and miRNAs can be pointed to be responsible for the differential expression of the genes observed in the list. We must take special care in the interpretation of over-expressed or under-expressed genes in a functional analysis. In the case of TFs, if we are working with the list of over-expressed genes, the significant results makes reference to active TFs in one condition with respect to the other; while significant results of under-expressed genes makes reference to inactive TFs. In miRNAs, significant results of over-expressed genes will point to inactive miRNAs, while significant results of under-expressed genes will point to active miRNAs when comparing conditions.</p>";
  845. default: return "";
  846. }
  847. break;
  848. case "variant":
  849. switch (groupName){
  850. case "Variants by Consequence Type": return "Click this link: <a class='ok' target='_blank' href='http://docs.bioinfo.cipf.es/projects/variant/wiki/Output_columns'>Output columns</a>";
  851. default: return "";
  852. }
  853. break;
  854. default: return "";
  855. }
  856. };