| Title: | Publication-Quality Circular and Linear Plasmid Maps |
|---|---|
| Description: | Draws circular and linear plasmid maps with 'grid' graphics. Features are shown as colored arcs with optional arrowheads, callout labels that are laid out to avoid overlap, an automatic base-pair scale, and the plasmid name and size. A style is built from a handful of shape parameters, with presets as named combinations of them, and the layout follows the molecule's topology. Maps can be built up feature by feature or imported from 'GenBank', 'EMBL', 'FASTA' and 'SnapGene' files, whose format is detected from content rather than file extension. Restriction sites can be located in the sequence and labeled. Ships eight visual styles, including one inspired by the 'AngularPlasmid' JavaScript library, and seven categorical palettes checked for colorblind safety. Palettes from other packages can be used directly, as a color vector or as a palette function, and checked against the same criteria. |
| Authors: | Qiyou Pan [aut, cre] |
| Maintainer: | Qiyou Pan <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.0 |
| Built: | 2026-09-25 09:53:36 UTC |
| Source: | https://github.com/dkturingfz/plasmidplot |
A plasmid object holds the plasmid name, its length in base pairs, and
the list of features (markers) added with pp_marker(). Plot it with
plot.plasmid().
plasmid(name, length)plasmid(name, length)
name |
Plasmid name, shown in the center of the map. |
length |
Plasmid length in base pairs (a single positive number). |
An object of class plasmid.
p <- plasmid("pBR322", 4361) p <- pp_marker(p, 86, 1276, label = "TcR") plot(p)p <- plasmid("pBR322", 4361) p <- pp_marker(p, 86, 1276, label = "TcR") plot(p)
Renders the plasmid as a circular or linear map: a backbone with a base-pair scale, colored feature arcs (with optional arrowheads), callout labels with leader lines, restriction sites, and the plasmid name and size.
## S3 method for class 'plasmid' plot(x, style = "angular", bg = NULL, newpage = TRUE, ...)## S3 method for class 'plasmid' plot(x, style = "angular", bg = NULL, newpage = TRUE, ...)
x |
A |
style |
A preset name or a |
bg |
Background to paint behind the map. |
newpage |
Start a new grid page first (default |
... |
Ignored. |
The layout follows the plasmid's topology unless the style says
otherwise; see the layout shape parameter in pp_style().
Invisibly, x.
p <- plasmid("pBR322", 4361) |> pp_marker(86, 1276, label = "TcR", arrow = "end") |> pp_marker(2535, 3122, label = "ori") |> pp_marker(3293, 4153, label = "AmpR", arrow = "start") plot(p, style = "angular") plot(p, style = "dark", bg = pp_canvas("dark")) plot(p, style = pp_style("angular", layout = "linear"))p <- plasmid("pBR322", 4361) |> pp_marker(86, 1276, label = "TcR", arrow = "end") |> pp_marker(2535, 3122, label = "ori") |> pp_marker(3293, 4153, label = "AmpR", arrow = "start") plot(p, style = "angular") plot(p, style = "dark", bg = pp_canvas("dark")) plot(p, style = pp_style("angular", layout = "linear"))
Styles do not paint a background; the device or surrounding viewport shows through. This returns the ground a style was designed against, so a dark preset can be given one explicitly.
pp_canvas(style)pp_canvas(style)
style |
A preset name or |
A color string.
pp_canvas("dark") p <- pp_demo_plasmid() plot(p, style = "neon", bg = pp_canvas("neon"))pp_canvas("dark") p <- pp_demo_plasmid() plot(p, style = "neon", bg = pp_canvas("neon"))
Runs the measurable checks a categorical palette has to pass, using the
same transforms and thresholds the built-in palettes were validated with.
Use it on any palette you bring from another package – ggsci,
RColorBrewer, viridis, ggpubr – before relying on it.
pp_check_palette( colors, mode = c("light", "dark"), surface = NULL, pairs = c("adjacent", "all"), n = 8L )pp_check_palette( colors, mode = c("light", "dark"), surface = NULL, pairs = c("adjacent", "all"), n = 8L )
colors |
A vector of colors, a |
mode |
|
surface |
The background the marks sit on. Defaults to the mode's
standard surface. Pass |
pairs |
|
n |
Number of colors to draw when |
Five checks are computed. Two of them – CVD separation and the normal-vision floor – decide whether a reader can tell two features apart at all; failing either means the palette is unsafe as it stands. The other three govern how the palette looks and how it sits on the surface, and failing them means the colors are legible but sit outside the band the built-in palettes hold to. The printed summary says which kind failed, because most palettes from other packages miss the cosmetic bands while remaining perfectly readable.
Lightness band – OKLCH L inside the band for the mode.
Chroma floor – OKLCH C at or above 0.10, below which a hue reads gray.
CVD separation – OKLab dE between slots under simulated protanopia and deuteranopia (tritanopia reported alongside). At or above 8 passes; 6 to 8 is a warning band that is sound only with a second channel – on a plasmid map every feature carries a text label, which supplies it. Below 6 fails.
Normal-vision floor – worst pair at or above dE 15 under ordinary vision. This one is a hard gate: below it, full-color readers cannot tell the two apart either, and a text label does not excuse it.
Contrast vs surface – WCAG ratio of at least 3:1. A warning here obliges visible labels, which the maps always draw.
An object of class pp_palette_check: a data frame of one row per
check with columns check, status ("PASS", "WARN" or "FAIL") and
detail, carrying an ok attribute that is FALSE if anything failed.
pp_check_palette("default") pp_check_palette("default_dark", mode = "dark") # A palette brought from elsewhere: pp_check_palette(c("#E64B35", "#4DBBD5", "#00A087", "#3C5488")) # A palette function is called with n. pp_check_palette(function(n) grDevices::hcl.colors(n, "Dark 3"), n = 6) pp_check_palette(grDevices::palette.colors(8, "Okabe-Ito"))pp_check_palette("default") pp_check_palette("default_dark", mode = "dark") # A palette brought from elsewhere: pp_check_palette(c("#E64B35", "#4DBBD5", "#00A087", "#3C5488")) # A palette function is called with n. pp_check_palette(function(n) grDevices::hcl.colors(n, "Dark 3"), n = 6) pp_check_palette(grDevices::palette.colors(8, "Okabe-Ito"))
Plots pp_demo_plasmid() in the given style. Handy for previewing styles;
see pp_style() for the list of presets.
pp_demo(style = "angular")pp_demo(style = "angular")
style |
A preset name or |
The demo paints the style's own pp_canvas() so the dark presets are
legible on a white device; ordinary plotting leaves the background alone.
Invisibly, the demo plasmid object.
pp_demo("angular") pp_demo("neon")pp_demo("angular") pp_demo("neon")
Builds a small pBR322 map (positions approximate) without plotting it.
pp_demo_plasmid()pp_demo_plasmid()
A plasmid object.
pp_demo_plasmid()pp_demo_plasmid()
The recognition sequences pp_find_sites() searches for.
pp_enzymes()pp_enzymes()
A data frame with columns enzyme, site (recognition sequence,
IUPAC codes allowed) and cut (0-based cut offset on the top strand
within the recognition sequence).
head(pp_enzymes()) subset(pp_enzymes(), enzyme %in% c("EcoRI", "BamHI"))head(pp_enzymes()) subset(pp_enzymes(), enzyme %in% c("EcoRI", "BamHI"))
A vectorized pp_marker(): one row per feature. Only start and end
are required; any other column named after a pp_marker() argument is
used, and unknown columns are ignored.
pp_features(p, df)pp_features(p, df)
p |
A |
df |
A data frame with columns |
The updated plasmid object.
feats <- data.frame( start = c(86, 2535, 3293), end = c(1276, 3122, 4153), label = c("TcR", "ori", "AmpR"), arrow = c("end", "none", "start") ) plot(pp_features(plasmid("pBR322", 4361), feats))feats <- data.frame( start = c(86, 2535, 3293), end = c(1276, 3122, 4153), label = c("TcR", "ori", "AmpR"), arrow = c("end", "none", "start") ) plot(pp_features(plasmid("pBR322", 4361), feats))
Searches the sequence kept by the readers and adds a pp_site() for each
cut position. On a circular plasmid the search wraps the origin, so a site
straddling position 1 is not missed.
pp_find_sites( p, enzymes = NULL, unique_only = TRUE, max_sites = 3L, show_position = TRUE )pp_find_sites( p, enzymes = NULL, unique_only = TRUE, max_sites = 3L, show_position = TRUE )
p |
A |
enzymes |
Enzyme names from |
unique_only |
Keep only enzymes that cut exactly once (default
|
max_sites |
Drop enzymes cutting more than this many times. Ignored
when |
show_position |
Append the cut position to each label, e.g.
|
The updated plasmid object.
p <- read_genbank(system.file("extdata", "pDemo.gb", package = "plasmidplot")) p <- pp_find_sites(p, c("EcoRI", "BamHI", "HindIII", "NotI")) p plot(p) # Every unique cutter the built-in table knows about: plot(pp_find_sites(read_genbank( system.file("extdata", "pDemo.gb", package = "plasmidplot"))))p <- read_genbank(system.file("extdata", "pDemo.gb", package = "plasmidplot")) p <- pp_find_sites(p, c("EcoRI", "BamHI", "HindIII", "NotI")) p plot(p) # Every unique cutter the built-in table knows about: plot(pp_find_sites(read_genbank( system.file("extdata", "pDemo.gb", package = "plasmidplot"))))
Markers are drawn as colored arcs on the plasmid backbone. A marker whose
end is smaller than its start is taken to wrap across the origin
(position 1). Calls are pipe-friendly: each returns the updated object.
pp_marker( p, start, end, label = NULL, color = NULL, group = NULL, arrow = c("none", "end", "start", "both"), offset = 0, width = NULL )pp_marker( p, start, end, label = NULL, color = NULL, group = NULL, arrow = c("none", "end", "start", "both"), offset = 0, width = NULL )
p |
A |
start, end
|
Feature boundaries in base pairs (1-based, inclusive). |
label |
Optional text label, drawn outside the map with a leader line. |
color |
Arc color. Defaults to the next color of the style palette. |
group |
Optional grouping key. Markers sharing a group take the same
palette color, so e.g. every CDS can be drawn in one color without
naming the color here. Ignored when |
arrow |
Arrowhead placement: |
offset |
Radial offset from the backbone in npc units. Positive moves the marker outward; useful to separate overlapping features. |
width |
Arc thickness in npc units. Defaults to the style's
|
The updated plasmid object.
p <- plasmid("pUC19", 2686) |> pp_marker(146, 469, label = "lacZ-alpha", arrow = "end") |> pp_marker(1629, 2486, label = "AmpR", arrow = "start") plot(p)p <- plasmid("pUC19", 2686) |> pp_marker(146, 469, label = "lacZ-alpha", arrow = "end") |> pp_marker(1629, 2486, label = "AmpR", arrow = "start") plot(p)
Named color sets that can be passed to pp_style() as palette = "<name>".
pp_palette(name)pp_palette(name)
name |
Palette name. If missing, returns the names of all palettes. |
A palette is only the colors. The geometry, chrome and typography of a map
are a style – see pp_style() – and the two are chosen independently:
any palette can be paired with any style. Names ending in _dark are
stepped for a dark ground and will be washed out on a light one.
Every palette here was checked pair-by-pair under protanopia, deuteranopia and tritanopia simulation against the surface it is meant for, and against a normal-vision separation floor:
"default" (light), "default_dark" (dark) and "jewel" (light) clear
every gate, contrast included.
"vivid" and "candy" (light) clear every separation gate.
"muted" (light) clears the separation floors, with its closest
colorblind pair in the band that is sound only because each feature also
carries a text label – identity here never rests on hue alone.
"neon_dark" clears contrast and both separation floors on a dark
ground. It sits deliberately brighter than the others; that is the look.
Slot order carries the safety, so take the colors in the order given. Palettes of near-neighbor hues (all-brown, all-blue sets) were dropped during development because adjacent features became indistinguishable under red-green colorblindness.
A character vector of hex colors, or of palette names.
pp_palette() pp_palette("muted") plot(pp_demo_plasmid(), style = pp_style("angular", palette = "vivid"))pp_palette() pp_palette("muted") plot(pp_demo_plasmid(), style = pp_style("angular", palette = "vivid"))
Sites are drawn as a radial tick outside the feature ring with a label,
the way restriction sites are shown on a classic plasmid map. Unlike
pp_marker() they occupy one position rather than a span.
pp_site(p, position, label = NULL, color = NULL)pp_site(p, position, label = NULL, color = NULL)
p |
A |
position |
Position in base pairs. |
label |
Site label, e.g. an enzyme name. |
color |
Tick color. Defaults to the style's |
The updated plasmid object.
pp_find_sites() to add restriction sites from the sequence.
p <- plasmid("pUC19", 2686) |> pp_marker(146, 469, label = "lacZ", arrow = "end") |> pp_site(396, "EcoRI") |> pp_site(447, "BamHI") plot(p)p <- plasmid("pUC19", 2686) |> pp_marker(146, 469, label = "lacZ", arrow = "end") |> pp_site(396, "EcoRI") |> pp_site(447, "BamHI") plot(p)
A style is built from a handful of shape parameters plus secondary ink and type settings. Set the shape parameters directly; the presets are only named combinations of them, and everything a preset does can be written out by hand.
pp_style(preset, ...)pp_style(preset, ...)
preset |
Base preset to start from; see the table above. Call
|
... |
Named overrides. The shape parameters are |
An object of class pp_style, or a character vector of preset
names when called with no arguments.
These decide the construction of the map. They are the arguments worth reaching for first:
layout"auto" draws a circular map for a circular plasmid and
a linear one for a linear plasmid, following the object's topology.
Force it with "circular" or "linear".
anchorWhere features sit relative to the backbone: "center"
on it, "outside" clear of it (outward on a circle, above the line on
a linear map), or "inside".
backbone"ring" draws the backbone as a filled band, "line"
as a single stroke, "none" omits it.
radiusCircular only: the backbone's radius, in npc units of a square viewport, so the usable maximum is 0.5.
trackBackbone thickness, used when backbone = "ring".
arcFeature thickness.
gapClearance between backbone and features when anchor is
"outside" or "inside".
Every preset is exactly the shape below, plus colors. dark is angular
restepped for a dark ground, which is why their shapes match.
| preset | layout | anchor | backbone | radius | track | arc |
angular |
auto | center | ring | 0.30 | 0.045 | 0.058 |
classic |
auto | outside | line | 0.26 | 0.045 | 0.050 |
dark |
auto | center | ring | 0.30 | 0.045 | 0.058 |
snapgene |
auto | center | ring | 0.30 | 0.012 | 0.042 |
soft |
auto | center | ring | 0.28 | 0.090 | 0.090 |
neon |
auto | outside | ring | 0.25 | 0.030 | 0.050 |
minimal |
auto | center | line | 0.30 | 0.045 | 0.022 |
blueprint |
auto | inside | line | 0.33 | 0.045 | 0.050 |
Their default palettes are default, except soft (muted), dark and
blueprint (default_dark) and neon (neon_dark). A palette is an
independent choice – see pp_palette().
pp_style() p <- pp_demo_plasmid() # Compose a style from the shape parameters, no preset involved. plot(p, style = pp_style(anchor = "outside", backbone = "line", radius = 0.26, arc = 0.05)) # Or start from a preset and change one thing. plot(p, style = pp_style("angular", arc = 0.09)) plot(p, style = pp_style("minimal", layout = "linear")) # A palette can be a vector of colors, or a function of n returning n # colors -- the form ggsci, RColorBrewer and viridis palettes take. plot(p, style = pp_style("angular", palette = grDevices::hcl.colors(8, "Set2"))) plot(p, style = pp_style("angular", palette = function(n) grDevices::hcl.colors(n, "Dark 3")))pp_style() p <- pp_demo_plasmid() # Compose a style from the shape parameters, no preset involved. plot(p, style = pp_style(anchor = "outside", backbone = "line", radius = 0.26, arc = 0.05)) # Or start from a preset and change one thing. plot(p, style = pp_style("angular", arc = 0.09)) plot(p, style = pp_style("minimal", layout = "linear")) # A palette can be a vector of colors, or a function of n returning n # colors -- the form ggsci, RColorBrewer and viridis palettes take. plot(p, style = pp_style("angular", palette = grDevices::hcl.colors(8, "Set2"))) plot(p, style = pp_style("angular", palette = function(n) grDevices::hcl.colors(n, "Dark 3")))
EMBL's feature table uses the same location grammar as GenBank, so
complement(...), join(...) and partial boundaries behave identically;
only the line prefixes differ.
read_embl( file, name = NULL, types = NULL, skip_types = "source", label_from = c("label", "gene", "product", "standard_name", "note", "locus_tag"), colors = c("style", "file"), color_by = c("feature", "type"), arrows = TRUE, sequence = TRUE )read_embl( file, name = NULL, types = NULL, skip_types = "source", label_from = c("label", "gene", "product", "standard_name", "note", "locus_tag"), colors = c("style", "file"), color_by = c("feature", "type"), arrows = TRUE, sequence = TRUE )
file |
Path to a |
name |
Plasmid name. Defaults to the |
types |
Feature types to keep (e.g. |
skip_types |
Feature types to drop. |
label_from |
Qualifier names to try, in order, when labeling a feature. Falls back to the feature type. |
colors |
|
color_by |
|
arrows |
Draw arrowheads for stranded features (default |
sequence |
Keep the |
A plasmid object.
read_genbank(), read_plasmid()
embl <- system.file("extdata", "pDemo.embl", package = "plasmidplot") p <- read_embl(embl) pembl <- system.file("extdata", "pDemo.embl", package = "plasmidplot") p <- read_embl(embl) p
FASTA carries no feature table, so the result is a bare backbone: name,
length and sequence, with no markers. Add features with pp_marker(), or
restriction sites with pp_find_sites(), which needs exactly this.
read_fasta(file, name = NULL, circular = TRUE, ...)read_fasta(file, name = NULL, circular = TRUE, ...)
file |
Path to a FASTA file, or a file holding only sequence letters. |
name |
Plasmid name. Defaults to the FASTA header (up to its first space), or the file name when there is no header. |
circular |
Whether the sequence is circular (default |
... |
Ignored, so |
A plasmid object.
fa <- tempfile(fileext = ".fa") writeLines(c(">pMini test plasmid", strrep("ATGC", 500)), fa) p <- read_fasta(fa) p unlink(fa)fa <- tempfile(fileext = ".fa") writeLines(c(">pMini test plasmid", strrep("ATGC", 500)), fa) p <- read_fasta(fa) p unlink(fa)
Parses the LOCUS line for the name and length and the FEATURES block
for markers. Handles complement(...), join(...), and the </>
partial-boundary markers. A join() whose first segment starts after its
last segment ends is kept as an origin-crossing feature.
read_genbank( file, name = NULL, types = NULL, skip_types = "source", label_from = c("label", "gene", "product", "standard_name", "note", "locus_tag"), colors = c("style", "file"), color_by = c("feature", "type"), arrows = TRUE, sequence = TRUE )read_genbank( file, name = NULL, types = NULL, skip_types = "source", label_from = c("label", "gene", "product", "standard_name", "note", "locus_tag"), colors = c("style", "file"), color_by = c("feature", "type"), arrows = TRUE, sequence = TRUE )
file |
Path to a |
name |
Plasmid name. Defaults to the |
types |
Feature types to keep (e.g. |
skip_types |
Feature types to drop. |
label_from |
Qualifier names to try, in order, when labeling a feature. Falls back to the feature type. |
colors |
|
color_by |
|
arrows |
Draw arrowheads for stranded features (default |
sequence |
Keep the |
A plasmid object.
read_snapgene(), read_plasmid(), pp_find_sites()
gb <- system.file("extdata", "pBR322.gb", package = "plasmidplot") p <- read_genbank(gb) p plot(p)gb <- system.file("extdata", "pBR322.gb", package = "plasmidplot") p <- read_genbank(gb) p plot(p)
Detects the format from the file's content rather than its extension, so a
.dna file is read as SnapGene or as plain sequence depending on what it
actually contains, and a GenBank record saved as .txt still works.
read_plasmid(file, ...)read_plasmid(file, ...)
file |
Path to the file. |
... |
Passed to the underlying reader. |
Recognized formats: SnapGene (.dna binary), GenBank, EMBL, FASTA, and a
bare sequence with no header at all.
A plasmid object.
read_genbank(), read_snapgene(), read_embl(), read_fasta()
gb <- system.file("extdata", "pBR322.gb", package = "plasmidplot") plot(read_plasmid(gb))gb <- system.file("extdata", "pBR322.gb", package = "plasmidplot") plot(read_plasmid(gb))
Parses a SnapGene .dna file: sequence length and topology from the
sequence segment, and features (name, type, range, strand, color) from the
embedded feature table.
read_snapgene( file, name = NULL, types = NULL, skip_types = character(), label_from = c("label", "name", "gene", "product", "note"), colors = c("style", "file"), color_by = c("feature", "type"), arrows = TRUE, sequence = TRUE )read_snapgene( file, name = NULL, types = NULL, skip_types = character(), label_from = c("label", "name", "gene", "product", "note"), colors = c("style", "file"), color_by = c("feature", "type"), arrows = TRUE, sequence = TRUE )
file |
Path to a |
name |
Plasmid name. Defaults to the file name without its extension. |
types |
Feature types to keep. |
skip_types |
Feature types to drop. |
label_from |
Qualifier names to try, in order, when labeling a
feature. |
colors |
|
color_by |
|
arrows |
Draw arrowheads for stranded features (default |
sequence |
Keep the sequence on the result (default |
SnapGene records carry no plasmid name, so the file's base name is used
unless name is given.
A plasmid object.
Requires the xml2 package, which is only needed for this reader.
read_genbank(), read_plasmid()
if (requireNamespace("xml2", quietly = TRUE)) { dna <- system.file("extdata", "pDemo.dna", package = "plasmidplot") p <- read_snapgene(dna) print(p) plot(p, style = "snapgene") # Keep the colors the file itself stores, rather than the style's palette. plot(read_snapgene(dna, colors = "file")) }if (requireNamespace("xml2", quietly = TRUE)) { dna <- system.file("extdata", "pDemo.dna", package = "plasmidplot") p <- read_snapgene(dna) print(p) plot(p, style = "snapgene") # Keep the colors the file itself stores, rather than the style's palette. plot(read_snapgene(dna, colors = "file")) }