D Implementation of SpaceX

SpaceX function extimates shared and cluster specfic gene co-expression networks for spatial transcriptomics data. More details about the SpaceX method can be found in the main manuscript. See below for detailed discussion on installation of SpaceX package, Data inputs and outputs followed by an example.

D.1 Installation

This package requires a Fortran compiler in order to work. Here are the instructions:

  • Windows: install the Rtools package that is appropriate for your version of R

  • Mac: Go to this website and follow the instructions: (https://mac.R-project.org/tools/)

  • Linux: From a terminal, do the following: sudo apt install gcc. That will bring in multiple compilers.

The package requires a dependency that is not available on CRAN. Install it with:

remotes::install_github("rdevito/MSFA")

You can install the released version of SpaceX from (https://github.com/SatwikAch/SpaceX) with:

devtools::install_github("SatwikAch/SpaceX")
library(SpaceX)

D.2 Data inputs

Please make sure to provide both inputs as dataframe.

The first input is Gene_expression_mat which is \(N \times G\) dataframe. Here \(N\) denotes the number of spatial locations and \(G\) denotes number of genes.

The second input is Spatial_locations is a dataframe which contains spatial coordinates.

The third input is Cluster_annotations.

The fourth input is sPMM. If TRUE, the code will return the estimates of sigma1_sq and sigma2_sq from the spatial Poisson mixed model.

The fifth input is Post_process. If FALSE, the code will return the posterior samples of \(\Phi\) and \(\Psi^c\) (based on definition in equation 1 of the SpaceX paper) only. Default is TRUE and the code will return all the posterior samples, shared and cluster specific co-expressions.

The final input is numCore. The number of requested cores for parallel computing and default is set to be 1.

D.3 Output

You will obtain a list of objects as output.

Posterior_samples contains all the posterior samples.

Shared_network provides the shared co-expression matrix (transformed correlation matrix of \(G_{s} = \Phi \Phi^{T}\)).

Cluster_network provides the cluster specific co-expression matrices (transformed correlation matrices of \(G_{c} = \Phi \Phi^{T} + \Psi^{c} {\Psi^{c^{T}}}\)).

D.4 Example

Here we provide an example to run the SpaceX method.

# Reading the Breast cancer data

# Spatial locations
head(BC_loc)

# Gene expression for data
head(BC_count) 

# Data processing
G <-dim(BC_count)[2] # number of genes
N <-dim(BC_count)[1] # number of locations

Next, we’ll apply the SpaceX method on the Breast cancer dataset.

# Application to SpaceX method
BC_fit <- SpaceX(BC_count,BC_loc[,1:2],BC_loc[,3],sPMM=FALSE,Post_process = TRUE, numCore=2)

# Shared_network :: Shared co-expression matrix
# Cluster_network :: Cluster specific co-expression matrices