| Title: | Regular Expressions for Glycan Structures |
|---|---|
| Description: | Compile and match glycan structural regular expressions with a stringr-like interface. Supports residue classes, linkage constraints, branches, repetition, assertions, and named captures on glyrepr graphs, including explicit reducing-end anomeric information. |
| Authors: | Bin Fu [aut, cre] |
| Maintainer: | Bin Fu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-10-18 10:51:52 UTC |
| Source: | https://github.com/glycoverse/glyrex |
Compile a reusable structural query. Patterns run from the non-reducing end towards the reducing end; they are not text regular expressions.
rex_compile(pattern)rex_compile(pattern)
pattern |
One non-missing pattern string, or a compiled pattern. |
Compilation validates the pattern syntax and prepares it for reuse with
query functions such as rex_detect() and rex_extract(). Passing an
already compiled pattern returns it unchanged.
A glyrex_pattern containing a parsed syntax tree and capture names.
vignette("glyco-regex-syntax", package = "glyrex") for a step-by-step
guide to pattern syntax. See rex_detect() for matching and result
conventions.
p <- rex_compile("Galb4-(Fuca3-)GlcNAc") rex_detect("Gal(b1-4)[Fuc(a1-3)]GlcNAc", p) rex_detect(c("GlcNAc(a1-", "GlcNAc(b1-"), "GlcNAca$")p <- rex_compile("Galb4-(Fuca3-)GlcNAc") rex_detect("Gal(b1-4)[Fuc(a1-3)]GlcNAc", p) rex_detect(c("GlcNAc(a1-", "GlcNAc(b1-"), "GlcNAca$")
Count the structural matches of a pattern in each glycan.
rex_count(glycans, pattern)rex_count(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
An integer vector, with zero for no match and NA_integer_ for
missing glycans or patterns.
Other glycan queries:
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_count(x, "HexNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_count(x, "HexNAc")
Test whether each glycan contains a structural pattern.
rex_detect(glycans, pattern, negate = FALSE)rex_detect(glycans, pattern, negate = FALSE)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
negate |
Invert detection when |
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.
A logical vector. Missing glycans or patterns return NA.
Other glycan queries:
rex_count(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_detect(x, "Gal-HexNAc") rex_detect(x, "Gal", negate = TRUE)x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_detect(x, "Gal-HexNAc") rex_detect(x, "Gal", negate = TRUE)
Extract the first matching fragment from each glycan.
rex_extract(glycans, pattern)rex_extract(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
A character vector of canonical glyrepr IUPAC strings for character input, or a glyrepr structure vector for structure or graph input. No match or missing input returns a missing value. A cut fragment retains the anomer and donor position of its former attachment linkage.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_extract(x, "HexNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_extract(x, "HexNAc")
Extract all matching fragments from each glycan.
rex_extract_all(glycans, pattern)rex_extract_all(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
A list of character vectors of canonical glyrepr IUPAC strings for character input, or glyrepr structure vectors for structure or graph input. No match returns an empty vector; missing input returns a length-one missing vector. A cut fragment retains the anomer and donor position of its former attachment linkage.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_extract_all(x, "HexNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_extract_all(x, "HexNAc")
Locate the nodes and edges of the first match in each glycan.
rex_locate(glycans, pattern)rex_locate(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
A data frame with integer list-columns nodes and edges, and one
row per input. No match or missing input uses NA_integer_ in both
columns. IDs are one-based and refer to the input graph, or the
canonical graph obtained from character input, as in
glyrepr::structure_nodes() and glyrepr::structure_edges(). Only
edges within the match are returned.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_locate(x, "Gal-GlcNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_locate(x, "Gal-GlcNAc")
Locate the nodes and edges of all matches in each glycan.
rex_locate_all(glycans, pattern)rex_locate_all(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
A list of data frames with integer list-columns nodes and edges.
No match produces zero rows; missing input produces one row with
NA_integer_ in both columns. IDs are one-based and refer to the input
graph, or the canonical graph obtained from character input, as in
glyrepr::structure_nodes() and glyrepr::structure_edges(). Only
edges within the match are returned.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_match(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_locate_all(x, "Gal-GlcNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_locate_all(x, "Gal-GlcNAc")
Extract the first match and its named capture groups from each glycan.
rex_match(glycans, pattern)rex_match(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
A character matrix with one row per input, a match column, and
columns for named captures. No match or missing input produces a
missing row; unmatched captures are NA. Fragments are canonical
glyrepr IUPAC strings. Vectorized patterns must have identical capture
names.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match_all(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_match(x, "(?<terminal>Gal)-GlcNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_match(x, "(?<terminal>Gal)-GlcNAc")
Extract all matches and their named capture groups from each glycan.
rex_match_all(glycans, pattern)rex_match_all(glycans, pattern)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
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.
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.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_subset(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_match_all(x, "(?<terminal>Gal)-GlcNAc")x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_match_all(x, "(?<terminal>Gal)-GlcNAc")
Keep glycans that match a structural pattern.
rex_subset(glycans, pattern, negate = FALSE)rex_subset(glycans, pattern, negate = FALSE)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
negate |
Invert detection when |
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.
A subset preserving the input representation and names. Missing
results are omitted. For a single graph input, returns the graph on a
match and NULL otherwise. The pattern must have length one or the
length of glycans.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_which()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_subset(x, "Gal") rex_subset(x, "Gal", negate = TRUE)x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_subset(x, "Gal") rex_subset(x, "Gal", negate = TRUE)
Return the indices of glycans that match a structural pattern.
rex_which(glycans, pattern, negate = FALSE)rex_which(glycans, pattern, negate = FALSE)
glycans |
A character vector of glycan expressions in any format
supported by |
pattern |
A character vector of patterns or one |
negate |
Invert detection when |
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.
An integer vector of matching input indices. Missing results are
omitted. The pattern must have length one or the length of glycans.
Other glycan queries:
rex_count(),
rex_detect(),
rex_extract(),
rex_extract_all(),
rex_locate(),
rex_locate_all(),
rex_match(),
rex_match_all(),
rex_subset()
x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_which(x, "Fuc") rex_which(x, "Gal", negate = TRUE)x <- c("Gal(b1-4)GlcNAc", "Fuc(a1-3)GlcNAc", NA) rex_which(x, "Fuc") rex_which(x, "Gal", negate = TRUE)