-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCRC_analysis.Rmd
141 lines (90 loc) · 5.58 KB
/
CRC_analysis.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
---
title: "CRC_analysis"
output: html_document
date: "2023-07-12"
---
---
title: "SpaceANOVA"
author: Souvik Seal
output: rmarkdown::github_document
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#",
out.width = "100%",
messages = FALSE,
warnings = FALSE
)
```
This is an R package implementing the proposed method from the paper, "SpaceANOVA: Spatial co-occurrence analysis of cell types in multiplex imaging data using point
process and functional ANOVA". It can be used to study differential spatial co-occurrence of pairs of cell types across multiple groups, such as case/control, in multiplex imaging datasets. Here, we show how this package was used on the CRC dataset from yhe main manuscript.
## Loading the package
We install and load the developmental version of SpaceANOVA from GitHub.
```{r loading packages, message=FALSE}
suppressWarnings(devtools::install_github('sealx017/SpaceANOVA', quiet = TRUE))
require(SpaceANOVA)
require(spatstat)
require(tidyr)
require(dplyr)
require(fda.usc)
require(ggplot2)
require(cowplot)
require(gridExtra)
```
## Loading the example dataset
Next, we import the colorectal cancer (CRC) MIF dataset [1]. There are two groups of subjects: one group (18 subjects) with the “Crohn’slike reaction” (CLR) tumor invasive front, while the other group (17 subjects) is defined by the presence of diffuse inflammatory infiltration (DII).
```{r loading the marker expression, out.width = "50%"}
data("MIF_CRC")
knitr::kable(head(MIF_CRC), format="markdown")
MIF_CRC %>% group_by(Group, ID) %>% reframe(n = n()) # check group and subject IDs, and respective cell counts (spread across multiple images)
```
## Computing the summary functions and performing association analysis
We keep the range of radius r was kept between [0, 100] with a step size of 10 which is higher than what we considered in the other two real data analyses because the number of cells is much lower in this dataset, and a finer grid of r would result in noisier and less smooth g-functions. For a similar reason and the tissue missing-ness not being a highlighted issue by Schutch et al. (2020) [1], we consider unadjusted
versions of SpaceANOVA Univ. and SpaceANOVA Mult. (perm = FALSE) in this case.
```{r Computing spatial summary functions, and performing both univariate and multivariate differential co-occurrence analysis, echo = T, results = T}
Final_result = All_in_one(data = MIF_CRC, fixed_r = seq(0, 100, by = 10), Summary_function = "g", Hard_ths = 20, homogeneous = TRUE, interaction_adjustment = TRUE, perm = TRUE, cores = 8)
```
## Extracting p-values
Extract the p-values of the univariate and multivariate tests: SpaceANOVA Univ. and SpaceANOVA Mult. and print.
```{r P-value extraction}
p_res = p_extract(Final_result)
Univ_p = p_res[[1]]
Mult_p = p_res[[2]]
print(Univ_p)
```
## Heatmap of -log10 of p-values
Display the -log10 of the p-values using heatmap.
```{r P-value visualization, out.width="50%", out.height = "100%"}
Plot.heatmap(Univ_p, main = "SpaceANOVA Univ.")
```
## Visualizing summary functions
Next, we can check the summary functions corresponding to those pairs of cell types whose p-values turned out to be significant. Here, we visualize the g-functions of pairs: (b_cells, tumor_cells) and (vasculature, tumor_cells). For every pair, the first panel shows subject-level mean functions (averaged across the images of a subject), while the second panel shows image-level summary functions. We do not display the point-wise F-values here, i.e., Fvals = NULL but one can specify Fvals = Pointwise_Fvals to check the associated pointwise F values.
### Pair: (b_cells, tumor_cells)
We notice that the spatial co-occurrence of b_cells and tumor cells is negative in the CLR group for smaller values of r, while in DII the co-occurrence is always negative.
```{r plotting summary functions 1, out.width="100%", out.height = "80%"}
Pointwise_Fvals = Final_result[[1]][[2]]
Functional_results = Final_result[[2]]
# Pair: (b_cells, tumor_cells)
Plot.functions(Functional_results, pair = c("b_cells", "tumor_cells"), Fvals = NULL)
```
### Pair: (vasculature, tumor_cells)
```{r plotting summary functions 2, out.width="100%", out.height = "80%"}
# Pair: (beta, Tc)
Plot.functions(Functional_results, pair = c("vasculature", "tumor_cells"), Fvals = NULL)
```
## Visualizing cellular organization
We can visualize cellular organization in different images of every subject. We create a reduced dataset first to focus only on b_cells, tumor_cells and vasculature.
```{r plotting celluar organization, out.width="100%", out.height = "500px"}
MIF_CRC_reduced = MIF_CRC
MIF_CRC_reduced$cellType = as.character(MIF_CRC_reduced$cellType)
MIF_CRC_reduced$cellType = ifelse(MIF_CRC_reduced$cellType %in% c("b_cells", "tumor_cells", "vasculature"), MIF_CRC_reduced$cellType, "Others")
table(MIF_CRC_reduced$cellType)
palette = c("red", "grey", "purple", "green4") #assign colors to cell types
Plot.cellTypes(data = MIF_CRC_reduced, ID = "28", imageID = c("reg055_A", "reg056_A"), palette = palette)
Plot.cellTypes(data = MIF_CRC_reduced, ID = "3", imageID = c("reg005_A", "reg006_A"), palette = palette)
```
## References
1\) Schürch, C. M., Bhate, S. S., Barlow, G. L., Phillips, D. J., Noti, L., Zlobec, I., ... & Nolan, G. P. (2020). Coordinated cellular neighborhoods orchestrate antitumoral immunity at the colorectal cancer invasive front. Cell, 182(5), 1341-1359.
2\) Baddeley, A., Rubak, E., and Turner, R. (2015). Spatial point patterns: methodology and applications with R. CRC press.
3\) Zhang, J.-T. (2013). Analysis of variance for functional data. CRC press.