Skip to contents

Convert an object to a glycan composition. The resulting composition can contain both monosaccharides and substituents.

Usage

as_glycan_composition(x)

Arguments

x

An object to convert to a glycan composition. Can be a named integer vector, a list of named integer vectors, a glycan structure vector, or an existing glyrepr_composition object.

Value

A glyrepr_composition object.

Details

When converting from glycan structures, both monosaccharides and substituents are counted. Substituents are extracted from the sub attribute of each vertex in the structure. For example, a vertex with sub = "3Me" contributes one "Me" substituent to the composition.

Examples

# Convert a named vector
as_glycan_composition(c(Hex = 5, HexNAc = 2))
#> <glycan_composition[1]>
#> [1] Hex(5)HexNAc(2)

# Convert a named vector with substituents
as_glycan_composition(c(Glc = 2, Gal = 1, Me = 1, S = 1))
#> <glycan_composition[1]>
#> [1] Glc(2)Gal(1)Me(1)S(1)

# Convert a list of named vectors
as_glycan_composition(list(c(Hex = 5, HexNAc = 2), c(Hex = 3, HexNAc = 1)))
#> <glycan_composition[2]>
#> [1] Hex(5)HexNAc(2)
#> [2] Hex(3)HexNAc(1)

# Convert an existing composition (returns as-is)
comp <- glycan_composition(c(Hex = 5, HexNAc = 2))
as_glycan_composition(comp)
#> <glycan_composition[1]>
#> [1] Hex(5)HexNAc(2)

# Convert a glycan structure vector
strucs <- c(n_glycan_core(), o_glycan_core_1())
as_glycan_composition(strucs)
#> <glycan_composition[2]>
#> [1] Man(3)GlcNAc(2)
#> [2] Gal(1)GalNAc(1)

# Convert structures with substituents
# (This will count both monosaccharides and any substituents present)