From 893e3cca796dcd023c053e01d85bf1b36e167f6b Mon Sep 17 00:00:00 2001 From: Daniel Bojar Date: Mon, 11 Mar 2024 11:55:01 +0100 Subject: [PATCH] support glycan graphs as input in get_match --- build/lib/glycowork/motif/annotate.py | 5 +---- glycowork/motif/annotate.py | 5 +---- glycowork/motif/regex.py | 6 +++++- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/build/lib/glycowork/motif/annotate.py b/build/lib/glycowork/motif/annotate.py index 650b8c7a..98ba0325 100644 --- a/build/lib/glycowork/motif/annotate.py +++ b/build/lib/glycowork/motif/annotate.py @@ -76,10 +76,7 @@ def annotate_glycan(glycan, motifs = None, termini_list = [], gmotifs = None): out = pd.DataFrame(columns = motifs.motif_name if isinstance(motifs, pd.DataFrame) else motifs) out.loc[0] = res out.loc[0] = out.loc[0].astype('int') - if isinstance(glycan, str): - out.index = [glycan] - else: - out.index = [graph_to_string(glycan)] + out.index = [glycan] if isinstance(glycan, str) else [graph_to_string(glycan)] return out diff --git a/glycowork/motif/annotate.py b/glycowork/motif/annotate.py index 650b8c7a..98ba0325 100644 --- a/glycowork/motif/annotate.py +++ b/glycowork/motif/annotate.py @@ -76,10 +76,7 @@ def annotate_glycan(glycan, motifs = None, termini_list = [], gmotifs = None): out = pd.DataFrame(columns = motifs.motif_name if isinstance(motifs, pd.DataFrame) else motifs) out.loc[0] = res out.loc[0] = out.loc[0].astype('int') - if isinstance(glycan, str): - out.index = [glycan] - else: - out.index = [graph_to_string(glycan)] + out.index = [glycan] if isinstance(glycan, str) else [graph_to_string(glycan)] return out diff --git a/glycowork/motif/regex.py b/glycowork/motif/regex.py index 19c517e0..7fe8ba2d 100644 --- a/glycowork/motif/regex.py +++ b/glycowork/motif/regex.py @@ -621,7 +621,11 @@ def get_match(pattern, glycan, return_matches = True): lookahead_snuck_in = False if any([k in glycan for k in [';', '-D-', 'RES', '=']]): glycan = canonicalize_iupac(glycan) - ggraph = glycan_to_nxGraph(glycan) + if isinstance(glycan, str): + ggraph = glycan_to_nxGraph(glycan) + else: + ggraph = glycan + glycan = graph_to_string(ggraph) pattern_components = preprocess_pattern(pattern) if isinstance(pattern, str) else pattern pattern_matches = match_it_up(pattern_components, glycan, ggraph) if pattern_matches: