Skip to content

Commit

Permalink
A notebook that creates an example of an SBOL2 generic location using…
Browse files Browse the repository at this point in the history
… pysbol2. This addresses #26
  • Loading branch information
PrashantVaidyanathan committed Sep 14, 2024
1 parent f4d88c5 commit ef9b136
Showing 1 changed file with 143 additions and 0 deletions.
143 changes: 143 additions & 0 deletions examples/sbol2/CreatingSBOL2Objects/GenericLocation.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Using `GenericLocation` to Define Regions on a Sequence\n",
"\n",
"In some cases, a region may not have well-defined boundaries, or the sequence might be incomplete. In such cases, we can use the `GenericLocation` class in SBOL to annotate regions where the precise start and end points are not required.\n",
"\n",
"This is especially useful in synthetic biology for:\n",
"- Annotating regions with unknown or non-linear sequences.\n",
"- Handling circular DNA or non-linear structures.\n",
"- Providing sequence annotations for partially designed components.\n",
"\n",
"In this example, we'll create a sequence and annotate it using `GenericLocation`, specifying two regions: one on the forward strand (`inline`) and another on the reverse strand (`reverse complement`)."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"import sbol2\n",
"\n",
"# Create an SBOL document\n",
"doc = sbol2.Document()\n",
"\n",
"# Set a namespace for the document\n",
"sbol2.setHomespace('https://github.com/SynBioDex/SBOL-Notebooks')\n",
"\n",
"# Create a Sequence object with an arbitrary DNA sequence\n",
"sequence_elements = 'ATGCGTACGTAGCTAGTCTGATCGTAGCTAGTCGATGCA'\n",
"seq = sbol2.Sequence('example_sequence')\n",
"seq.elements = sequence_elements\n",
"seq.encoding = sbol2.SBOL_ENCODING_IUPAC\n",
"\n",
"# Add the sequence to the document\n",
"doc.addSequence(seq)\n",
"\n",
"# Create a ComponentDefinition for the sequence\n",
"comp_def = sbol2.ComponentDefinition('example_component', sbol2.BIOPAX_DNA)\n",
"comp_def.sequences = [seq.identity] # Link the sequence to the ComponentDefinition\n",
"\n",
"# Add the ComponentDefinition to the document\n",
"doc.addComponentDefinition(comp_def)\n",
"\n",
"# --- GenericLocation 1: Forward Strand (SBOL_ORIENTATION_INLINE) with sequence reference ---\n",
"# Create a SequenceAnnotation for a region on the forward strand\n",
"forward_annotation = sbol2.SequenceAnnotation('forward_region_annotation')\n",
"\n",
"# Define a GenericLocation for a region on the forward strand and link it to the sequence\n",
"forward_generic_location = sbol2.GenericLocation('forward_generic_location')\n",
"forward_generic_location.orientation = sbol2.SBOL_ORIENTATION_INLINE\n",
"forward_generic_location.sequence = comp_def.sequences[0] # Reference the sequence in the ComponentDefinition\n",
"\n",
"# Add the GenericLocation to the SequenceAnnotation\n",
"forward_annotation.locations.add(forward_generic_location)\n",
"\n",
"# Add the SequenceAnnotation to the ComponentDefinition\n",
"comp_def.sequenceAnnotations.add(forward_annotation)\n",
"\n",
"# --- GenericLocation 2: Reverse Complement Strand (SBOL_ORIENTATION_REVERSE_COMPLEMENT) without sequence reference ---\n",
"# Create a SequenceAnnotation for a region on the reverse complement strand\n",
"reverse_annotation = sbol2.SequenceAnnotation('reverse_region_annotation')\n",
"\n",
"# Define a GenericLocation for a region on the reverse complement strand (no sequence reference)\n",
"reverse_generic_location = sbol2.GenericLocation('reverse_generic_location')\n",
"reverse_generic_location.orientation = sbol2.SBOL_ORIENTATION_REVERSE_COMPLEMENT\n",
"\n",
"# Add the GenericLocation to the SequenceAnnotation\n",
"reverse_annotation.locations.add(reverse_generic_location)\n",
"\n",
"# Add the SequenceAnnotation to the ComponentDefinition\n",
"comp_def.sequenceAnnotations.add(reverse_annotation)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Valid.'"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Validate the document to ensure compliance with SBOL standards\n",
"doc.validate()"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Valid.'"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"# Save the document to an SBOL file\n",
"doc.write('generic_location_example.xml')"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "sbol_env",
"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.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 2
}

0 comments on commit ef9b136

Please sign in to comment.