Estimate spot-level cell type proportions from a spatial Seurat object
using a single-cell Seurat reference and spacexr RCTD.
Usage
RunRCTD(
srt,
reference,
reference_label = "celltype",
assay = NULL,
reference_assay = NULL,
layer = "counts",
reference_layer = "counts",
features = NULL,
image = NULL,
coord.cols = c("x", "y"),
rctd_mode = c("full", "multi", "doublet"),
max_cores = 1,
min_cells = 25,
prefix = "RCTD",
store_results = TRUE,
round_counts = TRUE,
create_rctd_params = list(),
run_rctd_params = list(),
verbose = TRUE,
...,
coordinate_space = c("raw", "legacy_display"),
tool_name = "RCTD"
)Arguments
- srt
Spatial
Seuratobject used as the RCTD query.- reference
Reference
Seuratobject containing annotated single cells.- reference_label
Metadata column in
referencewith cell type labels.- assay
Assay used in
srt. IfNULL, the default assay is used.- reference_assay
Assay used in
reference.- layer, reference_layer
Assay layers used for spatial and reference raw counts.
- features
Features used for RCTD. If
NULL, shared features are used.- image
Name of the Seurat spatial image used to recover coordinates when
coord.colsare not available.- coord.cols
Metadata coordinate columns used when no image coordinate source is requested or available.
- rctd_mode
RCTD mode passed to
spacexr."full"is the default for Visium spot deconvolution.- max_cores
Number of cores passed to
spacexr.- min_cells
Minimum number of reference cells required for each cell type. Old
spacexrRCTD requires at least 25 cells per type.- prefix
Prefix for metadata columns.
- store_results
Whether to store detailed RCTD results in
srt@tools.- round_counts
Whether to round non-integer counts to the nearest integer before passing data to
spacexr. RCTD requires integer count matrices; this defaults toTRUEso bundled example data with scaled non-integer reference counts can run directly.- create_rctd_params
Additional parameters passed to
spacexr::createRctd()orspacexr::create.RCTD().- run_rctd_params
Additional parameters passed to
spacexr::runRctd()orspacexr::run.RCTD().- verbose
Whether to print the message. Default is
TRUE.- ...
Additional parameters passed to the RCTD run step.
- coordinate_space
Coordinate space used for distance-sensitive input. The default is raw acquisition coordinates, so backend distances use raw coordinate units. Use
"legacy_display"explicitly to reproduce the display-scaled coordinates used before scop 0.9.0.- tool_name
Name used to store the plain result bundle in
srt@tools.
Value
A Seurat object with RCTD proportion columns in metadata and
dominant cell type summaries. When store_results = TRUE, detailed results
are also stored in srt@tools[[tool_name]].
Examples
data(visium_human_pancreas_sub)
spatial <- visium_human_pancreas_sub
rctd_weights <- data.frame(
RCTD_prop_Ductal = seq(0.75, 0.15, length.out = ncol(spatial)),
RCTD_prop_Endocrine = seq(0.15, 0.65, length.out = ncol(spatial)),
RCTD_prop_Stromal = 0.10,
row.names = colnames(spatial)
)
rctd_weights <- rctd_weights / rowSums(rctd_weights)
spatial <- Seurat::AddMetaData(spatial, rctd_weights)
spatial$RCTD_dominant_type <- sub(
"^RCTD_prop_",
"",
colnames(rctd_weights)[max.col(rctd_weights)]
)
spatial$RCTD_max_prop <- apply(rctd_weights, 1, max)
SpatialSpotPlot(
spatial,
group.by = "RCTD_dominant_type",
overlay_image = FALSE,
coord.cols = c("x", "y")
)
SpatialSpotPlot(
spatial,
group.by = "RCTD_dominant_type",
plot_type = "pie",
overlay_image = FALSE,
coord.cols = c("x", "y")
)
data(panc8_sub)
spatial <- spatial[, seq_len(120)]
#> Warning: Not validating Centroids objects
#> Warning: Not validating Centroids objects
#> Warning: Not validating FOV objects
#> Warning: Not validating FOV objects
#> Warning: Not validating FOV objects
#> Warning: Not validating FOV objects
#> Warning: Not validating FOV objects
#> Warning: Not validating FOV objects
#> Warning: Not validating Seurat objects
reference <- panc8_sub[, panc8_sub$celltype %in% c("ductal", "alpha", "beta")]
reference <- Seurat::FindVariableFeatures(reference, nfeatures = 300, verbose = FALSE)
features_use <- intersect(
SeuratObject::VariableFeatures(reference),
rownames(spatial)
)
spatial <- RunRCTD(
srt = spatial,
reference = reference,
reference_label = "celltype",
assay = "Spatial",
reference_assay = "RNA",
layer = "counts",
reference_layer = "counts",
features = features_use,
rctd_mode = "full",
max_cores = 1,
min_cells = 25,
prefix = "RCTD",
verbose = FALSE
)
#> Warning: Reference: some nUMI values are less than min_UMI = 100, and these cells will be removed. Optionally, you may lower the min_UMI parameter.
#> Begin: process_cell_type_info
#> process_cell_type_info: number of cells in reference: 694
#> process_cell_type_info: number of genes in reference: 97
#>
#> ductal beta alpha
#> 211 304 179
#> End: process_cell_type_info
#> create.RCTD: getting regression differentially expressed genes:
#> get_de_genes: ductal found DE genes: 24
#> get_de_genes: beta found DE genes: 7
#> get_de_genes: alpha found DE genes: 51
#> get_de_genes: total DE genes: 82
#> create.RCTD: getting platform effect normalization differentially expressed genes:
#> get_de_genes: ductal found DE genes: 27
#> get_de_genes: beta found DE genes: 8
#> get_de_genes: alpha found DE genes: 55
#> get_de_genes: total DE genes: 90
#> fitBulk: decomposing bulk
#> chooseSigma: using initial Q_mat with sigma = 1
#> Likelihood value: 565.708541011282
#> Sigma value: 0.84
#> Likelihood value: 554.037735497346
#> Sigma value: 0.69
#> Likelihood value: 544.81606233551
#> Sigma value: 0.61
#> Likelihood value: 540.997124129871
#> Sigma value: 0.53
#> Likelihood value: 538.284148657321
#> Sigma value: 0.45
#> Likelihood value: 537.061480361226
#> Sigma value: 0.44
#> Likelihood value: 537.038433383715
#> Sigma value: 0.44
rctd_cols <- grep("^RCTD_prop_", colnames(spatial@meta.data), value = TRUE)
SpatialSpotPlot(
spatial,
group.by = "RCTD_dominant_type",
overlay_image = FALSE,
coord.cols = c("x", "y"),
theme_use = "theme_scop"
)
SpatialSpotPlot(
spatial,
group.by = rctd_cols[1:min(3, length(rctd_cols))],
palette = "Spectral",
overlay_image = FALSE,
coord.cols = c("x", "y"),
theme_use = "theme_scop"
)