Group cells into pseudobulk fragment sets
pseudobulk_fragments.RdResolves cells into groups and returns one lazy IterableFragments per
group, filtered to the same region universe peak calling uses. Nothing is read
from disk until a write_pseudobulk_*() function runs.
Usage
# S3 method for class 'MarchRProject'
pseudobulk_fragments(
proj,
group_by = "clusters",
dataset_names = character(0),
frags_name = character(0),
blacklist = TRUE,
exclude_chr = c("chrM"),
min_fragments = NULL,
on_low_depth = c("warn", "abort", "drop"),
verbose = getOption("MarchR.verbose", FALSE),
...
)Arguments
- proj
(MarchRProject) Project holding fragments, or for the default method a named character vector of group labels (names = cell names).
- group_by
(character or NULL) Metadata column name, named vector of group labels (names = cell names), or
NULLto collapse all cells into a single"all"group. Default"clusters".- dataset_names
(character) Datasets to include. Defaults to all.
- frags_name
(character) Fragment slot to use. Auto-selected when unambiguous.
- blacklist
(logical, data.frame, or GRanges)
TRUEuses the project genome's blacklist. DefaultTRUE.- exclude_chr
(character) Chromosomes to drop. Default
c("chrM").- min_fragments
(numeric) Depth floor per group.
NULLreports depths without gating. DefaultNULL.- on_low_depth
(character) Response when a group falls below
min_fragments. One of"warn","abort","drop". Default"warn".- verbose
(logical) Print progress messages. Default
getOption("MarchR.verbose", FALSE).- ...
Passed to methods.
Value
A MarchRPseudobulk object: a list with fragments (named list of
IterableFragments), manifest (tibble, one row per group), and
params (the resolution parameters).
Details
Which pseudobulk do you want? If the downstream tool needs to know where
within a feature a read fell, use this function. If it only needs a count per
feature per group, use BPCells::pseudobulk_matrix() on the assay directly.
Prerequisites. Only fragments and a cell-to-group labelling are required. A
grouping can come from any categorical metadata column, a named vector, or NULL
for a single whole-dataset bulk, so this does not depend on having run
add_clusters or any dimensionality reduction. Exporting peaks with
write_pseudobulk_peaks is the one step that additionally needs
add_reproducible_peak_set.
Fragments are concatenated across datasets, then blacklist- and chromosome-filtered through the same helper peak calling uses, so an export and its peak set describe the same region universe.
Depth and TSS enrichment in the manifest are read from stored fragment QC when
run_fragment_qc has run. Otherwise depth is measured with a single
streaming pass, so the min_fragments gate is usable either way.
Methods (by class)
pseudobulk_fragments(MarchRProject): Resolve pseudobulk fragments for a MarchRProject.
See also
write_pseudobulk_fragments and
write_pseudobulk_coverage for writing artifacts.
Other pseudobulk:
write_pseudobulk_bigwig(),
write_pseudobulk_chrom_sizes(),
write_pseudobulk_coverage(),
write_pseudobulk_fragments(),
write_pseudobulk_manifest(),
write_pseudobulk_peaks(),
write_sce2g_inputs()
Examples
if (FALSE) { # \dontrun{
# Grouped by any categorical column, or a named vector, or NULL for one bulk
pb <- pseudobulk_fragments(proj, group_by = "cell_type")
pb <- pb %>%
write_pseudobulk_fragments(out_dir) %>%
write_pseudobulk_coverage(out_dir) %>%
write_pseudobulk_peaks(out_dir) %>%
write_pseudobulk_manifest(out_dir)
} # }