| Title: | Hierarchical Glycan Annotation |
|---|---|
| Description: | Hierarchical annotation of glycans based on molecule mass, composition, and structure. Starting from a molecule mass, glyanno calculates possible glycan compositions. Given a glycan composition, glyanno further deduces possible glycan structures. For glycan structures with generic monosaccharides (e.g., "Hex", "HexNAc"), glyanno refines them into specific types (e.g., "Glc", "Gal"). For structures lacking linkage information (e.g., "Gal(??-?)GalNAc(??-"), glyanno infers the most likely linkages (e.g., "Gal(b1-3)GalNAc(a1-"). |
| Authors: | Bin Fu [aut, cre] (ORCID: <https://orcid.org/0000-0001-8567-2997>) |
| Maintainer: | Bin Fu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.7.0 |
| Built: | 2026-10-22 19:54:13 UTC |
| Source: | https://github.com/glycoverse/glyanno |
build_glyanno_cache() is the magic that makes glyanno fast.
It precalculates database views and annotation indexes from the installed glydb.
You will only need to call this function once on your computer.
When glydb is updated, you'll also need to call this function to update the cache.
But don't worry. We'll remind you then.
build_glyanno_cache() reuses a valid cache unless force = TRUE.
glyanno_cache_info() inspects it without building it, and
clear_glyanno_cache() removes it and clears the session cache.
build_glyanno_cache(force = FALSE) glyanno_cache_info() clear_glyanno_cache()build_glyanno_cache(force = FALSE) glyanno_cache_info() clear_glyanno_cache()
force |
Rebuild even when the cache is current. |
The cache lives in tools::R_user_dir("glyanno", "cache"). Set the
glyanno.cache_dir option to use another directory. Only an explicit call
to build_glyanno_cache() writes persistent data. Without a disk cache,
annotation builds the required views in memory for the current session.
On interactive attachment, a startup message reminds you to build a missing,
outdated, or unreadable cache. No computation or questions block attachment.
The cache is invalidated by a changed glydb version, glyrepr or igraph version,
R major/minor version, collation locale, or internal cache schema. Restart R
after updating dependencies. Development data changes without a version bump
require force = TRUE.
Cached data include concrete/generic compositions, intact/topological structures, confidence ranks, exact and compatible composition indexes, residue counts, species/type membership, floating-structure flags, masses for all built-in dictionaries, and local GlyTouCan accession keys. Structure vectors retain their parsed graphs. Arbitrary structure matching still uses glymotif at query time. Custom databases are never persisted.
A complete replacement is written before the previous cache is replaced;
failed builds preserve the previous file. Only one completed cache is kept.
Metadata inspection reads a small file header and checks the file size.
The compressed annotation payload is loaded and validated on first use.
Use force = TRUE to repair a damaged payload whose header is still valid.
build_glyanno_cache() invisibly returns the cache file path.
glyanno_cache_info() returns a list with path, status (one of
"missing", "outdated", "unreadable", or "ready"), size_bytes,
expected, and stored version metadata.
clear_glyanno_cache() invisibly returns NULL.
glyanno_cache_info()glyanno_cache_info()
This function calculates m/z values from glycans. Different adducts, mass types, and derivatives are supported. Custom mass dictionaries are also supported.
calculate_mz(glycans, charge = 1, adduct = "H+", mass_dict = NULL, safe = TRUE)calculate_mz(glycans, charge = 1, adduct = "H+", mass_dict = NULL, safe = TRUE)
glycans |
Glycans to calculate m/z values from. Valid inputs include:
|
charge |
Charge to use. Can be 0, 1, 2, 3, -1, -2, -3, etc. 0 means neutral. Default is 1. |
adduct |
Adduct to use. Can be "H+", "K+", "Na+", "NH4+", "H-", "Cl-", "HCO3-". Default is "H+".
|
mass_dict |
A named numeric vector of the mass of each monosaccharide residue.
Default is |
safe |
Whether to raise an error when unsupported monosaccharides or substituents are found.
|
A numeric vector of m/z values.
library(glyrepr) # Different input types calculate_mz(glycan_composition(c(Gal = 1, GalNAc = 1)), charge = 0) calculate_mz("Gal(1)GalNAc(1)", charge = 0) calculate_mz(as_glycan_structure("Gal(b1-3)GalNAc(a1-"), charge = 0) calculate_mz("Gal(b1-3)GalNAc(a1-", charge = 0) # For common situation in MALDI-TOF MS calculate_mz("Man(5)GlcNAc(2)", charge = 1,adduct = "Na+") # For common situation in ESI MS calculate_mz("Man(5)GlcNAc(2)", charge = 1, adduct = "H+") # Calculate permethylated m/z values calculate_mz("Man(5)GlcNAc(2)", charge = 0, mass_dict = glyanno_mass_dict(deriv = "permethyl")) # Calculate average mass calculate_mz("Man(5)GlcNAc(2)", charge = 0, mass_dict = glyanno_mass_dict(mass_type = "average")) # Vectorization calculate_mz(c("Man(5)GlcNAc(2)", "Gal(1)GalNAc(1)"), charge = 1, adduct = "Na+")library(glyrepr) # Different input types calculate_mz(glycan_composition(c(Gal = 1, GalNAc = 1)), charge = 0) calculate_mz("Gal(1)GalNAc(1)", charge = 0) calculate_mz(as_glycan_structure("Gal(b1-3)GalNAc(a1-"), charge = 0) calculate_mz("Gal(b1-3)GalNAc(a1-", charge = 0) # For common situation in MALDI-TOF MS calculate_mz("Man(5)GlcNAc(2)", charge = 1,adduct = "Na+") # For common situation in ESI MS calculate_mz("Man(5)GlcNAc(2)", charge = 1, adduct = "H+") # Calculate permethylated m/z values calculate_mz("Man(5)GlcNAc(2)", charge = 0, mass_dict = glyanno_mass_dict(deriv = "permethyl")) # Calculate average mass calculate_mz("Man(5)GlcNAc(2)", charge = 0, mass_dict = glyanno_mass_dict(mass_type = "average")) # Vectorization calculate_mz(c("Man(5)GlcNAc(2)", "Gal(1)GalNAc(1)"), charge = 1, adduct = "Na+")
Given glycan compositions, this function matches them to all compatible
glycan structures in the glydb database. Generic, concrete, and mixed
residue identities are matched residue by residue.
comp_to_struc( comps, db = lifecycle::deprecated(), return_best = FALSE, glycan_type = NULL, species = NULL, structure_level = "intact", mono_type = "concrete", mono_range = NULL )comp_to_struc( comps, db = lifecycle::deprecated(), return_best = FALSE, glycan_type = NULL, species = NULL, structure_level = "intact", mono_type = "concrete", mono_range = NULL )
comps |
Glycan compositions to match against. Can be either:
|
db |
|
return_best |
If |
glycan_type |
Glycan type to select from |
species |
Species to select, matched without regard to letter case. |
structure_level |
Structure resolution, |
mono_type |
Monosaccharide resolution, |
mono_range |
Named list of monosaccharide count ranges; see
|
Filter the built-in database with glycan_type, species,
structure_level, mono_type, and mono_range.
If return_best=TRUE:
A glyrepr::glycan_structure() vector with the same length as comps.
Unmatched compositions are returned as NA.
If return_best=FALSE:
A tibble with the following columns:
composition: The glycan compositions, as glyrepr::glycan_composition() vector.
structure: The possible glycan structures, as glyrepr::glycan_structure() vector.
confidence: The database confidence score for each structure, or NA
when no score is available.
Note that one glycan composition can have multiple rows in the result,
corresponding to different possible glycan structures.
comp_to_struc("H5N2")comp_to_struc("H5N2")
Given a generic or mixed glycan composition (e.g. Hex(5)HexNAc(2)), this function gives all possible compatible concrete glycan compositions (e.g. Man(5)GlcNAc(2)).
enhance_comp( comps, db = lifecycle::deprecated(), return_best = FALSE, glycan_type = NULL, species = NULL, mono_type = "concrete", mono_range = NULL )enhance_comp( comps, db = lifecycle::deprecated(), return_best = FALSE, glycan_type = NULL, species = NULL, mono_type = "concrete", mono_range = NULL )
comps |
A |
db |
|
return_best |
Logical. If |
glycan_type |
Glycan type to select from |
species |
Species to select, matched without regard to letter case. |
mono_type |
Monosaccharide resolution; only |
mono_range |
Named list of monosaccharide count ranges; see
|
Filter the built-in database with glycan_type, species,
mono_type, and mono_range.
If return_best=TRUE:
A glyrepr::glycan_composition() vector with the same length as comps.
Unmatched compositions are returned as NA.
If return_best=FALSE:
A tibble with the following columns:
raw: The original compositions.
enhanced: The enhanced compositions.
confidence: The database confidence score for each enhanced
composition, or NA when no score is available.
Note that one raw composition can have different enhanced compositions
as multiple rows in the result.
enhance_comp("Hex(5)HexNAc(2)")enhance_comp("Hex(5)HexNAc(2)")
Given a glycan structure vector of any resolution level (see
glyrepr::get_structure_level() for details), this function gives compatible
structures with more specific residue identities or linkage information.
enhance_struc( strucs, db = lifecycle::deprecated(), return_best = FALSE, glycan_type = NULL, species = NULL, structure_level = "intact", mono_type = "concrete", mono_range = NULL )enhance_struc( strucs, db = lifecycle::deprecated(), return_best = FALSE, glycan_type = NULL, species = NULL, structure_level = "intact", mono_type = "concrete", mono_range = NULL )
strucs |
A |
db |
|
return_best |
Logical. If |
glycan_type |
Glycan type to select from |
species |
Species to select, matched without regard to letter case. |
structure_level |
Structure resolution, |
mono_type |
Monosaccharide resolution, |
mono_range |
Named list of monosaccharide count ranges; see
|
Input and database vectors may mix generic, concrete, and mixed residues, as well as topological, partial, and intact structures. Each database candidate is matched against each input independently.
If return_best=TRUE:
An unnamed glyrepr::glycan_structure() vector with the same length as strucs.
Unmatched structures are returned as NA.
If return_best=FALSE:
A tibble with the following columns:
raw: The original glycan structures.
enhanced: The enhanced glycan structures.
confidence: The database confidence score for each enhanced
structure, or NA when no score is available.
Note that one raw glycan structure can have different enhanced
structures as multiple rows in the result.
enhance_struc("Gal(??-?)GalNAc(??-", glycan_type = "O-GalNAc", species = "Homo sapiens")enhance_struc("Gal(??-?)GalNAc(??-", glycan_type = "O-GalNAc", species = "Homo sapiens")
Reconstructs generic topological N-glycans from their core and branches. Every non-missing input must have only generic residues and no linkage information. Inputs that cannot be reconstructed de novo are matched against a fallback database at "topological" level.
Topological de-novo enhancement preserves optional core fucose and bisecting GlcNAc residues. Complex N-glycan branches are matched against the internal branch data. For hybrid N-glycans, the all-Hex arm is assigned as mannose and the HexNAc-bearing arm uses branch matching. High-mannose candidates are constrained to core-aligned subtrees of the Glc3Man9 precursor.
enhance_struc_denovo(strucs, fallback_db = NULL)enhance_struc_denovo(strucs, fallback_db = NULL)
strucs |
A |
fallback_db |
A |
An unnamed glyrepr::glycan_structure() vector with the same length
as strucs. Unmatched structures are returned as NA.
n_generic <- glyrepr::n_glycan_core(linkage = FALSE, mono_type = "generic") enhance_struc_denovo(n_generic)n_generic <- glyrepr::n_glycan_core(linkage = FALSE, mono_type = "generic") enhance_struc_denovo(n_generic)
A named numeric vector of the mass of each monosaccharide residue.
Used by default as the mass_dict argument in calculate_mz().
The names includes:
Monosaccharides: Hex, HexNAc, dHex, dHexNAc, ddHex, Pen, HexA, HexN, NeuAc, NeuGc, Kdn, Neu
Ions: H+, H, H2O, K+, Na+, NH4+, H-, Cl-, HCO3-
Substituents: S, P
Reducing end: red_end, which is the additional mass of the reducing end of the glycan.
glyanno_mass_dict(deriv = "none", mass_type = "mono")glyanno_mass_dict(deriv = "none", mass_type = "mono")
deriv |
A character scalar of the derivatization method to use. Can be "none", "permethyl", or "peracetyl". Default is "none". |
mass_type |
"mono" for monoisotopic mass, "average" for average mass. Default is "mono". |
A named numeric vector.
glyanno_mass_dict(deriv = "none", mass_type = "mono") glyanno_mass_dict(deriv = "permethyl", mass_type = "mono") glyanno_mass_dict(deriv = "none", mass_type = "average")glyanno_mass_dict(deriv = "none", mass_type = "mono") glyanno_mass_dict(deriv = "permethyl", mass_type = "mono") glyanno_mass_dict(deriv = "none", mass_type = "average")
Given m/z values, this function matches them to all possible glycan compositions in the glydb database.
mz_to_comp( mz, tol = ppm(10), db = lifecycle::deprecated(), return_best = FALSE, charge = 1, adduct = "H+", mass_dict = NULL, glycan_type = NULL, species = NULL, mono_type = "concrete", mono_range = NULL )mz_to_comp( mz, tol = ppm(10), db = lifecycle::deprecated(), return_best = FALSE, charge = 1, adduct = "H+", mass_dict = NULL, glycan_type = NULL, species = NULL, mono_type = "concrete", mono_range = NULL )
mz |
A numeric vector of m/z values. |
tol |
A numeric scalar of the tolerance for the m/z value in Da or a |
db |
|
return_best |
A logical scalar. If |
charge |
Charge to use. Can be 0, 1, 2, 3, -1, -2, -3, etc. 0 means neutral. Default is 1. |
adduct |
Adduct to use. Can be "H+", "K+", "Na+", "NH4+", "H-", "Cl-", "HCO3-". Default is "H+".
|
mass_dict |
A named numeric vector of the mass of each monosaccharide residue.
Default is |
glycan_type |
Glycan type to select from |
species |
Species to select, matched without regard to letter case. |
mono_type |
Monosaccharide resolution, |
mono_range |
Named list of monosaccharide count ranges; see
|
If return_best=TRUE:
An unnamed glyrepr::glycan_composition() vector with the same length as mz.
Unmatched m/z values are returned as NA.
If return_best=FALSE:
A tibble with the following columns:
mz: The molecule m/z values, same as the input mz.
composition: The possible glycan compositions, as glyrepr::glycan_composition() vector.
confidence: The database confidence score for each composition, or
NA when no score is available.
Note that one m/z value can have multiple rows in the result,
corresponding to different possible glycan compositions.
Use glycan_type, species, mono_type, and mono_range to select
compositions from glydb::glydb_compositions(). For example,
mz_to_comp(mz, species = "Homo sapiens", glycan_type = "N")
mz_to_comp(933.3175, charge = 1, adduct = "Na+")mz_to_comp(933.3175, charge = 1, adduct = "Na+")
This helper function should be used in mz_to_comp() as the tol argument.
It makes the function using PPM as dynamic tolerance.
ppm(x)ppm(x)
x |
A numeric scalar of the PPM value. |
A function that takes a numeric vector of m/z values and returns a numeric vector of tolerances.
ppm(10)(2368.84) ppm(10)(c(2368.84, 2368.85))ppm(10)(2368.84) ppm(10)(c(2368.84, 2368.85))
This function takes a vector of glycan structures and returns the corresponding GlyTouCan accessions. It first looks up structures from glydb::glydb_data, then uses the GlycanFormatConverter API maintained by the Glycosmos project for structures not found locally.
struc_to_glytoucan(strucs)struc_to_glytoucan(strucs)
strucs |
A |
For "topological" structures (e.g., "Gal(??-?)GalNAc(??-"),
this function will first call glyrepr::fill_anomer_pos() to fill in the missing
anomeric positions before looking up accessions. This is necessary because
all glycan structures in GlyTouCan must have defined anomeric positions.
A character vector of GlyTouCan accessions corresponding to the input glycan structures.
If a structure cannot be converted to a GlyTouCan accession, the corresponding entry will be NA.