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

A notebook that creates an example of an SBOL2 Component #33

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
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
171 changes: 171 additions & 0 deletions examples/sbol2/CreatingSBOL2Objects/Component.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Introduction\n",
"\n",
"A `Component` is used to compose `ComponentDefinition` objects into a structural hierarchy. For example, the `ComponentDefinition` of a gene could contain four `Component` objects: a promoter, RBS, CDS, and terminator. In turn, the `ComponentDefinition` of the promoter `Component` could contain Component objects defined as various operator sites.\n",
"\n",
"`Component` objects have the following properties of note:\n",
"\n",
"- `definition`: Identifies the `ComponentDefinition` that provides the detailed description or blueprint for the Component. It is `MANDATORY`.\n",
"\n",
"- `roles`: describes the expected purpose and function of the component. Used when the `role` of the component differes from that of the `sub-componentDefinition`. For example, A component Definition that is an activator is being used as a repressor. \n",
"\n",
"- `roleIntegration`: Specifies the relationship between a Component instance’s own set of roles and the set of roles on the included sub-ComponentDefinition. It is only mandatory to set if one or more `roles` are set. It can be set to:\n",
" 1. `SBOL_ROLE_INTEGRATION_MERGE`: This option combines the roles from both the current Component and the included sub-ComponentDefinition, resulting in the union of their roles​. It is the default.\n",
" 2. `SBOL_ROLE_INTEGRATION_OVERRIDE`: This option instructs that any roles specified for the included sub-ComponentDefinition should be ignored, and only the roles explicitly defined for the current Component should be used.\n",
"\n",
"- `sourceLocations`: Indicates which elements of a `ComponentDefinition`'s `Sequence` are to be included in the `Component`'s Parent. It is optional. If it is not set, the whole `Sequence` is assumed to be included.\n",
"\n",
"- `mapsTo`: Defines relationships between `Component` objects in different contexts, such as hierarchical designs. For details, see the `MapsTo` Notebook.\n",
"\n",
"- `access`: the access property of a Component controls whether it can be referenced by other components or modules through a `MapsTo` object. There are two options:\n",
"\n",
" 1. `SBOL_ACCESS_PUBLIC`: The component is visible and accessible to other designs, meaning it can be used in different parts of a larger system.\n",
" 2. `SBOL_ACCESS_PRIVATE`: The component is only accessible within the design it belongs to and cannot be used by external components.\n",
"\n",
"- `measures`: The measures property is OPTIONAL and MAY contain a set of Measure objects. For details, see the `Measures` Notebook.\n",
"\n",
"For more information on the `Component` class and its properties, check out page 28 of the SBOL 2.3.0 specifications, which can be found at the following [link](https://sbolstandard.org/docs/SBOL2.3.0.pdf)."
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
"# import dependency\n",
"import sbol2\n",
"\n",
"# Create the document and set the namespace\n",
"doc = sbol2.Document()\n",
"sbol2.setHomespace('https://github.com/SynBioDex/SBOL-Notebooks')\n",
"\n",
"# Create a Sequence object for the genetic construct\n",
"genetic_construct_sequence = sbol2.Sequence('genetic_construct_sequence')\n",
"genetic_construct_sequence.elements = 'ATGCGTACGATCGTAAAGAGGAGAAAATGCGTACGTAGCTAGTCTGATCGTAGCTAGTTGGCTCTGGTTTACTGGGCG'\n",
"genetic_construct_sequence.encoding = sbol2.SBOL_ENCODING_IUPAC\n",
"doc.addSequence(genetic_construct_sequence)\n",
"\n",
"# Create a ComponentDefinition object to house the genetic construct sequence\n",
"genetic_construct_cd = sbol2.ComponentDefinition('genetic_construct_component_definition', component_type=sbol2.BIOPAX_DNA)\n",
"genetic_construct_cd.addRole(sbol2.SBO_GENE)\n",
"genetic_construct_cd.sequence = genetic_construct_sequence\n",
"doc.addComponentDefinition(genetic_construct_cd)\n",
"\n"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Steps in Creating A `Component`"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
"# --- First Component: Promoter ---\n",
"# Step 1: Ceate a ComponentDefinition object for the promoter\n",
"promoter_component_definition = sbol2.ComponentDefinition('promoter_component_definition', component_type=sbol2.BIOPAX_DNA)\n",
"promoter_component_definition.addRole(sbol2.SO_PROMOTER)\n",
"doc.addComponentDefinition(promoter_component_definition)\n",
"\n",
"# Step 2: Create a Component object for the promoter\n",
"promotor_component = sbol2.Component('promoter_comoponent')\n",
"\n",
"# Step 3: Connect the Component object to the ComponentDefinition object through the definition property\n",
"promotor_component.definition = promoter_component_definition\n",
"\n",
"# Step 4: Add the Component to the the components list in the parent ComponentDefinition\n",
"genetic_construct_cd.components.add(promotor_component)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can also specify which elements of the gene-construct `ComponentDefinition` is to be included in the promoter. Let us say that the promoter spans the first 26 DNA nucleotides of the gene-construct."
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# Create a range objects to specify the location of the promotor on the genetic construct sequence\n",
"promotor_range = sbol2.Range('promoter_range', start=1, end=26)\n",
"promotor_component.sourceLocations.add(promotor_range)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Creating the CDS `Component`\n",
"We will now create a second Sub-Component for the gene-construct: A CDS. "
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"\n",
"# --- Second Component: CDS ---\n",
"# Step 1: Ceate a ComponentDefinition object for the promoter\n",
"cds_component_definition = sbol2.ComponentDefinition('cds_component_definition', component_type=sbol2.BIOPAX_DNA)\n",
"cds_component_definition.addRole(sbol2.SO_CDS)\n",
"\n",
"doc.addComponentDefinition(cds_component_definition)\n",
"\n",
"# Step 2: Create a Component object for the promoter\n",
"cds_component = sbol2.Component('cds_component')\n",
"\n",
"# Step 3: Connect the Component object to the ComponentDefinition object through the definition property\n",
"cds_component.definition = cds_component_definition\n",
"\n",
"# Step 4: Add the Component to the the components list in the parent ComponentDefinition\n",
"genetic_construct_cd.components.add(cds_component)\n",
"\n",
"\n",
"# Check if the SBOL document is valid\n",
"doc.validate()\n",
"\n",
"# Save the document to an SBOL file\n",
"doc.write('component_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
}