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

Implement 'find_feature' Utility Function in SBOL Tutorial #237

Open
wants to merge 1 commit into
base: develop
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
16 changes: 15 additions & 1 deletion sbol_utilities/helper_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,4 +363,18 @@ def is_circular(obj: Union[sbol3.Component, sbol3.LocalSubComponent, sbol3.Exter
:param obj: design to be checked
:return: true if circular
"""
return any(n==sbol3.SO_CIRCULAR for n in obj.types)
return any(n==sbol3.SO_CIRCULAR for n in obj.types)
def find_feature(doc: sbol3.Document, matching: Callable[[sbol3.Feature], bool]) -> Optional[sbol3.Feature]:
"""
Search for a feature in the given SBOL document that matches the condition specified by the `matching` callable.

:param doc: The SBOL document to search within.
:param matching: A callable that takes an sbol3.Feature as input and returns True if the feature matches the desired condition.
:return: The first sbol3.Feature that matches the condition, or None if no matching feature is found.
"""
for obj in doc.objects:
if isinstance(obj, sbol3.Component):
for feature in obj.features:
if matching(feature):
return feature
return None
Loading