1 Introduction

Cell-Type-specific Spatially Variable gene detection, or CTSV, is an R package for identifying cell-type-specific spatially variable genes in bulk sptial transcriptomics data. In this Vignette, we will introduce a standard workflow of CTSV. By utilizing single-cell RNA sequencing data as reference, we can first use existing deconvolution methods to obtain cell type proportions for each spot. Subsequently, we take the cell type proportions, location coordinates and spatial expression data as input to CTSV.

2 Usage guide

2.1 Install CTSV

CTSV is an R package available in the Bioconductor repository. It requires installing the R open source statistical programming language, which can be accessed on any operating system from CRAN. Next, you can install CTSV by using the following commands in your R session:

if (!requireNamespace("BiocManager", quietly = TRUE)) {
      install.packages("BiocManager")
  }

BiocManager::install("CTSV", version = "devel")

## Check that you have a valid Bioconductor installation
BiocManager::valid()

If there are any issues with the installation procedure or package features, the best place would be to commit an issue at the GitHub repository.

2.2 Load example data

In order to run RCTD, the first step is to get cell-type proportions. There are some deconvolution methods such as RCTD, SPOTlight, SpatialDWLS and CARD. We provide an example data including the observed raw count bulk ST data, the location coordinate matrix, the cell-type proportion matrix and the true SV gene patterns.

suppressPackageStartupMessages(library(CTSV))
suppressPackageStartupMessages(library(SpatialExperiment))
data("CTSVexample_data", package="CTSV")
spe <- CTSVexample_data[[1]]
W <- CTSVexample_data[[2]]
gamma_true <- CTSVexample_data[[3]]
Y <- assay(spe)
# dimension of bulk ST data
dim(Y)
#> [1]  20 100
# dimension of cell-type proportion matrix:
dim(W)
#> [1] 100   2
# SV genes in each cell type:
colnames(Y)[which(gamma_true[,1] == 1)]
#> [1] "spot11" "spot12" "spot13"
colnames(Y)[which(gamma_true[,2] == 1)]
#> [1] "spot14" "spot15" "spot16"
# Number of SV genes at the aggregated level:
sum(rowSums(gamma_true)>0)
#> [1] 6

2.3 Running CTSV

We are now ready to run CTSV on the bulk ST data using ctsv function.

  • spe is a SpatialExperiment class object.
  • W is the cell-type-specific matrix with \(n\times K\) dimensions, where \(K\) is the number of cell types.
  • num_core: for parallel processing, the number of cores used. If set to 1, parallel processing is not used. The system will additionally be checked for number of available cores. Note, that we recommend setting num_core to at least 4 or 8 to improve efficiency.
  • BPPARAM: Optional additional argument for parallelization. The default is NULL, in which case num_core will be used.
result <- CTSV(spe,W,num_core = 8)
#> Warning:   'IS_BIOC_BUILD_MACHINE' environment variable detected, setting
#>   BiocParallel workers to 4 (was 8)

2.4 CTSV results

The results of CTSV are located in a list.

  • pval, combined p-values, a \(G\times 2K\) matrix.
  • qval stores adjusted q-values of the combined p-values, it is a \(G \times 2K\) matrix.
# View on q-value matrix
head(result$qval)
#>             [,1]       [,2]      [,3]      [,4]
#> gene1 0.19608207 0.05511312 0.4798779 0.1473743
#> gene2 0.48137993 0.13405251 0.5496452 0.1111611
#> gene3 0.51617622 0.44324575 0.5396361 0.4848865
#> gene4 0.32941849 0.46443029 0.3294185 0.5622572
#> gene5 0.06301154 0.41376648 0.5202113 0.1050798
#> gene6 0.13405251 0.52238341 0.3294185 0.3078813

Then we want to extra SV genes with an FDR level at 0.05 using svGene function. We use the q-value matrix qval returned by the CTSV function and a threshold of 0.05 as input. The output of the svGene is a list containing two elements, the first of which is a \(G\times 2K\) 0-1 matrix indicating SV genes in each cell type and axis, denoted as SV. The second element is a list with names of SV genes in each cell type, denoted as SVGene.

re <- svGene(result$qval,0.05)
# SV genes in each cell type:
re$SVGene
#> [[1]]
#> [1] "gene8"  "gene11" "gene12" "gene13"
#> 
#> [[2]]
#> [1] "gene7"  "gene14" "gene15" "gene16" "gene17" "gene19"

3 Session information

sessionInfo()
#> R Under development (unstable) (2024-10-21 r87258)
#> Platform: x86_64-pc-linux-gnu
#> Running under: Ubuntu 24.04.1 LTS
#> 
#> Matrix products: default
#> BLAS:   /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB              LC_COLLATE=C              
#>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
#>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: America/New_York
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats4    stats     graphics  grDevices utils     datasets  methods  
#> [8] base     
#> 
#> other attached packages:
#>  [1] SpatialExperiment_1.17.0    SingleCellExperiment_1.29.0
#>  [3] SummarizedExperiment_1.37.0 Biobase_2.67.0             
#>  [5] GenomicRanges_1.59.0        GenomeInfoDb_1.43.0        
#>  [7] IRanges_2.41.0              S4Vectors_0.45.0           
#>  [9] BiocGenerics_0.53.0         MatrixGenerics_1.19.0      
#> [11] matrixStats_1.4.1           CTSV_1.9.0                 
#> [13] BiocStyle_2.35.0           
#> 
#> loaded via a namespace (and not attached):
#>  [1] gtable_0.3.6            rjson_0.2.23            xfun_0.48              
#>  [4] bslib_0.8.0             ggplot2_3.5.1           lattice_0.22-6         
#>  [7] vctrs_0.6.5             tools_4.5.0             generics_0.1.3         
#> [10] parallel_4.5.0          tibble_3.2.1            fansi_1.0.6            
#> [13] pkgconfig_2.0.3         Matrix_1.7-1            lifecycle_1.0.4        
#> [16] GenomeInfoDbData_1.2.13 compiler_4.5.0          stringr_1.5.1          
#> [19] munsell_0.5.1           codetools_0.2-20        htmltools_0.5.8.1      
#> [22] sass_0.4.9              yaml_2.3.10             pillar_1.9.0           
#> [25] crayon_1.5.3            jquerylib_0.1.4         MASS_7.3-61            
#> [28] BiocParallel_1.41.0     DelayedArray_0.33.0     cachem_1.1.0           
#> [31] magick_2.8.5            abind_1.4-8             tidyselect_1.2.1       
#> [34] digest_0.6.37           stringi_1.8.4           dplyr_1.1.4            
#> [37] reshape2_1.4.4          bookdown_0.41           splines_4.5.0          
#> [40] fastmap_1.2.0           grid_4.5.0              SparseArray_1.7.0      
#> [43] colorspace_2.1-1        cli_3.6.3               magrittr_2.0.3         
#> [46] S4Arrays_1.7.0          utf8_1.2.4              scales_1.3.0           
#> [49] UCSC.utils_1.3.0        rmarkdown_2.28          XVector_0.47.0         
#> [52] httr_1.4.7              qvalue_2.39.0           evaluate_1.0.1         
#> [55] knitr_1.48              pscl_1.5.9              rlang_1.1.4            
#> [58] Rcpp_1.0.13             glue_1.8.0              BiocManager_1.30.25    
#> [61] jsonlite_1.8.9          R6_2.5.1                plyr_1.8.9             
#> [64] zlibbioc_1.53.0