R/io_glycan_parse.R
pGlyco3_to_tree.RdParse a pGlyco3-style glycan expression (e.g. "N(H(H))")
and reconstruct the residue sequence and edge relationships
as a tree suitable for downstream structural analysis. This parser assumes
simple pGlyco3 monosaccharide symbols (e.g. "N", "H", "A", "F").
pGlyco3_to_tree(expr)A list with:
node: character vector of residue types
edge: character vector of edges in "a-b" format
This function interprets parentheses as branch delimiters and assigns:
one residue per character (e.g. N, H, A)
parent–child edges based on bracket nesting
Each residue is assigned a synthetic node label
(a, b, c, …), ensuring compatibility with
graph-based trait extraction.
# Example: parse a pGlyco3-style glycan expression into a tree
pGlyco_expr <- "(N(N(H(H(H))(H(H)(H)(H(H))))))"
# Convert to glycan tree structure
tree <- pGlyco3_to_tree(pGlyco_expr)
tree
#> $node
#> [1] "N" "N" "H" "H" "H" "H" "H" "H" "H" "H"
#>
#> $edge
#> [1] "a-b" "b-c" "c-d" "d-e" "c-f" "f-g" "f-h" "f-i" "i-j"
#>