Skip to content

Commit

Permalink
Add sequence annotations to all template CDs and fix abstract represe…
Browse files Browse the repository at this point in the history
…ntation in SBOL
  • Loading branch information
vidyaap committed Jul 24, 2020
1 parent b1fcf8a commit 3d16884
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = Object.freeze({
COMBINATORIAL: '_derivation',
GENERIC_LOCATION: '_generic_location',
SEQUENCE_ANNOTATION: 'sequence_annotation',
SEQUENCE_CONSTRAINT: '_sequence_constraint',
SEQUENCE_CONSTRAINT: 'sequence_constraint',
COMPONENT: '_component',
VARIABLE: '_variable',
ORREGION: 'or_unit',
Expand Down
11 changes: 8 additions & 3 deletions lib/edgeSBOL.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,20 +292,25 @@ function generateCombinatorialSBOL(stateGraph, categories, designName, numDesign
for (let role in categories[atomText]) {
// if abstract part
if (categories[atomText][role].length === 0) {
collection.addMember(sbolDoc.makeAtomComponentDefinition(role, [role], true));
if (!sbolDoc.atomMap[atomText].collection){
let abstractCD = sbolDoc.makeAtomComponentDefinition(role, [role], true);
collection.addMember(abstractCD);
if (!sbolDoc.atomMap[atomText].collections){
sbolDoc.atomMap[atomText].collections = [];
}
sbolDoc.atomMap[atomText].collections.push(collection);
sbolDoc.atomMap[atomText].abstract = true;
// for abstract parts, store the CD in the atom map to reference later
sbolDoc.atomMap[atomText].compDef = abstractCD;
continue;
}
// if not abstract part
for (let id of categories[atomText][role]) {
collection.addMember(sbolDoc.makeAtomComponentDefinition(id, [role]));
if (!sbolDoc.atomMap[atomText].collection){
if (!sbolDoc.atomMap[atomText].collections){
sbolDoc.atomMap[atomText].collections = [];
}
sbolDoc.atomMap[atomText].collections.push(collection);
sbolDoc.atomMap[atomText].abstract = false;
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions lib/nodeSBOL.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,20 +183,25 @@ function generateCombinatorialSBOL(stateGraph, categories, designName, numDesign
for (let role in categories[atomText]) {
// if no IDs in a role, create member for the role instead (abstract)
if (categories[atomText][role].length === 0) {
collection.addMember(sbolDoc.makeAtomComponentDefinition(role, [role], true));
if (!sbolDoc.atomMap[atomText].collection){
let abstractCD = sbolDoc.makeAtomComponentDefinition(role, [role], true);
collection.addMember(abstractCD);
if (!sbolDoc.atomMap[atomText].collections){
sbolDoc.atomMap[atomText].collections = [];
}
sbolDoc.atomMap[atomText].collections.push(collection);
sbolDoc.atomMap[atomText].abstract = true;
// for abstract parts, store the CD in the atom map to reference later
sbolDoc.atomMap[atomText].compDef = abstractCD;
continue;
}
// if not abstract
for (let id of categories[atomText][role]) {
collection.addMember(sbolDoc.makeAtomComponentDefinition(id, [role]));
if (!sbolDoc.atomMap[atomText].collection){
if (!sbolDoc.atomMap[atomText].collections){
sbolDoc.atomMap[atomText].collections = [];
}
sbolDoc.atomMap[atomText].collections.push(collection);
sbolDoc.atomMap[atomText].abstract = false;
}
}
}
Expand Down
39 changes: 25 additions & 14 deletions lib/sbol.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ class sbolGeneration {
}
}

static createVariantComponentObj(operator, component, variantDVs, collections){
static createVariantComponentObj(operator, name, component, variantDVs, collections){
return {
operator: operator,
name: name,
component: component,
variantDVs: variantDVs,
collections: collections
Expand Down Expand Up @@ -104,9 +105,9 @@ class sbolGeneration {
if (stacks.templates.length > 0){
// if there's already a template on the stack, then add component to the template
const lastTemplate = stacks.templates[stacks.templates.length-1].template;
const component = this.makeComponent(componentDefinition, lastTemplate);
const component = this.makeComponent(componentDefinition, name, lastTemplate);
lastTemplate.addComponent(component);
stacks.variantComponents.push(sbolGeneration.createVariantComponentObj(operator, component, variantDerivations, collections));
stacks.variantComponents.push(sbolGeneration.createVariantComponentObj(operator, name, component, variantDerivations, collections));
}else{
// else, this is a new componentDef for the root
stacks.componentDefs.push(sbolGeneration.createComponentDefObj(operator, componentDefinition, variantDerivations, collections, name));
Expand All @@ -131,7 +132,7 @@ class sbolGeneration {
if (!stackObj.componentDef) {
stackObj.componentDef = this.makeComponentDefinition(stackObj.name);
}
component = this.makeComponent(stackObj.componentDef, templateCD);
component = this.makeComponent(stackObj.componentDef, stackObj.name, templateCD);
templateCD.addComponent(component);
}

Expand All @@ -148,7 +149,7 @@ class sbolGeneration {

object = component;
if (subject && object){
const sequenceConstraint = this.makeSequenceConstraint(templateCD, subject, object);
const sequenceConstraint = this.makeSequenceConstraint(templateCD, name, subject, object);
templateCD.addSequenceConstraint(sequenceConstraint);
}
subject = object;
Expand Down Expand Up @@ -291,6 +292,9 @@ class sbolGeneration {

makeComponentDefinition(name, variantDerivations, makeTemplate, makeRoot) {
if(name in this.atomMap && !makeTemplate && !makeRoot){
if (this.atomMap[name].abstract) {
return this.atomMap[name].compDef;
}
return this.makeTemplateSubCD(name);
}

Expand Down Expand Up @@ -320,13 +324,14 @@ class sbolGeneration {
if(!makeTemplate && !makeRoot){
if (!this.atomMap[name]) {
this.atomMap[name] = {};
this.atomMap[name].locURI = constants.INLINE_URI;
}
this.atomMap[name].componentDefinition = componentDefinition;
}
return componentDefinition;
}

makeComponent(componentDefinition, template){
makeComponent(componentDefinition, name, template){
let num = 1;
// make name unique if component is already in the template
for (let comp of template.components){
Expand All @@ -335,7 +340,7 @@ class sbolGeneration {
}
}

const displayId = componentDefinition.displayId + constants.COMPONENT + num;
const displayId = name + constants.COMPONENT + num;
const persistentId = template.persistentIdentity + constants.DELIMITER + displayId;
const atomComponent = this.doc.component(persistentId + constants.DELIMITER + constants.VERSION);
atomComponent.displayId = displayId;
Expand Down Expand Up @@ -370,9 +375,9 @@ class sbolGeneration {
return variableComponent;
}

makeSequenceConstraint(templateCD, subject, object){
makeSequenceConstraint(templateCD, name, subject, object){
//subject precedes object
let displayId = templateCD.displayId + constants.SEQUENCE_CONSTRAINT + this.sequenceConstraintCount;
let displayId = constants.SEQUENCE_CONSTRAINT + this.sequenceConstraintCount;
const persistentId = templateCD.persistentIdentity + constants.DELIMITER + displayId;
const sequenceConstraint = this.doc.sequenceConstraint(persistentId + constants.DELIMITER + constants.VERSION);
sequenceConstraint.displayId = displayId;
Expand Down Expand Up @@ -405,7 +410,17 @@ class sbolGeneration {
switch (key) {
case constants.ATOM:
if (!fromOr) {
this.addToStacks(stacks, stackObj[key], constants.ONE, null, null);
if (!this.atomMap[stackObj[key]].abstract) {
this.addToStacks(stacks, stackObj[key], constants.ONE, null, null);
} else { // if something is an abstract part, don't make a new CD for it but add the rest of the information to the stacks
let collections = [];
let operator = constants.ONE;
if (this.atomMap[stackObj[key]]){
collections = this.atomMap[stackObj[key]].collections;
operator = this.atomMap[stackObj[key]].operator;
}
stacks.componentDefs.push({operator, name: stackObj[key], collections});
}
} else { // single atoms that are being OR-ed do not need their own ComponentDefinitions
let collections = [];
let operator = constants.ONE;
Expand All @@ -427,15 +442,11 @@ class sbolGeneration {
for (let orRegion of stackObj[key]){
let orStack = [];
this.makeSBOLFromStack(orRegion, orStack, true);
if (orStack.length === 1 && orStack[0].operator === constants.ONE){
orCollections.push(...orStack[0].collections);
} else {
let orSubIdentity = orIdentity + constants.ORSUBREGION + orSubRegionCount;
orSubRegionCount += 1;
const orTemplate = this.makeComponentDefinition(orSubIdentity, [], true);
const cv = this.addComponentsAndRestraintsToTemplate(orTemplate, orStack, null, orSubIdentity);
variantDerivations.push(cv);
}
}
break;
case constants.ONE_MORE: //fall through
Expand Down

0 comments on commit 3d16884

Please sign in to comment.