Applies data transformation methods to spatial transcriptomics samples within an STlist

transform_data(
  x = NULL,
  method = "log",
  scale_f = 10000,
  sct_n_regr_genes = 3000,
  sct_min_cells = 5,
  cores = NULL
)

Arguments

x

an STlist with raw count matrices.

method

one of log or sct. If log, log-normalization is performed. If sct, then the SCTransform method is applied by calling sctransform::vst

scale_f

the scale factor used in logarithmic transformation

sct_n_regr_genes

the number of genes to be used in the regression model during SCTransform. The function sctransform::vst makes a random gene selection based on this number

sct_min_cells

The minimum number of spots/cells to be used in the regression model fit by sctransform::vst

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

x an updated STlist with transformed counts.

Details

This function takes an STlist with raw counts and performs data transformation. The user has the option to select between log transformation after library size normalization (method='log'), or SCTransform (method='sct'). In the case of logarithmic transformation, a scaling factor (10^4 by default) is applied. The function uses parallelization using "forking" (not available in Windows OS). Note that the method sct returns a matrix with less genes as filtering is done for low expression genes.

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')