
Prepare a Seurat Object for Uniform Downstream Analysis
PrepObject.RdAssigns color palettes and factor-level orderings to one or more metadata
variables and stores them in seurat_object@misc$nk_settings. All
downstream scSidekick functions look there first for colors and default
parameters; they only fall back to automatic palette generation when a
variable is not stored.
Additive by default. Calling PrepObject again for a new
variable (e.g. after cell-type assignment) does not overwrite existing
settings - it only adds or updates the variables you name. Set
force = TRUE to regenerate a variable that is already stored.
Auto-palette selection:
"auto":Nour_pal("all")for variables with \(\leq 8\) levels (warm, distinct),Nour_pal("spectrum")for \(> 8\) levels (broader color range).Specify per-variable, either by name
palettes = c(Cluster = "all", Sample = "spectrum")or by position (one entry pervariables, same order)palettes = c("spectrum", "all", "all").
Arguments
- seurat_object
A Seurat object.
- variables
Character vector of metadata column names to color and prepare. Can be a single name; re-run
PrepObjectat any time to add more.- palettes
Palette name(s). One of:
A single string (
"auto","all","spectrum", ...) applied to every variable.A named character vector keyed by variable (
c(Cluster = "all", Sample = "spectrum")); names not listed fall back to"auto".An unnamed character vector of the same length as
variables, matched by position (c("spectrum", "all", "all")).
Default
"auto".- reverse
Logical, named logical vector, or an unnamed logical vector matched by position to
variables.TRUEreverses the palette for all variables; a named vector reverses selectively (e.g.c(Cluster = TRUE, Sample = FALSE)). DefaultFALSE.- custom_colors
Named list of named character vectors that override automatic palette generation entirely for specific variables. E.g.
list(Sample = c(Control = "#3B4CC0", NRF1_mRNA = "#B40426")).- var_levels
Named list of character vectors that set the factor level ordering for each variable, controlling sort order in heatmap columns, violin plots, and ggplot2 facets. E.g.
list(Sample = c("Control", "NRF1_mRNA")).- group.by
Character. Store the preferred primary grouping column. Downstream scSidekick functions use this as the default
group.bywhen none is specified in the call. PassNAto explicitly clear a previously stored value.- split.by
Character. Store the preferred secondary split column. Downstream functions use this as the default
split.by. PassNAto explicitly disable the stored default (even if one exists).- donor.by
Character or
NULL. Metadata column that identifies the biological replicate / library unit – the donor, patient, mouse, or sample from which each cell/spot was obtained. When set, plotting functions include the number of unique donors in figure legends (e.g. "8,691 cells from 36 samples"). PassNAto clear a previously stored value.- assay_type
Character or
NULL. Sequencing modality. Controls the observation-level word used in auto-generated legend and methods text. Recognized values (same vocabulary aslog_analysis_params):"scRNAseq"– "cells" (default)"snRNAseq"– "nuclei""Visium"– "spots""VisiumHD"– "bins""Xenium"– "cells""Spatial"– "spots""scATACseq","scMultiome"– "cells"
Pass
NULLto leave unchanged;NAto clear.- output_dir
Character. Store the preferred output directory for saving PDFs and plots. All downstream scSidekick functions walk up to this value when their own
output_dirargument isNULL. PassNAto explicitly clear a stored value.- object_name
Character. Label used to prefix output file names.
- subset_name
Character. Optional subset label appended to output file names (e.g.
"NoNeurons").- AutoSavePlots
Logical or
NULL. Controls whether plotting functions automatically save PDFs to the storedoutput_dirwhen nooutput_diris passed explicitly in the function call.TRUE(default when not set): plotting functions walk up and use the storedoutput_dirautomatically – existing behavior.FALSE: the walk-up is suppressed; functions return the plot object without saving unless the caller explicitly passesoutput_dir = "..."in the plotting call.
Pass
NULLto leave the current setting unchanged.- force
Logical. If
FALSE(default), variables that already have stored colors are left unchanged. IfTRUE, existing colors are regenerated for every variable listed invariables.
Value
The seurat_object with @misc$nk_settings updated.
Return the object and re-assign: seurat_object <- PrepObject(...).