diff --git a/src/app/analysis.service.ts b/src/app/analysis.service.ts index e33eaae68c63768bd328f9e708eefaafbb4ed078..e2e80770ba7da3fbdafdefc25d27c666ec70ae33 100644 --- a/src/app/analysis.service.ts +++ b/src/app/analysis.service.ts @@ -60,6 +60,38 @@ export class AnalysisService { } } + public addAllHostProteins(nodes, proteins) { + const visibleIds = new Set<string>(nodes.getIds()); + for (const protein of proteins) { + const nodeId = protein.proteinAc; + const found = visibleIds.has(nodeId) || visibleIds.has('p_' + nodeId); + if (found && !this.inSelection(protein.name)) { + this.addItem({ + name: protein.proteinAc, + type: 'Host Protein', + data: protein + }); + } + } + } + + public addAllViralProteins(nodes, effects) { + const visibleIds = new Set<string>(nodes.getIds()); + for (const effect of effects) { + const nodeId = effect.effectId; + const found = visibleIds.has(nodeId) || visibleIds.has('eff_' + effect.effectName + '_' + + effect.datasetName + '_' + effect.virusName); + if (found && !this.inSelection(effect.effectName + '_' + + effect.datasetName + '_' + effect.virusName)) { + this.addItem({ + name: effect.effectId, + type: 'Viral Protein', + data: effect + }); + } + } + } + resetSelection() { const oldSelection = this.selectedItems.values(); for (const item of oldSelection) { @@ -110,14 +142,14 @@ export class AnalysisService { // const finishedDate = new Date(task.info.finishedAt); if (status === 'DONE') { toastMessage = 'Computation finished succesfully.'; - // \n- Algorithm: ${task.info.algorithm} - // \n- Started At: ${startDate.getHours()}:${startDate.getMinutes()} - // \n- Finished At: ${finishedDate.getHours()}:${finishedDate.getMinutes()}`; + // \n- Algorithm: ${task.info.algorithm} + // \n- Started At: ${startDate.getHours()}:${startDate.getMinutes()} + // \n- Finished At: ${finishedDate.getHours()}:${finishedDate.getMinutes()}`; toastType = 'is-success'; } else if (status === 'FAILED') { toastMessage = 'Computation failed.'; - // \n- Algorithm: ${task.info.algorithm} - // \n- Started At: ${startDate.getHours()}:${startDate.getMinutes()}`; + // \n- Algorithm: ${task.info.algorithm} + // \n- Started At: ${startDate.getHours()}:${startDate.getMinutes()}`; toastType = 'is-danger'; } @@ -128,7 +160,7 @@ export class AnalysisService { pauseOnHover: true, type: toastType, position: 'top-center', - animate: { in: 'fadeIn', out: 'fadeOut' } + animate: {in: 'fadeIn', out: 'fadeOut'} }); } diff --git a/src/app/components/analysis-window/analysis-window.component.ts b/src/app/components/analysis-window/analysis-window.component.ts index bad571f4a4da4a86eb09aed24e551ce1dc5a6199..8e50e28f1298232ba2e2fe70662f7182e1757c83 100644 --- a/src/app/components/analysis-window/analysis-window.component.ts +++ b/src/app/components/analysis-window/analysis-window.component.ts @@ -29,6 +29,9 @@ interface Scored { }) export class AnalysisWindowComponent implements OnInit, OnChanges { + constructor(private http: HttpClient, public analysis: AnalysisService) { + } + @Input() token: string | null = null; @Output() tokenChange = new EventEmitter<string | null>(); @@ -47,14 +50,17 @@ export class AnalysisWindowComponent implements OnInit, OnChanges { public showDrugs = false; public tab = 'network'; + + private proteins: any; + public effects: any; + public tableDrugs: Array<Drug & Scored> = []; public tableProteins: Array<Protein & Scored> = []; public tableViralProteins: Array<ViralProtein & Scored> = []; public tableNormalize = false; public tableHasScores = false; - constructor(private http: HttpClient, public analysis: AnalysisService) { - } + @Output() visibleItems: EventEmitter<any> = new EventEmitter(); async ngOnInit() { } @@ -186,6 +192,15 @@ export class AnalysisWindowComponent implements OnInit, OnChanges { }); } } + this.emitVisibleItems(true); + } + + public emitVisibleItems(on: boolean) { + if (on) { + this.visibleItems.emit([this.nodeData.nodes, [this.proteins, this.effects]]); + } else { + this.visibleItems.emit(null); + } } private async getTask(token: string): Promise<any> { @@ -195,6 +210,7 @@ export class AnalysisWindowComponent implements OnInit, OnChanges { close() { this.token = null; this.tokenChange.emit(this.token); + this.emitVisibleItems(false); } discard() { @@ -256,6 +272,8 @@ export class AnalysisWindowComponent implements OnInit, OnChanges { const nodeAttributes = result.nodeAttributes || []; + this.proteins = []; + this.effects = []; for (let i = 0; i < result.networks.length; i++) { const network = result.networks[i]; @@ -264,9 +282,12 @@ export class AnalysisWindowComponent implements OnInit, OnChanges { const isSeed = attributes.isSeed || {}; const scores = attributes.scores || {}; const details = attributes.details || {}; - - for (const node of network.nodes) { + if (nodeTypes[node] === 'host') { + this.proteins.push(details[node]); + } else if (nodeTypes[node] === 'virus') { + this.effects.push(details[node]); + } nodes.push(this.mapNode(node, nodeTypes[node] || this.inferNodeType(node), isSeed[node], scores[node], details[node])); } diff --git a/src/app/pages/explorer-page/explorer-page.component.html b/src/app/pages/explorer-page/explorer-page.component.html index 42055cf36964aba417f12adc8d86a61f13663222..e3badb796f0aaea1a351527cc8ed829a4faf7828 100644 --- a/src/app/pages/explorer-page/explorer-page.component.html +++ b/src/app/pages/explorer-page/explorer-page.component.html @@ -187,7 +187,9 @@ <div class="analysis-view" *ngIf="selectedAnalysisToken"> <app-analysis-window [(token)]="selectedAnalysisToken" - (showDetailsChange)="showDetails = $event[0]; changeInfo($event[1])"></app-analysis-window> + (showDetailsChange)="showDetails = $event[0]; changeInfo($event[1])" + (visibleItems)="analysisWindowChanged($event)" + ></app-analysis-window> </div> </div> @@ -398,7 +400,7 @@ </i> </div> <footer class="card-footer"> - <a (click)="addAllHostProteins()" class="card-footer-item has-text-success"> + <a (click)="analysis.addAllHostProteins(currentViewNodes, currentViewProteins)" class="card-footer-item has-text-success"> <span class="icon"> <i class="fa fa-plus"></i> </span> @@ -406,7 +408,7 @@ Host Proteins </span> </a> - <a (click)="addAllViralProteins()" class="card-footer-item has-text-success"> + <a (click)="analysis.addAllViralProteins(currentViewNodes, currentViewEffects)" class="card-footer-item has-text-success"> <span class="icon"> <i class="fa fa-plus"></i> </span> diff --git a/src/app/pages/explorer-page/explorer-page.component.ts b/src/app/pages/explorer-page/explorer-page.component.ts index 3c9e92d1886064b788106f5108cbc8f312d60b6d..ef2e61300a66acc6c6decb51ab856fcf81834e72 100644 --- a/src/app/pages/explorer-page/explorer-page.component.ts +++ b/src/app/pages/explorer-page/explorer-page.component.ts @@ -47,7 +47,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { public edges: any; private network: any; - private nodeData: { nodes: any, edges: any } = {nodes: null, edges: null}; + public nodeData: { nodes: any, edges: any } = {nodes: null, edges: null}; private dumpPositions = false; public physicsEnabled = false; @@ -61,6 +61,10 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { public currentDataset = []; private screenshotArray = [0]; + public currentViewProteins: Protein[]; + public currentViewEffects: ViralProtein[]; + public currentViewNodes: Node[]; + public datasetItems: Array<{ id: string, label: string, datasets: string, data: Array<[string, string]> }> = [ { id: 'All (TUM & Krogan)', @@ -321,6 +325,10 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { data: effect }); }); + + this.currentViewNodes = this.nodeData.nodes; + this.currentViewProteins = this.proteins; + this.currentViewEffects = this.effects; } public async filterNodes() { @@ -457,32 +465,6 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { }; } - public addAllHostProteins() { - const visibleIds = new Set<string>(this.nodeData.nodes.getIds()); - for (const protein of this.proteinData.proteins) { - const nodeId = `p_${protein.proteinAc}`; - const found = visibleIds.has(nodeId); - if (found && !this.analysis.inSelection(protein.name)) { - this.analysis.addItem({name: protein.proteinAc, type: 'Host Protein', data: protein}); - } - } - } - - public addAllViralProteins() { - const visibleIds = new Set<string>(this.nodeData.nodes.getIds()); - for (const effect of this.proteinData.effects) { - const nodeId = `eff_${effect.effectName + '_' + effect.datasetName + '_' + effect.virusName}`; - const found = visibleIds.has(nodeId); - if (found && !this.analysis.inSelection(effect.effectName + '_' + effect.datasetName + '_' + effect.virusName)) { - this.analysis.addItem({ - name: effect.effectId, - type: 'Viral Protein', - data: effect - }); - } - } - } - public toCanvas() { this.screenshotArray.forEach((key, index) => { const elem = document.getElementById(index.toString()); @@ -496,4 +478,15 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { }); } + analysisWindowChanged($event: any) { + if ($event) { + this.currentViewNodes = $event[0]; + this.currentViewProteins = $event[1][0]; + this.currentViewEffects = $event[1][1]; + } else { + this.currentViewNodes = this.nodeData.nodes; + this.currentViewProteins = this.proteins; + this.currentViewEffects = this.effects; + } + } }