From 4f12259ea7283e2b2479370bdac25a31a56b92bb Mon Sep 17 00:00:00 2001 From: tmushayahama Date: Fri, 27 Dec 2024 17:29:17 -0800 Subject: [PATCH 1/2] added pccNode for protein containing complex expand error --- src/components/gocam-viz/gocam-viz.tsx | 11 +- .../@noctua.form/models/activity/activity.ts | 120 ++++++++---------- 2 files changed, 54 insertions(+), 77 deletions(-) diff --git a/src/components/gocam-viz/gocam-viz.tsx b/src/components/gocam-viz/gocam-viz.tsx index c87c496..b08794a 100644 --- a/src/components/gocam-viz/gocam-viz.tsx +++ b/src/components/gocam-viz/gocam-viz.tsx @@ -4,7 +4,6 @@ import cytoscape from 'cytoscape'; import dagre from 'cytoscape-dagre'; import { Activity, ActivityType, Cam, - ActivityNodeType, NoctuaFormConfigService, NoctuaGraphService, Triple @@ -392,13 +391,10 @@ export class GoCamViz { createComplex(activity: Activity, expandComplex = false): any[] { const label = activity.gpNode?.term.label || activity.label || ''; - let el - // result.push(el) - if (expandComplex) { - - const edges = activity.getEdges(ActivityNodeType.GoProteinContainingComplex) + const edges = activity.getEdges(activity.pccNode?.id) + if (expandComplex && edges) { const gps = edges.map(edge => { const geneShorthand = this.configService.getGeneShorthand(edge.object.term?.label) return geneShorthand @@ -418,7 +414,6 @@ export class GoCamViz { width: Math.max(115, geneString.length * 11), textwidth: Math.max(115, geneString.length * 9), "backgroundColor": activity.backgroundColor || 'white', - // degree: (child * 10 + parent) } } @@ -432,11 +427,9 @@ export class GoCamViz { width: Math.max(115, label.length * 11), textwidth: Math.max(115, label.length * 9), "backgroundColor": activity.backgroundColor || 'white', - // degree: (child * 10 + parent) } } } - // result.push(...gps) return [el] } diff --git a/src/globals/@noctua.form/models/activity/activity.ts b/src/globals/@noctua.form/models/activity/activity.ts index 41f1eb6..6362a43 100644 --- a/src/globals/@noctua.form/models/activity/activity.ts +++ b/src/globals/@noctua.form/models/activity/activity.ts @@ -1,19 +1,15 @@ import { v4 as uuid } from 'uuid'; import { noctuaFormConfig } from './../../noctua-form-config'; import { SaeGraph } from './sae-graph'; -import { ActivityError, ErrorLevel, ErrorType } from './parser/activity-error'; import { ActivityNode, ActivityNodeType, compareNodeWeight } from './activity-node'; import { Evidence } from './evidence'; import { Triple } from './triple'; import { Entity } from './entity'; import { Predicate } from './predicate'; -import { subtractNodes } from './noctua-form-graph'; import * as ShapeDescription from './../../data/config/shape-definition'; import { each, filter, find, orderBy } from 'lodash'; import { NoctuaFormUtils } from './../../utils/noctua-form-utils'; import { TermsSummary } from './summary'; - - import moment from 'moment'; export enum ActivityState { @@ -84,6 +80,7 @@ export class Activity extends SaeGraph { mfNode: ActivityNode; bpNode: ActivityNode; ccNode: ActivityNode; + pccNode: ActivityNode; /** * Used for HTML id attribute @@ -164,11 +161,10 @@ export class Activity extends SaeGraph { postRunUpdate() { - const self = this; // for enabled by if (this.activityType !== ActivityType.ccOnly) { - const edge = self.enabledByEdge; + const edge = this.enabledByEdge; if (this.mfNode && edge) { this.mfNode.showEvidence = false; @@ -226,45 +222,46 @@ export class Activity extends SaeGraph { } } + if (this.activityType === ActivityType.proteinComplex) { + this.pccNode = this.gpNode + } }) } updateDate() { - const self = this; const rootNode = this.rootNode; if (!rootNode) return; - self.date = (moment as any)(rootNode.date, 'YYYY-MM-DD') + this.date = (moment as any)(rootNode.date, 'YYYY-MM-DD') - self.nodes.forEach((node: ActivityNode) => { + this.nodes.forEach((node: ActivityNode) => { const nodeDate = (moment as any)(node.date, 'YYYY-MM-DD') - if (nodeDate > self.date) { - self.date = nodeDate + if (nodeDate > this.date) { + this.date = nodeDate } }); - each(self.edges, (triple: Triple) => { + each(this.edges, (triple: Triple) => { each(triple.predicate.evidence, (evidence: Evidence) => { const evidenceDate = (moment as any)(evidence.date, 'YYYY-MM-DD') - if (evidenceDate > self.date) { - self.date = evidenceDate + if (evidenceDate > this.date) { + this.date = evidenceDate } }) }); - this.formattedDate = self.date.format('ll'); + this.formattedDate = this.date.format('ll'); } updateSummary() { - const self = this; let summary = new TermsSummary() let coverage = 0; - const filteredNodes = self.nodes.filter(node => node.term.hasValue()) + const filteredNodes = this.nodes.filter(node => node.term.hasValue()) filteredNodes.forEach((node: ActivityNode) => { if (node.type === ActivityNodeType.GoMolecularFunction) { @@ -295,9 +292,8 @@ export class Activity extends SaeGraph { updateShapeMenuShex(rootTypes?) { - const self = this; - each(self.nodes, (node: ActivityNode) => { + each(this.nodes, (node: ActivityNode) => { const subjectIds = node.category.map((category) => { return category.category }); @@ -310,15 +306,7 @@ export class Activity extends SaeGraph { const insertNodes: ShapeDescription.ShapeDescription[] = []; each(canInsertNodes, (nodeDescription: ShapeDescription.ShapeDescription) => { - /* if (nodeDescription.cardinality === ShapeDescription.CardinalityType.oneToOne) { - const edgeTypeExist = self.edgeTypeExist(node.id, nodeDescription.predicate.id, node.type, nodeDescription.node.type); - - if (!edgeTypeExist) { - insertNodes.push(nodeDescription); - } - } else { */ insertNodes.push(nodeDescription); - // } }); @@ -327,15 +315,12 @@ export class Activity extends SaeGraph { return true; }); - /* node.insertMenuNodes = filter(insertNodes, (insertNode: ShapeDescription.ShapeDescription) => { - return insertNode.node.showInMenu; - }); */ }); } updateEdgesShex(subjectNode: ActivityNode, insertNode: ActivityNode, predicate: Predicate) { - const self = this; + const canInsertSubjectNodes = ShapeDescription.canInsertEntity[subjectNode.type] || []; let updated = false; @@ -343,13 +328,13 @@ export class Activity extends SaeGraph { if (predicate.edge.id === nodeDescription.predicate.id) { if (nodeDescription.cardinality === ShapeDescription.CardinalityType.oneToOne) { - const edgeTypeExist = self.edgeTypeExist(subjectNode.id, nodeDescription.predicate.id, subjectNode.type, nodeDescription.node.type); + const edgeTypeExist = this.edgeTypeExist(subjectNode.id, nodeDescription.predicate.id, subjectNode.type, nodeDescription.node.type); if (edgeTypeExist) { edgeTypeExist.object.treeLevel++; - self.removeEdge(edgeTypeExist.subject, edgeTypeExist.object, edgeTypeExist.predicate); - self.addEdge(edgeTypeExist.subject, insertNode, edgeTypeExist.predicate); - self.addEdge(insertNode, edgeTypeExist.object, predicate); + this.removeEdge(edgeTypeExist.subject, edgeTypeExist.object, edgeTypeExist.predicate); + this.addEdge(edgeTypeExist.subject, insertNode, edgeTypeExist.predicate); + this.addEdge(insertNode, edgeTypeExist.object, predicate); updated = true; return false; @@ -359,13 +344,13 @@ export class Activity extends SaeGraph { }); if (!updated) { - self.addEdgeById(subjectNode.id, insertNode.id, predicate); + this.addEdgeById(subjectNode.id, insertNode.id, predicate); } } updateEdges(subjectNode: ActivityNode, insertNode: ActivityNode, predicate: Predicate) { - const self = this; + const canInsertSubjectNodes = ShapeDescription.canInsertEntity[subjectNode.type] || []; let updated = false; @@ -373,13 +358,13 @@ export class Activity extends SaeGraph { if (predicate.edge.id === nodeDescription.predicate.id) { if (nodeDescription.cardinality === ShapeDescription.CardinalityType.oneToOne) { - const edgeTypeExist = self.edgeTypeExist(subjectNode.id, nodeDescription.predicate.id, subjectNode.type, nodeDescription.node.type); + const edgeTypeExist = this.edgeTypeExist(subjectNode.id, nodeDescription.predicate.id, subjectNode.type, nodeDescription.node.type); if (edgeTypeExist) { edgeTypeExist.object.treeLevel++; - self.removeEdge(edgeTypeExist.subject, edgeTypeExist.object, edgeTypeExist.predicate); - self.addEdge(edgeTypeExist.subject, insertNode, edgeTypeExist.predicate); - self.addEdge(insertNode, edgeTypeExist.object, predicate); + this.removeEdge(edgeTypeExist.subject, edgeTypeExist.object, edgeTypeExist.predicate); + this.addEdge(edgeTypeExist.subject, insertNode, edgeTypeExist.predicate); + this.addEdge(insertNode, edgeTypeExist.object, predicate); updated = true; return false; @@ -389,15 +374,15 @@ export class Activity extends SaeGraph { }); if (!updated) { - self.addEdgeById(subjectNode.id, insertNode.id, predicate); + this.addEdgeById(subjectNode.id, insertNode.id, predicate); } } getNodesByType(type: ActivityNodeType): ActivityNode[] { - const self = this; - const result = filter(self.nodes, (activityNode: ActivityNode) => { + + const result = filter(this.nodes, (activityNode: ActivityNode) => { return activityNode.type === type; }); @@ -408,7 +393,7 @@ export class Activity extends SaeGraph { getRootNodeByType(type: ActivityNodeType): ActivityNode { - const self = this; + const rootEdges = this.getEdges(this.rootNode.id) const found = find(rootEdges, ((node: Triple) => { return node.object.type === type @@ -433,23 +418,22 @@ export class Activity extends SaeGraph { } adjustActivity() { - const self = this; - if (self.activityType === noctuaFormConfig.activityType.options.bpOnly.name) { + if (this.activityType === noctuaFormConfig.activityType.options.bpOnly.name) { const rootMF = noctuaFormConfig.rootNode.mf; - const mfNode = self.mfNode; - const bpNode = self.bpNode + const mfNode = this.mfNode; + const bpNode = this.bpNode mfNode.term = new Entity(rootMF.id, rootMF.label); mfNode.predicate.evidence = bpNode.predicate.evidence; - if (self.bpOnlyEdge) { - this.bpPartOfEdge.predicate.edge.id = bpNode.predicate.edge.id = self.bpOnlyEdge.id; - this.bpPartOfEdge.predicate.edge.label = bpNode.predicate.edge.label = self.bpOnlyEdge.label; + if (this.bpOnlyEdge) { + this.bpPartOfEdge.predicate.edge.id = bpNode.predicate.edge.id = this.bpOnlyEdge.id; + this.bpPartOfEdge.predicate.edge.label = bpNode.predicate.edge.label = this.bpOnlyEdge.label; } } - if (self.activityType !== ActivityType.ccOnly && self.activityType !== ActivityType.molecule) { + if (this.activityType !== ActivityType.ccOnly && this.activityType !== ActivityType.molecule) { if (this.mfNode && this.enabledByEdge) { this.enabledByEdge.predicate.evidence = this.mfNode.predicate.evidence; @@ -459,9 +443,9 @@ export class Activity extends SaeGraph { copyValues(srcActivity) { - const self = this; - each(self.nodes, function (destNode: ActivityNode) { + + each(this.nodes, function (destNode: ActivityNode) { const srcNode = srcActivity.getNode(destNode.id); if (srcNode) { destNode.copyValues(srcNode); @@ -474,8 +458,8 @@ export class Activity extends SaeGraph { } getEdgesByEdgeId(edgeId: string): Triple[] { - const self = this; - const found = filter(self.edges, ((node: Triple) => { + + const found = filter(this.edges, ((node: Triple) => { return node.predicate.edge.id === edgeId })) @@ -485,13 +469,13 @@ export class Activity extends SaeGraph { } get title() { - const self = this; - const gp = self.gpNode; + + const gp = this.gpNode; const gpText = gp ? gp.getTerm().label : ''; let title = ''; - if (self.activityType === ActivityType.ccOnly || - self.activityType === ActivityType.molecule) { + if (this.activityType === ActivityType.ccOnly || + this.activityType === ActivityType.molecule) { title = gpText; } else { title = `enabled by (${gpText})`; @@ -501,24 +485,24 @@ export class Activity extends SaeGraph { } get presentation() { - const self = this; + if (this._presentation) { return this._presentation; } - const gp = self.gpNode; - const mf = self.mfNode; + const gp = this.gpNode; + const mf = this.mfNode; const gpText = gp ? gp.getTerm().label : ''; const mfText = mf ? mf.getTerm().label : ''; let qualifier = ''; let title = ''; - if (self.activityType === ActivityType.ccOnly) { + if (this.activityType === ActivityType.ccOnly) { title = gpText; - } else if (self.activityType === ActivityType.molecule) { + } else if (this.activityType === ActivityType.molecule) { title = gpText; - } else if (self.activityType === ActivityType.proteinComplex) { + } else if (this.activityType === ActivityType.proteinComplex) { title = gpText; } else { qualifier = mf?.isComplement ? 'NOT' : ''; @@ -534,7 +518,7 @@ export class Activity extends SaeGraph { fd: {}, }; - const sortedNodes = self.nodes.sort(compareNodeWeight); + const sortedNodes = this.nodes.sort(compareNodeWeight); each(sortedNodes, function (node: ActivityNode) { if (node.displaySection && node.displayGroup) { From 0149a186a956383c5f6bd6784013a495a03972a0 Mon Sep 17 00:00:00 2001 From: tmushayahama Date: Fri, 27 Dec 2024 17:46:27 -0800 Subject: [PATCH 2/2] checked if the edge is hasPart --- src/components/gocam-viz/gocam-viz.tsx | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/gocam-viz/gocam-viz.tsx b/src/components/gocam-viz/gocam-viz.tsx index b08794a..3f81a91 100644 --- a/src/components/gocam-viz/gocam-viz.tsx +++ b/src/components/gocam-viz/gocam-viz.tsx @@ -4,6 +4,7 @@ import cytoscape from 'cytoscape'; import dagre from 'cytoscape-dagre'; import { Activity, ActivityType, Cam, + noctuaFormConfig, NoctuaFormConfigService, NoctuaGraphService, Triple @@ -395,10 +396,13 @@ export class GoCamViz { const edges = activity.getEdges(activity.pccNode?.id) if (expandComplex && edges) { - const gps = edges.map(edge => { - const geneShorthand = this.configService.getGeneShorthand(edge.object.term?.label) - return geneShorthand - }); + const gps = edges + .filter(edge => edge.predicate?.edge?.id === noctuaFormConfig.edge.hasPart.id) + .map(edge => { + const geneShorthand = this.configService.getGeneShorthand(edge.object.term?.label); + return geneShorthand; + }); + const truncatedGps = gps.slice(0, 3) let geneString = gps.join(', ')