Skip to content

Commit

Permalink
duplicate annos now only removed if they have equal ranges as well as…
Browse files Browse the repository at this point in the history
… id's
  • Loading branch information
doublergreer committed Aug 2, 2024
1 parent c9c7055 commit 2aae316
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
14 changes: 9 additions & 5 deletions apps/web/src/modules/sbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,16 +200,20 @@ export function hasSequenceAnnotationSBOL(componentDefinition, annotationId) {
* @param {array} sequenceAnnotations
*/
export function removeDuplicateComponentAnnotation(componentDefinition, id) {
console.log(id)
if (!hasSequenceAnnotationSBOL(componentDefinition, id))
return

const duplicateAnnotation = componentDefinition.sequenceAnnotations.find(sa => sa.persistentIdentity == id)
const associatedComponent = duplicateAnnotation.component

const annotation = componentDefinition.sequenceAnnotations.find(sa => sa.persistentIdentity == id)
const associatedComponent = annotation.component
const origIdNum = Number(id.slice(-1)) - 1
const originalAnnotation = componentDefinition.sequenceAnnotations.find(sa => sa.persistentIdentity == id.slice(0, -1) + origIdNum)

annotation.destroy()
associatedComponent.destroy()
if (originalAnnotation.rangeMax === duplicateAnnotation.rangeMax && originalAnnotation.rangeMin === duplicateAnnotation.rangeMin) {
console.log("removing duplicate annotation: " + duplicateAnnotation.displayId)
duplicateAnnotation.destroy()
associatedComponent.destroy()
}
}

/**
Expand Down
3 changes: 0 additions & 3 deletions apps/web/src/modules/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,8 @@ export const useStore = create((set, get) => ({

//remove duplicate annotation and component instance
for (const rootAnno of get().document.root.sequenceAnnotations) {
console.log(rootAnno.persistentIdentity)
for (const anno of annotations) {
if (rootAnno.persistentIdentity && (anno.id.slice(0, -2) === rootAnno.persistentIdentity.slice(0, -2) && rootAnno.persistentIdentity.slice(-1) >= 2)) { //potential bug: persistentIdentities may match but locations are different. The second instance will be removed if the part appears multiple times in the sequence
console.log("duplicate: " + rootAnno.persistentIdentity)
removeDuplicateComponentAnnotation(get().document.root, rootAnno.persistentIdentity)
}
}
Expand All @@ -162,7 +160,6 @@ export const useStore = create((set, get) => ({

//if disabled(in annos array but enabled=false), REMOVE: component & sequence annotation (children of root component definition), component definition, associated sequence
for (const anno of annotations) {
console.log(anno.id + " enabled=" + anno.enabled)
if (!anno.enabled) removeAnnotationWithDefinition(get().document.root, anno.id)
}

Expand Down

0 comments on commit 2aae316

Please sign in to comment.