diff --git a/src/app/analysis.service.ts b/src/app/analysis.service.ts index bccdf162a6bd407a236f317468bc2c8b3e10030f..aaf632bd7b32d92b3a99b5a843731a70e6411f36 100644 --- a/src/app/analysis.service.ts +++ b/src/app/analysis.service.ts @@ -82,7 +82,7 @@ export class AnalysisService { }); } - public addItems(wrappers: Wrapper[]) { + public addItems(wrappers: Wrapper[]): number { const addedWrappers: Wrapper[] = []; for (const wrapper of wrappers) { if (!this.inSelection(wrapper)) { @@ -91,6 +91,7 @@ export class AnalysisService { } } this.selectListSubject.next({items: addedWrappers, selected: true}); + return addedWrappers.length; } public removeItems(wrappers: Wrapper[]) { @@ -103,7 +104,7 @@ export class AnalysisService { this.selectListSubject.next({items: removedWrappers, selected: false}); } - public addVisibleHostProteins(nodes, proteins) { + public addVisibleHostProteins(nodes, proteins): number { const items: Wrapper[] = []; const visibleIds = new Set<string>(nodes.getIds()); for (const protein of proteins) { @@ -115,9 +116,10 @@ export class AnalysisService { } } this.selectListSubject.next({items, selected: true}); + return items.length; } - public addVisibleViralProteins(nodes, viralProteins) { + public addVisibleViralProteins(nodes, viralProteins): number { const items: Wrapper[] = []; const visibleIds = new Set<string>(nodes.getIds()); for (const viralProtein of viralProteins) { @@ -129,6 +131,7 @@ export class AnalysisService { } } this.selectListSubject.next({items, selected: true}); + return items.length; } public removeAllHostProteins() { diff --git a/src/app/components/custom-proteins/custom-proteins.component.html b/src/app/components/custom-proteins/custom-proteins.component.html index 9073664887f9a0c0ea947ba6c7c674d3f28320e9..0d12b5304b4aec2f3ff6192cf3a908a5e5de2148 100644 --- a/src/app/components/custom-proteins/custom-proteins.component.html +++ b/src/app/components/custom-proteins/custom-proteins.component.html @@ -9,10 +9,24 @@ <button (click)="close()" class="delete" aria-label="close"></button> </header> <section class="modal-card-body"> - <div class="notification is-success" *ngIf="itemsAdded.length > 0"> - {{itemsAdded.length}} host proteins have been added to the selection. + <div class="notification is-success" *ngIf="addedCount > 0"> + {{addedCount}} host proteins have been added to the selection. + <div *ngIf="itemsFound.length > addedCount && !selectOnly"> + {{itemsFound.length - addedCount}} proteins have already been selected before. + </div> + <div *ngIf="itemsFound.length > addedCount && selectOnly"> + {{itemsFound.length - addedCount}} proteins either have been selected already or did not appear in the current graph. + </div> + </div> + <div class="notification is-warning" *ngIf="itemsFound.length > 0 && addedCount === 0"> + <div *ngIf="itemsFound.length > addedCount && !selectOnly"> + {{itemsFound.length - addedCount}} proteins have already been selected before. + </div> + <div *ngIf="itemsFound.length > addedCount && selectOnly"> + {{itemsFound.length - addedCount}} proteins either have been selected already or did not appear in the current graph. + </div> </div> - <div class="notification is-warning" *ngIf="notFound.length > 0"> + <div class="notification is-danger" *ngIf="notFound.length > 0"> The following {{notFound.length}} Uniprot IDs could not be found and have been ignored: <ul><li class="not-found" *ngFor="let nf of notFound">{{nf}}</li></ul> </div> @@ -28,7 +42,7 @@ </section> <footer class="modal-card-foot"> <button (click)="addProteins();" class="button is-success is-rounded has-tooltip" - data-tooltip="Add list of proteins to the selection." + data-tooltip="Add all to the selection." [disabled]="proteins.length === 0"> <span class="icon"> <i class="fa fa-plus"></i> @@ -37,6 +51,16 @@ Add </span> </button> + <button (click)="addVisibleProteins();" class="button is-success is-rounded has-tooltip" + data-tooltip="Add to selection if they appear in the current network." + [disabled]="proteins.length === 0"> + <span class="icon"> + <i class="fas fa-expand"></i> + </span> + <span> + Select + </span> + </button> <button (click)="close()" class="button is-rounded has-tooltip" data-tooltip="Close the current window.">Close </button> </footer> diff --git a/src/app/components/custom-proteins/custom-proteins.component.ts b/src/app/components/custom-proteins/custom-proteins.component.ts index 483ce2d907ee3f91edc3982002ee235298651d4d..55bb13ddedb789d650c87f576e0eb41288ac5ff3 100644 --- a/src/app/components/custom-proteins/custom-proteins.component.ts +++ b/src/app/components/custom-proteins/custom-proteins.component.ts @@ -1,7 +1,7 @@ import {Component, EventEmitter, Input, OnInit, Output} from '@angular/core'; import {HttpClient} from '@angular/common/http'; import {environment} from '../../../environments/environment'; -import {getWrapperFromProtein, Wrapper} from '../../interfaces'; +import {getWrapperFromProtein, Protein, Wrapper} from '../../interfaces'; import {AnalysisService} from '../../analysis.service'; @Component({ @@ -15,11 +15,15 @@ export class CustomProteinsComponent implements OnInit { public show = false; @Output() public showChange = new EventEmitter<boolean>(); + @Input() + public visibleNodes: Array<any> = []; public textList = ''; public proteins: Array<string> = []; public notFound: Array<string> = []; - public itemsAdded: Array<Wrapper> = []; + public itemsFound: Array<Wrapper> = []; + public addedCount = 0; + public selectOnly = false; constructor(private http: HttpClient, private analysis: AnalysisService) { } @@ -28,23 +32,49 @@ export class CustomProteinsComponent implements OnInit { public close() { this.show = false; + this.textList = ''; + this.proteins = []; + this.notFound = []; + this.itemsFound = []; this.showChange.emit(this.show); + this.addedCount = 0; + this.selectOnly = false; } public async addProteins() { this.notFound = []; - this.itemsAdded = []; + this.itemsFound = []; + const proteins = this.proteins; + this.changeTextList(''); + const result = await this.http.post<any>(`${environment.backend}query_proteins/`, proteins).toPromise(); + this.notFound = result.notFound; + const details = result.details; + const items = []; + for (const detail of details) { + items.push(getWrapperFromProtein(detail)); + } + this.itemsFound = items; + this.addedCount = this.analysis.addItems(items); + this.selectOnly = false; + } + + public async addVisibleProteins() { + this.notFound = []; + this.itemsFound = []; const proteins = this.proteins; this.changeTextList(''); const result = await this.http.post<any>(`${environment.backend}query_proteins/`, proteins).toPromise(); this.notFound = result.notFound; const details = result.details; + const proteinItems = []; const items = []; for (const detail of details) { + proteinItems.push(detail as Protein); items.push(getWrapperFromProtein(detail)); } - this.itemsAdded = items; - this.analysis.addItems(items); + this.itemsFound = items; + this.addedCount = this.analysis.addVisibleHostProteins(this.visibleNodes, proteinItems); + this.selectOnly = true; } public changeTextList(textList) { diff --git a/src/app/pages/explorer-page/explorer-page.component.html b/src/app/pages/explorer-page/explorer-page.component.html index ad18cfdcd8af565819ae39d5b77034ed2dfeda00..2d2c24c4fdfbf0180859441a6973e9f06caeb63d 100644 --- a/src/app/pages/explorer-page/explorer-page.component.html +++ b/src/app/pages/explorer-page/explorer-page.component.html @@ -4,7 +4,7 @@ [dataset]="selectedDataset.backendId"> </app-launch-analysis> - <app-custom-proteins [(show)]="showCustomProteinsDialog"> + <app-custom-proteins [(show)]="showCustomProteinsDialog" [visibleNodes]="currentViewNodes"> </app-custom-proteins> <div class="covex explorer"> @@ -433,7 +433,7 @@ Host Proteins </span> </a> - <a (click)="analysis.addVisibleViralProteins(currentViewNodes, currentViewEffects)" + <a (click)="analysis.addVisibleViralProteins(currentViewNodes, currentViewViralProteins)" class="card-footer-item has-text-success" data-tooltip="Add all visible viral proteins."> <span class="icon"> <i class="fa fa-eye"></i> diff --git a/src/app/pages/explorer-page/explorer-page.component.ts b/src/app/pages/explorer-page/explorer-page.component.ts index bca79bbad3474f5308e5395834619d5c0107f206..a92060ae1ce055aef23be9a9885816401301723b 100644 --- a/src/app/pages/explorer-page/explorer-page.component.ts +++ b/src/app/pages/explorer-page/explorer-page.component.ts @@ -67,8 +67,8 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { public currentDataset = []; public currentViewProteins: Protein[]; - public currentViewEffects: ViralProtein[]; - public currentViewNodes: Node[]; + public currentViewViralProteins: ViralProtein[]; + public currentViewNodes: any[]; public datasetItems: Dataset[] = [ { @@ -306,7 +306,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { this.currentViewNodes = this.nodeData.nodes; this.currentViewProteins = this.proteins; - this.currentViewEffects = this.effects; + this.currentViewViralProteins = this.effects; } public async filterNodes() { @@ -459,11 +459,11 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { if ($event) { this.currentViewNodes = $event[0]; this.currentViewProteins = $event[1][0]; - this.currentViewEffects = $event[1][1]; + this.currentViewViralProteins = $event[1][1]; } else { this.currentViewNodes = this.nodeData.nodes; this.currentViewProteins = this.proteins; - this.currentViewEffects = this.effects; + this.currentViewViralProteins = this.effects; } } }