Skip to content
Snippets Groups Projects
Commit f14c6d42 authored by AndiMajore's avatar AndiMajore
Browse files

added legend service; reworked legend node context management

parent 7c70f118
No related branches found
No related tags found
No related merge requests found
Showing with 122 additions and 69 deletions
......@@ -226,7 +226,6 @@
<app-network
networkType="analysis"
[nodeData]="nodeData"
[legendContext]="legendContext"
></app-network>
<!-- network end -->
</div>
......
......@@ -35,7 +35,7 @@ import {mapCustomEdge, mapCustomNode} from 'src/app/main-network';
import {downLoadFile, pieChartContextRenderer, removeDuplicateObjectsFromList} from 'src/app/utils';
import {DrugstoneConfigService} from 'src/app/services/drugstone-config/drugstone-config.service';
import {NetworkHandlerService} from 'src/app/services/network-handler/network-handler.service';
import {LegendService} from 'src/app/services/legend-service/legend-service.service';
declare var vis: any;
......@@ -84,7 +84,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
public nodeData: { nodes: any, edges: any } = {nodes: null, edges: null};
// private drugNodes: any[] = [];
// private drugEdges: any[] = [];
public showDrugs = false;
public tab: 'meta' | 'network' | 'table' = 'table';
// public adjacentDrugs = false;
......@@ -121,9 +120,7 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
public expressionMap: NodeAttributeMap;
public legendContext: LegendContext = 'drug';
constructor(public networkHandler: NetworkHandlerService, public drugstoneConfig: DrugstoneConfigService, private http: HttpClient, public analysis: AnalysisService, public netex: NetexControllerService) {
constructor(public legendService: LegendService, public networkHandler: NetworkHandlerService, public drugstoneConfig: DrugstoneConfigService, private http: HttpClient, public analysis: AnalysisService, public netex: NetexControllerService) {
}
async ngOnInit() {
......@@ -174,6 +171,11 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
if (this.task && this.task.info.done) {
this.result = await this.netex.getTaskResult(this.token);
if (this.result.parameters.target === 'drug') {
this.legendService.add_to_context('drug')
} else {
this.legendService.add_to_context('drugTarget')
}
const nodeAttributes = this.result.nodeAttributes || {};
this.networkHandler.activeNetwork.seedMap = nodeAttributes.isSeed || {};
......@@ -182,7 +184,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
this.nodeData = {nodes: null, edges: null};
this.networkHandler.activeNetwork.networkEl.nativeElement.innerHTML = '';
this.networkHandler.activeNetwork.networkInternal = null;
this.showDrugs = false;
// Create
const {nodes, edges} = this.createNetwork(this.result);
......@@ -328,7 +329,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
}
this.emitVisibleItems(true);
this.networkHandler.activeNetwork.setLegendContext();
}
public emitVisibleItems(on: boolean) {
......@@ -349,10 +349,11 @@ export class AnalysisPanelComponent implements OnInit, OnChanges, AfterViewInit
this.expressionMap = undefined;
this.networkHandler.activeNetwork.seedMap = {};
this.networkHandler.activeNetwork.highlightSeeds = false;
this.showDrugs = false;
this.analysis.switchSelection('main');
this.token = null;
this.tokenChange.emit(this.token);
this.legendService.remove_from_context('drug')
this.legendService.remove_from_context('drugTarget')
this.emitVisibleItems(false);
}
......
......@@ -2,6 +2,7 @@ import {Component, Input, OnInit} from '@angular/core';
import { LegendContext } from 'src/app/interfaces';
import { DrugstoneConfigService } from 'src/app/services/drugstone-config/drugstone-config.service';
import {IConfig} from '../../../config';
import {LegendService} from "src/app/services/legend-service/legend-service.service";
@Component({
selector: 'app-network-legend',
......@@ -18,17 +19,6 @@ export class NetworkLegendComponent implements OnInit {
};
@Input() config: IConfig;
private contextNodeGroupsToDelete = {
'explorer': ['foundNode', 'foundDrug', 'seedNode', 'default', 'defaultDisorder', 'connectorNode'],
'adjacentDrugs': ['foundNode', 'seedNode', 'default', 'defaultDisorder', 'connectorNode'],
'adjacentDisorders': ['foundDrug', 'foundNode', 'seedNode', 'default', 'connectorNode'],
'adjacentDrugsAndDisorders': ['foundNode', 'seedNode', 'default', 'connectorNode'],
'drugTarget': ['foundDrug', 'seedNode', 'default', 'defaultDisorder'],
'drug': ['seedNode', 'default', 'defaultDisorder'],
'drugTargetAndSeeds': ['foundDrug', 'default', 'defaultDisorder'],
'drugAndSeeds': ['default', 'defaultDisorder']
}
private contextEdgeGroupsToDelete = {
'explorer': ['default'],
'adjacentDrugs': ['default'],
......@@ -45,7 +35,7 @@ export class NetworkLegendComponent implements OnInit {
// selected node is not supposed to appear in legend
return false;
}
return !this.contextNodeGroupsToDelete[this._context].includes(nodeGroupKey);
return !this.legendService.get_nodes_to_delete().includes(nodeGroupKey);
}
public checkEdgeGroupContext(edgeGroupKey) {
......@@ -56,7 +46,7 @@ export class NetworkLegendComponent implements OnInit {
return Object.keys(this.config.edgeGroups).some(key => this.checkEdgeGroupContext(key));
}
constructor(public drugstoneConfig: DrugstoneConfigService) { }
constructor(public drugstoneConfig: DrugstoneConfigService, public legendService: LegendService) { }
ngOnInit(): void {
}
......
......@@ -36,7 +36,6 @@
<div *ngIf="drugstoneConfig.config.showLegend">
<app-network-legend
[config]="drugstoneConfig.config"
[context]="legendContext"
></app-network-legend>
</div>
<div class="center image1 fullheight" #network>
......
......@@ -21,6 +21,7 @@ import {AnalysisService} from 'src/app/services/analysis/analysis.service';
import {NetworkSettings} from 'src/app/network-settings';
import {pieChartContextRenderer} from 'src/app/utils';
import {NetworkHandlerService} from 'src/app/services/network-handler/network-handler.service';
import {LegendService} from "../../services/legend-service/legend-service.service";
@Component({
......@@ -32,8 +33,6 @@ export class NetworkComponent implements OnInit {
@Input() public networkType: NetworkType;
@Input() public nodeData: NodeData;
@Input() public legendContext: LegendContext;
@ViewChild('network', {static: false}) networkEl: ElementRef;
@ViewChild('networkWithLegend', {static: false}) networkWithLegendEl: ElementRef;
......@@ -82,7 +81,7 @@ export class NetworkComponent implements OnInit {
public nodeRenderer = null;
constructor(public networkHandler: NetworkHandlerService, public analysis: AnalysisService, public drugstoneConfig: DrugstoneConfigService, public netex: NetexControllerService, public omnipath: OmnipathControllerService) {
constructor(public legendService: LegendService, public networkHandler: NetworkHandlerService, public analysis: AnalysisService, public drugstoneConfig: DrugstoneConfigService, public netex: NetexControllerService, public omnipath: OmnipathControllerService) {
}
ngOnInit(): void {
......@@ -116,7 +115,7 @@ export class NetworkComponent implements OnInit {
public updateAdjacentProteinDisorders(bool: boolean) {
this.adjacentDisordersProtein = bool;
if (this.adjacentDisordersProtein) {
this.legendService.add_to_context('adjacentDisorders')
this.netex.adjacentDisorders(this.nodeData.nodes.get(), 'proteins', this.drugstoneConfig.config.associatedProteinDisorder, this.drugstoneConfig.config.licensedDatasets).subscribe(response => {
const proteinMap = this.getProteinMap()
const addedEdge = {}
......@@ -146,13 +145,14 @@ export class NetworkComponent implements OnInit {
this.nodeData.edges.add(this.adjacentProteinDisorderEdgesList);
this.updateQueryItems();
});
this.legendContext = this.adjacentDrugs ? 'adjacentDrugsAndDisorders' : 'adjacentDisorders';
} else {
if (!this.adjacentDisordersDrug) {
this.legendService.remove_from_context('adjacentDisorders');
}
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.updateQueryItems();
}
}
......@@ -160,6 +160,7 @@ export class NetworkComponent implements OnInit {
public updateAdjacentDrugDisorders(bool: boolean) {
this.adjacentDisordersDrug = bool;
if (this.adjacentDisordersDrug) {
this.legendService.add_to_context('adjacentDisorders');
this.netex.adjacentDisorders(this.nodeData.nodes.get(), 'drugs', this.drugstoneConfig.config.indicationDrugDisorder, this.drugstoneConfig.config.licensedDatasets).subscribe(response => {
for (const interaction of response.edges) {
const edge = {from: interaction.drug, to: interaction.disorder};
......@@ -174,13 +175,13 @@ export class NetworkComponent implements OnInit {
this.nodeData.edges.add(this.adjacentDrugDisorderEdgesList);
this.updateQueryItems();
});
this.legendContext = this.adjacentDrugs ? 'adjacentDrugsAndDisorders' : 'adjacentDisorders';
} else {
if (!this.adjacentDisordersProtein)
this.legendService.remove_from_context('adjacentDisorders');
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.updateQueryItems();
}
}
......@@ -212,6 +213,7 @@ export class NetworkComponent implements OnInit {
public updateAdjacentDrugs(bool: boolean) {
this.adjacentDrugs = bool;
if (this.adjacentDrugs) {
this.legendService.add_to_context("adjacentDrugs")
const addedEdge = {}
const proteinMap = this.getProteinMap()
this.netex.adjacentDrugs(this.drugstoneConfig.config.interactionDrugProtein, this.drugstoneConfig.config.licensedDatasets, this.nodeData.nodes.get()).subscribe(response => {
......@@ -245,18 +247,19 @@ export class NetworkComponent implements OnInit {
this.nodeData.edges.add(this.adjacentDrugEdgesList);
this.updateQueryItems();
})
this.legendContext = this.adjacentDisordersDrug || this.adjacentDisordersProtein ? 'adjacentDrugsAndDisorders' : 'adjacentDrugs';
} else {
// remove adjacent drugs, make sure that also drug associated disorders are removed
if (this.adjacentDisordersDrug) {
this.updateAdjacentDrugDisorders(false);
}
this.legendService.remove_from_context('adjacentDrugs');
// if (!this.adjacentDisordersProtein)
// this.legendService.remove_from_context('adjacentDisorders')
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.updateQueryItems();
}
}
......@@ -443,22 +446,6 @@ export class NetworkComponent implements OnInit {
return false;
}
public setLegendContext() {
if (this.hasDrugsLoaded() || this.adjacentDrugs) {
if (this.highlightSeeds) {
this.legendContext = "drugAndSeeds";
} else {
this.legendContext = "drug";
}
} else {
if (this.highlightSeeds) {
this.legendContext = "drugTargetAndSeeds";
} else {
this.legendContext = 'drugTarget';
}
}
}
public getGradient(nodeId: string) {
return (this.gradientMap !== {}) && (this.gradientMap[nodeId]) ? this.gradientMap[nodeId] : 1.0;
}
......@@ -470,6 +457,10 @@ export class NetworkComponent implements OnInit {
public updateHighlightSeeds(bool: boolean) {
this.highlightSeeds = bool;
const updatedNodes = [];
if (this.highlightSeeds)
this.legendService.add_to_context('seeds')
else
this.legendService.remove_from_context('seeds')
for (const item of this.currentViewProteins) {
if (item.drugstoneId === undefined) {
// nodes that are not mapped to backend remain untouched
......@@ -497,7 +488,8 @@ export class NetworkComponent implements OnInit {
updatedNodes.push(node);
}
this.nodeData.nodes.update(updatedNodes);
this.setLegendContext();
}
public toggleFullscreen() {
......
......@@ -48,7 +48,7 @@ export type NodeType= 'protein' | 'drug' | 'disorder' | 'other'
export type NetworkType = 'explorer' | 'analysis'
export type LegendContext = 'explorer' | 'adjacentDrugs' | 'drug' | 'drugTarget' |
'drugTargetAndSeeds' | 'drugAndSeeds' | 'adjacentDisorders' | 'adjacentDrugsAndDisorders';
'seeds' | 'adjacentDisorders';
/// drugstoneId to expressionlvl
export type NodeAttributeMap = { string: number } | {};
......
......@@ -513,7 +513,6 @@
<app-network
networkType="explorer"
[nodeData]="nodeData"
legendContext="explorer"
></app-network>
</div>
<!-- End network block -->
......
import { TestBed } from '@angular/core/testing';
import { LegendService } from './legend-service.service';
describe('LegendService', () => {
let service: LegendService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(LegendService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
import {Injectable} from '@angular/core';
import {LegendContext} from "../../interfaces";
@Injectable({
providedIn: 'root'
})
export class LegendService {
constructor() {
}
private default_delete = ['foundNode', 'foundDrug', 'seedNode', 'default', 'defaultDisorder', 'connectorNode'];
private context = [];
private contextNodeGroupsToDelete = {
adjacentDrugs: ['foundNode', 'seedNode', 'default', 'defaultDisorder', 'connectorNode'],
adjacentDisorders: ['foundDrug', 'foundNode', 'seedNode', 'default', 'connectorNode'],
drugTarget: ['foundDrug', 'seedNode', 'default', 'defaultDisorder'],
drug: ['foundNode', 'seedNode', 'default', 'defaultDisorder'],
seeds: ['default', 'foundNode', 'foundDrug', 'defaultDisorder']
};
public add_to_context(value: LegendContext) {
if (this.context.indexOf(value) === -1) {
this.context.push(value);
}
}
public remove_from_context(value: LegendContext) {
const idx = this.context.indexOf(value);
if (idx > -1) {
this.context.splice(idx, 1);
}
}
public get_nodes_to_delete() {
const out = [].concat(this.default_delete);
for (const node of this.default_delete) {
let keep = false;
for (const c of this.context) {
if (this.contextNodeGroupsToDelete[c].indexOf(node) === -1) {
keep = true;
break;
}
}
if (keep) {
out.splice(out.indexOf(node), 1);
}
}
return out;
}
}
......@@ -6,18 +6,20 @@ import { AnalysisService } from '../analysis/analysis.service';
import {DrugstoneConfigService} from '../drugstone-config/drugstone-config.service';
import {NetexControllerService} from '../netex-controller/netex-controller.service';
import {OmnipathControllerService} from '../omnipath-controller/omnipath-controller.service';
import {LegendService} from "../legend-service/legend-service.service";
@Injectable({
providedIn: 'root'
})
export class NetworkHandlerService {
constructor(public networkHandler: NetworkHandlerService, public analysis: AnalysisService, public drugstoneConfig: DrugstoneConfigService, public netex: NetexControllerService, public omnipath: OmnipathControllerService) { }
constructor(public legendService: LegendService, public networkHandler: NetworkHandlerService, public analysis: AnalysisService, public drugstoneConfig: DrugstoneConfigService, public netex: NetexControllerService, public omnipath: OmnipathControllerService) {
}
private change = new Subject<any>();
public networks: { NetworkType: NetworkComponent } | {} = {};
public activeNetwork: NetworkComponent = new NetworkComponent(this.networkHandler, this.analysis, this.drugstoneConfig, this.netex, this.omnipath);
public activeNetwork: NetworkComponent = new NetworkComponent(this.legendService, this.networkHandler, this.analysis, this.drugstoneConfig, this.netex, this.omnipath);
public setActiveNetwork(network: NetworkType) {
this.triggerChange();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment