Colour a two-dimensional embedding (UMAP, t-SNE, PCA, MDS) by factor activity, one panel per factor. Pass a native fit or view together with a named samples by 2 coordinate matrix; a Seurat object with its reduction name also works.
Arguments
- object
Native fit or view from
standardize_factors(), or a Seurat object holding original factor and embedding reductions.- reduction
For a fit or view: named numeric matrix with one row per sample and at least two columns of embedding coordinates. For a Seurat object: the embedding reduction name.
- factors
Character factor IDs to display, one panel each.
- display
"activity"(default) or"percentile"(display-only empirical percentile againstreference_samples).- ...
Optional
reference_samples(percentile reference IDs),max_samples(default 2000),seed(default 1),palette(negative, zero, positive colours),limits; andactivity_reductionfor a Seurat object only.
Value
A ggplot object; $data has sample, factor, estimate, x, y,
with sampled IDs, reference IDs and basis metadata attributes.
Details
Origin: NEW_QOL / call_only. Credits factor-space activity display workflow; use factor_provenance("plot_factor_embedding") for audited sources and runtime versions. Input units and basis are retained; display/conditional results do not establish biological replication.
Author
David Zemmour / Zemmour Lab (ImmGenT workflows). Full source and dependency credits: https://github.com/mdmanurung/flashier-utils/blob/main/CREDITS.md.
Examples
if (FALSE) {
set.seed(3)
X <- tcrossprod(matrix(rnorm(48), 24, 2), matrix(rnorm(32), 16, 2)) +
matrix(rnorm(384, sd = 0.2), 24, 16)
dimnames(X) <- list(paste0("s", 1:24), paste0("g", 1:16))
fit <- fit_ebmf(X, "rows",
max_factors = 2, seed = 4, verbose = 0,
ebnm_fn = list(ebnm::ebnm_normal, ebnm::ebnm_point_laplace),
nullcheck = FALSE, backfit = TRUE, feature_scale = "simulated_centered_intensity"
)
view <- standardize_factors(fit)
# Adapter mechanics on simulated cells; no biological inference.
counts <- Matrix::Matrix(matrix(1, 16, 24, dimnames = list(colnames(X), rownames(X))), sparse = TRUE)
object <- SeuratObject::CreateSeuratObject(counts, assay = "panel")
object <- add_factors_to_seurat(object, view)
object <- embed_factors(object, seed = 4, n_neighbors = 4, n_epochs = 20, init = "random")
plot_factor_embedding(object, "ebmfumap", "F1", display = "percentile", max_samples = 12, seed = 4)
}