Parse 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)

Arguments

expr

A character string representing the pGlyco3 glycan structure.

Value

A list with:

  • node: character vector of residue types

  • edge: character vector of edges in "a-b" format

Details

This function interprets parentheses as branch delimiters and assigns:

  1. one residue per character (e.g. N, H, A)

  2. 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.

Examples

# 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"
#>