diff --git a/src/app/components/analysis-panel/analysis-panel.component.ts b/src/app/components/analysis-panel/analysis-panel.component.ts index 59ba4596aa84ecd3f5af101b00bfce6894bf2e2e..a0ae4b81c6a9ee11629586a200b495317e863adc 100644 --- a/src/app/components/analysis-panel/analysis-panel.component.ts +++ b/src/app/components/analysis-panel/analysis-panel.component.ts @@ -197,6 +197,12 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit this.networkHandler.activeNetwork.networkInternal = new vis.Network(container, this.nodeData, options); + this.networkHandler.activeNetwork.networkInternal.on('stabilizationIterationsDone', () => { + if (!this.drugstoneConfig.config.physicsOn) { + this.networkHandler.activeNetwork.updatePhysicsEnabled(false); + } + }); + this.tableDrugs = nodes.filter(e => e.drugstoneId && e.drugstoneId.startsWith('d')); this.tableDrugs.forEach((r) => { r.rawScore = r.score; @@ -400,80 +406,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit } } - - // public saveAddNodes(nodeList: Node[]) { - // const existing = this.nodeData.nodes.get().map(n => n.id); - // const toAdd = nodeList.filter(n => existing.indexOf(n.id) === -1) - // this.nodeData.nodes.add(toAdd); - // } - - // public saveRemoveDisorders(nodeList: Node[]) { - // const other = this.adjacentDrugDisorderList === nodeList ? this.adjacentProteinDisorderList : this.adjacentDrugDisorderList - // if (other == null) - // this.nodeData.nodes.remove(nodeList); - // else { - // const otherIds = other.map(d => d.id); - // const rest = nodeList.filter(d => otherIds.indexOf(d.id) === -1) - // this.nodeData.nodes.remove(rest) - // } - // } - - // public updateAdjacentProteinDisorders(bool: boolean) { - // this.adjacentDisordersProtein = bool; - // if (this.adjacentDisordersProtein) { - // this.netex.adjacentDisorders(this.nodeData.nodes, 'proteins').subscribe(response => { - // for (const interaction of response.edges) { - // const edge = {from: interaction.protein, to: interaction.disorder}; - // this.adjacentProteinDisorderEdgesList.push(mapCustomEdge(edge, this.myConfig)); - // } - // for (const disorder of response.disorders) { - // disorder.group = 'defaultDisorder'; - // disorder.id = disorder.drugstoneId; - // this.adjacentProteinDisorderList.push(mapCustomNode(disorder, this.myConfig)) - // } - // this.saveAddNodes(this.adjacentProteinDisorderList); - // this.nodeData.edges.add(this.adjacentProteinDisorderEdgesList); - // this.emitVisibleItems(true); - // }); - // this.legendContext = this.adjacentDrugs ? 'adjacentDrugsAndDisorders' : 'adjacentDisorders'; - // } else { - // this.saveRemoveDisorders(this.adjacentProteinDisorderList); - // this.nodeData.edges.remove(this.adjacentProteinDisorderEdgesList); - // this.adjacentProteinDisorderList = []; - // this.adjacentProteinDisorderEdgesList = []; - // this.legendContext = this.adjacentDisordersDrug ? this.legendContext : this.adjacentDrugs ? 'adjacentDrugs' : 'explorer'; - // this.emitVisibleItems(true); - // } - // } - - // public updateAdjacentDrugDisorders(bool: boolean) { - // this.adjacentDisordersDrug = bool; - // if (this.adjacentDisordersDrug) { - // this.netex.adjacentDisorders(this.nodeData.nodes, 'drugs').subscribe(response => { - // for (const interaction of response.edges) { - // const edge = {from: interaction.drug, to: interaction.disorder}; - // this.adjacentDrugDisorderEdgesList.push(mapCustomEdge(edge, this.myConfig)); - // } - // for (const disorder of response.disorders) { - // disorder.group = 'defaultDisorder'; - // disorder.id = disorder.drugstoneId; - // this.adjacentDrugDisorderList.push(mapCustomNode(disorder, this.myConfig)); - // } - // this.saveAddNodes(this.adjacentDrugDisorderList); - // this.nodeData.edges.add(this.adjacentDrugDisorderEdgesList); - // this.emitVisibleItems(true); - // }); - // this.legendContext = this.adjacentDrugs ? 'adjacentDrugsAndDisorders' : 'adjacentDisorders'; - // } else { - // this.saveRemoveDisorders(this.adjacentDrugDisorderList); - // this.nodeData.edges.remove(this.adjacentDrugDisorderEdgesList); - // this.adjacentDrugDisorderList = []; - // this.adjacentDrugDisorderEdgesList = []; - // this.legendContext = this.adjacentDisordersProtein ? this.legendContext : this.adjacentDrugs ? 'adjacentDrugs' : 'explorer'; - // this.emitVisibleItems(true); - // } - // } - public downloadLink(view: string): string { return `${environment.backend}task_result/?token=${this.token}&view=${view}&fmt=csv`; } @@ -589,72 +521,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit }; } - // hasDrugsLoaded(): boolean { - // if (this.nodeData == null || this.nodeData.nodes == null) - // return false; - // return this.nodeData.nodes.get().filter((node: Node) => node.drugId && node.drugstoneId.startsWith('dr')).length > 0; - // } - - // public updateAdjacentDrugs(bool: boolean) { - // this.adjacentDrugs = bool; - // if (this.adjacentDrugs) { - // this.netex.adjacentDrugs(this.myConfig.interactionDrugProtein, this.nodeData.nodes).subscribe(response => { - // for (const interaction of response.pdis) { - // const edge = {from: interaction.protein, to: interaction.drug}; - // this.adjacentDrugEdgesList.push(mapCustomEdge(edge, this.myConfig)); - // } - // for (const drug of response.drugs) { - // drug.group = 'foundDrug'; - // drug.id = getDrugNodeId(drug) - // this.adjacentDrugList.push(mapCustomNode(drug, this.myConfig)) - // } - // this.nodeData.nodes.add(this.adjacentDrugList); - // this.nodeData.edges.add(this.adjacentDrugEdgesList); - // this.emitVisibleItems(true); - // }) - // this.legendContext = this.adjacentDisordersDrug || this.adjacentDisordersProtein ? 'adjacentDrugsAndDisorders' : 'adjacentDrugs'; - // } else { - // this.nodeData.nodes.remove(this.adjacentDrugList); - // this.nodeData.edges.remove(this.adjacentDrugEdgesList); - // this.adjacentDrugList = []; - // this.adjacentDrugEdgesList = []; - - // this.legendContext = this.adjacentDisordersDrug || this.adjacentDisordersProtein ? 'adjacentDisorders' : 'explorer'; - // this.emitVisibleItems(true); - // } - // } - - // public updatePhysicsEnabled(bool: boolean) { - // this.drugstoneConfig.config.physicsOn = bool; - // this.networkHandler.activeNetwork.networkInternal.setOptions({ - // physics: { - // enabled: this.drugstoneConfig.config.physicsOn, - // stabilization: { - // enabled: false, - // }, - // } - // }); - // } - - // public toImage() { - // this.downloadDom(this.networkWithLegendEl.nativeElement).catch(error => { - // console.error("Falling back to network only screenshot. Some components seem to be inaccessable, most likely the legend is a custom image with CORS access problems on the host server side.") - // this.downloadDom(this.networkHandler.activeNetwork.networkEl.nativeElement).catch(e => { - // console.error("Some network content seems to be inaccessable for saving as a screenshot. This can happen due to custom images used as nodes. Please ensure correct CORS accessability on the images host server.") - // console.error(e) - // }); - // }); - // } - - // public downloadDom(dom: object) { - // return domtoimage.toPng(dom, {bgcolor: '#ffffff'}).then((generatedImage) => { - // const a = document.createElement('a'); - // a.href = generatedImage; - // a.download = `Network.png`; - // a.click(); - // }); - // } - public tableProteinSelection = (e): void => { const oldSelection = [...this.tableSelectedProteins]; this.tableSelectedProteins = e; diff --git a/src/app/network-settings.ts b/src/app/network-settings.ts index 38881ef2847af33da6e95ed6824728ab0dd6758b..971f137d242d821f91144684781f603ad0bbf4d6 100644 --- a/src/app/network-settings.ts +++ b/src/app/network-settings.ts @@ -56,7 +56,8 @@ export class NetworkSettings { length: 250 }; private static mainPhysics = { - enabled: false + enabled: true, + stabilization: true }; static getOptions(network: 'main' | 'analysis' | 'analysis-big', physicsOn) { diff --git a/src/app/pages/explorer-page/explorer-page.component.ts b/src/app/pages/explorer-page/explorer-page.component.ts index 79f3f692127b00ff2ffecde0e8bc372b013c24d9..c69b9394438b38e992f793882d9b172c01a7b325 100644 --- a/src/app/pages/explorer-page/explorer-page.component.ts +++ b/src/app/pages/explorer-page/explorer-page.component.ts @@ -282,6 +282,12 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { this.networkHandler.activeNetwork.networkInternal = new vis.Network(container, this.nodeData, options); + this.networkHandler.activeNetwork.networkInternal.on('stabilizationIterationsDone', () => { + if (!this.drugstoneConfig.config.physicsOn) { + this.networkHandler.activeNetwork.updatePhysicsEnabled(false); + } + }); + if (!this.drugstoneConfig.config.showSidebar) { // skip network options for selecting nodes when there are no options to use it return diff --git a/src/index.html b/src/index.html index 8c682413579d3467855e7916f748fa6cb8800346..347102d5275f6fe70b9a40d98b7c46df8e6be227 100644 --- a/src/index.html +++ b/src/index.html @@ -51,7 +51,7 @@ <drugst-one id="netexp1" pluginId="2" groups='{"nodeGroups":{"patient":{"type":"patient","color":"#000000","font":{"color":"#000000"},"groupName":"Patient","shape":"image","image":"https://static.thenounproject.com/png/22780-200.png"},"condition":{"type":"condition","color":"#000000","font":{"color":"#000000"},"groupName":"Condition","shape":"text"},"important":{"type":"gene","color":"#ff881f","font":{"color":"#000000"},"groupName":"Important Gene","shape":"star"},"gene":{"type":"gene","color":"#4da300","font":{"color":"#f0f0f0"},"groupName":"Gene","shape":"circle"},"foundDrug":{"type":"drug","color":"#F12590","font":{"color":"#000000"},"groupName":"Drug","shape":"diamond"}},"edgeGroups":{"genotype":{"color":"#000000","groupName":"Relevant Gene"},"has-condition":{"color":"#000000","groupName":"Has Condition","dashes":[2,2]},"default":{"color":"#000000","groupName":"default edge"},"ggi":{"color":"#000000","groupName":"Interaction","dashes":[3,2]}}}' - config='{"identifier":"symbol","title":"Breast cancer example network","nodeShadow":true,"edgeShadow":false,"autofillEdges":false,"showLegend":true}' + config='{"physicsOn":false,"identifier":"symbol","title":"Breast cancer example network","nodeShadow":true,"edgeShadow":false,"autofillEdges":false,"showLegend":true}' network='{"nodes":[{"id":"patient-1","group":"patient","x":592,"y":446},{"id":"patient-2","group":"patient","x":235,"y":87},{"id":"patient-3","group":"patient","x":105,"y":369},{"id":"ATM","label":"ATM","group":"gene","x":289,"y":242},{"id":"BARD1","label":"BARD1","group":"gene","x":44,"y":250},{"id":"BRCA1","label":"BRCA1","group":"gene","x":466,"y":576},{"id":"BRCA2","label":"BRCA2","group":"gene","x":507,"y":285},{"id":"BRIP1","label":"BRIP1","group":"gene","x":54,"y":474},{"id":"CHEK2","label":"CHEK2","group":"gene","x":216,"y":590},{"id":"CDH1","label":"CDH1","group":"gene","x":320,"y":-57},{"id":"NF1","label":"NF1","group":"gene","x":481,"y":111},{"id":"NBN","label":"NBN","group":"gene","x":-57,"y":314},{"id":"PALB2","label":"PALB2","group":"gene","x":450,"y":190},{"id":"PTEN","label":"PTEN","group":"important","x":305,"y":494},{"id":"RAD51C","label":"RAD51C","group":"gene","x":182,"y":-90},{"id":"RAD51D","label":"RAD51D","group":"gene","x":368,"y":73},{"id":"STK11","label":"STK11","group":"gene","x":686,"y":330},{"id":"TP53","label":"TP53","group":"important","x":333,"y":316},{"id":"subtype-1","label":"Subtype 1","group":"condition","x":556,"y":171},{"id":"subtype-2","label":"Subtype 2","group":"condition","x":-87,"y":221}],"edges":[{"from":"BRCA1","to":"BRCA2","group":"ggi"},{"from":"ATM","to":"BARD1","group":"ggi"},{"from":"BRCA1","to":"CHEK2","group":"ggi"},{"from":"RAD51C","to":"RAD51D","group":"ggi"},{"from":"STK11","to":"TP53","group":"ggi"},{"from":"TP53","to":"PALB2","group":"ggi"},{"from":"TP53","to":"RAD51D","group":"ggi"},{"from":"TP53","to":"NF1","group":"ggi"},{"from":"TP53","to":"BRCA1","group":"ggi"},{"from":"TP53","to":"BRCA2","group":"ggi"},{"from":"PTEN","to":"BRCA1","group":"ggi"},{"from":"PTEN","to":"BRCA2","group":"ggi"},{"from":"TP53","to":"PTEN","group":"ggi"},{"from":"ATM","to":"PTEN","group":"ggi"},{"from":"CDH1","to":"RAD51D","group":"ggi"},{"from":"CDH1","to":"PALB2","group":"ggi"},{"from":"NBN","to":"BRIP1","group":"ggi"},{"from":"BRIP1","to":"PTEN","group":"ggi"},{"from":"patient-1","to":"BRCA1","group":"genotype"},{"from":"patient-1","to":"TP53","group":"genotype"},{"from":"patient-1","to":"BRCA2","group":"genotype"},{"from":"patient-1","to":"PTEN","group":"genotype"},{"from":"patient-2","to":"TP53","group":"genotype"},{"from":"patient-2","to":"NF1","group":"genotype"},{"from":"patient-2","to":"BARD1","group":"genotype"},{"from":"patient-3","to":"TP53","group":"genotype"},{"from":"patient-3","to":"PTEN","group":"genotype"},{"from":"patient-3","to":"NBN","group":"genotype"},{"from":"patient-1","to":"subtype-1","group":"has-condition"},{"from":"patient-2","to":"subtype-1","group":"has-condition"},{"from":"patient-3","to":"subtype-2","group":"has-condition"}]}' > </drugst-one>