glydraw draws SNFG
glycan cartoons from glycan structure text or
glyrepr::glycan_structure() objects. The main workflow
is:
draw_cartoon().save_cartoon().export_cartoons().This vignette uses IUPAC-condensed strings because they are compact and easy to copy into examples.
The first argument, structure, is the glycan to draw. It
can be a character string in a notation supported by
glyparse::auto_parse(), or a
glyrepr::glycan_structure() value.
draw_cartoon() returns a ggplot2 object with class
glydraw_cartoon. You can print it directly, pass it to
save_cartoon(), or add normal ggplot2 layers when
needed.
show_linkageshow_linkage controls whether glycosidic linkage
annotations are shown. Substituent annotations are always shown.
orientorient controls the overall direction of the cartoon.
Use "H" for the default horizontal layout or
"V" for a vertical layout.
fuc_orientfuc_orient controls how Fuc triangles are rotated. The
default, "flex", points non-reducing Fuc residues toward
their rendered linkage direction. Use "up" when every Fuc
triangle should point upward.
red_endred_end controls the reducing-end annotation. The
default "" draws the standard reducing-end line. Use
"~" for a wavy reducing end, or pass any other string to
draw that string at the reducing end.
edge_linewidth and node_linewidthedge_linewidth controls linkage line width.
node_linewidth controls the border width of residue
symbols.
node_sizenode_size is a multiplier for the default residue-symbol
size. The default is 1. Larger nodes keep the same cartoon
layout but draw larger symbols.
draw_cartoon(n_core, node_size = 1.6)
#> Warning: Linkage annotations are hidden because `node_size` is larger than 1.2.
#> ℹ Set `show_linkage = FALSE` to silence this warning, or use a smaller
#> `node_size`.Very large symbols can overlap, so values larger than 2
are rejected. Linkage annotations are hidden with a warning when the
requested node size leaves too little annotation space.
colorscolors is an optional named character vector for
overriding monosaccharide fill colors. Names must be supported
monosaccharide names. Only the names you provide are changed; all other
monosaccharides keep their default SNFG colors.
highlighthighlight marks selected residue nodes. It is available
when structure is a
glyrepr::glycan_structure() object. Node indices match the
monosaccharide order in the printed IUPAC-condensed structure.
highlight_glycan <- glyrepr::as_glycan_structure(
"Gal(b1-3)[GlcNAc(b1-6)]GalNAc(a1-"
)
draw_cartoon(highlight_glycan, highlight = c(1, 3))Use save_cartoon() when you already have one cartoon
object.
cartoon <- draw_cartoon(n_core, red_end = "~")
outfile <- file.path(tempdir(), "n-core.png")
save_cartoon(cartoon, outfile, scale = 2)
outfile
#> [1] "/tmp/RtmpSsVBDx/n-core.png"glydraw does not expose separate width and
height controls because each cartoon has a natural size
calculated from its glycan structure. scale preserves the
aspect ratio and relative symbol sizes.
Use export_cartoons() to draw and save a vector of
glycans in one call. The input can be a character vector or a
glyrepr::glycan_structure() vector.
glycans <- c(
core = "Man(a1-3)Man(b1-4)GlcNAc(b1-",
antenna = "Gal(b1-4)GlcNAc(b1-",
fucosylated = "Gal(b1-4)[Fuc(a1-3)]GlcNAc(b1-"
)
outdir <- file.path(tempdir(), "glydraw-cartoons")
suppressMessages(
cartoons <- export_cartoons(
glycans,
outdir,
file_ext = "png",
scale = 1.5,
red_end = "~",
node_size = 1.1
)
)
list.files(outdir)
#> [1] "antenna.png" "core.png" "fucosylated.png"export_cartoons() creates dirname when
needed and returns the list of cartoons invisibly. File names come from
vector names when present. Unnamed inputs use sanitized IUPAC-condensed
structure text as file names, and duplicate names are made unique.