Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chemical reference #71

Merged
merged 3 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/components/gocam-viz/gocam-viz.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ export class GoCamViz {
});

const truncatedGps = gps.slice(0, 3)
let geneString = gps.join(', ')
let geneString = truncatedGps.join(', ')

if (gps.length > truncatedGps.length) {
geneString += ' and ' + (gps.length - truncatedGps.length).toString() + ' more'
Expand Down
298 changes: 1 addition & 297 deletions src/globals/@noctua.form/models/activity/cam.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { noctuaFormConfig } from './../../noctua-form-config';
import { Activity, ActivitySortField, ActivityType } from './activity'
import { ActivityNode, ActivityNodeType } from './activity-node';
import { Group } from '../group';
import { Contributor } from '../contributor';
import { Evidence } from './evidence';
import { Triple } from './triple';
import { Entity } from './entity';
import { each, find, orderBy, groupBy } from 'lodash';
import { each, find, groupBy } from 'lodash';
import { NoctuaFormUtils } from './../../utils/noctua-form-utils';
import { PendingChange } from './pending-change';

export enum ReloadType {
RESET = 'reset',
Expand Down Expand Up @@ -135,7 +132,6 @@ export class Cam {
manualLayout = false;
layoutChanged = false;

private _filteredActivities: Activity[] = [];
activities: Activity[] = [];
storedActivities: Activity[] = [];
private _id: string;
Expand All @@ -153,15 +149,6 @@ export class Cam {
this.displayId = NoctuaFormUtils.cleanID(id);
}

updateSortBy(field: ActivitySortField, label: string) {
this.sortBy.field = field
this.sortBy.label = label
}

toggleExpand() {
this.expanded = !this.expanded;
}

groupActivitiesByProcess() {
const groupedActivities = groupBy(this.activities, (activity: Activity) => {
if (activity.activityType === ActivityType.molecule) {
Expand All @@ -174,57 +161,6 @@ export class Cam {
return groupedActivities;
}


expandAllActivities(expand: boolean) {
const self = this;

each(self.activities, (activity: Activity) => {
activity.expanded = expand;
});
}

getCausalRelation(subjectId: string, objectId: string): Triple<Activity> {
const self = this;

return self.causalRelations.find((triple: Triple<Activity>) => {
if (triple.predicate?.isReverseLink) {
return triple.object?.id === subjectId && triple.object?.id === subjectId;
}
return triple.subject?.id === subjectId && triple.object?.id === objectId;
})
}

clearHighlight() {
const self = this;

each(self.activities, (activity: Activity) => {
each(activity.nodes, (node: ActivityNode) => {
node.term.highlight = false;
each(node.predicate.evidence, (evidence: Evidence) => {
evidence.evidence.highlight = false;
evidence.referenceEntity.highlight = false;
evidence.withEntity.highlight = false;
});
});
});
}

findNodeById(uuid, activities: Activity[]): ActivityNode {
const self = this;
let found
each(activities, (activity) => {
found = find(activity.nodes, (node: ActivityNode) => {
return node.uuid === uuid;
});

if (found) {
return false;
}
})

return found;
}

findActivityById(id) {
const self = this;

Expand All @@ -233,220 +169,6 @@ export class Cam {
});
}

findActivityByNodeUuid(nodeId): Activity[] {
const self = this;

const result: Activity[] = [];

each(self.activities, (activity: Activity) => {
each(activity.nodes, (node: ActivityNode) => {
if (node.uuid === nodeId) {
result.push(activity)
}
each(node.predicate.evidence, (evidence: Evidence) => {
if (evidence.uuid === nodeId) {
result.push(activity)
}
});
});
});
return result;
}


applyFilter() {
const self = this;

self.clearHighlight();

if (self.queryMatch && self.queryMatch.terms.length > 0) {
self._filteredActivities = [];
self.matchedCount = 0;

each(self.activities, (activity: Activity) => {
let match = false;
each(activity.nodes, (node: ActivityNode) => {
each(self.queryMatch.terms, (term) => {

if (node.term.uuid === term.uuid) {
node.term.highlight = true;
node.term.activityDisplayId = term.activityDisplayId = activity.displayId;

self.matchedCount += 1;
match = true;
}
});

each(node.predicate.evidence, (evidence: Evidence) => {
each(self.queryMatch.terms, (term) => {

if (evidence.uuid === term.uuid) {
evidence.referenceEntity.highlight = true;
evidence.referenceEntity.activityDisplayId = term.activityDisplayId = activity.displayId;

self.matchedCount += 1;
match = true;
}
});
});
});

if (match) {
self._filteredActivities.push(activity);
}
});
}
}

applyWeights(weight = 0) {
const self = this;

if (self.queryMatch && self.queryMatch.terms.length > 0) {

each(self.activities, (activity: Activity) => {
each(activity.nodes, (node: ActivityNode) => {
const matchNode = find(self.queryMatch.terms, { uuid: node.term.uuid }) as Entity;

if (matchNode) {
matchNode.weight = node.term.weight = weight;
weight++;
}

each(node.predicate.evidence, (evidence: Evidence) => {
const matchNode = find(self.queryMatch.terms, { uuid: evidence.referenceEntity.uuid }) as Entity;

if (matchNode) {
matchNode.weight = evidence.referenceEntity.weight = weight;
weight++;
}
});
});

});
}
}

addPendingChanges(findEntities: Entity[], replaceWith: string, category) {
const self = this;

each(self.activities, (activity: Activity) => {
each(activity.nodes, (node: ActivityNode) => {
each(findEntities, (entity: Entity) => {
if (category.name === noctuaFormConfig.findReplaceCategory.options.reference.name) {
each(node.predicate.evidence, (evidence: Evidence, key) => {
if (evidence.uuid === entity.uuid) {
const oldReference = new Entity(evidence.reference, evidence.reference);
const newReference = new Entity(replaceWith, replaceWith);

evidence.pendingReferenceChanges = new PendingChange(evidence.uuid, oldReference, newReference);
evidence.pendingReferenceChanges.uuid = evidence.uuid;
}
});
} else {
if (node.term.uuid === entity.uuid) {
const newValue = new Entity(replaceWith, replaceWith);
node.pendingEntityChanges = new PendingChange(node.uuid, node.term, newValue);
}
}
});
});
});
}

getNodesByType(type: ActivityNodeType): any[] {
const self = this;
const result = [];

each(self.activities, (activity: Activity) => {
result.push({
activity,
title: activity.title,
activityNodes: activity.getNodesByType(type)
});
});

return result;
}

getNodesByTypeFlat(type: ActivityNodeType): ActivityNode[] {
const self = this;
const result = [];

each(self.activities, (activity: Activity) => {
result.push(...activity.getNodesByType(type));
});

return result;
}

getTerms(formActivity: Activity) {
const self = this;
const result = [];

if (formActivity && formActivity.nodes) {
each(formActivity.nodes, (node: ActivityNode) => {
result.push(node);
});
}

each(self.activities, (activity: Activity) => {
each(activity.nodes, (node: ActivityNode) => {
result.push(node);
});
});

return result;
}

getEvidences(formActivity?: Activity) {
const self = this;
const result = [];

if (formActivity && formActivity.nodes) {
each(formActivity.nodes, (node: ActivityNode) => {
each(node.predicate.evidence, (evidence: Evidence) => {
if (evidence.hasValue()) {
result.push(evidence);
}
});
});
}

each(self.activities, (activity: Activity) => {
each(activity.edges, (triple: Triple<ActivityNode>) => {
each(triple.predicate.evidence, (evidence: Evidence) => {
if (evidence.hasValue()) {
result.push(evidence);
}
});
});
});

return result;
}

tableCanDisplayEnabledBy(node: ActivityNode) {
return node.predicate.edge && node.predicate.edge.id === noctuaFormConfig.edge.enabledBy.id;
}

tableDisplayExtension(node: ActivityNode) {
if (node.id === 'mf') {
return '';
} else if (node.isComplement) {
return 'NOT ' + node.predicate.edge.label;
} else {
return node.predicate.edge.label;
}
}

updateActivityDisplayNumber() {
const self = this;

each(self.activities, (activity: Activity, key) => {
activity.displayNumber = self.displayNumber + '.' + (key + 1).toString();
});
}

updateProperties() {
const self = this;

Expand All @@ -457,23 +179,5 @@ export class Cam {
this.sortBy.label = noctuaFormConfig.activitySortField.options[this.sortBy.field]?.label
}

private _getGPText(a: Activity): string {
return a.presentation.gpText.toLowerCase()
}

private _getMFText(a: Activity): string {
if (!a.mfNode) return ''
return a.mfNode.term.label;
}
private _getBPText(a: Activity): string {
if (!a.bpNode) return ''
return a.bpNode.term.label;
}
private _getCCText(a: Activity): string {
if (!a.ccNode) return ''
return a.ccNode.term.label;
}


}

Loading
Loading