Skip to content

Commit

Permalink
Merge pull request #64 from geneontology/issue-61-expand-pcc
Browse files Browse the repository at this point in the history
added pccNode for protein containing complex expand error
  • Loading branch information
tmushayahama authored Jan 3, 2025
2 parents ec1bcdd + 0149a18 commit 6c5e8fc
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 80 deletions.
21 changes: 9 additions & 12 deletions src/components/gocam-viz/gocam-viz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import cytoscape from 'cytoscape';
import dagre from 'cytoscape-dagre';
import {
Activity, ActivityType, Cam,
ActivityNodeType,
noctuaFormConfig,
NoctuaFormConfigService,
NoctuaGraphService,
Triple
Expand Down Expand Up @@ -392,17 +392,17 @@ 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(activity.pccNode?.id)

const edges = activity.getEdges(ActivityNodeType.GoProteinContainingComplex)
if (expandComplex && edges) {
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 gps = edges.map(edge => {
const geneShorthand = this.configService.getGeneShorthand(edge.object.term?.label)
return geneShorthand
});
const truncatedGps = gps.slice(0, 3)
let geneString = gps.join(', ')

Expand All @@ -418,7 +418,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)
}
}

Expand All @@ -432,11 +431,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]

}
Expand Down
120 changes: 52 additions & 68 deletions src/globals/@noctua.form/models/activity/activity.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -84,6 +80,7 @@ export class Activity extends SaeGraph<ActivityNode> {
mfNode: ActivityNode;
bpNode: ActivityNode;
ccNode: ActivityNode;
pccNode: ActivityNode;

/**
* Used for HTML id attribute
Expand Down Expand Up @@ -164,11 +161,10 @@ export class Activity extends SaeGraph<ActivityNode> {


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;
Expand Down Expand Up @@ -226,45 +222,46 @@ export class Activity extends SaeGraph<ActivityNode> {
}
}

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<ActivityNode>) => {
each(this.edges, (triple: Triple<ActivityNode>) => {
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) {
Expand Down Expand Up @@ -295,9 +292,8 @@ export class Activity extends SaeGraph<ActivityNode> {


updateShapeMenuShex(rootTypes?) {
const self = this;

each(self.nodes, (node: ActivityNode) => {
each(this.nodes, (node: ActivityNode) => {
const subjectIds = node.category.map((category) => {
return category.category
});
Expand All @@ -310,15 +306,7 @@ export class Activity extends SaeGraph<ActivityNode> {
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);
// }
});


Expand All @@ -327,29 +315,26 @@ export class Activity extends SaeGraph<ActivityNode> {
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;

each(canInsertSubjectNodes, (nodeDescription: ShapeDescription.ShapeDescription) => {

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;
Expand All @@ -359,27 +344,27 @@ export class Activity extends SaeGraph<ActivityNode> {
});

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;

each(canInsertSubjectNodes, (nodeDescription: ShapeDescription.ShapeDescription) => {

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;
Expand All @@ -389,15 +374,15 @@ export class Activity extends SaeGraph<ActivityNode> {
});

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;
});

Expand All @@ -408,7 +393,7 @@ export class Activity extends SaeGraph<ActivityNode> {


getRootNodeByType(type: ActivityNodeType): ActivityNode {
const self = this;

const rootEdges = this.getEdges(this.rootNode.id)
const found = find(rootEdges, ((node: Triple<ActivityNode>) => {
return node.object.type === type
Expand All @@ -433,23 +418,22 @@ export class Activity extends SaeGraph<ActivityNode> {
}

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;
Expand All @@ -459,9 +443,9 @@ export class Activity extends SaeGraph<ActivityNode> {


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);
Expand All @@ -474,8 +458,8 @@ export class Activity extends SaeGraph<ActivityNode> {
}

getEdgesByEdgeId(edgeId: string): Triple<ActivityNode>[] {
const self = this;
const found = filter(self.edges, ((node: Triple<ActivityNode>) => {

const found = filter(this.edges, ((node: Triple<ActivityNode>) => {
return node.predicate.edge.id === edgeId
}))

Expand All @@ -485,13 +469,13 @@ export class Activity extends SaeGraph<ActivityNode> {
}

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})`;
Expand All @@ -501,24 +485,24 @@ export class Activity extends SaeGraph<ActivityNode> {
}

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' : '';
Expand All @@ -534,7 +518,7 @@ export class Activity extends SaeGraph<ActivityNode> {
fd: {},
};

const sortedNodes = self.nodes.sort(compareNodeWeight);
const sortedNodes = this.nodes.sort(compareNodeWeight);

each(sortedNodes, function (node: ActivityNode) {
if (node.displaySection && node.displayGroup) {
Expand Down

0 comments on commit 6c5e8fc

Please sign in to comment.