Skip to content
Snippets Groups Projects
Commit 29295607 authored by Maiykol's avatar Maiykol
Browse files

throw helpful errors when node or edges have undefined groups

parent 9a33cf67
No related branches found
No related tags found
No related merge requests found
Pipeline #11032 failed
...@@ -58,7 +58,6 @@ ...@@ -58,7 +58,6 @@
} }
function changeConfigStr(config) { function changeConfigStr(config) {
console.log(config);
const netexp = document.getElementById('netexp1'); const netexp = document.getElementById('netexp1');
netexp.setAttribute('config', config); netexp.setAttribute('config', config);
} }
......
...@@ -377,6 +377,7 @@ export class AnalysisPanelComponent implements OnInit, OnChanges { ...@@ -377,6 +377,7 @@ export class AnalysisPanelComponent implements OnInit, OnChanges {
* For the third case, fall back to a default case which can also be set by user. * For the third case, fall back to a default case which can also be set by user.
*/ */
public inferNodeGroup(wrapper: Wrapper): string { public inferNodeGroup(wrapper: Wrapper): string {
console.log(wrapper)
if (wrapper.data.group !== undefined) { if (wrapper.data.group !== undefined) {
return wrapper.data.group return wrapper.data.group
} }
...@@ -408,7 +409,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges { ...@@ -408,7 +409,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges {
} }
} }
/** /**
* Maps analysis result returned from database to valid Vis.js network input * Maps analysis result returned from database to valid Vis.js network input
* *
...@@ -436,7 +436,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges { ...@@ -436,7 +436,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges {
for (const node of network.nodes) { for (const node of network.nodes) {
// backend converts object keys to PascalCase: p_123 --> p123 // backend converts object keys to PascalCase: p_123 --> p123
const nodeObjectKey = node.split('_').join(''); const nodeObjectKey = node.split('_').join('');
console.log(nodeObjectKey)
if (nodeTypes[nodeObjectKey] === 'protein') { if (nodeTypes[nodeObjectKey] === 'protein') {
// node is protein from database, has been mapped on init to backend protein from backend // node is protein from database, has been mapped on init to backend protein from backend
// or was found during analysis // or was found during analysis
...@@ -474,6 +473,11 @@ export class AnalysisPanelComponent implements OnInit, OnChanges { ...@@ -474,6 +473,11 @@ export class AnalysisPanelComponent implements OnInit, OnChanges {
if (typeof group === 'undefined' || typeof config.nodeGroups[group] === 'undefined') { if (typeof group === 'undefined' || typeof config.nodeGroups[group] === 'undefined') {
group = 'default'; group = 'default';
} }
console.log("node group")
console.log(group)
console.log(config.nodeGroups)
console.log(config.nodeGroups[group]);
const node = JSON.parse(JSON.stringify(config.nodeGroups[group])); const node = JSON.parse(JSON.stringify(config.nodeGroups[group]));
node.id = wrapper.id; node.id = wrapper.id;
node.label = this.inferNodeLabel(config, wrapper); node.label = this.inferNodeLabel(config, wrapper);
...@@ -551,7 +555,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges { ...@@ -551,7 +555,6 @@ export class AnalysisPanelComponent implements OnInit, OnChanges {
// } // }
for (const interaction of edges) { for (const interaction of edges) {
console.log(interaction)
const edge = {from: interaction.uniprotAc, to: interaction.drugId}; const edge = {from: interaction.uniprotAc, to: interaction.drugId};
this.drugEdges.push(this.mapEdge(edge, 'protein-drug')); this.drugEdges.push(this.mapEdge(edge, 'protein-drug'));
} }
......
...@@ -47,12 +47,12 @@ export class ProteinNetwork { ...@@ -47,12 +47,12 @@ export class ProteinNetwork {
* @returns * @returns
*/ */
private mapCustomNode(customNode: any, config: IConfig): Node { private mapCustomNode(customNode: any, config: IConfig): Node {
let group = customNode.group;
if (typeof group === 'undefined' || typeof config.nodeGroups[group] === 'undefined') { if (config.nodeGroups[customNode.group] === undefined) {
group = 'default'; throw `Node with id ${customNode.id} has undefined node group ${customNode.group}.`
} }
console.log(config.nodeGroups[group])
let node = JSON.parse(JSON.stringify(config.nodeGroups[group])); let node = JSON.parse(JSON.stringify(config.nodeGroups[customNode.group]));
// update the node with custom node properties, including values fetched from backend // update the node with custom node properties, including values fetched from backend
node = { node = {
...@@ -77,18 +77,12 @@ export class ProteinNetwork { ...@@ -77,18 +77,12 @@ export class ProteinNetwork {
* @returns * @returns
*/ */
private mapCustomEdge(customEdge: NodeInteraction, config: IConfig): any { private mapCustomEdge(customEdge: NodeInteraction, config: IConfig): any {
let group = customEdge.group;
if (typeof group === 'undefined' || typeof config.edgeGroups[group] === 'undefined') {
group = 'default';
}
let edge = JSON.parse(JSON.stringify(config.edgeGroups[group]));
console.log("edge")
console.log(edge) if (config.edgeGroups[customEdge.group] === undefined) {
throw `Edge "from ${customEdge.from}" - "to ${customEdge.to}" has undefined edge group ${customEdge.group}.`
console.log("customEdge") }
console.log(customEdge)
let edge = JSON.parse(JSON.stringify(config.edgeGroups[customEdge.group]));
edge = { edge = {
...edge, ...edge,
......
...@@ -384,7 +384,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit { ...@@ -384,7 +384,7 @@ export class ExplorerPageComponent implements OnInit, AfterViewInit {
* @param values * @param values
*/ */
public setConfigEdgeGroup(key: string, edgeGroups: Array<EdgeGroup>) { public setConfigEdgeGroup(key: string, edgeGroups: Array<EdgeGroup>) {
if (edgeGroups === undefined || !edgeGroups.length) { if (edgeGroups === undefined || !Object.keys(edgeGroups).length) {
// if edge groups are not set or empty, use default edge group(s) // if edge groups are not set or empty, use default edge group(s)
this.myConfig[key] = defaultConfig.edgeGroups; this.myConfig[key] = defaultConfig.edgeGroups;
// stop if edgeGroups do not contain any information // stop if edgeGroups do not contain any information
......
...@@ -38,22 +38,13 @@ ...@@ -38,22 +38,13 @@
<network-expander id="netexp1" <network-expander id="netexp1"
config='{ config='{
"nodeGroups":{ "nodeGroups": {"0.5": {"type": "gene", "color": "rgb(204, 255, 51)", "groupName": "0.5", "shape": "circle"}, "patient_group": {"type": "patient", "color": "red", "groupName": "patient group", "shape": "circle"}},
"0.5":{"type":"gene","color":"#CCFF33FF","groupName":"0.5","shape":"circle"}, "edgeGroups": {"dashes": {"color": "black", "groupName": "Dashes Group", "dashes": [1, 2]}},
"1.5":{"type":"gene","color":"#66FF33FF","groupName":"1.5","shape":"circle"}, "identifier": "symbol"
"2.0":{"type":"gene","color":"#33CC33FF","groupName":"2.0","shape":"circle"},
"patient_group":{"type":"gene","color":"#FF0000FF","groupName":"-2.0","shape":"circle"}
},
"edgeGroups":{
"custom":{"color":"black","groupName":"Custom Group"}
},
"identifier":"symbol",
"legendUrl":"https://exbio.wzw.tum.de/covex/assets/leg1.png"
}' }'
network='{ network='{
"nodes": [{"id": "TP53", "group": "0.5"}, {"id": "C5", "group": "0.5"}, {"id": "Patient", "group": "patient_group"}, {"label": "PTEN", "id": "PTEN", "group": 0.5}], "nodes": [{"id": "TP53", "group": "0.5"}, {"id": "C5", "group": "0.5"}, {"id": "Patient", "group": "patient_group"}, {"label": "PTEN", "id": "PTEN", "group": 0.5}],
"edges":[] "edges": [{"from": "TP53","to": "C5","group": "dashes", "label": "this is a label", "title": "this is a title"}]
}' }'
style="height: 100%; width: 100vw; display: block;" style="height: 100%; width: 100vw; display: block;"
></network-expander> ></network-expander>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment