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

Bug fixes #59

Merged
merged 2 commits into from
Nov 4, 2024
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: 2 additions & 0 deletions src/@noctua.editor/inline-editor/inline-editor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ export class NoctuaInlineEditorComponent implements OnInit, OnDestroy {
@Input() cam: Cam;
@Input() activity: Activity;
@Input() annotationActivity: AnnotationActivity;
@Input() autocompleteCategory;
@Input() entity: ActivityNode;
@Input() category: EditorCategory;
@Input() evidenceIndex = 0;
Expand Down Expand Up @@ -62,6 +63,7 @@ export class NoctuaInlineEditorComponent implements OnInit, OnDestroy {
//for Standard Editor
editorType: this.editorType,
annotationActivity: this.annotationActivity,
autocompleteCategory: this.autocompleteCategory
};

if (this.editorType === EditorType.DEFAULT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ export class NoctuaEditorStandardDropdownComponent implements OnInit, OnDestroy
this.cam = data.cam;
this.annotationActivity = data.annotationActivity;
this.entity = data.entity;
this.autocompleteCategory = data.autocompleteCategory;
this.category = data.category;
this.insertEntity = data.insertEntity;
this.relationshipChoices = data.relationshipChoices;
Expand Down Expand Up @@ -118,7 +119,6 @@ export class NoctuaEditorStandardDropdownComponent implements OnInit, OnDestroy
}

// Will refactor later

save() {
let termId: string = this.dynamicForm.value[FormStructureKeys.TERM]?.id;
let relationId: string = this.dynamicForm.value[FormStructureKeys.RELATION]?.id;
Expand All @@ -133,10 +133,27 @@ export class NoctuaEditorStandardDropdownComponent implements OnInit, OnDestroy
};

switch (this.category) {
case EditorCategory.GP:
if (termId) {
this.annotationFormService.editAnnotationNode(this.cam, this.annotationActivity.gp, termId)
.pipe(takeUntil(this._unsubscribeAll))
.subscribe(handleResponse);
} else {
this.noctuaFormDialogService.openInfoToast(`Please select term from autocomplete.`, 'OK');
}
break
case EditorCategory.TERM:
if (termId) {
this.annotationFormService.editAnnotationNode(this.cam, this.annotationActivity.goterm, termId)
.pipe(takeUntil(this._unsubscribeAll))
.subscribe(handleResponse);
} else {
this.noctuaFormDialogService.openInfoToast(`Please select term from autocomplete.`, 'OK');
}
break
case EditorCategory.EVIDENCE_CODE:
if (termId) {
this.annotationFormService.editAnnotation(this.category, this.cam, this.annotationActivity, termId)
this.annotationFormService.editEvidence(this.category, this.cam, this.annotationActivity, termId)
.pipe(takeUntil(this._unsubscribeAll))
.subscribe(handleResponse);
} else {
Expand All @@ -145,7 +162,7 @@ export class NoctuaEditorStandardDropdownComponent implements OnInit, OnDestroy
break;
case EditorCategory.WITH:
case EditorCategory.REFERENCE:
this.annotationFormService.editAnnotation(this.category, this.cam, this.annotationActivity, termString)
this.annotationFormService.editEvidence(this.category, this.cam, this.annotationActivity, termString)
.pipe(takeUntil(this._unsubscribeAll))
.subscribe(handleResponse);
break;
Expand Down Expand Up @@ -189,8 +206,17 @@ export class NoctuaEditorStandardDropdownComponent implements OnInit, OnDestroy
this.dynamicForm.get(FormStructureKeys.RELATION).setValue(this.annotationActivity.gpToTermEdge.inverseEntity);
this.relationshipChoices = this.annotationActivity.gpToTermEdges;
break;
case EditorCategory.GP:
this.displaySection.term = true;
this.autocompleteType = AutocompleteType.TERM
this.dynamicForm.get(FormStructureKeys.TERM).setValue(this.annotationActivity.gp.term.label);
this.autocompleteCategory = this.annotationActivity?.gp.category;
break;
case EditorCategory.TERM:
this.displaySection.term = true;
this.autocompleteType = AutocompleteType.TERM
this.dynamicForm.get(FormStructureKeys.TERM).setValue(this.annotationActivity.goterm.term.label);
this.autocompleteCategory = this.annotationActivity?.goterm.category;
break;
case EditorCategory.EVIDENCE_CODE:
this.displaySection.term = true;
Expand Down
2 changes: 2 additions & 0 deletions src/@noctua.editor/models/editor-category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { PositionStrategy } from "@angular/cdk/overlay";
import { Cam, Activity, Entity, ActivityNode, AnnotationActivity } from "@noctua.form";

export enum EditorCategory {
GP = 'GP',
RELATIONSHIP = 'RELATIONSHIP',
TERM = 'TERM',
EVIDENCE = 'EVIDENCE',
Expand Down Expand Up @@ -37,6 +38,7 @@ export interface EditorConfig extends EditorDropdownDialogConfig {
annotationActivity?: AnnotationActivity;
entity?: ActivityNode;
category: EditorCategory;
autocompleteCategory?: any;
evidenceIndex?: any;
relationshipChoices?: any;
}
18 changes: 18 additions & 0 deletions src/@noctua.form/data/config/data-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,22 @@ export class DataUtils {
return predicates;
}


public static processHasParticipants(data): any[] {
const nodeMap = new Map(data.nodes.map(node => [node.id, node.lbl]));

return data.edges
.filter(edge => edge.pred === "RO:0000057")
.map(edge => ({
id: edge.obj,
label: nodeMap.get(edge.obj) || ''
}));
}

public static findCommonItems(itemsA, itemsB) {
const idSetB = new Set(itemsB.map(item => item.id));

return itemsA.filter(item => idSetB.has(item.id));
}

}
2 changes: 2 additions & 0 deletions src/@noctua.form/models/activity/activity-node.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ export class ActivityNode implements ActivityNodeDisplay {
pendingEntityChanges: PendingChange;
pendingRelationChanges: PendingChange;

chemicalParticipants = []


constructor(activityNode?: Partial<ActivityNodeDisplay>) {
if (activityNode) {
Expand Down
1 change: 0 additions & 1 deletion src/@noctua.form/models/activity/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ 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 * as EntityDefinition from './../../data/config/entity-definition';
import { Evidence } from './evidence';
import { Triple } from './triple';
import { Entity } from './entity';
Expand Down
4 changes: 4 additions & 0 deletions src/@noctua.form/models/activity/evidence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ export class Evidence {
}

public static formatWithFrom(value: string) {
if (!value) {
return value;
}

const formatted = value.replace(/\s+/g, "");
return formatted;
}
Expand Down
1 change: 1 addition & 0 deletions src/@noctua.form/models/golr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export interface GOlrResponse {
rootTypes: Entity[];
xref: string;
notAnnotatable: boolean;
neighborhoodGraphJson: string;
}
7 changes: 4 additions & 3 deletions src/@noctua.form/noctua-form-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ const simpleAnnotationEdgeConfig: SAConfigEdgeMap = {
mfNodeRequired: true
},
[inverseEdge.isActiveIn.id]: {
gpToTermPredicate: edge.enabledBy.id,
mfToTermPredicate: edge.occursIn.id,
mfNodeRequired: true
gpToTermPredicate: edge.isActiveIn.id,
mfNodeRequired: false,
gpToTermReverse: false
},
[inverseEdge.actsUpstreamOf.id]: {
gpToTermPredicate: edge.enabledBy.id,
Expand Down Expand Up @@ -551,6 +551,7 @@ export const noctuaFormConfig = {

ccOnlyEdges: [
edge.locatedIn.id,
edge.isActiveIn.id,
edge.partOf.id,
edge.contributesTo.id,
],
Expand Down
37 changes: 36 additions & 1 deletion src/@noctua.form/services/activity-connector.service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import { Injectable } from '@angular/core';
import { Observable, BehaviorSubject } from 'rxjs';
import { Observable, BehaviorSubject, forkJoin } from 'rxjs';
import { FormGroup, FormBuilder } from '@angular/forms';
import { NoctuaFormConfigService } from './config/noctua-form-config.service';
import { NoctuaLookupService } from './lookup.service';
Expand All @@ -16,6 +16,9 @@ import { Entity } from '../models/activity/entity';
import { noctuaFormConfig } from '../noctua-form-config';
import { Triple } from '../models/activity/triple';
import { cloneDeep } from 'lodash';
import { Predicate } from '@noctua.form/models/activity/predicate';



@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -114,6 +117,38 @@ export class NoctuaActivityConnectorService {
return connectorForm;
}

saveChemicalParticipants(subjectNode: ActivityNode, objectNode: ActivityNode, chemicals: any[]) {
const nodes = chemicals.map((chemical) => {
const nodes = new ActivityNode()
nodes.term.id = chemical.id

return nodes
});

const triples = nodes.map((node) => {
const edge = new Entity(noctuaFormConfig.edge.hasInput.id, '')
const predicate = new Predicate(edge);
const triple = new Triple<ActivityNode>(
subjectNode, node, predicate)
return triple
});

const triples2 = nodes.map((node) => {
const edge = new Entity(noctuaFormConfig.edge.hasOutput.id, '')
const predicate = new Predicate(edge);
const triple = new Triple<ActivityNode>(
objectNode, node, predicate)
return triple
});





return forkJoin(this.bbopGraphService.addActivity(this.cam, nodes, [...triples, ...triples2], this.cam.title));

}

saveActivity() {
const self = this;

Expand Down
34 changes: 33 additions & 1 deletion src/@noctua.form/services/annotation-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Injectable } from '@angular/core';
import { BehaviorSubject, catchError, finalize, forkJoin, from, Observable, of, throwError } from 'rxjs';
import { FormGroup, FormBuilder } from '@angular/forms';
import { NoctuaFormConfigService } from './config/noctua-form-config.service';
import { ActivityNode } from './../models/activity/activity-node';
import { Activity, ActivityType } from './../models/activity/activity';
import { BbopGraphService } from './bbop-graph.service';
import { CamService } from './cam.service';
Expand Down Expand Up @@ -211,9 +212,26 @@ export class NoctuaAnnotationFormService {
return forkJoin(this.bbopGraphService.addActivity(this.cam, saveData.nodes, saveData.triples, saveData.title));
}

editAnnotationNode(
cam: Cam,
oldNode: ActivityNode,
newNodeId: string
): Observable<any> {

const actionPromise = this.bbopGraphService.editNode(cam, oldNode, newNodeId);

return from(actionPromise).pipe(
finalize(() => {
this.cam.loading.status = false;
}),
catchError((error) => {
console.error('Error editing annotation:', error);
return of(null);
})
)
}

editAnnotation(
editEvidence(
editorCategory: EditorCategory,
cam: Cam,
annotationActivity: AnnotationActivity,
Expand Down Expand Up @@ -278,6 +296,20 @@ export class NoctuaAnnotationFormService {
)
}

toggleIsComplement(annotationActivity: AnnotationActivity): Observable<any> {
const cam = this.cam;

return from(this.bbopGraphService.toggleIsComplement(cam, annotationActivity.goterm)).pipe(
finalize(() => {
this.cam.loading.status = false;
}),
catchError((error) => {
console.error('Error updating NOT Qualifier:', error);
return of(null);
})
)
}

updateComment(
cam: Cam,
annotationActivity: AnnotationActivity,
Expand Down
75 changes: 58 additions & 17 deletions src/@noctua.form/services/bbop-graph.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ export class BbopGraphService {

result.id = type.class_id();
result.label = type.class_label();
result.classExpression = type;
result.classExpression = srcType;
});

return result;
Expand Down Expand Up @@ -1306,22 +1306,6 @@ export class BbopGraphService {
return null;
}

editIndividual(reqs, cam: Cam, srcNode, destNode) {
if (srcNode.hasValue() && destNode.hasValue()) {
reqs.remove_type_from_individual(
srcNode.classExpression,
srcNode.uuid,
cam.id,
);

reqs.add_type_to_individual(
class_expression.cls(destNode.getTerm().id),
srcNode.uuid,
cam.id,
);
}
}

bulkEditIndividual(reqs, camId: string, node: ActivityNode) {
if (node.hasValue() && node.pendingEntityChanges) {
reqs.remove_type_from_individual(
Expand Down Expand Up @@ -1472,6 +1456,63 @@ export class BbopGraphService {

}

editNode(cam: Cam, oldNode: ActivityNode, newNodeId: string) {
const reqs = new minerva_requests.request_set(this.noctuaUserService.baristaToken, cam.id);

reqs.remove_type_from_individual(
oldNode.classExpression,
oldNode.uuid,
cam.id,
);

let ce

if (oldNode.isComplement) {
ce = new class_expression();
ce.as_complement(newNodeId);
} else {
ce = class_expression.cls(newNodeId)
}

reqs.add_type_to_individual(
ce,
oldNode.uuid,
cam.id,
);

reqs.store_model(cam.id);
return cam.replaceManager.request_with(reqs);
}

toggleIsComplement(cam: Cam, oldNode: ActivityNode) {
const reqs = new minerva_requests.request_set(this.noctuaUserService.baristaToken, cam.id);
const newNodeId = oldNode.term.id;

reqs.remove_type_from_individual(
oldNode.classExpression,
oldNode.uuid,
cam.id,
);

let ce

if (oldNode.isComplement) {
ce = class_expression.cls(newNodeId)
} else {
ce = new class_expression();
ce.as_complement(newNodeId);
}

reqs.add_type_to_individual(
ce,
oldNode.uuid,
cam.id,
);

reqs.store_model(cam.id);
return cam.replaceManager.request_with(reqs);
}


editEvidenceCode(cam: Cam, oldEvidenceCodes: Entity[], newEvidenceCode: string) {
const reqs = new minerva_requests.request_set(this.noctuaUserService.baristaToken, cam.id);
Expand Down
Loading