PageRenderTime 339ms CodeModel.GetById 32ms RepoModel.GetById 0ms app.codeStats 0ms

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

https://github.com/wojcieszek-michal/js-common-libs
JavaScript | 1024 lines | 760 code | 133 blank | 131 comment | 121 complexity | 0d02c0fcd9ab9f22e82020141298b484 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 GcsaManager();
  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.id;
  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. //accountId, sessionId, bucketname, jobId, format
  84. this.adapter.jobResult($.cookie("bioinfo_account"), sid, $.cookie("bioinfo_bucket"), this.jobId, "json");
  85. //this.adapter.jobResult(this.jobId, "json", sid);
  86. }else{
  87. // this.panel.setLoading(false);
  88. Ext.getCmp(this.targetId).setActiveTab(this.panel);
  89. }
  90. };
  91. ResultWidget.prototype.render = function (){
  92. var _this=this;
  93. console.log(this.application);
  94. if(this.data.outputItems.length != 0){
  95. var outputItems = this.data.inputItems.concat(this.data.outputItems);
  96. //obtener todos los grupos quitando los repetidos
  97. var obj = {};
  98. for(var i = 0; i < outputItems.length; i++){
  99. var group = outputItems[i].group;
  100. if(group != "" ){ //no meter items con grupo distinto a ""
  101. if(group.indexOf(".")!=-1){//comprobar si alguno tiene un subgrupo
  102. var parent_group = group.split(".")[0];
  103. var sub_group = group.split(".")[1];
  104. if(obj[parent_group]==null) {
  105. obj[parent_group]={};
  106. }
  107. if(obj[parent_group][sub_group]==null){
  108. obj[parent_group][sub_group]=[];
  109. }
  110. //ESTE if quita los resultados para los pvalue = 0.005, 0.01, 0.1, deja solo los 0.05
  111. if(this.checkPValue(outputItems[i].title)){
  112. obj[parent_group][sub_group].push(outputItems[i]);
  113. }
  114. }else {
  115. if(obj[group]==null){
  116. obj[group]={};
  117. obj[group]["items"]=[];
  118. }
  119. //QUITAR la cadena de texto ${pvalue} si existe y la sustituye por 0.05
  120. this.renamePValue(outputItems[i]);
  121. obj[group]["items"].push(outputItems[i]);
  122. }
  123. }
  124. }
  125. if(this.application == 'renato' || this.application == 'variant'){
  126. obj["Interactive Results"]={items:[]};
  127. }
  128. console.log(obj);
  129. var topLink = Ext.create('Ext.container.Container', {html:'<a name="'+this.jobId+'top"></a>'});
  130. var info = Ext.create('Ext.container.Container', {
  131. margin: "15 0 5 15",
  132. html:'<p >The job named <span class="info">'+this.record.data.name+' </span>'+
  133. 'was launched on <span class="err">'+this.record.data.creationTime+' </span>'+
  134. //'and has been visited <span class="dis">'+this.record.data.visites+' times</span></p>'+
  135. //'You can download the job results by pressing the <b>download</b> button.'
  136. '<br>'
  137. });
  138. var result = [];
  139. //Solo grupos juntos al principio
  140. var i=1;
  141. for (key in obj){
  142. var groupId = this.jobId+key+"group";
  143. var groupBox = Ext.create('Ext.container.Container', {
  144. padding:"0 0 2 15",
  145. //html:'<p class="s110 emph">'+i+'. <a href="#'+key+'">'+key+'</a></p>'
  146. groupId:groupId,
  147. html:'<span class="s110 emph">'+i+'. '+key+'</span>',
  148. listeners:{
  149. afterrender:function(){
  150. this.getEl().addClsOnOver("ssel u");
  151. this.getEl().addCls("dedo");
  152. var groupId = this.groupId;
  153. //inlineblock
  154. this.getEl().on("click",function(){
  155. var pos = $('#'+groupId).position().top;
  156. $(_this.panel.getEl().dom).children().scrollTop(pos);
  157. });
  158. }
  159. }
  160. });
  161. result.push(groupBox);
  162. i++;
  163. }
  164. //Grupos con resultados a continuacion
  165. var i=1;
  166. for (key in obj){
  167. //Grupo
  168. var infoId = (this.jobId+key+"info").replace(/ /gi, "");
  169. var groupId = this.jobId+key+"group";
  170. var groupBox = Ext.create('Ext.container.Container', {
  171. infoId:infoId,
  172. groupName:key,
  173. padding:"60 15 5 15",
  174. //html:'<p class="panel-border-bottom"><span class="s140 emph">'+i+'. <a name="'+key+'" href="#'+this.jobId+'top">'+key+'</a>'+
  175. //' </span><span class="info" id="'+infoId+'"></span></p>',
  176. html:'<p id="'+groupId+'" class="panel-border-bottom"><span class="s140 emph">'+i+'. '+key+''+
  177. ' </span><span class="info" id="'+infoId+'"></span></p>',
  178. listeners:{
  179. afterrender:function(){
  180. this.getEl().addClsOnOver("ssel u");
  181. this.getEl().addCls("dedo");
  182. this.getEl().on("click",function(){
  183. $(_this.panel.getEl().dom).children().scrollTop(0);
  184. });
  185. var text = _this.getInfo(this.groupName);
  186. if(text!=""){
  187. $("#"+this.infoId).html("+info");
  188. var infoTip = Ext.create('Ext.tip.Tip',{
  189. html:text,
  190. listeners:{
  191. show:function(){
  192. var este = this;
  193. this.getEl().on("mouseleave",function(){
  194. este.hide();
  195. });
  196. }
  197. }
  198. });
  199. $("#"+this.infoId).mouseover(function(ev){
  200. $(this).css({cursor:"pointer"});
  201. infoTip.showAt(ev.clientX,ev.clientY);
  202. });
  203. $("#"+this.infoId).click(function(){
  204. infoTip.hide();
  205. });
  206. }
  207. }
  208. }
  209. });
  210. result.push(groupBox);
  211. //Resultados - se le pasa el array de items
  212. result.push(this.getResults(obj[key].items));
  213. //Comprobamos si tiene subgrupos 1 - nivel solo
  214. var c = 1;
  215. for(clave in obj[key]){
  216. if (clave != "items"){
  217. //Grupo
  218. var groupBox = Ext.create('Ext.container.Container', {
  219. padding:"15 15 5 30",
  220. cls:"inlineblock",
  221. html:'<p class="panel-border-bottom s120 emph">'+i+'.'+c+' '+clave+'</p>'
  222. });
  223. //si la clave es Your annotation tratarlo de otra manera... para mas adelante
  224. // console.log(clave)
  225. result.push(groupBox);
  226. // debugger
  227. //Resultados - se le pasa el array de items
  228. result.push(this.getResults(obj[key][clave]));
  229. c++;
  230. }
  231. }//subgrupos
  232. i++;
  233. }
  234. var downloadButton = Ext.create('Ext.button.Button', {
  235. text: 'Download',
  236. margin: "0 0 25 15",
  237. handler: function (){
  238. _this.adapter.download(_this.jobId, $.cookie('bioinfo_sid'));
  239. }
  240. });
  241. var deleteJobButton = Ext.create('Ext.button.Button', {
  242. text: 'Delete',
  243. margin: "0 0 25 30",
  244. handler: function (){
  245. Ext.Msg.confirm("Delete job", "Are you sure you want to delete this job?", function (btnClicked){
  246. // console.log(btnClicked);
  247. if(btnClicked == "yes") {
  248. _this.adapter.onDeleteJob.addEventListener(function (sender, data){
  249. var msg = "";
  250. if(data.response.indexOf("OK") != -1) {
  251. Ext.getCmp(_this.targetId).getActiveTab().close();
  252. msg = "The job has been succesfully deleted.";
  253. }
  254. else {
  255. msg = "ERROR: could not delete job.";
  256. }
  257. Ext.Msg.alert("Delete job", msg);
  258. });
  259. // console.log("Job id: "+_this.jobId+" Cookie: "+$.cookie('bioinfo_sid'));
  260. _this.adapter.deleteJob(_this.jobId, $.cookie('bioinfo_sid'));
  261. }
  262. });
  263. }
  264. });
  265. this.panel.add(topLink);
  266. this.panel.add(info);
  267. //this.panel.add(downloadButton);
  268. //this.panel.add(deleteJobButton);
  269. this.panel.add(result);
  270. _this.onViewRendered.notify();
  271. }//else
  272. };
  273. ResultWidget.prototype.getResults = function (items){
  274. //Resultados
  275. var boxes = [];
  276. for (var j = 0; j < items.length; j++){
  277. var item = items[j];
  278. //Obtener el container con el resultado
  279. var itemBox = this.showInfo(item);
  280. boxes.push(itemBox);
  281. //A帽adir el container para resultados adicionales segun el type y el tag si procede
  282. var container = this.showTypeInfo(item);
  283. if(container){
  284. boxes.push(container);
  285. }
  286. var container = this.showTagInfo(item);
  287. if(container!=null){
  288. boxes.push(container);
  289. }
  290. }
  291. var itemsBox = Ext.create('Ext.container.Container', {
  292. layout: {type: 'table',columns: 1, tableAttrs: {style: {width: '100%'}}},
  293. items:boxes
  294. });
  295. return itemsBox;
  296. };
  297. ResultWidget.prototype.showInfo = function (item){
  298. var _this=this;
  299. var itemTpl = new Ext.XTemplate(
  300. // '<tpl for="tags">',
  301. // '<span class="ok">{.} </span>:: ',
  302. // '</tpl>',
  303. // '<span class="err">{type} </span>',
  304. '<span class="key">{title} </span>',
  305. '<span class="{[ this.setCSS(values) ]}">{value}</span><br>'
  306. ,
  307. {
  308. // XTemplate configuration:
  309. disableFormats: true,
  310. // member functions:
  311. setCSS: function(item){
  312. switch(item.type){
  313. case 'FILE':
  314. return 'file';
  315. break;
  316. case 'MESSAGE':
  317. //Setting species code
  318. if (item.name == "species"){
  319. _this.species=item.value;
  320. }
  321. return 'message';
  322. break;
  323. }
  324. }
  325. });
  326. //fin template
  327. return itemBox = Ext.create('Ext.container.Container', {
  328. data:item,
  329. datos:item,
  330. margin:"0 10 0 20",
  331. padding:5,
  332. tpl:itemTpl,
  333. cls:"inlineblock",
  334. listeners:{
  335. afterrender:function(){
  336. var datos = this.datos;
  337. if(this.datos.type == 'FILE'){
  338. this.getEl().addClsOnOver("encima");
  339. this.getEl().addCls("whiteborder");
  340. if(_this.application=="variant" && datos.title.toLowerCase().indexOf("filter")!=-1){
  341. _this.filteredVcfFile=datos.value;
  342. }
  343. this.getEl().on("click",function(){
  344. console.log(datos);
  345. var value = datos.value.trim();
  346. _this.adapter.poll($.cookie('bioinfo_account'),$.cookie('bioinfo_sid'),$.cookie('bioinfo_bucket'), _this.jobId, value, true);
  347. });
  348. }
  349. }
  350. }
  351. });
  352. };
  353. ResultWidget.prototype.showTypeInfo = function (item){
  354. var _this=this;
  355. var box = Ext.create('Ext.container.Container',{
  356. margin:"0 10 0 10",
  357. padding:5
  358. });
  359. switch(item.type){
  360. case 'IMAGE':
  361. /*width="400" height="200" */
  362. var filename = item.value.trim();
  363. box.html = '<div><img width="900" src="'+_this.adapter.pollurl($.cookie('bioinfo_account'),$.cookie('bioinfo_sid'), $.cookie('bioinfo_bucket'), _this.jobId,filename)+'"></div>';
  364. return box;
  365. break;
  366. default: return null;
  367. }
  368. };
  369. ResultWidget.prototype.showTagInfo = function (item){
  370. var _this=this;
  371. var box = Ext.create('Ext.container.Container',{
  372. margin:"0 10 0 10",
  373. flex:1,
  374. padding:5,
  375. html:""
  376. });
  377. for(var i = 0; i < item.tags.length ; i++){
  378. switch(item.tags[i]){
  379. case 'TABLE':
  380. var value = item.value.trim();
  381. var id = _this.jobId+value+item.tags;
  382. _this.resultTables[id] = new ResultTable (_this.jobId, value, item.tags,{targetId:'resultTable_'+id});
  383. // _this.resultTables[id].onRendered.
  384. box.html += '<div id="resultTable_'+id+'" style="padding:5px;"></div>';
  385. return box;
  386. break;
  387. case 'HISTOGRAM':
  388. var id = "histogram_"+_this.jobId+item.value+item.tags;
  389. _this.resultHistograms[id] = item.value;
  390. box.html = '<div id="'+id+'" style="padding:5px;"></div>';
  391. return box;
  392. break;
  393. case 'GCHART':
  394. var id = 'gchart_'+item.name;
  395. _this.resultGCharts[id] = item.value;
  396. box.html = '<div id="'+id+'"></div>';
  397. return box;
  398. break;
  399. case 'CONSEQUENCE_TYPE_VARIANTS':
  400. this.variantFiles[item.name] = item.title;
  401. break;
  402. }
  403. }
  404. return null;
  405. };
  406. ResultWidget.prototype.drawTables = function (){
  407. // console.log(this.resultTables);
  408. for(id in this.resultTables){
  409. this.resultTables[id].draw();
  410. }
  411. };
  412. ResultWidget.prototype.drawHistograms = function (){
  413. //se dibujan todas las tablas
  414. // console.log(this.resultHistograms);
  415. for(id in this.resultHistograms){
  416. var adapterPoll = new GcsaManager();
  417. adapterPoll.onPoll.addEventListener(function(sender,data){
  418. if(data!=""){
  419. var lines = data.split("\n");
  420. var fields=[];
  421. var names=[];
  422. var values=[];
  423. var normValues=[];
  424. var total = 0;
  425. for ( var i = 0; i < lines.length; i++) {
  426. fields.push(lines[i].split("\t"));
  427. if(fields[i][0]!=""){
  428. names.push(fields[i][0]);
  429. }
  430. if(fields[i][1]!=null){
  431. total = total + parseFloat(fields[i][1]);
  432. values.push(fields[i][1]);
  433. }
  434. }
  435. for ( var i = 0; i < values.length; i++) {
  436. normValues.push(Math.round(parseFloat(values[i])/total*100));
  437. }
  438. names = names.toString().replace(/,/gi,"|");
  439. 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">';
  440. document.getElementById(id).innerHTML=img;
  441. }
  442. });
  443. //adapterPoll.poll(this.jobId,this.resultHistograms[id],false,$.cookie('bioinfo_sid'));
  444. adapterPoll.poll($.cookie("bioinfo_account"), $.cookie('bioinfo_sid'), $.cookie("bioinfo_bucket"), this.jobId, this.resultHistograms[id], false);
  445. }
  446. };
  447. ResultWidget.prototype.drawGCharts = function (){
  448. for(id in this.resultGCharts){
  449. drawChart(id, this.resultGCharts[id]);
  450. }
  451. };
  452. ResultWidget.prototype.drawApplicationItems = function (){
  453. var _this=this;
  454. var viewerContainer = Ext.create('Ext.container.Container', {
  455. id:this.application+this.id+"Container",
  456. border: true,
  457. margin:"50 50 0 50",
  458. html:'<div class="greyborder" id="'+this.id+'Container"></div><div style="height:40px"></div>'
  459. });
  460. switch (this.application){
  461. case "variant":
  462. viewerContainer.on("afterrender",function(){
  463. _this.createGenomeViewer(_this.id+"Container");
  464. });
  465. break;
  466. case "renato":
  467. //***********bar
  468. var pbar = Ext.create('Ext.ProgressBar', {id:this.id+'pbar',margin:"5 0 0 50",width: 500});
  469. // Wait for 5 seconds, then update the status el (progress bar will auto-reset)
  470. pbar.wait({
  471. interval: 500, //bar will move fast!
  472. duration: 50000,
  473. increment: 15,
  474. text: 'Getting database information and drawing the network, please wait...',
  475. scope: this,
  476. fn: function(){
  477. pbar.updateText('Done!');
  478. }
  479. });
  480. //Add de bar to the main panel
  481. this.panel.add(pbar);
  482. /*************************/
  483. viewerContainer.on("afterrender",function(){
  484. _this.createCellBrowser(_this.id+"Container");
  485. });
  486. break;
  487. default: return null;
  488. }
  489. this.panel.add(viewerContainer);
  490. };
  491. ResultWidget.prototype.createGenomeViewer = function (targetId){
  492. var _this = this;
  493. var width = Ext.getCmp(this.application+targetId).getWidth();
  494. var height = Ext.getCmp(this.application+targetId).getHeight();
  495. //var genomeViewer = new GenomeViewer(targetId, AVAILABLE_SPECIES[0],{
  496. //version:"",
  497. //zoom:75,
  498. //width:width-2,
  499. //height:height-2
  500. //});
  501. //genomeViewer.setMenuBar(this.getGenomeViewerResultBar(genomeViewer));
  502. genomeViewer = new GenomeViewer(targetId, DEFAULT_SPECIES,{
  503. sidePanelCollapsed:true,
  504. width:width-2,
  505. height:700-2
  506. });
  507. genomeViewer.afterRender.addEventListener(function(sender,event){
  508. _this.app.setTracks(genomeViewer);
  509. genomeViewer.addSidePanelItems();
  510. var variantFilterWidget = new VariantFilterWidget(_this.jobId,{
  511. width:width-2,
  512. targetId:_this.application+targetId,
  513. viewer:genomeViewer,
  514. fileNames:_this.variantFiles
  515. });
  516. });
  517. genomeViewer.draw();
  518. var adapter = new GcsaManager();
  519. adapter.onPoll.addEventListener(function(sender, data){
  520. if(data.indexOf("ERROR")!=1){
  521. console.error(data);
  522. }
  523. var vcfDataAdapter = new VCFDataAdapter(new StringDataSource(data),{async:false,species:genomeViewer.species});
  524. var vcfTrack = new TrackData("VCF file",{
  525. adapter: vcfDataAdapter
  526. });
  527. genomeViewer.addTrack(vcfTrack,{
  528. id:"VCF file",
  529. featuresRender:"MultiFeatureRender",
  530. histogramZoom:50,
  531. height:150,
  532. visibleRange:{start:0,end:100},
  533. featureTypes:FEATURE_TYPES
  534. });
  535. //var feature = vcfDataAdapter.featureCache.getFirstFeature();
  536. //genomeViewer.region.load(feature);
  537. //genomeViewer.setRegion({sender:""});
  538. // genomeViewer.setZoom(75);
  539. });
  540. // console.log(this.filteredVcfFile)
  541. if(this.filteredVcfFile != null){
  542. adapter.poll($.cookie("bioinfo_account"), $.cookie('bioinfo_sid'), $.cookie("bioinfo_bucket"), _this.jobId, this.filteredVcfFile, false);
  543. //adapter.poll(_this.jobId, this.filteredVcfFile, false, $.cookie('bioinfo_sid'));
  544. }else{
  545. console.log("No filtered VCF file.");
  546. }
  547. };
  548. var mostSignificativesFeatures = new Array();
  549. ResultWidget.prototype.createCellBrowser = function (targetId){
  550. var _this = this;
  551. record = this.record;
  552. //hide network-viewer, all nodes mut be rendered before show
  553. Ext.getCmp(this.application+targetId).disable();
  554. var width = Ext.getCmp(this.application+targetId).getWidth();
  555. var height = Ext.getCmp(this.application+targetId).getHeight();
  556. //Pako creating cellBrowser
  557. this.networkViewer = new NetworkViewer(targetId,this.getSpeciesItem(this.species),{
  558. width:width-2,
  559. height:height-2
  560. });
  561. // this.networkViewer.setSpeciesMenu(AVAILABLE_SPECIES);
  562. this.networkViewer.draw();
  563. //setting a empty data and format, nodes will be draw later using the interface
  564. var dataset = new GraphDataset();
  565. var layout = new LayoutDataset();
  566. var formatter = new NetworkDataSetFormatter({
  567. "defaultFormat": {"type":"LineEdgeNetworkFormatter","opacity":1, "fill":"#000000", "radius":"5", "strokeWidth":"1", "stroke":"#000000", "size":"2", "title":{"fontSize":10, "fill":"#000000"}},
  568. "selected": {"opacity":0.9, "fill":"#FF0000", "radius":"5", "stroke":"#000000", "size":"2"},
  569. "over": {"opacity":1, "fill":"#DF0101", "radius":"5", "stroke":"#000000", "size":"2", "strokeWidth":"1"}
  570. },
  571. {
  572. "defaultFormat": { "opacity":0.8,"stroke":"#000000", "strokeWidth":"1", "strokeOpacity":0.5, "title":{"fontSize":6, "fontColor":"#000000"}},
  573. "selected": {"stroke":"#DF0101", "fill":"#FF0000"},
  574. "over": { "stroke":"#DF0101","strokeOpacity":1, "strokeWidth":"4"}
  575. },
  576. // { "labeled":false, "height":height,"width":this.width,"right":this.width,"backgroundColor":"#FFFFFF", "balanceNodes":false, "nodesMaxSize":4, "nodesMinSize":2});
  577. { "labeled":false, "backgroundColor":"#FFFFFF", "balanceNodes":false, "nodesMaxSize":4, "nodesMinSize":2});
  578. formatter.dataBind(dataset);
  579. layout.dataBind(dataset);
  580. formatter.setHeight(height - 140);
  581. formatter.setWidth(width-2-13);
  582. this.networkViewer.drawNetwork(dataset, formatter, layout);
  583. //Getting significant_your_annotation_0.05.txt
  584. var adapter2 = new WumRestAdapter();
  585. adapter2.onPoll.addEventListener(function(sender, data){
  586. var lines = data.split("\n");
  587. var significativesFeatures = new Array();
  588. for ( var i = 1; i < lines.length; i++) {
  589. var column = 13;
  590. if(record.data.toolName == "fatiscan"){
  591. if(lines[i].split("\t").length==7){
  592. //we are in the case of logistic model
  593. column = 6;
  594. }
  595. }
  596. var significativeValue = lines[i].split("\t")[column];
  597. if(significativeValue < 1000000){
  598. significativesFeatures.push(lines[i].split("\t")[0]);
  599. }
  600. }
  601. console.log('significativesFeatures.length: '+significativesFeatures.length);
  602. /** TFBS **/
  603. var adapter3 = new WumRestAdapter();
  604. adapter3.onPoll.addEventListener(function(sender, data){
  605. var genes = data.split("\n");
  606. /** Para elminar la linea en blanco: Gorrion Rules! **/
  607. genes.pop();
  608. console.log('genes.length: '+genes.length);
  609. _this.loadNetworkOnCellBrowser(genes, significativesFeatures, targetId);
  610. });
  611. var file = "clean_list1.txt";
  612. if(record.data.toolName == "fatiscan")
  613. file = "id_list.txt";
  614. adapter3.poll(_this.jobId, file, false, $.cookie('bioinfo_sid'));
  615. });
  616. adapter2.poll(this.jobId, "significant_your_annotation_0.05.txt", false, $.cookie('bioinfo_sid'));
  617. //END getting significant_your_annotation_0.05.txt
  618. // By Nacho
  619. // getting 50 most significant genes
  620. console.log('getting ranked_list...');
  621. var cleanListWumAdapater = new WumRestAdapter();
  622. cleanListWumAdapater.onPoll.addEventListener(function(sender, data) {
  623. var lines = data.split("\n");
  624. var numGenes = lines.length;
  625. var cont = 0;
  626. console.log('getting top clean_list...');
  627. for(var i = 0; cont < 50 && i < numGenes; i++) {
  628. if(lines[i].indexOf('#') < 0) {
  629. // console.log('getting top ranked_list... '+lines[i]);
  630. // console.log('getting top ranked_list... '+lines[i].split("\t")[0]);
  631. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  632. cont++;
  633. }
  634. }
  635. cont = 0;
  636. console.log('getting bottom clean_list...');
  637. for(var i = numGenes-1; cont < 50 && i > 0; i--) {
  638. if(lines[i].indexOf('#') < 0) {
  639. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  640. cont++;
  641. }
  642. }
  643. });
  644. cleanListWumAdapater.poll(this.jobId, "clean_list1.txt", false, $.cookie('bioinfo_sid'));
  645. // END getting 50 most significant genes
  646. // getting ranked_list
  647. console.log('getting ranked_list...');
  648. var rankedListWumAdapater = new WumRestAdapter();
  649. rankedListWumAdapater.onPoll.addEventListener(function(sender, data) {
  650. var lines = data.split("\n");
  651. var numGenes = lines.length;
  652. var cont = 0;
  653. console.log('getting top ranked_list...');
  654. for(var i = 0; cont < 50 && i < numGenes; i++) {
  655. if(lines[i].indexOf('#') < 0) {
  656. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  657. cont++;
  658. }
  659. }
  660. cont = 0;
  661. console.log('getting bottom ranked_list...');
  662. for(var i = numGenes-1; cont < 50 && i > 0; i--) {
  663. if(lines[i].indexOf('#') < 0) {
  664. mostSignificativesFeatures[lines[i].split("\t")[0]] = true;
  665. cont++;
  666. }
  667. }
  668. });
  669. rankedListWumAdapater.poll(this.jobId, "ranked_list.txt", false, $.cookie('bioinfo_sid'));
  670. //END getting ranked_list
  671. };
  672. ResultWidget.prototype.loadNetworkOnCellBrowser = function (genes, tfbs, targetId){
  673. var _this = this;
  674. //tfbs and mirna nodes are rendered
  675. //2 indicates that mirna and tfbs are done
  676. var nodesRendered = 0;
  677. //Getting tfbs by gene
  678. var cellBaseManager = new CellBaseManager(this.networkViewer.species);
  679. cellBaseManager.success.addEventListener(function (evt, response){
  680. var data_tfbs = response.result;
  681. var tfbsByGene = new Object();
  682. for (var i = 0; i < data_tfbs.length; i++){
  683. for ( var j = 0; j < data_tfbs[i].length; j++) {
  684. if(tfbs.toString().indexOf(data_tfbs[i][j].tfName) != -1){
  685. if (tfbsByGene[data_tfbs[i][j].tfName] == null){
  686. tfbsByGene[data_tfbs[i][j].tfName] = new Object();
  687. }
  688. if(tfbsByGene[data_tfbs[i][j].tfName][genes[i]] == null){
  689. tfbsByGene[data_tfbs[i][j].tfName][genes[i]] = true;
  690. }
  691. }
  692. }
  693. }
  694. console.log(tfbsByGene);
  695. console.log(data_tfbs.length);
  696. console.log('contando TFBSs...');
  697. // check the number of elemts to be rendered
  698. // if there are more than 500 then select the most significant
  699. var numElements = 0;
  700. for ( var tf in tfbsByGene) {
  701. if(numElements > 500) {
  702. break;
  703. }
  704. for ( var gene in tfbsByGene[tf]) {
  705. numElements++;
  706. }
  707. }
  708. console.log('menos de 500: '+numElements);
  709. for ( var tf in tfbsByGene) {
  710. _this.networkViewer.networkWidget.getDataset().addNode(tf, {type:"tf"});
  711. var verticeId = _this.networkViewer.networkWidget.getDataset().getVerticesCount() - 1;
  712. _this.networkViewer.networkWidget.getFormatter().getVertexById(verticeId).getDefault().setFill("#DF0101");
  713. // console.log(tfbsByGene[tf]);
  714. // console.log(_this.networkViewer.networkWidget.getFormatter().getVertexById(verticeId));
  715. for ( var gene in tfbsByGene[tf]) {
  716. if(numElements < 500 || mostSignificativesFeatures[gene] == true) {
  717. // console.log(gene);
  718. /** Conecto los tfbs con sus genes **/
  719. if(_this.networkViewer.networkWidget.getDataset().getVertexByName(gene).length == 0){
  720. _this.networkViewer.networkWidget.getDataset().addNode(gene, {type:"gene"});
  721. }
  722. // console.log(_this.networkViewer.networkWidget.getDataset());
  723. // getVertexByName returns an array
  724. var vertexGeneId = _this.networkViewer.networkWidget.getDataset().getVertexByName(gene)[0].id;
  725. var vertexTfbsId = _this.networkViewer.networkWidget.getDataset().getVertexByName(tf)[0].id;
  726. _this.networkViewer.networkWidget.getDataset().addEdge("tfbs_" + vertexGeneId + "_" + vertexTfbsId, vertexTfbsId, vertexGeneId);
  727. _this.networkViewer.networkWidget.getFormatter().getVertexById(vertexGeneId).getDefault().setFill("#0000FF");
  728. }
  729. }
  730. }
  731. _this.networkViewer.networkWidget.getLayout().getLayout("neato");
  732. _this.networkViewer.networkWidget.getLayout().layoutDone.addEventListener(function (evt){
  733. nodesRendered++;
  734. if(nodesRendered==2){
  735. Ext.getCmp(_this.id+'pbar').destroy();
  736. Ext.getCmp(_this.application+targetId).enable();
  737. }
  738. });
  739. });
  740. if(genes.length>0){
  741. cellBaseManager.get("feature", "gene", genes, "tfbs");
  742. }
  743. //getting mirna target by gene
  744. var cellBaseManagerMirna = new CellBaseManager(this.networkViewer.species);
  745. cellBaseManagerMirna.success.addEventListener(function (evt, response){
  746. var data_tfbs = response.result;
  747. var tfbsByGene = new Object();
  748. for (var i = 0; i < data_tfbs.length; i++){
  749. for ( var j = 0; j < data_tfbs[i].length; j++) {
  750. if(tfbs.toString().indexOf(data_tfbs[i][j].mirbaseId) != -1){
  751. if (tfbsByGene[data_tfbs[i][j].mirbaseId] == null){
  752. tfbsByGene[data_tfbs[i][j].mirbaseId] = new Object();
  753. }
  754. if(tfbsByGene[data_tfbs[i][j].mirbaseId][genes[i]] == null){
  755. tfbsByGene[data_tfbs[i][j].mirbaseId][genes[i]] = true;
  756. }
  757. }
  758. }
  759. }
  760. console.log(tfbsByGene);
  761. console.log(data_tfbs.length);
  762. console.log('contando miRNAs...');
  763. // check the number of elemts to be rendered
  764. // if there are more than 500 then select the most significant
  765. var numElements = 0;
  766. for ( var tf in tfbsByGene) {
  767. if(numElements > 500) {
  768. break;
  769. }
  770. for ( var gene in tfbsByGene[tf]) {
  771. numElements++;
  772. }
  773. }
  774. console.log('menos de 500: '+numElements);
  775. for ( var mirna in tfbsByGene) {
  776. _this.networkViewer.networkWidget.getDataset().addNode(mirna, {type:"mirna"});
  777. var verticeId = _this.networkViewer.networkWidget.getDataset().getVerticesCount() - 1;
  778. _this.networkViewer.networkWidget.getFormatter().getVertexById(verticeId).getDefault().setFill("red");
  779. for ( var gene in tfbsByGene[mirna]) {
  780. if(numElements < 500 || mostSignificativesFeatures[gene] == true) {
  781. // console.log(gene);
  782. if(_this.networkViewer.networkWidget.getDataset().getVertexByName(gene).length == 0){
  783. // if(_this.networkViewer.networkWidget.getDataset().getVertexByName(gene) == null) {
  784. _this.networkViewer.networkWidget.getDataset().addNode(gene, {type:"gene"});
  785. }
  786. var vertexGeneId = _this.networkViewer.networkWidget.getDataset().getVertexByName(gene)[0].id;
  787. var vertexTfbsId = _this.networkViewer.networkWidget.getDataset().getVertexByName(mirna)[0].id;
  788. _this.networkViewer.networkWidget.getDataset().addEdge("tfbs_" + vertexGeneId + "_" + vertexTfbsId, vertexTfbsId, vertexGeneId);
  789. _this.networkViewer.networkWidget.getFormatter().getVertexById(vertexGeneId).getDefault().setFill("blue");
  790. var edgeId = _this.networkViewer.networkWidget.getDataset().getEdgesCount() - 1;
  791. _this.networkViewer.networkWidget.getFormatter().changeEdgeType(edgeId, "CutDirectedLineEdgeNetworkFormatter");
  792. }
  793. }
  794. }
  795. _this.networkViewer.networkWidget.getLayout().getLayout("neato");
  796. _this.networkViewer.networkWidget.getLayout().layoutDone.addEventListener(function (evt){
  797. nodesRendered++;
  798. if(nodesRendered==2){
  799. Ext.getCmp(_this.id+'pbar').destroy();
  800. Ext.getCmp(_this.application+targetId).enable();
  801. }
  802. });
  803. });
  804. if(genes.length>0){
  805. cellBaseManagerMirna.get("feature", "gene", genes, "mirna_target");
  806. }else{
  807. Ext.getCmp(_this.id+'pbar').destroy();
  808. Ext.getCmp(_this.application+targetId).enable();
  809. }
  810. };
  811. ResultWidget.prototype.getGenomeViewerResultBar = function(genomeViewer) {
  812. var _this=this;
  813. switch (this.application){
  814. case "variant":
  815. var toolbarMenu = Ext.create('Ext.container.Container', {
  816. cls:'bio-toolbar',
  817. defaults:{margin:'1 0 0 2'},
  818. layout:'vbox',
  819. height:27,
  820. items : [
  821. {xtype:'button',text:'<span class="info">Variant filter tool...</span>',handler:function(){
  822. var variantFilterWidget = new VariantFilterWidget(_this.jobId,{viewer:genomeViewer,fileNames:_this.variantFiles});
  823. // variantFilterWidget.draw();
  824. // variantFilterWidget.parseData(data);
  825. // var wumRestAdapter = new WumRestAdapter();
  826. // wumRestAdapter.onPoll.addEventListener(function(sender, data){
  827. // });
  828. // wumRestAdapter.poll(_this.jobId, "variant.txt", false, $.cookie('bioinfo_sid'));
  829. }
  830. }
  831. ]
  832. });
  833. return toolbarMenu;
  834. break;
  835. default: return null;
  836. }
  837. };
  838. ResultWidget.prototype.getSpeciesItem = function(species) {
  839. //selecciona el objeto AVAILABLE_SPECIES segun el species code
  840. for ( var i = 0; i < AVAILABLE_SPECIES.length; i++) {
  841. if(AVAILABLE_SPECIES[i].species==species){
  842. return AVAILABLE_SPECIES[i];
  843. }
  844. }
  845. };
  846. //Quita los resultados para your annotation
  847. ResultWidget.prototype.checkPValue = function(str) {
  848. //return false si es 0.005, 0.01 贸 0.1
  849. if(str.indexOf("pvalue<0.005")!= -1 ||
  850. str.indexOf("pvalue<0.01")!= -1 ||
  851. str.indexOf("pvalue<0.1")!= -1
  852. ){
  853. return false;
  854. }
  855. return true;
  856. };
  857. //Quita los resultados para your annotation
  858. ResultWidget.prototype.renamePValue = function(item) {
  859. //reemplaza la cadena ${pvalue} por 0.05
  860. if(item.value.indexOf("${pvalue}") != -1){
  861. item.value = item.value.replace(/\$\{pvalue\}/gi, "0.05");
  862. }
  863. };
  864. //XXX no se usa por ahora...Para mas adelante
  865. ResultWidget.prototype.setPValue = function(value) {
  866. console.log(this.id);
  867. var divId="#pvalue"+this.id;
  868. $(divId).html(value);
  869. };
  870. //Quita los resultados para your annotation
  871. ResultWidget.prototype.getInfo = function(groupName) {
  872. switch (this.application){
  873. case "renato":
  874. switch (groupName){
  875. case "Input data": return "This section is a reminder of the parameters or settings you have submitted to run the analysis.";
  876. 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>";
  877. 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>";
  878. 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.";
  879. 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>";
  880. default: return "";
  881. }
  882. break;
  883. case "variant":
  884. switch (groupName){
  885. 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>";
  886. default: return "";
  887. }
  888. break;
  889. default: return "";
  890. }
  891. };