-
Notifications
You must be signed in to change notification settings - Fork 0
/
spatial_integrate.R
260 lines (221 loc) · 8.76 KB
/
spatial_integrate.R
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
library(Seurat)
library(dplyr)
library(harmony)
library(SeuratDisk)
s1 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK001_157785_RZ_FZ_P5.h5seurat")
s1$sample <- s1
s1$sample_id <- "P5"
s1$region <- "FZ"
s1$days_postMI <- 101
s1$disease <-"ICM"
s1 <- SCTransform(s1, assay = "RNA", verbose = FALSE)
s2 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK002_157779_IZ_P3.h5seurat")
s2$sample <- s2
s2$sample_id <-"P3"
s2$region <- "IZ"
s2$days_postMI <- 2
s2$disease <- "AMI"
s2 <- SCTransform(s2, assay = "RNA", verbose = FALSE)
s3 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK002_157781_RZ_BZ_P3.h5seurat")
s3$sample <- s3
s3$sample_id <- "P3"
s3$region <- "BZ"
s3$days_postMI <- 2
s3$disease <-"AMI"
s3 <- SCTransform(s3, assay = "RNA", verbose = FALSE)
s4 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK002_157782_RZ_P3.h5seurat")
s4$sample <- s4
s4$sample_id <- "P3"
s4$region <- "RZ"
s4$days_postMI <- 2
s4$disease <- "AMI"
s4 <- SCTransform(s4, assay = "RNA", verbose = FALSE)
s5 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK003_157775_IZ_BZ_P2.h5seurat")
s5$sample <- s5
s5$sample_id <- "P2"
s5$region <- "IZ"
s5$days_postMI <- 5
s5$disease <- "AMI"
s5 <- SCTransform(s5, assay = "RNA", verbose = FALSE)
s6 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK003_157777_RZ_BZ_P2.h5seurat")
s6$sample <- s6
s6$sample_id <- "P2"
s6$region <- "BZ"
s6$days_postMI <- 5
s6$disease <- "AMI"
s6 <- SCTransform(s6, assay = "RNA", verbose = FALSE)
s7 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK004_157772_FZ_GT_P4.h5seurat")
s7$sample <- s7
s7$sample_id <- "P4"
s7$region <- "FZ"
s7$days_postMI <- 88
s7$disease <- "IZM"
s7 <- SCTransform(s7, assay = "RNA", verbose = FALSE)
s8 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/AKK006_157771_control_P1.h5seurat")
s8$sample <- s8
s8$sample_id <- "P1"
s8$region <- "control"
s8$days_postMI <- "control"
s8$disease <- "control"
s8 <- SCTransform(s8, assay = "RNA", verbose = FALSE)
s9 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_1_CK279_control_P17.h5seurat")
s9$sample <- s9
s9$sample_id <- "P17"
s9$region <- "control"
s9$days_postMI <- "control"
s9$disease <- "control"
s9 <- SCTransform(s9, assay = "RNA", verbose = FALSE)
s10 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_2_CK280_RZ_P6.h5seurat")
s10$sample <- s10
s10$sample_id <- "P6"
s10$region <- "RZ"
s10$days_postMI <- 3
s10$disease <- "AMI"
s10 <- SCTransform(s10, assay = "RNA", verbose = FALSE)
s11 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_3_CK281_control_P7.h5seurat")
s11$sample <- s11
s11$sample_id <- "P7"
s11$region <- "control"
s11$days_postMI <- "control"
s11$disease <- "control"
s11 <- SCTransform(s11, assay = "RNA", verbose = FALSE)
s12 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_4_CK282_control_P8.h5seurat")
s12$sample <- s12
s12$sample_id <- "P8"
s12$region <- "control"
s12$days_postMI <- "control"
s12$disease <- "control"
s12 <- SCTransform(s12, assay = "RNA", verbose = FALSE)
s13 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_5_CK283_RZ_GT_P2.h5seurat")
s13$sample <- s13
s13$sample_id <- "P2"
s13$region <- "RZ"
s13$days_postMI <- 5
s13$disease <- "AMI"
s13 <- SCTransform(s13, assay = "RNA", verbose = FALSE)
s14 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_6_CK284_RZ_P9.h5seurat")
s14$sample <- s14
s14$sample_id <- "P9"
s14$region <- "RZ"
s14$days_postMI <- 2
s14$disease <- "AMI"
s14 <- SCTransform(s14, assay = "RNA", verbose = FALSE)
s15 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_7_CK285_IZ_P10.h5seurat")
s15$sample <- s15
s15$sample_id <- "P10"
s15$region <- "IZ"
s15$days_postMI <- 6
s15$disease <- "AMI"
s15 <- SCTransform(s15, assay = "RNA", verbose = FALSE)
s16 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_8_CK286_RZ_P11.h5seurat")
s16$sample <- s16
s16$sample_id <- "P11"
s16$region <- "RZ"
s16$days_postMI <- 31
s16$disease <- "ICM"
s16 <- SCTransform(s16, assay = "RNA", verbose = FALSE)
s17 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_9_CK287_GT_IZ_P9.h5seurat")
s17$sample <- s17
s17$sample_id <- "P9"
s17$region <- "IZ"
s17$days_postMI <- 2
s17$disease <- "AMI"
s17 <- SCTransform(s17, assay = "RNA", verbose = FALSE)
s18 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_10_CK288_RZ_BZ_P12.h5seurat")
s18$sample <- s18
s18$sample_id <- "P12"
s18$region <- "BZ"
s18$days_postMI <- 31
s18$disease <- "ICM"
s18 <- SCTransform(s18, assay = "RNA", verbose = FALSE)
s19 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_11_CK289_GT_IZ_P13.h5seurat")
s19$sample <- s19
s19$sample_id <- "P13"
s19$region <- "IZ"
s19$days_postMI <- 45
s19$disease <- "ICM"
s19 <- SCTransform(s19, assay = "RNA", verbose = FALSE)
s20 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_12_CK290_FZ_P14.h5seurat")
s20$sample <- s20
s20$sample_id <- "P14"
s20$region <- "FZ"
s20$days_postMI <- "62"
s20$disease <- "ICM"
s20 <- SCTransform(s20, assay = "RNA", verbose = FALSE)
s21 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_13_CK291_FZ_P18.h5seurat")
s21$sample <- s21
s21$sample_id <- "P14"
s21$region <- "FZ"
s21$days_postMI <- 62
s21$disease <- "ICM"
s21 <- SCTransform(s21, assay = "RNA", verbose = FALSE)
s22 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_14_CK292_FZ_GT_P19.h5seurat")
s22$sample <- s22
s22$sample_id <- "P19"
s22$region <- "FZ"
s22$days_postMI <- 40
s22$disease <- "ICM"
s22 <- SCTransform(s22, assay = "RNA", verbose = FALSE)
s23 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_15_CK293_IZ_P16.h5seurat")
s23$sample <- s23
s23$sample_id <- "P16"
s23$region <- "IZ"
s23$days_postMI <- 4
s23$disease <- "AMI"
s23 <- SCTransform(s23, assay = "RNA", verbose = FALSE)
s24 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_16_CK294_FZ_P20.h5seurat")
s24$sample <- s24
s24$sample_id <- "P20"
s24$region <- "FZ"
s24$days_postMI <- 166
s24$disease <- "ICM"
s24 <- SCTransform(s24, assay = "RNA", verbose = FALSE)
s25 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_17_CK295_RZ_P6.h5seurat")
s25$sample <- s25
s25$sample_id <- "P6"
s25$region <- "RZ"
s25$days_postMI <- 3
s25$disease <- "AMI"
s25 <- SCTransform(s25, assay = "RNA", verbose = FALSE)
s26 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_18_CK296_GT_IZ_P15.h5seurat")
s26$sample <- s26
s26$sample_id <- "P15"
s26$region <- "IZ"
s26$days_postMI <- 11
s26$disease <- "AMI"
s26 <- SCTransform(s26, assay = "RNA", verbose = FALSE)
s27 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_19_CK297_GT_IZ_P9_rep2.h5seurat")
s27$sample <- s27
s27$sample_id <- "P9"
s27$region <- "IZ"
s27$days_postMI <- 2
s27$disease <- "AMI"
s27 <- SCTransform(s27, assay = "RNA", verbose = FALSE)
s28 <- LoadH5Seurat("/data/Junedh/Amgen_ICM/Spatial/converted_for_seurat/Visium_20_CK298_IZ_P15.h5seurat")
s28$sample <- s28
s28$sample_id <- "P15"
s28$region <- "IZ"
s28$days_postMI <- 11
s28$disease <- "AMI"
s28 <- SCTransform(s28, assay = "RNA", verbose = FALSE)
sample <- merge(s1, y = c(s2,s3,s4,s5,s6,s7,s8,s9,s10,s11,s12,s13,s14,
s15,s16,s17,s18,s19,s20,s21,s22,s23,s24,s25,
s26,s27,s28))
saveRDS(sample, "./spatial_merged_normalized.rds")
DefaultAssay(sample) <- "SCT"
VariableFeatures(sample) <- c(VariableFeatures(s1),VariableFeatures(s2),VariableFeatures(s3),
VariableFeatures(s4),VariableFeatures(s5),VariableFeatures(s6),
VariableFeatures(s7),VariableFeatures(s8),VariableFeatures(s9),
VariableFeatures(s10),VariableFeatures(s11),VariableFeatures(s12),
VariableFeatures(s13),VariableFeatures(s14),VariableFeatures(s15),
VariableFeatures(s16),VariableFeatures(s17),VariableFeatures(s18),
VariableFeatures(s19),VariableFeatures(s20),VariableFeatures(s21),
VariableFeatures(s22),VariableFeatures(s23),VariableFeatures(s24),
VariableFeatures(s25),VariableFeatures(s26),VariableFeatures(s27),
VariableFeatures(s28))
sample <- RunPCA(sample, npcs=100, verbose=TRUE)
sample <- RunHarmony(sample, c("sample"), reduction = "pca", reduction.save = "harmony", assay.use = "SCT")
sample <- RunUMAP(sample, reduction = "harmony", dims = 1:50)
sample <- FindNeighbors(sample, reduction = "harmony", dims = 1:50)
sample <- FindClusters(sample, graph.name = "SCT_snn", algorithm = 3, resolution = c(0.1,0.2,0.3,0.4,0.5), verbose = TRUE)
saveRDS(sample, "/data/Junedh/Amgen_ICM/Spatial/kuppe_spatial_integrated.rds")