Skip to contents

Wrapper around BPCells' trackplot functions that extracts fragments, cell groupings, and gene annotations from a MarchRProject to produce a stacked genome browser view with coverage, gene models, and optional loop/peak tracks.

Usage

plot_browser_track(
  proj,
  region = NULL,
  gene_symbol = NULL,
  group_by = "clusters",
  use_groups = NULL,
  dataset_names = character(0),
  frags_name = character(0),
  tracks = c("coverage", "peaks", "gene"),
  bins = 500L,
  tile_size = NULL,
  norm_method = c("nFrags", "ReadsInTSS", "nCells"),
  norm_style = c("rpkm", "archr"),
  annotation_name = character(0),
  gene_track_mode = c("gene", "transcript"),
  loops = NULL,
  loop_color_by = NULL,
  loop_track_label = "Links",
  loop_within_region = TRUE,
  features = NULL,
  upstream = 50000,
  downstream = 50000,
  extend_bp = 1e+05,
  base_size = 10,
  strip_position = c("right", "left", "top", "bottom"),
  ylab_style = c("archr", "bpcells"),
  combine = c("patchwork", "bpcells", "none"),
  colors = NULL,
  title = NULL,
  verbose = getOption("MarchR.verbose", FALSE)
)

Arguments

proj

(MarchRProject) Project containing fragments, cell metadata, and genome annotations.

region

(character or NULL) Genomic region as "chr:start-end". If NULL, computed from gene_symbol.

gene_symbol

(character or NULL) Gene symbol to center the view on. Used only if region is NULL.

group_by

(character) Cell metadata column name for grouping cells into coverage tracks. Default is "clusters".

use_groups

(character or NULL) Subset of group labels to plot. NULL (default) plots all groups.

dataset_names

(character) Names of datasets to include. Default is all datasets.

frags_name

(character) Name of fragments to use. Auto-selected if only one exists.

tracks

(character) Track types to include. Options: "coverage", "peaks", "gene", "loop", "scalebar". Default is c("coverage", "peaks", "gene").

bins

(integer) Number of bins for coverage tiling. Default is 500. Ignored when tile_size is set.

tile_size

(integer or NULL) Fixed bin width in base pairs (ArchR's tileSize). When set, bins is derived as region_width %/% tile_size. NULL (default) uses bins.

norm_method

(character) Normalization method for coverage tracks. "nFrags" (default) normalizes by total fragments per cell. "ReadsInTSS" normalizes by TSS-overlapping reads. "nCells" normalizes by number of cells per group (no per-cell scaling - pass a vector of ones).

norm_style

(character) Coverage scaling formula. "rpkm" (default, BPCells) scales by 1e9 / (group_reads * bin_width) (insertions per kilobase per normalized read). "archr" reproduces ArchR's plotBrowserTrack scaling, 1e4 / group_reads (per-bin, not divided by bin width), yielding ArchR-comparable y-axis values.

annotation_name

(character) Name of gene annotation stored in the project genome to use for the gene track. Defaults to "transcripts" (required shape for BPCells' trackplot_gene()). Only used when gene_track_mode = "transcript".

gene_track_mode

(character) Gene-track renderer. "gene" (default) draws one row per gene from the project's "genes" annotation, with merged exons from a stored "exons" annotation (or, as a fallback, exon rows filtered out of "transcripts"). "transcript" delegates to BPCells::trackplot_gene() and draws one row per transcript using the annotation named by annotation_name (default "transcripts").

loops

(data.frame, GRanges, or NULL) Loop/interaction data with chr, start, end columns. Only used when "loop" is in tracks.

loop_color_by

(character or NULL) Name of a numeric loops column (e.g. correlation) to color arcs by. NULL (default) disables coloring.

loop_track_label

(character) Y-axis label for the loop track. Default "Links".

loop_within_region

(logical) Keep only loops with both anchors inside the region (ArchR behavior). When FALSE, loops with one anchor in the region are drawn truncated. Default TRUE.

features

(GRanges, data.frame, or NULL) Peak intervals for the "peaks" track. NULL (default) uses the project's stored peak set via get_peak_set().

upstream

(numeric) Base pairs to extend upstream of the TSS when resolving a region from gene_symbol. Default 5e4.

downstream

(numeric) Base pairs to extend downstream of the TSS when resolving a region from gene_symbol. Default 5e4.

extend_bp

(numeric) Base pairs to extend on each side when computing region from gene_symbol. Default is 1e5.

base_size

(numeric) Base font size (pt) for axis and strip text. Default 10.

strip_position

(character) Side where per-group facet labels appear. One of "right" (default), "left", "top", "bottom".

ylab_style

(character) Y-axis label style. One of "archr" (default) or "bpcells". See Details.

combine

(character) How to assemble the stacked track plots. "patchwork" (default) uses patchwork::wrap_plots() so the X-axis renders under the coverage track. "bpcells" delegates to BPCells::trackplot_combine(), which strips the X-axis from non-bottom plots. "none" returns a named list (tracks, title, region) for the caller to compose.

colors

(character or NULL) Color vector for groups. NULL uses BPCells' default palette.

title

(character or NULL) Plot title.

verbose

(logical) Print progress messages. Default getOption("MarchR.verbose", FALSE).

Value

A patchwork ggplot object with stacked tracks.

Details

Analogous to ArchR's plotBrowserTrack(). Coverage is computed lazily from fragments using BPCells' trackplot_coverage(); no pre-computed BigWig or coverage files are needed.

Aesthetic alignment with ArchR (as of ArchR plotBrowserTrack in R/ArchRBrowser.R):

  • Title is prefixed with "chr:start-end" from the resolved region. ArchR uses start(region) - 1 on its 1-based GRanges; MarchR builds the region as a 0-based string directly from BPCells annotations, so the displayed start is equivalent.

  • Facet strips render on the strip_position side (default "right") with a grey fill and black border.

  • When ylab_style = "archr", the Y-axis reads "Coverage\n(Norm. ATAC Signal by <norm_method>)"; when "bpcells", BPCells' own label is preserved.

  • upstream/downstream match ArchR's semantics and are applied strand-aware around the TSS via gene_region().

  • The gene track defaults to gene_track_mode = "gene", which draws one row per gene from the "genes" annotation with union from "exons" annotation.

  • The "peaks" track renders reproducible peaks as blocks, mirroring ArchR's featureTrack.

Normalization uses IPKM (insertions per kilobase per million mapped reads) via BPCells. The norm_method parameter controls which per-cell metric is used as the denominator: nFrags (total fragments), ReadsInTSS (TSS-overlapping reads, matching ArchR's default), or nCells (uniform weighting).