From 5f701d20b6f34ba069e4e568648f60e28d0de6c6 Mon Sep 17 00:00:00 2001 From: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> Date: Mon, 1 Apr 2024 23:31:39 +0530 Subject: [PATCH] function Signed-off-by: Vinayakjeet Singh Karki <139736674+vinayakjeet@users.noreply.github.com> --- sbol_utilities/helper_functions.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/sbol_utilities/helper_functions.py b/sbol_utilities/helper_functions.py index 168debfc..0abe9d7c 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