Run STdeconvolve reference-free spatial deconvolution
Source:R/RunSTdeconvolve.R
RunSTdeconvolve.RdEstimate spot-level topic proportions from a spatial Seurat object using
the optional STdeconvolve package.
Usage
RunSTdeconvolve(
srt,
assay = NULL,
layer = "counts",
features = NULL,
k = NULL,
k_candidates = 2:9,
opt = "min",
clean_counts = TRUE,
clean_counts_params = list(),
restrict_corpus = TRUE,
restrict_corpus_params = list(),
fit_lda_params = list(),
get_beta_theta_params = list(),
prefix = "STdeconvolve",
tool_name = "STdeconvolve",
store_results = TRUE,
round_counts = TRUE,
verbose = TRUE,
...
)Arguments
- srt
Spatial
Seuratobject used as the RCTD query.- assay
Assay used in
srt. IfNULL, the default assay is used.- layer
Assay layer used as STdeconvolve input.
- features
Features used for RCTD. If
NULL, shared features are used.- k
Number of topics. If
NULL, models are fit overk_candidatesandSTdeconvolve::optimalModel()is used to choose a model.- k_candidates
Candidate topic numbers used when
k = NULL.- opt
Optimal model selector passed to
STdeconvolve::optimalModel().- clean_counts
Whether to call
STdeconvolve::cleanCounts().- clean_counts_params
Additional parameters passed to
STdeconvolve::cleanCounts().- restrict_corpus
Whether to call
STdeconvolve::restrictCorpus().- restrict_corpus_params
Additional parameters passed to
STdeconvolve::restrictCorpus().- fit_lda_params
Additional parameters passed to
STdeconvolve::fitLDA().- get_beta_theta_params
Additional parameters passed to
STdeconvolve::getBetaTheta().- prefix
Prefix for metadata columns.
- tool_name
Name used to store detailed results in
srt@tools.- store_results
Whether to store detailed RCTD results in
srt@tools.- round_counts
Whether to round non-integer counts before model fitting.
- verbose
Whether to print the message. Default is
TRUE.- ...
Additional parameters passed to the RCTD run step.
Value
A Seurat object with topic proportions in metadata and detailed
results stored in srt@tools[[tool_name]] when store_results = TRUE.
Examples
data(visium_human_pancreas_sub)
spatial <- visium_human_pancreas_sub
topic_weights <- data.frame(
STdeconvolve_prop_topic_1 = seq(0.75, 0.20, length.out = ncol(spatial)),
STdeconvolve_prop_topic_2 = seq(0.20, 0.70, length.out = ncol(spatial)),
STdeconvolve_prop_topic_3 = 0.10,
row.names = colnames(spatial)
)
topic_weights <- topic_weights / rowSums(topic_weights)
spatial <- Seurat::AddMetaData(spatial, topic_weights)
spatial$STdeconvolve_dominant_type <- sub(
"^STdeconvolve_prop_",
"",
colnames(topic_weights)[max.col(topic_weights)]
)
spatial$STdeconvolve_max_prop <- apply(topic_weights, 1, max)
SpatialSpotPlot(
spatial,
group.by = "STdeconvolve_dominant_type",
overlay_image = FALSE,
coord.cols = c("x", "y")
)
spatial <- RunSTdeconvolve(
spatial,
assay = "Spatial",
features = rownames(spatial)[1:300],
k = 3,
verbose = FALSE
)
#> Removing 0 genes present in 100% or more of pixels...
#> 300 genes remaining...
#> Removing 0 genes present in 5% or less of pixels...
#> 300 genes remaining...
#> Restricting to overdispersed genes with alpha = 0.05...
#> Calculating variance fit ...
#> Using gam with k=5...
#> 68 overdispersed genes ...
#> Using top 1000 overdispersed genes.
#> number of top overdispersed genes available: 68
#> Time to fit LDA models was 0.07 mins
#> Computing perplexity for each fitted model...
#> Time to compute perplexities was 0.04 mins
#> Getting predicted cell-types at low proportions...
#> Time to compute cell-types at low proportions was 0 mins
#> Plotting...
#> Warning: Ignoring unknown parameters: `linewidth`
#> Warning: Ignoring unknown parameters: `linewidth`
#> Warning: The `size` argument of `element_line()` is deprecated as of ggplot2 3.4.0.
#> ℹ Please use the `linewidth` argument instead.
#> ℹ The deprecated feature was likely used in the STdeconvolve package.
#> Please report the issue at
#> <https://github.com/JEFworks-Lab/STdeconvolve/issues>.
#> `geom_line()`: Each group consists of only one observation.
#> ℹ Do you need to adjust the group aesthetic?
#> `geom_line()`: Each group consists of only one observation.
#> ℹ Do you need to adjust the group aesthetic?
#> Filtering out cell-types in pixels that contribute less than 0.05 of the pixel proportion.
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
#> Warning: no non-missing arguments to max; returning -Inf
STdeconvolvePlot(
spatial,
topics = 1:2,
overlay_image = FALSE,
coord.cols = c("x", "y")
)
STdeconvolvePlot(
spatial,
plot_type = "pie",
overlay_image = FALSE,
coord.cols = c("x", "y")
)