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
)

Arguments

x

an STlist

genes

a vector of gene names to compute statistics

samples

the samples to compute statistics

method

The spatial statistic(s) to estimate. It can be set to 'moran', 'geary' or both. Default is 'moran'

k

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.

overwrite

logical indicating if previous statistics should be overwritten. Default to FALSE (do not overwrite)

cores

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.

Value

an STlist containing spatial statistics

Details

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.

Examples

# Using included melanoma example (Thrane et al.)
library('spatialGE')
data_files <- list.files(system.file("extdata", package="spatialGE"), recursive=T, full.names=T)
count_files <- grep("counts", data_files, value=T)
coord_files <- grep("mapping", data_files, value=T)
clin_file <- grep("thrane_clinical", data_files, value=T)
melanoma <- STlist(rnacounts=count_files[c(1,2)], spotcoords=coord_files[c(1,2)], samples=clin_file) # Only first two samples
#> Warning: Sample ST_mel2_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel2_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel3_rep1 was not found among the count/coordinate files.
#> Warning: Sample ST_mel3_rep2 was not found among the count/coordinate files.
#> Warning: Sample ST_mel4_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 min.
#> 
get_gene_meta(melanoma, sthet_only=T)
#> # A tibble: 4 × 15
#>   sample      patient slice gender BRAF_…¹ NRAS_…² CDKN2…³ survi…⁴ survi…⁵   RIN
#>   <chr>         <dbl> <chr> <chr>  <chr>   <chr>   <chr>   <chr>     <dbl> <dbl>
#> 1 ST_mel1_re…       1 A     Male   mut     wt      hd      10_plu…     120   6.2
#> 2 ST_mel1_re…       1 A     Male   mut     wt      hd      10_plu…     120   6.2
#> 3 ST_mel1_re…       1 B     Male   mut     wt      hd      10_plu…     120   6.2
#> 4 ST_mel1_re…       1 B     Male   mut     wt      hd      10_plu…     120   6.2
#> # … with 5 more variables: gene <chr>, gene_mean <dbl>, gene_stdevs <dbl>,
#> #   moran_i <dbl>, geary_c <lgl>, and abbreviated variable names ¹​BRAF_status,
#> #   ²​NRAS_status, ³​CDKN2A_status, ⁴​survival, ⁵​survival_months