libSBOLpy is a wrapper around libSBOLc, the C library for the Synthetic Biology Open Language (SBOL).
To use SBOL in your own code, copy the sbol
folder somewhere on your PYTHONPATH
. Then you can start writing:
import sbol
# create document
doc = sbol.Document()
# create components
dc1 = sbol.DNAComponent(doc, 'http://example.com/dc1')
dc2 = sbol.DNAComponent(doc, 'http://example.com/dc2')
dc1.display_id = 'DC1'
dc2.display_id = 'DC2'
dc1.name = 'DnaComponent1'
dc2.name = 'DnaComponent2'
dc1.description = 'DnaComponent with one sequence annotation'
dc2.description = 'Another DNA component'
# add seqeuence
ds1 = sbol.DNASequence(doc, 'http://example.com/ds1')
ds1.nucleotides = 'tccctatcagtgat'
dc1.sequence = ds1
# add annotation
sa1 = sbol.SequenceAnnotation(doc, 'http://example.com/sa1')
sa1.subcomponent = dc2
dc1.annotations += sa1
# write to file
doc.write('valid04_dna_component_annotation.xml')
Note: if you try to import sbol
and the interpreter crashes with an error like "Py_GetThreadedState...", you're probably using the wrong Python version. libSBOLpy currently works with Python 2.6 and 2.7.
You can also access the low-level wrapper directly:
from sbol import libsbol
That could be useful for prototyping C algorithms in the Python interpreter.
You can run python sbol/sbol_test.py
to verify that everything is working.
But a word of caution! The tests aren't comprehensive--in fact, they just test getting and setting each property of each of the SBOL core objects. Please report anything weird that happens while using the module! It's not always straightforward getting the Python garbage collector to free the right pointers at the right times, and fairly "minor" bugs in memory management can crash the interpreter.
Here's a quick breakdown of the source files:
-
__init__.py is a one-liner.
-
_libsbol.so and libsbol.py are generated by SWIG as part of a libSBOLc build. They shouldn't be modified directly. If you do need to change something, make the changes in libSBOLc and copy over the updated files.
-
sbol.py is a high-level wrapper around the SWIG wrapper. It defines proxy objects that behave (more or less) pythonically, but actually do everything with calls to libsbol.py.
-
sbol_test.py contains the unit tests.
If you come across something that needs to be changed in the C code, see "Updating the Python wrapper" in the libSBOLc documentation. It's actually pretty quick--that is, once you've checked out libSBOLc and installed CMake and SWIG.