diff --git a/build/lib/glycowork/motif/graph.py b/build/lib/glycowork/motif/graph.py index 62ec8ef3..60eb09f6 100644 --- a/build/lib/glycowork/motif/graph.py +++ b/build/lib/glycowork/motif/graph.py @@ -274,7 +274,7 @@ def subgraph_isomorphism(glycan, motif, termini_list = [], count = False, wildca return (0, []) if return_matches else 0 if count else False motif_comp = min_process_glycans([motif, glycan]) if wildcards_ptm: - glycan, motif = [re.sub(r"(?<=[a-zA-Z])\d+(?=[a-zA-Z])", 'O', glycan).replace('NeuOAc', 'Neu5Ac').replace('NeuOGc', 'Neu5Gc') for glycan in [glycan, motif]] + glycan, motif = [re.sub(r"(?<=[a-zA-Z])\d+(?=[a-zA-Z])", 'O', g).replace('NeuOAc', 'Neu5Ac').replace('NeuOGc', 'Neu5Gc') for g in [glycan, motif]] g1 = glycan_to_nxGraph(glycan, termini = 'calc') if termini_list else glycan_to_nxGraph(glycan) g2 = glycan_to_nxGraph(motif, termini = 'provided', termini_list = termini_list) if termini_list else glycan_to_nxGraph(motif) else: @@ -322,11 +322,11 @@ def subgraph_isomorphism(glycan, motif, termini_list = [], count = False, wildca return counts if not return_matches else (counts, mappings) else: if graph_pair.subgraph_is_isomorphic(): - mapping = graph_pair.mapping - mapping = {v: k for k, v in mapping.items()} - res = all(mapping[node] < mapping[neighbor] for node, neighbor in g2.edges()) - return res if not return_matches else (int(res), mappings) - return False if not return_matches else (0, []) + for mapping in graph_pair.subgraph_isomorphisms_iter(): + mapping = {v: k for k, v in mapping.items()} + if all(mapping[node] < mapping[neighbor] for node, neighbor in g2.edges()): + return True if not return_matches else (1, mappings) + return False if not return_matches else (0, []) def generate_graph_features(glycan, glycan_graph = True, label = 'network'): diff --git a/glycowork/motif/graph.py b/glycowork/motif/graph.py index 62ec8ef3..60eb09f6 100644 --- a/glycowork/motif/graph.py +++ b/glycowork/motif/graph.py @@ -274,7 +274,7 @@ def subgraph_isomorphism(glycan, motif, termini_list = [], count = False, wildca return (0, []) if return_matches else 0 if count else False motif_comp = min_process_glycans([motif, glycan]) if wildcards_ptm: - glycan, motif = [re.sub(r"(?<=[a-zA-Z])\d+(?=[a-zA-Z])", 'O', glycan).replace('NeuOAc', 'Neu5Ac').replace('NeuOGc', 'Neu5Gc') for glycan in [glycan, motif]] + glycan, motif = [re.sub(r"(?<=[a-zA-Z])\d+(?=[a-zA-Z])", 'O', g).replace('NeuOAc', 'Neu5Ac').replace('NeuOGc', 'Neu5Gc') for g in [glycan, motif]] g1 = glycan_to_nxGraph(glycan, termini = 'calc') if termini_list else glycan_to_nxGraph(glycan) g2 = glycan_to_nxGraph(motif, termini = 'provided', termini_list = termini_list) if termini_list else glycan_to_nxGraph(motif) else: @@ -322,11 +322,11 @@ def subgraph_isomorphism(glycan, motif, termini_list = [], count = False, wildca return counts if not return_matches else (counts, mappings) else: if graph_pair.subgraph_is_isomorphic(): - mapping = graph_pair.mapping - mapping = {v: k for k, v in mapping.items()} - res = all(mapping[node] < mapping[neighbor] for node, neighbor in g2.edges()) - return res if not return_matches else (int(res), mappings) - return False if not return_matches else (0, []) + for mapping in graph_pair.subgraph_isomorphisms_iter(): + mapping = {v: k for k, v in mapping.items()} + if all(mapping[node] < mapping[neighbor] for node, neighbor in g2.edges()): + return True if not return_matches else (1, mappings) + return False if not return_matches else (0, []) def generate_graph_features(glycan, glycan_graph = True, label = 'network'): diff --git a/glycowork/motif/regex.py b/glycowork/motif/regex.py index 7fe8ba2d..21d9b891 100644 --- a/glycowork/motif/regex.py +++ b/glycowork/motif/regex.py @@ -113,6 +113,8 @@ def convert_pattern_component(pattern_component): | Returns a string for simple components and a dict of form string : occurrence for complex components """ if not any([k in pattern_component for k in ['[', '{', '*', '+', '=', '