SThet.Rd
Computes the global spatial autocorrelation statistics Moran's I and/or Geary's C for a set of genes
SThet(
x = NULL,
genes = NULL,
samples = NULL,
method = "moran",
k = NULL,
overwrite = T,
cores = NULL
)
an STlist
a vector of gene names to compute statistics
the samples to compute statistics
The spatial statistic(s) to estimate. It can be set to 'moran', 'geary' or both. Default is 'moran'
the number of neighbors to estimate weights. By default NULL, meaning that spatial weights will be estimated from Euclidean distances. If an positive integer is entered, then the faster k nearest-neighbors approach is used. Please keep in mind that estimates are not as accurate as when using the default distance-based method.
logical indicating if previous statistics should be overwritten. Default to FALSE (do not overwrite)
integer indicating the number of cores to use during parallelization.
If NULL, the function uses half of the available cores at a maximum. The parallelization
uses parallel::mclapply
and works only in Unix systems.
an STlist containing spatial statistics
The function computes global spatial autocorrelation statistics (Moran's I and/or
Geary's C) for the requested genes and samples. Then computation uses the
package spdep
. The calculated statistics are stored in the STlist, which can
be accessed with the get_gene_meta
function. For visual comparative analysis,
the function compare_SThet
can be used afterwards.
# Using included melanoma example (Thrane et al.)
# Download example data set from spatialGE_Data
thrane_tmp = tempdir()
unlink(thrane_tmp, recursive=TRUE)
dir.create(thrane_tmp)
lk='https://github.com/FridleyLab/spatialGE_Data/raw/refs/heads/main/melanoma_thrane.zip?download='
download.file(lk, destfile=paste0(thrane_tmp, '/', 'melanoma_thrane.zip'), mode='wb')
zip_tmp = list.files(thrane_tmp, pattern='melanoma_thrane.zip$', full.names=TRUE)
unzip(zipfile=zip_tmp, exdir=thrane_tmp)
# Generate the file paths to be passed to the STlist function
count_files <- list.files(paste0(thrane_tmp, '/melanoma_thrane'),
full.names=TRUE, pattern='counts')
coord_files <- list.files(paste0(thrane_tmp, '/melanoma_thrane'),
full.names=TRUE, pattern='mapping')
clin_file <- list.files(paste0(thrane_tmp, '/melanoma_thrane'),
full.names=TRUE, pattern='clinical')
# Create STlist
library('spatialGE')
melanoma <- STlist(rnacounts=count_files[c(1,2)],
spotcoords=coord_files[c(1,2)],
samples=clin_file) # Only first two samples
#> Warning: Sample ST_mel3_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel4_rep2 was not found among the count/coordinate files.
#> Found matrix data
#> Matching gene expression and coordinate data...
#> Converting counts to sparse matrices
#> Completed STlist!
melanoma <- transform_data(melanoma, method='log')
melanoma <- SThet(melanoma, genes=c('MLANA', 'TP53'), method='moran')
#> SThet started.
#> Calculating spatial weights...
#> SThet completed in 0.02 min.
get_gene_meta(melanoma, sthet_only=TRUE)
#> # A tibble: 4 × 15
#> sample patient slice gender BRAF_status NRAS_status CDKN2A_status survival
#> <chr> <dbl> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 ST_mel1_r… 1 B Male mut wt hd 10_plus…
#> 2 ST_mel1_r… 1 B Male mut wt hd 10_plus…
#> 3 ST_mel2_r… 2 A Female wt wt hd 401_days
#> 4 ST_mel2_r… 2 A Female wt wt hd 401_days
#> # ℹ 7 more variables: survival_months <dbl>, RIN <dbl>, gene <chr>,
#> # gene_mean <dbl>, gene_stdevs <dbl>, moran_i <dbl>, geary_c <lgl>