-
Notifications
You must be signed in to change notification settings - Fork 0
/
04-Implementation-of-SpaceX.Rmd
executable file
·75 lines (48 loc) · 2.94 KB
/
04-Implementation-of-SpaceX.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# Implementation of SpaceX {#ImplementSpaceX}
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.
## 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:
```{r, eval=FALSE}
remotes::install_github("rdevito/MSFA")
```
You can install the released version of SpaceX from (https://github.com/SatwikAch/SpaceX) with:
```{r, eval=FALSE}
devtools::install_github("SatwikAch/SpaceX")
library(SpaceX)
```
## 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.
## 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}}}$).
## Example
Here we provide an example to run the SpaceX method.
```{r, eval=FALSE}
# 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.
```{r, eval=FALSE}
# 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
```