Skip to content

Commit

Permalink
Added implementation for multiple backbones.
Browse files Browse the repository at this point in the history
  • Loading branch information
wdrav committed Feb 15, 2024
1 parent ffb4eb0 commit cb76a96
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 47 deletions.
125 changes: 98 additions & 27 deletions excelutils/excel_sbol_utils/library3.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import logging
import sbol3
import warnings
import excel_sbol_utils.helpers as helpers
import helpers as helpers


def objectType(rowobj):
Expand Down Expand Up @@ -34,6 +34,7 @@ def addToDescription(rowobj):
'different from': sbol3.SBOL_DIFFERENT_FROM,
'same orientation as': sbol3.SBOL_SAME_ORIENTATION_AS,
'different orientation from': sbol3.SBOL_SAME_ORIENTATION_AS}

def make_constraint(constraint, part_list, template):
m = constraint_pattern.match(constraint)
if not m:
Expand Down Expand Up @@ -63,16 +64,58 @@ def subcomponents(rowobj): #UPDATE TO WORK WITH CELL DICT, ALLOW CONSTRAINTS


if 'backbone' in rowobj.col_cell_dict:
temp = sbol3.Component(identity=f'{rowobj.obj.displayId}_ins_template', types=sbol3.SBO_DNA, name=f'{rowobj.obj.displayId}_ins_template')
newobj = sbol3.CombinatorialDerivation(identity=f'{rowobj.obj.displayId}_ins', template=temp, name=f'{rowobj.obj.displayId}_ins', strategy=sbol3.SBOL_ENUMERATE)
rowobj.doc.add(temp)
rowobj.doc.add(newobj)
rowobj.obj_dict[temp.display_id] = {'uri': temp.type_uri, 'object': temp,
'displayId': temp.display_id}
backbones = list(rowobj.col_cell_dict['backbone'].values())
back = True
oldobj = rowobj.obj
rowobj.obj = newobj
# If this row has a backbone, create a new combinatorial derivation

# Determine if there are multiple comps per part
multiple = False

for sub in rowobj.col_cell_dict['subcomp']:
if "," in rowobj.col_cell_dict['subcomp'][sub]:
multiple = True
break
else:
multiple = False

# 1. If there are multiple comps per part, create ins_templat

if multiple:
temp = sbol3.Component(identity=f'{rowobj.obj.displayId}_ins_template', types=sbol3.SBO_DNA)

newobj = sbol3.CombinatorialDerivation(identity=f'{rowobj.obj.displayId}_ins', template=temp, name=f'{rowobj.obj.name} insert', \
strategy=sbol3.SBOL_ENUMERATE, description=rowobj.obj.description)

rowobj.obj.description = None

rowobj.doc.add(temp) # Add the template
rowobj.doc.add(newobj) # Add the combdev _ins to the document connected to the template

rowobj.obj_dict[temp.display_id] = {'uri': temp.type_uri, 'object': temp,
'displayId': temp.display_id}
backbones = list(rowobj.col_cell_dict['backbone'].values())
backbones = backbones[0].split(", ")

back = True
oldobj = rowobj.obj
rowobj.obj = newobj
else:
# 2. Otherwise, create _ins without the template

# Create new component _ins without the template
newobj = sbol3.Component(identity=f'{rowobj.obj.displayId}_ins', name=f'{rowobj.obj.name} insert', \
description=rowobj.obj.description, types=sbol3.SBO_DNA, roles=sbol3.SO_ENGINEERED_REGION)

# Set description to None
rowobj.obj.description = None

rowobj.doc.add(newobj)

backbones = list(rowobj.col_cell_dict['backbone'].values())
backbones = backbones[0].split(", ")


back = True
oldobj = rowobj.obj
rowobj.obj = newobj
else:
back = False

Expand All @@ -89,19 +132,40 @@ def subcomponents(rowobj): #UPDATE TO WORK WITH CELL DICT, ALLOW CONSTRAINTS
variant_comps = []
comp_ind = 0

# Need to update for multiple backbones, as well as remove hardcoding
# Check SBOL Utilities for reasoning for multiple backbones

if back:
# Currently this code creates a template for the insertion of the backbone into the main combinatorialderivation
tempObj = rowobj.obj_dict[f'{oldobj.display_id}_template']['object']
sub = sbol3.LocalSubComponent(types=sbol3.SBO_DNA, name="Inserted construct")

sub = sbol3.LocalSubComponent(types=sbol3.SBO_DNA, name="Inserted Construct")
tempObj.features.append(sub)
backbone_sub = sbol3.VariableFeature(cardinality=sbol3.SBOL_ONE, variable=sub, variant_derivations=rowobj.obj)
oldobj.variable_features.append(backbone_sub)

subComp = sbol3.SubComponent(instance_of=rowobj.obj_dict[backbones[0]]['object'])
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].features.append(subComp)
constr1 = sbol3.Constraint(restriction=sbol3.SBOL_MEETS, object=subComp, subject=sub)
constr2 = sbol3.Constraint(restriction=sbol3.SBOL_MEETS, object=sub, subject=subComp)
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].constraints.append(constr1)
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].constraints.append(constr2)
if len(backbones) == 1:

subComp = sbol3.SubComponent(instance_of=rowobj.obj_dict[backbones[0]]['object'])
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].features.append(subComp)
constr1 = sbol3.Constraint(restriction=sbol3.SBOL_MEETS, object=subComp, subject=sub)
constr2 = sbol3.Constraint(restriction=sbol3.SBOL_MEETS, object=sub, subject=subComp)
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].constraints.append(constr1)
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].constraints.append(constr2)
else:

newLocalSub = sbol3.LocalSubComponent(name="Vector", types=sbol3.SBO_DNA)
tempObj.features.append(newLocalSub)

newVarFeature = sbol3.VariableFeature(variable=newLocalSub, variants=(rowobj.obj_dict[i]['object'] for i in backbones), cardinality=sbol3.SBOL_ONE)
oldobj.variable_features.append(newVarFeature)

constr1 = sbol3.Constraint(restriction=sbol3.SBOL_MEETS, object=newLocalSub, subject=sub)
constr2 = sbol3.Constraint(restriction=sbol3.SBOL_MEETS, object=sub, subject=newLocalSub)

rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].constraints.append(constr1)
rowobj.obj_dict[f'{oldobj.display_id}_template']['object'].constraints.append(constr2)


else:
temp = rowobj.obj_dict[f'{rowobj.obj.display_id}_template']['object']
Expand All @@ -124,7 +188,7 @@ def subcomponents(rowobj): #UPDATE TO WORK WITH CELL DICT, ALLOW CONSTRAINTS

comp_ind += 1
else:
tempSub = sbol3.SubComponent(name=f'Part {comp_ind}', instance_of=f'{rowobj.obj_dict[comp]["uri"]}', orientation=sbol3.SBOL_INLINE)
tempSub = sbol3.SubComponent(name=f'Part {comp_ind + 1}', instance_of=f'{rowobj.obj_dict[comp]["uri"]}', orientation=sbol3.SBOL_INLINE)
temp.features.append(tempSub)
variant_comps.append(tempSub)
if comp_ind != 0:
Expand Down Expand Up @@ -223,8 +287,8 @@ def sequence(rowobj):
# create sequence object
sequence = sbol3.Sequence(f"{rowobj.obj.namespace}/{rowobj.obj.display_id}_sequence",
elements=val, encoding=sbol3.IUPAC_DNA_ENCODING, namespace=rowobj.obj.namespace)
if rowobj.obj.name is not None:
sequence.name = f"{rowobj.obj.name} Sequence"
# if rowobj.obj.name is not None:
# sequence.name = f"{rowobj.obj.name} Sequence"

rowobj.doc.add(sequence)

Expand All @@ -239,6 +303,11 @@ def sequence(rowobj):

def circular(rowobj): # NOT IMPLEMENTED
# if false add to linear collection if true add to types

tempObj = rowobj.obj
if rowobj.col_cell_dict['Circular'] not in tempObj.types:
tempObj.types.append(rowobj.col_cell_dict['Circular'])

pass

def finalProduct(rowobj):
Expand All @@ -253,28 +322,30 @@ def finalProduct(rowobj):

sbol_objs = doc.objects
sbol_objs_names = [x.name for x in sbol_objs]
if 'FinalProducts' not in sbol_objs_names:
colec = sbol3.Collection('FinalProducts', name='FinalProducts')
if 'Final Products' not in sbol_objs_names:
colec = sbol3.Collection('FinalProducts', name='Final Products')
colec.description = 'Final products desired for actual fabrication'

sbol_objs = doc.objects
sbol_objs_names = [x.name for x in sbol_objs]

doc.add(colec)
colec.members.append(rowobj.obj_uri)
else:
colec = sbol_objs[sbol_objs_names.index('FinalProducts')]
colec = sbol_objs[sbol_objs_names.index('Final Products')]
colec.members.append(rowobj.obj_uri)

if 'LinearDNAProducts' not in sbol_objs_names:
colec = sbol3.Collection('LinearDNAProducts', name='LinearDNAProducts')
if 'Linear DNA Products' not in sbol_objs_names:
colec = sbol3.Collection('LinearDNAProducts', name='Linear DNA Products')
colec.description = 'Linear DNA constructs to be fabricated'

sbol_objs = doc.objects
sbol_objs_names = [x.name for x in sbol_objs]

doc.add(colec)
colec.members.append(rowobj.obj)
else:
colec = sbol_objs[sbol_objs_names.index('LinearDNAProducts')]
colec = sbol_objs[sbol_objs_names.index('Linear DNA Products')]
colec.members.append(rowobj.obj)


Expand Down
21 changes: 21 additions & 0 deletions excelutils/excel_sbol_utils/temp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import sbol2
import sbol3
import excel_sbol_utils.library2 as l2
import excel_sbol_utils.library3 as l3
import excel_sbol_utils.helpers as help
import excel2sbol.comp_column_functions2 as ccf
import excel2sbol.converter as conv
import os

# Build a barebones combinatorial derivation object
# Attempt to build subcomponent on it

obj = sbol2.combinatorialderivation()

doc = sbol2.Document()
obj_dict = {}
sheet = 'Composite Parts'




36 changes: 28 additions & 8 deletions temp3.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import excel_sbol_utils.helpers as h

direct = os.path.split(__file__)[0]
file_path_in = os.path.join(direct, 'SBOL3_simple_library4.nt')
file_path_in = os.path.join(direct, 'two_backbones.nt')

# Purpose: After converting the combinatorial derivations, the references to the objects in other parts must be updated
# Input: SBOL3 Document object, SBOL3 Dictionary of combinatorial derivations after conversion
Expand All @@ -21,11 +21,12 @@ def updateVariableFeatures(doc, combdev):
insert = item + "_ins"
obj = doc.find(insert)

if obj == None:
if obj == None or type(obj) != sbol3.combderiv.CombinatorialDerivation:
ins = False
obj = doc.find(item)
obj.strategy = sbol3.SBOL_ENUMERATE

if ins:
if doc.find(f'{insert}_template'):
template = doc.find(f'{insert}_template')
else:
template = doc.find(f'{item}_template')
Expand All @@ -34,7 +35,21 @@ def updateVariableFeatures(doc, combdev):
# 2: Go through every variable feature
for variable_feature in list(obj.variable_features):

if len(variable_feature.variants) > 1:
# Go through and ensure that variantderivations are correct

removeList = []
addList = []
for variant in variable_feature.variants:
if str(variant) in combdev:
addList.append(variant)
removeList.append(variant)

for item in removeList:
variable_feature.variants.remove(item)
for item in addList:
variable_feature.variant_derivations.append(item)

if len(variable_feature.variants) > 1 or len(variable_feature.variant_derivations) > 0:
continue # Leave as a variable feature
else:
variant = variable_feature.variants[0]
Expand Down Expand Up @@ -63,6 +78,7 @@ def updateVariableFeatures(doc, combdev):

template.features.remove(localsub)
obj.variable_features.remove(variable_feature)



if edited:
Expand Down Expand Up @@ -93,7 +109,7 @@ def updateVariableFeatures(doc, combdev):

# Copy the variable features and add them to copiedVariableFeatures

copyFeature = sbol3.VariableFeature(variants=variable_feature.variants, name=variable_feature.name, variable=variable_feature.variable, cardinality=variable_feature.cardinality)
copyFeature = sbol3.VariableFeature(variants=variable_feature.variants, variant_derivations=variable_feature.variant_derivations, name=variable_feature.name, variable=variable_feature.variable, cardinality=variable_feature.cardinality)
copiedVariableFeatures[number] = copyFeature

# Remove the variable feature from the object
Expand Down Expand Up @@ -264,11 +280,14 @@ def updateDescriptions(doc):
if type(obj) == sbol3.Collection:
for item in list(obj.members):
temp = doc.find(item)
if not temp:
continue

if "_ins" in temp.name:
continue
if temp.description == None:
temp.description = ""
if doc.find(item + "_ins") == None:
temp.description = ""

return doc

Expand Down Expand Up @@ -305,7 +324,8 @@ def convCombDeriv(file_path_in):
if ins in dictionaryObj:
combdev[item] = dictionaryObj[item]
tempcombdev.pop(item)
tempcombdev.pop(ins)
if ins in tempcombdev:
tempcombdev.pop(ins)


# 2. Go through the remaining combinatorial derivation objects and check each variable feature to see if it has more than one variant
Expand Down Expand Up @@ -404,5 +424,5 @@ def convCombDeriv(file_path_in):
doc = updateCollectionNames(doc)
doc = updateDescriptions(doc)

file_path_out = "SampleTemp3Output.nt"
file_path_out = "two_backbones_ud.nt"
doc.write(file_path_out, file_format="sorted nt")
20 changes: 14 additions & 6 deletions two_backbones.nt
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,16 @@
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature1> <http://sbols.org/v3#variable> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature1> <http://sbols.org/v3#variantDerivation> <http://sbolstandard.org/testfiles/Two_by_six_ins> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#VariableFeature> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> <http://sbols.org/v3#cardinality> <http://sbols.org/v3#one> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> <http://sbols.org/v3#displayId> "VariableFeature2" .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> <http://sbols.org/v3#variable> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> <http://sbols.org/v3#variant> <http://sbolstandard.org/testfiles/pOpen_v4> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> <http://sbols.org/v3#variant> <http://sbolstandard.org/testfiles/pSB1C3> .
<http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#VariableFeature> .
<http://sbolstandard.org/testfiles/Two_by_six> <http://sbols.org/v3#displayId> "Two_by_six" .
<http://sbolstandard.org/testfiles/Two_by_six> <http://sbols.org/v3#hasNamespace> <http://sbolstandard.org/testfiles> .
<http://sbolstandard.org/testfiles/Two_by_six> <http://sbols.org/v3#hasVariableFeature> <http://sbolstandard.org/testfiles/Two_by_six/VariableFeature1> .
<http://sbolstandard.org/testfiles/Two_by_six> <http://sbols.org/v3#hasVariableFeature> <http://sbolstandard.org/testfiles/Two_by_six/VariableFeature2> .
<http://sbolstandard.org/testfiles/Two_by_six> <http://sbols.org/v3#name> "Two by six" .
<http://sbolstandard.org/testfiles/Two_by_six> <http://sbols.org/v3#template> <http://sbolstandard.org/testfiles/Two_by_six_template> .
<http://sbolstandard.org/testfiles/Two_by_six> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#CombinatorialDerivation> .
Expand Down Expand Up @@ -183,27 +190,28 @@
<http://sbolstandard.org/testfiles/Two_by_six_ins_template> <http://sbols.org/v3#type> <https://identifiers.org/SBO:0000251> .
<http://sbolstandard.org/testfiles/Two_by_six_ins_template> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#Component> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> <http://sbols.org/v3#displayId> "Constraint1" .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> <http://sbols.org/v3#object> <http://sbolstandard.org/testfiles/Two_by_six_template/SubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> <http://sbols.org/v3#object> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> <http://sbols.org/v3#restriction> <http://sbols.org/v3#meets> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> <http://sbols.org/v3#subject> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#Constraint> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> <http://sbols.org/v3#displayId> "Constraint2" .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> <http://sbols.org/v3#object> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> <http://sbols.org/v3#restriction> <http://sbols.org/v3#meets> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> <http://sbols.org/v3#subject> <http://sbolstandard.org/testfiles/Two_by_six_template/SubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> <http://sbols.org/v3#subject> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> .
<http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#Constraint> .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> <http://sbols.org/v3#displayId> "LocalSubComponent1" .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> <http://sbols.org/v3#name> "Inserted Construct" .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> <http://sbols.org/v3#type> <https://identifiers.org/SBO:0000251> .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#LocalSubComponent> .
<http://sbolstandard.org/testfiles/Two_by_six_template/SubComponent1> <http://sbols.org/v3#displayId> "SubComponent1" .
<http://sbolstandard.org/testfiles/Two_by_six_template/SubComponent1> <http://sbols.org/v3#instanceOf> <http://sbolstandard.org/testfiles/pSB1C3> .
<http://sbolstandard.org/testfiles/Two_by_six_template/SubComponent1> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#SubComponent> .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> <http://sbols.org/v3#displayId> "LocalSubComponent2" .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> <http://sbols.org/v3#name> "Vector" .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> <http://sbols.org/v3#type> <https://identifiers.org/SBO:0000251> .
<http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#LocalSubComponent> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#displayId> "Two_by_six_template" .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#hasConstraint> <http://sbolstandard.org/testfiles/Two_by_six_template/Constraint1> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#hasConstraint> <http://sbolstandard.org/testfiles/Two_by_six_template/Constraint2> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#hasFeature> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#hasFeature> <http://sbolstandard.org/testfiles/Two_by_six_template/SubComponent1> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#hasFeature> <http://sbolstandard.org/testfiles/Two_by_six_template/LocalSubComponent2> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#hasNamespace> <http://sbolstandard.org/testfiles> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://sbols.org/v3#type> <https://identifiers.org/SBO:0000251> .
<http://sbolstandard.org/testfiles/Two_by_six_template> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://sbols.org/v3#Component> .
Expand Down
Binary file modified two_backbones.xlsx
Binary file not shown.
Loading

0 comments on commit cb76a96

Please sign in to comment.