
Build a Symphony reference from a SingleCells object
build_symphony_ref.RdRuns sparse PCA over the provided HVGs, runs Harmony for batch correction,
and compresses the result into the cached terms used at query time. The
Harmony version is auto-detected from the class of harmony_params.
Optionally snapshots one or more obs columns (e.g. cell type annotations)
into the reference's labels slot for downstream label transfer.
Usage
build_symphony_ref(
object,
batch_column,
additional_batch_columns = NULL,
hvg,
harmony_params = params_sc_harmony(),
pca_params = params_sc_pca(),
no_pcs = 30L,
slim = FALSE,
label_columns = NULL,
seed = 42L,
.verbose = TRUE
)Arguments
- object
SingleCells(the reference).- batch_column
String. Primary batch column in the obs table.
- additional_batch_columns
Optional character vector.
- hvg
Integer vector. R-style 1-based HVG indices into the gene universe of
object. Must be provided explicitly.- harmony_params
List. Output of
params_sc_harmony()orparams_sc_harmony_v2().- pca_params
List. Output of
params_sc_pca().- no_pcs
Integer. Number of principal components.
- slim
Boolean. If
TRUE, dropsz_origandrfrom the returned reference.z_corris always kept (needed for kNN label transfer).- label_columns
Optional character vector of obs column names to snapshot into the reference. Read in
cells_to_keeporder to align withz_corr. Required fortransfer_labels_symphony()unless populated later viaadd_symphony_labels().- seed
Integer.
- .verbose
Boolean or integer.
Value
A SymphonyReference object.
Examples
# two batch reference, cell type labels snapshotted along the way
ref <- demo_single_cells(
syn_data_params = params_sc_synthetic_data(
n_cells = 500L,
n_genes = 50L,
n_batches = 2L,
batch_effect_strength = "medium"
)
)
symphony_ref <- build_symphony_ref(
ref,
batch_column = "batch_index",
hvg = get_hvg(ref) + 1L,
harmony_params = params_sc_harmony(k = 10L),
no_pcs = 10L,
label_columns = "cell_grp",
.verbose = FALSE
)
symphony_ref
#> Symphony reference
#> Harmony backend: v1
#> No HVGs: 30
#> No PCs: 10
#> No clusters: 10
#> Batch variables: batch_index
#> Slim: FALSE
#> Labels: cell_grp
unlink(ref@dir_data, recursive = TRUE, force = TRUE)