From 3e6d441c1383c40b382a1c4f261a912cf80d6446 Mon Sep 17 00:00:00 2001 From: AndiMajore <andi.majore@googlemail.com> Date: Thu, 23 Sep 2021 18:33:56 +0200 Subject: [PATCH] added drug-disorder connections --- src/app/config.ts | 2 +- .../explorer-page.component.html | 16 +++- .../explorer-page/explorer-page.component.ts | 80 +++++++++++++++---- .../netex-controller.service.ts | 17 ++-- 4 files changed, 88 insertions(+), 27 deletions(-) diff --git a/src/app/config.ts b/src/app/config.ts index b938f880..eeb8d482 100644 --- a/src/app/config.ts +++ b/src/app/config.ts @@ -165,7 +165,7 @@ export const defaultConfig: IConfig = { background: '#ffa62f' }, }, - shape: 'diamond', + shape: 'triangle', type: 'default disorder type', }, seedNode: { diff --git a/src/app/pages/explorer-page/explorer-page.component.html b/src/app/pages/explorer-page/explorer-page.component.html index 0f1ba721..dc5e1158 100644 --- a/src/app/pages/explorer-page/explorer-page.component.html +++ b/src/app/pages/explorer-page/explorer-page.component.html @@ -301,13 +301,23 @@ ></app-toggle> <app-toggle class="footer-buttons network-footer-toolbar-element" - textOn="Disorders" + textOn="Disorders (protein)" textOff="Off" tooltipOn="Display adjacent disorders ON." tooltipOff="Display adjacent disorders OFF." [smallStyle]="smallStyle" - [value]="adjacentDisorders" - (valueChange)="updateAdjacentDisorders($event)" + [value]="adjacentDisordersProtein" + (valueChange)="updateAdjacentProteinDisorders($event)" + ></app-toggle> + <app-toggle + class="footer-buttons network-footer-toolbar-element" + textOn="Disorders (drugs)" + textOff="Off" + tooltipOn="Display adjacent disorders ON." + tooltipOff="Display adjacent disorders OFF." + [smallStyle]="smallStyle" + [value]="adjacentDisordersDrug" + (valueChange)="updateAdjacentDrugDisorders($event)" ></app-toggle> <app-toggle class="footer-buttons network-footer-toolbar-element" diff --git a/src/app/pages/explorer-page/explorer-page.component.ts b/src/app/pages/explorer-page/explorer-page.component.ts index 2a156407..6662d944 100644 --- a/src/app/pages/explorer-page/explorer-page.component.ts +++ b/src/app/pages/explorer-page/explorer-page.component.ts @@ -152,12 +152,16 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { private dumpPositions = false; public physicsEnabled = false; public adjacentDrugs = false; - public adjacentDisorders = false; + public adjacentDisordersProtein = false; + public adjacentDisordersDrug = false; public adjacentDrugList: Node[] = []; public adjacentDrugEdgesList: Node[] = []; - public adjacentDisorderList: Node[] = []; - public adjacentDisorderEdgesList: Node[] = []; + public adjacentProteinDisorderList: Node[] = []; + public adjacentProteinDisorderEdgesList: Node[] = []; + + public adjacentDrugDisorderList: Node[] = []; + public adjacentDrugDisorderEdgesList: Node[] = []; public queryItems: Wrapper[] = []; public showAnalysisDialog = false; @@ -488,32 +492,76 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { }); } - public updateAdjacentDisorders(bool: boolean){ - this.adjacentDisorders = bool; - if (this.adjacentDisorders){ - this.netex.adjacentDisorders(this.nodeData.nodes).subscribe(response => { - for (const interaction of response.pdis) { + 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.adjacentDisorderEdgesList.push(mapCustomEdge(edge, this.myConfig)); + this.adjacentProteinDisorderEdgesList.push(mapCustomEdge(edge, this.myConfig)); + } + for (const disorder of response.disorders) { + disorder.group = 'defaultDisorder'; + disorder.id = disorder.netexId; + this.adjacentProteinDisorderList.push(mapCustomNode(disorder, this.myConfig)) + } + this.saveAddNodes(this.adjacentProteinDisorderList); + this.nodeData.edges.add(this.adjacentProteinDisorderEdgesList); + }); + this.legendContext = 'adjacentDisorders'; + }else { + this.saveRemoveDisorders(this.adjacentProteinDisorderList); + this.nodeData.edges.remove(this.adjacentProteinDisorderEdgesList); + this.adjacentProteinDisorderList = []; + this.adjacentProteinDisorderEdgesList = []; + this.legendContext = 'explorer'; + } + } + + 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.netexId; - this.adjacentDisorderList.push(mapCustomNode(disorder, this.myConfig)) + this.adjacentDrugDisorderList.push(mapCustomNode(disorder, this.myConfig)); } - this.nodeData.nodes.add(this.adjacentDisorderList); - this.nodeData.edges.add(this.adjacentDisorderEdgesList); + this.saveAddNodes(this.adjacentDrugDisorderList); + this.nodeData.edges.add(this.adjacentDrugDisorderEdgesList); }); this.legendContext = 'adjacentDisorders'; }else { - this.nodeData.nodes.remove(this.adjacentDisorderList); - this.nodeData.edges.remove(this.adjacentDisorderEdgesList); - this.adjacentDisorderList = []; - this.adjacentDisorderEdgesList = []; + this.saveRemoveDisorders(this.adjacentDrugDisorderList); + this.nodeData.edges.remove(this.adjacentDrugDisorderEdgesList); + this.adjacentDrugDisorderList = []; + this.adjacentDrugDisorderEdgesList = []; this.legendContext = 'explorer'; } } + 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 updateAdjacentDrugs(bool: boolean) { this.adjacentDrugs = bool; if (this.adjacentDrugs) { diff --git a/src/app/services/netex-controller/netex-controller.service.ts b/src/app/services/netex-controller/netex-controller.service.ts index 93546b84..0570859e 100644 --- a/src/app/services/netex-controller/netex-controller.service.ts +++ b/src/app/services/netex-controller/netex-controller.service.ts @@ -96,13 +96,16 @@ export class NetexControllerService { return this.http.get(`${environment.backend}tissue_expression/`, {params}); } - public adjacentDisorders(nodes: Node[]): Observable<any> { - const genesBackendIds = nodes.map((node: Node) => node.netexId && !node.drugId && node.netexId.startsWith('p') ? node.netexId.slice(1) : undefined).filter(id => id != null); - const drugsBackendIds = nodes.map((node: Node) => node.drugId && node.netexId && node.netexId.startsWith('dr') ? node.netexId.slice(1) : undefined).filter(id => id != null); - const params = { - proteins: genesBackendIds, - drugs: drugsBackendIds, - }; + public adjacentDisorders(nodes: Node[], nodeType: string): Observable<any> { + + const params = {}; + if (nodeType === 'proteins') { + // @ts-ignore + params.proteins = nodes.map((node: Node) => node.netexId && node.netexId.startsWith('p') ? node.netexId.slice(1) : undefined).filter(id => id != null); + } else if (nodeType === 'drugs') { + // @ts-ignore + params.drugs = nodes.map((node: Node) => node.drugId && node.netexId.startsWith('dr') ? node.netexId.slice(2) : undefined).filter(id => id != null); + } return this.http.post<any>(`${environment.backend}adjacent_disorders/`, params); } -- GitLab