diff --git a/sbol_utilities/helper_functions.py b/sbol_utilities/helper_functions.py index 168debf..0abe9d7 100644 --- a/sbol_utilities/helper_functions.py +++ b/sbol_utilities/helper_functions.py @@ -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) \ No newline at end of file + 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