Skip to contents

Extract all matches and their named capture groups from each glycan.

Usage

rex_match_all(glycans, pattern)

Arguments

glycans

A character vector of glycan expressions in any format supported by glyparse::auto_parse(), a glyrepr_structure vector, or one glyrepr-compatible igraph. Character inputs may mix formats; malformed structures throw an error.

pattern

A character vector of patterns or one rex_compile() object. Inputs recycle only from length one. Missing glycans or patterns propagate.

Value

A list of character matrices with a match column followed by named capture columns. No match produces zero rows; missing input produces one missing row. Unmatched captures are NA. Fragments are canonical glyrepr IUPAC strings. Vectorized patterns must have identical capture names.

Details

The matching unit is a connected structural trace. As in glycowork, the first successful trace per starting node is retained, then strict subsets of other traces are removed. Distinct branches with equal sequences remain distinct matches. Matches are ordered by decreasing residue count and then starting node ID. Repeats are greedy unless marked lazy; successful traces may overlap. Counts therefore need not equal text-regex counts. Only connected rooted trees are supported; floating topology or floating substituents are rejected explicitly. See rex_compile() for syntax.

Examples

x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA)
rex_match_all(x, "(?<terminal>Gal)-GlcNAc")
#> [[1]]
#>      match                 terminal 
#> [1,] "Gal(b1-4)GlcNAc(?1-" "Gal(b1-"
#> 
#> [[2]]
#>      match terminal
#> 
#> [[3]]
#>      match terminal
#> [1,] NA    NA      
#>