
Calculate the local auto-correlation of a gene
hotspot_autocor_sc.RdThis method implements the HotSpot approach (see DeTomaso, et al.) to calculate the auto-correlation of a given gene in the kNN graph based on the chosen embedding. This can be used to identify genes that have strong local correlations and vary across the kNN graph.
Usage
hotspot_autocor_sc(
object,
embd_to_use = "pca",
use_knn = TRUE,
hotspot_params = params_sc_hotspot(),
no_embd_to_use = NULL,
cells_to_take = NULL,
genes_to_take = NULL,
streaming = NULL,
random_seed = 42L,
.verbose = TRUE
)Arguments
- object
SingleCellsorMetaCellsclass.- embd_to_use
String. The embedding to use. Defaults to
"pca".- use_knn
Boolean. Shall the internal kNN be used. If set to yes, you need to ensure consistency. If you provide
cells_to_take, the function will regenerate the kNN graph with these cells.- hotspot_params
List with hotspot parameters, see
params_sc_hotspot()with the following elements:model - String. Which of the available models to use for the gene expression. Choices are one of
c("danb", "normal", "bernoulli").normalise - Boolean. Shall the data be normalised.
weighted_graph - Boolean. Shall the Gaussian kernel be applied to the neighbour distances. If
FALSE, every retained edge weighs one.neighborhood_factor - Float. Kernel width for
weighted_graph.knn - List of kNN parameters. See
params_knn_defaults()for available parameters and their defaults.
- no_embd_to_use
Optional integer. Number of embedding dimensions to use. If
NULLall will be used.- cells_to_take
Optional string vector. If you want to only use selected cells. If
NULLwill default to all cells_to_keep in the class.- genes_to_take
Optional string vector. If you wish to limit the search to a subset of genes. If
NULLwill default to all genes in the class.- streaming
Optional Boolean. Shall the data be streamed in. Useful for larger data sets where you wish to avoid loading in the whole data. If
NULL, will automatically detect. Ignored forMetaCells, which are held in memory.- random_seed
Integer. Used for reproducibility.
- .verbose
Boolean or integer. Controls verbosity and returns run times.
FALSE-> quiet,TRUEor1L-> normal verbosity,2L-> detailed verbosity.
Details
Should a gene not be found in sufficient cells, the gene will be automatically filtered out from the results. This can occur for example if you have filtered out the cells that contain a given gene. The underlying genes are still available, but the cells that might contain them are not included.
Whether the neighbour distances need squaring before the kernel sees them
follows from the metric. With use_knn = TRUE it is taken from the metric
stored on the cached kNN graph, otherwise from ann_dist in
hotspot_params.
Examples
# local auto-correlation of every gene on the cached kNN graph
sc <- demo_single_cells()
res <- hotspot_autocor_sc(sc, .verbose = FALSE)
head(res, 3)
#> gene_id gaerys_c z_score pval fdr
#> <char> <num> <num> <num> <num>
#> 1: gene_01 0.4152188 29.01265 2.278132e-185 8.136184e-185
#> 2: gene_02 0.4358798 31.03719 8.494589e-212 5.309118e-211
#> 3: gene_03 0.4703848 32.60140 1.959130e-233 1.632609e-232
unlink(sc@dir_data, recursive = TRUE, force = TRUE)