Run CytoSPACE spatial assignment
Usage
RunCytoSPACE(
srt,
reference,
reference_label,
assay = NULL,
reference_assay = NULL,
layer = "counts",
reference_layer = "counts",
features = NULL,
cell_fractions = NULL,
n_cells_per_spot = NULL,
mean_cell_numbers = 5,
scRNA_max_transcripts_per_cell = 1500,
sampling_method = "duplicates",
seed = 1,
prefix = "CytoSPACE",
store_results = TRUE,
verbose = TRUE,
image = NULL,
coord.cols = c("col", "row"),
coordinate_space = c("raw", "legacy_display"),
backend = c("cpp", "r"),
max_dense_gib = 8
)Arguments
- srt
A
Seuratobject.- reference
Reference
Seuratobject containing annotated single cells.- reference_label
Metadata column in
referencewith cell type labels.- assay
Assay to use.
NULLuses the default assay.- reference_assay
Assay used in
reference.- layer, reference_layer
Assay layers used for spatial and reference expression.
- features
Features used for assignment. If
NULL, shared features are used.- cell_fractions
Optional cell-type fractions. Provide a named numeric vector, one-row matrix/data.frame, or a spot-by-cell-type matrix/data.frame. Spot-level rows are aggregated to the global composition used by the default CytoSPACE assignment workflow.
- n_cells_per_spot
Optional number of cells assigned to each spatial spot. If
NULL, counts are estimated from spatial RNA reads withmean_cell_numbers.- mean_cell_numbers
Mean number of cells per spot. Default
5, matching the CytoSPACE Visium default.- scRNA_max_transcripts_per_cell
Maximum reference transcripts per cell before assignment. Default
1500, matching CytoSPACE.- sampling_method
Sampling method. Only
"duplicates"is supported in the package runtime.- seed
Random seed used for deterministic reference downsampling and duplicate sampling.
- prefix
Prefix for metadata columns.
- store_results
Whether to store detailed assignment results in
srt@tools.- verbose
Whether to print the message. Default is
TRUE.- image
Optional Seurat image used for spatial coordinates.
- coord.cols
Metadata coordinate columns used when no image is selected.
- coordinate_space
Coordinate space used for assignment locations. The default is raw acquisition coordinates. Use
"legacy_display"explicitly to reproduce the display-scaled locations used before scop 0.9.0.- backend
Numerical backend used to estimate cell-type fractions when
cell_fractionsis not supplied."cpp"fuses normalization, reference centroid construction, correlation, and weighted aggregation;"r"keeps the reference implementation. Spot assignment uses C++ in both cases.- max_dense_gib
Maximum estimated GiB allowed for dense expression working matrices.
Value
A Seurat object with CytoSPACE metadata columns and detailed
results stored in srt@tools[["CytoSPACE"]].
Examples
data(visium_human_pancreas_sub)
data(panc8_sub)
spatial <- visium_human_pancreas_sub[, 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 <- RunCytoSPACE(
spatial,
reference = reference,
reference_label = "celltype",
features = features_use,
mean_cell_numbers = 1,
verbose = FALSE
)
SpatialSpotPlot(
visium_human_pancreas_sub,
group.by = "coda_label",
theme_use = "theme_scop"
)
SpatialSpotPlot(
spatial,
group.by = "CytoSPACE_dominant_type",
theme_use = "theme_scop"
)