Skip to content
161 changes: 161 additions & 0 deletions examples/sbol2/CreatingSBOL2Objects/SequenceConstraint.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using `SequenceConstraint` to place restrictions on `Components` within the same `ComponentDefinition`\n",
"\n",
"`SequenceConstraints` are used to describe the relative position and orientation between two components within the same `ComponentDefinition`. \n",
"\n",
"A minimally useful version of this object requires the existence of:\n",
"\n",
"- a parent ComponentDefinition\n",
"- Two child Components\n",
"\n",
"### Four Restriction Types:\n",
"1. `SBOL_RESTRICTION_PRECEDES`: `Component_A` precedes `Component_B` \n",
"2. `SBOL_RESTRICTION_SAME_ORIENTATION_AS`: The two `Components` have the same orrientation as each other\n",
"3. `SBOL_RESTRICTION_OPPOSITE_ORIENTATION_AS`: The two `Components` have the opposite orrientation as each other\n",
"4. `SBOL_RESTRICTION_DIFFERENT_FROM`: The two `Components` do not refer to the same `ComponentDefinition`\n",
"\n",
"For more information on the `SequenceConstraint` class and its properties, check out page 36 of the [SBOL 2.3.0 specifications](https://sbolstandard.org/docs/SBOL2.3.0.pdf).\n",
"\n",
"We will demonstrate `SBOL_RESTRICTION_PRECEDES` using the [Part:BBa_K174004](https://parts.igem.org/Part:BBa_K174004), a pspac promoter, designed by the The Newcastle 2009 iGEM team. The genetic device has two parts, a pspac promoter and a Lac operator, with the promoter directly preceding the operator. We can use `SBOL_RESTRICTION_PRECEDES` to model this relationship."
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"import sbol2\n",
"import sbol2.sequenceconstraint\n",
"\n",
"# Create a new SBOL document\n",
"doc = sbol2.Document()\n",
"\n",
"# Set the homespace (namespace) for the document\n",
"sbol2.setHomespace('https://github.com/SynBioDex/SBOL-Notebooks')\n",
"\n",
"\n",
"# Create a ComponentDefinition for the LacI operator\n",
"lacI_operator_comp_def = sbol2.ComponentDefinition('LacI_operator', sbol2.BIOPAX_DNA)\n",
"lacI_operator_comp_def.description = 'LacI binding site'\n",
"# The role \"SO:0000057\" is for an operator, as defined in the Sequence Ontology\n",
"lacI_operator_comp_def.roles = [\"http://identifiers.org/so/SO:0000057\"]\n",
"doc.addComponentDefinition(lacI_operator_comp_def)\n",
"\n",
"# Create a ComponentDefinition for the pspac promoter\n",
"pspac_promotor_comp_def = sbol2.ComponentDefinition('pspac', sbol2.BIOPAX_DNA)\n",
"pspac_promotor_comp_def.roles = [sbol2.SO_PROMOTER]\n",
"doc.addComponentDefinition(pspac_promotor_comp_def)\n",
"\n",
"# Create a ComponentDefinition for the genetic part\n",
"genetic_part_comp_def = sbol2.ComponentDefinition('BBa_K174004', sbol2.BIOPAX_DNA)\n",
"genetic_part_comp_def.description = 'pspac core promoter region'\n",
"genetic_part_comp_def.roles = [sbol2.SO_PROMOTER]\n",
"doc.addComponentDefinition(genetic_part_comp_def)\n",
"\n",
"# Create a Component instance for the pspac promoter and add it to the genetic part\n",
"pspac_promoter_comp = sbol2.Component('pspac')\n",
"pspac_promoter_comp.definition = pspac_promotor_comp_def.identity\n",
"genetic_part_comp_def.components.add(pspac_promoter_comp)\n",
"\n",
"# Create a Component instance for the LacI operator and add it to the genetic part\n",
"LacI_operator_comp = sbol2.Component('LacI_operator')\n",
"LacI_operator_comp.definition = lacI_operator_comp_def.identity\n",
"genetic_part_comp_def.components.add(LacI_operator_comp)\n",
"\n",
"# Create a SequenceConstraint specifying that the pspac promoter precedes the LacI operator\n",
"constraint = genetic_part_comp_def.sequenceConstraints.create('Constraint1')\n",
"constraint.subject = pspac_promoter_comp.identity # Set the subject to the identity of pspac promoter\n",
"constraint.object = LacI_operator_comp.identity # Set the object to the identity of LacI operator\n",
"constraint.restriction = sbol2.SBOL_RESTRICTION_PRECEDES # Use the SBOL_RESTRICTION_PRECEDES restriction\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you can see, creating a `SequenceConstraint` is very easy, as all that is needed are two `Components` within the same parent `ComponentDefinition`. For our next step, we will show off some of the functionality of `SequenceConstraint`. One useful aspect of `SequenceConstraint` is that if we have specified the `Sequences` of the individual Components we can calculate the `Sequence` of the entire Genetic part."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Create the pspac sequence\n",
"pspac_sequence = sbol2.Sequence('pspac_sequence')\n",
"pspac_sequence.elements = 'ttgttgactttatctacaaggtgtggcataatgtgtgg'\n",
"pspac_sequence.encoding = sbol2.SBOL_ENCODING_IUPAC\n",
"pspac_promotor_comp_def.sequence = pspac_sequence\n",
"\n",
"# Create the LacI sequence\n",
"LacI_sequence = sbol2.Sequence('LacI_sequence')\n",
"LacI_sequence.elements = 'attgtgagcgctcacaatt'\n",
"LacI_sequence.encoding = sbol2.SBOL_ENCODING_IUPAC\n",
"lacI_operator_comp_def.sequence = LacI_sequence"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<bound method ComponentDefinition.compile of <sbol2.componentdefinition.ComponentDefinition object at 0x0000023F6B6D3DF0>>\n"
]
},
{
"data": {
"text/plain": [
"'Valid.'"
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"print(genetic_part_comp_def.compile)\n",
"\n",
"\n",
"\n",
"# Validate the document to ensure compliance with SBOL standards\n",
"doc.validate()\n",
"\n",
"# Save the document to an SBOL file\n",
"doc.write('sequence_constraint_example.xml')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "SBOL-test",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.14"
}
},
"nbformat": 4,
"nbformat_minor": 2
}