Parse a WURCS (WURCS 2.0) glycan annotation and extract:

  • residue sequence (as a character vector)

  • edge list (parent–child relationships)

wurcs_to_tree(w)

Arguments

w

A character string containing a WURCS 2.0 glycan annotation.

Value

A list with two elements:

  • node: character vector of residue types in order

  • edge: character vector of edges in "A-B" format

Details

This function is used internally to convert WURCS strings into a tree representation that can support structural trait computation and graph construction.

The function performs several parsing steps:

  1. Remove the WURCS prefix and split the string into components.

  2. Extract UniqueRES entries and map them to residue symbols using the internal WURCS_RES_MAP table.

  3. Follow the RES sequence index to reconstruct the residue vector.

  4. Parse LIN entries and normalize them into simple "X-Y" edges.

Examples

# Example WURCS glycan string
w <- paste0(
  "WURCS=2.0/4,9,8/",
  "[u2122h_2*NCC/3=O]",
  "[a2122h-1b_1-5_2*NCC/3=O]",
  "[a1122h-1b_1-5]",
  "[a1122h-1a_1-5]",
  "/1-2-3-4-4-4-4-4-4/",
  "a4-b1_b4-c1_c3-d1_c6-f1_d2-e1_f3-g1_f6-h1_h2-i1"
)
tree <- wurcs_to_tree(w)
tree
#> $node
#>        [u2122h_2*NCC/3=O] [a2122h-1b_1-5_2*NCC/3=O]           [a1122h-1b_1-5] 
#>                       "N"                       "N"                       "H" 
#>           [a1122h-1a_1-5]           [a1122h-1a_1-5]           [a1122h-1a_1-5] 
#>                       "H"                       "H"                       "H" 
#>           [a1122h-1a_1-5]           [a1122h-1a_1-5]           [a1122h-1a_1-5] 
#>                       "H"                       "H"                       "H" 
#> 
#> $edge
#> [1] "a-b" "b-c" "c-d" "c-f" "d-e" "f-g" "f-h" "h-i"
#>