Skip to content

Commit 6dfa43d

Browse files
committed
Allow individual display of PTM Node Labels
1 parent 93f0ad4 commit 6dfa43d

File tree

1 file changed

+63
-24
lines changed

1 file changed

+63
-24
lines changed

src/BiowcPathwaygraph.ts

Lines changed: 63 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,25 +287,26 @@ export class BiowcPathwaygraph extends LitElement {
287287

288288
contextMenuStore?: Map<string, any>;
289289

290-
isAddingEdge: Boolean = false;
290+
isAddingEdge: boolean = false;
291291

292-
isCreatingGroup: Boolean = false;
292+
isCreatingGroup: boolean = false;
293293

294-
ptmNodeLabelsVisible: Boolean = false;
294+
allPtmNodeLabelsVisible: boolean = false;
295295

296-
kinaseSubstrateLinksVisible: Boolean = false;
296+
kinaseSubstrateLinksVisible: boolean = false;
297297

298-
perturbedNodesVisible: Boolean = false;
298+
perturbedNodesVisible: boolean = false;
299+
300+
// For the context menu I need to explicitly enumerate all possible class lists of gene protein nodes
301+
static regulation_strings = ['', '.down', '.up', '.both', '.not'];
302+
303+
static circle_strings = ['', '.circle-down', '.circle-up'];
299304

300-
// TODO: Is there no way I can generalize this to rect.node-rect?
301305
static geneProteinPathwayCompoundsNodes: string[] = [
302-
'rect.node-rect.gene_protein',
303-
'rect.node-rect.gene_protein.down',
304-
'rect.node-rect.gene_protein.up',
305-
'rect.node-rect.gene_protein.both',
306-
'rect.node-rect.gene_protein.not',
307-
'rect.node-rect.pathway',
308-
'rect.node-rect.compound',
306+
...this.regulation_strings.flatMap(s1 =>
307+
this.circle_strings.map(s2 => `rect.node-rect.gene_protein${s1}${s2}`)
308+
),
309+
...['rect.node-rect.pathway', 'rect.node-rect.compound'],
309310
];
310311

311312
static nodeTypes: { id: string; label: string }[] = [
@@ -598,6 +599,7 @@ export class BiowcPathwaygraph extends LitElement {
598599
['show-up', true],
599600
['show-down', true],
600601
['show-not', true],
602+
['peptide-label-visibility-map', {}],
601603
]);
602604

603605
this._initEditModeForms();
@@ -3900,19 +3902,21 @@ font-family: "Roboto Light", "Helvetica Neue", "Verdana", sans-serif'><strong st
39003902
a.click();
39013903
}
39023904

3903-
public toggleLabelPeptideNodes() {
3904-
this.ptmNodeLabelsVisible = !this.ptmNodeLabelsVisible;
3905+
public updatePeptideNodeLabels() {
39053906
this.d3Nodes!.forEach(node => {
39063907
if (node.type === 'ptm') {
3908+
const ptmNode = <PTMNodeD3>node;
39073909
// TODO: If available, use Site identifier before sequence
39083910
const ptmNodeLabel =
39093911
// @ts-ignore
3910-
(<PTMNodeD3>node).details?.Site?.text ||
3911-
(<PTMNodeD3>node).details!['Modified Sequence'] ||
3912-
(<PTMNodeD3>node).details!.Sequence ||
3912+
ptmNode.details?.Site?.text ||
3913+
ptmNode.details!['Modified Sequence'] ||
3914+
ptmNode.details!.Sequence ||
39133915
'test';
39143916
// eslint-disable-next-line no-param-reassign
3915-
node.currentDisplayedLabel = this.ptmNodeLabelsVisible
3917+
ptmNode.currentDisplayedLabel = this.contextMenuStore?.get(
3918+
'peptide-label-visibility-map'
3919+
)[ptmNode.geneProteinNode?.nodeId!]
39163920
? String(ptmNodeLabel)
39173921
: '';
39183922
}
@@ -4083,10 +4087,25 @@ font-family: "Roboto Light", "Helvetica Neue", "Verdana", sans-serif'><strong st
40834087
},
40844088
{
40854089
target: 'svg',
4086-
label: 'Show PTM Node Labels',
4087-
execute: () => this.toggleLabelPeptideNodes(),
4090+
label: 'Show PTM Labels',
4091+
execute: () => {
4092+
this.allPtmNodeLabelsVisible = !this.allPtmNodeLabelsVisible;
4093+
const peptideNodeVisibilityMap = this.contextMenuStore?.get(
4094+
'peptide-label-visibility-map'
4095+
);
4096+
this.d3Nodes!.forEach(node => {
4097+
peptideNodeVisibilityMap[node.nodeId!] =
4098+
this.allPtmNodeLabelsVisible;
4099+
});
4100+
this.contextMenuStore?.set(
4101+
'peptide-label-visibility-map',
4102+
peptideNodeVisibilityMap
4103+
);
4104+
4105+
this.updatePeptideNodeLabels();
4106+
},
40884107
type: 'radio',
4089-
checked: () => this.ptmNodeLabelsVisible,
4108+
checked: () => this.allPtmNodeLabelsVisible,
40904109
},
40914110
{
40924111
target: 'svg',
@@ -4179,8 +4198,28 @@ font-family: "Roboto Light", "Helvetica Neue", "Verdana", sans-serif'><strong st
41794198
},
41804199
];
41814200
this.contextMenuCommands.push(
4182-
...[
4201+
...(<ContextMenuCommand[]>[
41834202
// Context Menu for Gene/Protein Nodes
4203+
{
4204+
target: BiowcPathwaygraph.geneProteinPathwayCompoundsNodes,
4205+
label: 'Show PTM Labels for Node',
4206+
execute: (ctx: ExecuteOptions) => {
4207+
const peptideNodeVisibilityMap = this.contextMenuStore?.get(
4208+
'peptide-label-visibility-map'
4209+
);
4210+
// @ts-ignore
4211+
peptideNodeVisibilityMap[ctx.target.__data__.nodeId] =
4212+
// @ts-ignore
4213+
!peptideNodeVisibilityMap[ctx.target.__data__.nodeId];
4214+
this.updatePeptideNodeLabels();
4215+
},
4216+
type: 'radio',
4217+
checked: ctx =>
4218+
this.contextMenuStore?.get('peptide-label-visibility-map')[
4219+
// @ts-ignore
4220+
ctx.target.__data__.nodeId
4221+
],
4222+
},
41844223
{
41854224
target: BiowcPathwaygraph.geneProteinPathwayCompoundsNodes.concat([
41864225
'path.group-path',
@@ -4217,7 +4256,7 @@ font-family: "Roboto Light", "Helvetica Neue", "Verdana", sans-serif'><strong st
42174256
label: 'Alternative Names',
42184257
// Children will be created dynamically!
42194258
},
4220-
]
4259+
])
42214260
);
42224261

42234262
// Now we set up an event listener for nodes that dynamically creates the children of the 'Alternative Names' menu entry

0 commit comments

Comments
 (0)