sbol_utilities.helper_functions
Module Contents
Classes
This base class provides a do-nothing method for every SBOL3 visit type. |
Functions
|
Build a cache of identities from the given document to support |
|
Context manager for a document reference cache for use with |
|
Guess a genetic design file's type from its name |
|
Filters and returns iterable of TopLevel Objects in a document, |
|
Look up a child object; if it is not found, raise an exception |
|
Look up a top-level object; if it is not found, raise an exception |
|
Deprecated: switch to using itertools.chain(*collection) |
|
Sort a collection of SBOL objects and/or URIs by identity URI |
|
Check if an SBOL Component or Feature is circular. |
|
Check if an SBOL Component or Feature is a plasmid-like structure, i.e., either circular or having a plasmid role |
|
Given a document, determine the set of links to objects not in the document |
|
Prettify a URL by stripping standard genetic design file type suffixes off of it |
|
Ensure that an SBOL2 or SBOL3 URI is an SBOL3 URI by stripping any SBOL2 version identifier |
|
Find the unique TopLevel document object with the given name (rather than displayID or URI) |
|
Sanitize a URL string for use as an identity, turning everything after the last "/" to sanitize as a displayId |
Attributes
- exception ChildNotFound
Bases:
SBOLObjectNotFoundA child object should always be in the document, so if it is missing that is an error
Initialize self. See help(type(self)) for accurate signature.
- GENETIC_DESIGN_FILE_TYPES
- class SBOL3PassiveVisitor
This base class provides a do-nothing method for every SBOL3 visit type. This allows subclasses to override for only the parts they want to act on
- visit_activity(self, _)
- visit_agent(self, _)
- visit_association(self, _)
- visit_attachment(self, _)
- visit_binary_prefix(self, _)
- visit_collection(self, _)
- visit_combinatorial_derivation(self, _)
- visit_component(self, _)
- visit_component_reference(self, _)
- visit_constraint(self, _)
- visit_cut(self, _)
- visit_document(self)
- visit_entire_sequence(self, _)
- visit_experiment(self, _)
- visit_experimental_data(self, _)
- visit_externally_defined(self, _)
- visit_implementation(self, _)
- visit_interaction(self, _)
- visit_interface(self, _)
- visit_local_sub_component(self, _)
- visit_measure(self, _)
- visit_model(self, _)
- visit_participation(self, _)
- visit_plan(self, _)
- visit_prefixed_unit(self, _)
- visit_range(self, _)
- visit_sequence(self, _)
- visit_sequence_feature(self, _)
- visit_si_prefix(self, _)
- visit_singular_unit(self, _)
- visit_sub_component(self, _)
- visit_unit_division(self, _)
- visit_unit_exponentiation(self, _)
- visit_unit_multiplication(self, _)
- visit_usage(self, _)
- visit_variable_feature(self, _)
- exception SBOLObjectNotFound
Bases:
ExceptionBase Exception to be raised when an SBOL object lookup fails
Initialize self. See help(type(self)) for accurate signature.
- exception TopLevelNotFound
Bases:
SBOLObjectNotFoundA missing TopLevel object may be resolved be retrieving the object
Initialize self. See help(type(self)) for accurate signature.
- build_reference_cache(doc: sbol3.Document) dict[str, sbol3.Identified]
Build a cache of identities from the given document to support faster lookups of referenced objects.
- Parameters
doc – an sbol3 Document
- Returns
a cache of identities
- cached_references(doc: sbol3.Document) collections.abc.Generator[dict[str, sbol3.Identified]]
Context manager for a document reference cache for use with find_child and find_top_level.
```python with cached_references(doc) as cache:
find_top_level(component1.sequences[0], cache)
Can also be used implicitly, without passing the cache as an argument: ```python with cached_references(doc):
find_top_level(component1.sequences[0])
- Parameters
doc – an sbol3 Document
- Returns
a generator of a reference cache
- design_file_type(name: str) Optional[str]
Guess a genetic design file’s type from its name
- Parameters
name – file name (path allowed)
- Returns
type name (from GENETIC_DESIGN_FILE_TYPES) if known, None if not
- filter_top_level(doc: sbol3.Document, filter: Callable[[sbol3.TopLevel], bool]) Iterable[sbol3.TopLevel]
Filters and returns iterable of TopLevel Objects in a document, which match a criteria set by a callable argument.
- Parameters
doc – SBOL Document to search
filter – Callable acting as filter on List of TopLevel objects
- Returns
TopLevel iterator satisfying given filter
- find_child(ref: sbol3.refobj_property.ReferencedURI, cache: Optional[dict[str, sbol3.Identified]] = None)
Look up a child object; if it is not found, raise an exception
- Parameters
ref – reference to look up
cache – optional cache of identities to speed lookup
- Returns
object pointed to by reference
- Raises
ChildNotFound – if object cannot be retrieved
- find_top_level(ref: sbol3.refobj_property.ReferencedURI, cache: Optional[dict[str, sbol3.Identified]] = None)
Look up a top-level object; if it is not found, raise an exception
- Parameters
ref – reference to look up
cache – optional cache of identities to speed lookup
- Returns
object pointed to by reference
- Raises
TopLevelNotFound – if object cannot be retrieved
- id_sort(i: iter)
Sort a collection of SBOL objects and/or URIs by identity URI
- is_circular(obj: Union[sbol3.Component, sbol3.LocalSubComponent, sbol3.ExternallyDefined]) bool
Check if an SBOL Component or Feature is circular. :param obj: design to be checked :return: true if circular
- is_plasmid(obj: Union[sbol3.Component, sbol3.Feature]) bool
Check if an SBOL Component or Feature is a plasmid-like structure, i.e., either circular or having a plasmid role
- Parameters
obj – design to be checked
- Returns
true if plasmid
- outgoing_links(doc: sbol3.Document) set[rdflib.URIRef]
Given a document, determine the set of links to objects not in the document
- Parameters
doc – an SBOL document
- Returns
set of URIs for objects not contained in the document
- strip_filetype_suffix(identity: str) str
Prettify a URL by stripping standard genetic design file type suffixes off of it
- Parameters
identity – URL to sanitize
- Returns
sanitized URL
- strip_sbol2_version(identity: str) str
Ensure that an SBOL2 or SBOL3 URI is an SBOL3 URI by stripping any SBOL2 version identifier from the end to the URI
- Parameters
identity – URI to be sanitized
- Returns
URI without terminal version, if any
- toplevel_named(doc: sbol3.Document, name: str) Optional[sbol3.TopLevel]
Find the unique TopLevel document object with the given name (rather than displayID or URI)
- Parameters
doc – SBOL document to search
name – name to look for
- Returns
object, if found, or None if not
- Raises
ValueError – if there are multiple objects with the given name
- url_to_identity(url: str) str
Sanitize a URL string for use as an identity, turning everything after the last “/” to sanitize as a displayId
- Parameters
url – URL to sanitize
- Returns
equivalent identity