-
Notifications
You must be signed in to change notification settings - Fork 0
/
Visium_preprocessing.Rmd
508 lines (337 loc) · 18.5 KB
/
Visium_preprocessing.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
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
---
title: "Visium_V2"
author: Athena Golfinos-Owens
output: html_document
date: "2023-05-31"
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(Seurat)
library(hdf5r)
library(ggplot2)
library(patchwork)
library(SeuratDisk)
```
# Mouse spleen Visium
## Load and save objects
```{r}
m1001 <- readRDS(file = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\seurat_objs\\m1001.RDS")
#saveRDS(m1001, file = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\seurat_objs\\m1001.RDS")
m1007 <- readRDS(file = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m1007\\seurat_objs\\m1007.RDS')
#saveRDS(m1007, file = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m1007\\seurat_objs\\m1007.RDS')
m2007 <- readRDS(file = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m2007\\seurat_objs\\m2007.RDS')
#saveRDS(m2007, file = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m2007\\seurat_objs\\m2007.RDS')
```
## Pre-processing Visium
```{r}
m1001 <- visium_pp(in_dir = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\outs\\", h5_name = "filtered_feature_bc_matrix.h5", out_dir = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\")
m1007 <- visium_pp(in_dir = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1007\\outs\\", h5_name = "filtered_feature_bc_matrix.h5", out_dir = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1007\\")
m2007 <- visium_pp(in_dir = "Z:\\Computational_Toxicology\\Athena\\Visium\\m2007\\outs\\", h5_name = "filtered_feature_bc_matrix.h5", out_dir = "Z:\\Computational_Toxicology\\Athena\\Visium\\m2007\\")
```
# Clustering samples
```{r}
m1001 <- RunPCA(m1001, assay = "SCT", verbose = FALSE)
m1001 <- FindNeighbors(m1001, reduction = "pca", dims = 1:20)
m1001 <- FindClusters(m1001, graph.name = 'SCT_snn')
m1001 <- RunUMAP(m1001, reduction = "pca", dims = 1:20)
m1001_marks <- de_dotplot(m1001, metadata = 'SCT_snn_res.2', out = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\')
```
# Mouse spleen SCDC
## Load in
```{r}
# single cell object load in
seu <- readRDS("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS")
# Load in Visium Seurat objects
m1001 <- readRDS( file = "Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\seurat_objs\\m1001.RDS")
m1007 <- readRDS(file = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m1007\\seurat_objs\\m1007.RDS')
m2007 <- readRDS(file = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m2007\\seurat_objs\\m2007.RDS')
```
## SCDC run
```{r}
#sc_ref <- seu
#st_query <- st
#sc_meta <- 'global.cluster2'
#out <- 'C:\\Users\\GOLFIAX\\OneDrive - AbbVie Inc (O365)\\Desktop\\'
# sample m1001
m1001 <- scdc_decon(sc_ref = seu, st_query = m1001, sc_meta = 'global.cluster2', out = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m1001\\')
# sample m1007--does not work due to low # of detected genes
m1007 <- scdc_decon(sc_ref = seu, st_query = m1007, sc_meta = 'global.cluster2', out = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m1007\\')
# sample m2007
m2007 <- scdc_decon(sc_ref = seu, st_query = m2007, sc_meta = 'global.cluster2', out = 'Z:\\Computational_Toxicology\\Athena\\Visium\\m2007\\')
```
## Deconvolution plotting
```{r}
# setting the default assay as the deconvolution
DefaultAssay(m1001) <- 'SCDC'
DefaultAssay(m2007) <- 'SCDC'
# plotting Tregs, CD8 T cells, and B cells
SpatialPlot(m1001, features = rownames(m1001)[1:3], pt.size.factor = 2.5)
SpatialPlot(m2007, features = rownames(m2007)[1:3], pt.size.factor = 2.5)
# plotting CD4 T cells, neutrophils, dendritic cells
SpatialPlot(m1001, features = rownames(m1001)[4:6], pt.size.factor = 2.5)
SpatialPlot(m2007, features = rownames(m2007)[4:6], pt.size.factor = 2.5)
# plotting CD4 T cells, neutrophils, dendritic cells
SpatialPlot(m1001, features = rownames(m1001)[7:9], pt.size.factor = 2.5)
SpatialPlot(m2007, features = rownames(m2007)[7:9], pt.size.factor = 2.5)
```
# Global scRNA-seq prep
## Load and save objects
```{r}
seu <- readRDS("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS")
#saveRDS(seu, "Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS)
```
## Generate seurat object from Kimmel spleen data
```{r}
# List of h5 files
h5_files <- list.files("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/", pattern = "\\.h5$")
# generate one large seurat object that puts the ID into the name
seurat_obj <- NULL
count = 1
# Loop through h5 files
for (h5_file in h5_files) {
print(paste("Starting file ", as.character(h5_file)))
# Read h5 file into a matrix
seu_temp <- Seurat::Read10X_h5(paste("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/", h5_file, sep = ''))
if (count == 1){
seurat_obj <- CreateSeuratObject(seu_temp)
seurat_obj$orig.ident <- sapply(strsplit(h5_file, "_"), `[`, 2)
}
if (count > 1){
seu_temp <- CreateSeuratObject(seu_temp)
seu_temp$orig.ident <- sapply(strsplit(h5_file, "_"), `[`, 2)
# Add the cells from the temp Seurat object to the main Seurat object
seurat_obj <- merge(seurat_obj, seu_temp)
}
count = count + 1
}
saveRDS(seu, "Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS")
```
## Processing scRNA-seq data
```{r}
# run this in the console!
seu <- seu_pp1(seu, out="Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS", remove_doublets = F, feature_subset = F, batch_id = 'orig.ident', reduction = 'pca', harmony = F, seurat_integration = F, normalize = T, test_npcs = 100, assay = 'RNA')
seu <- seu[,seu$nCount_RNA < 20000]
seu <- seu[,seu$nFeature_RNA < 3000]
```
## Identify clusters
```{r}
# identifying B cell clusters
FeaturePlot(seu, features = c('Cd19', 'Ms4a1')) # clusters 0, 3, 6, 12
# identifying T cell clusters
FeaturePlot(seu, features = c('Cd3e', 'Cd4', 'Cd8a', 'Foxp3'))
# identifying myeloid cell clusters
FeaturePlot(seu, features = c('Cd86', 'Cd68', 'Cxcl9', 'Spp1'))
# identifying dendritic cell clusters
FeaturePlot(seu, features = c('Clec9a','Clec10a', 'Cd1c', 'Lamp3'))
# identifying NK cell cluster
FeaturePlot(seu, features = c('Nkg7', 'Cd3e'))
# identifying cap endo markers
VlnPlot(seu, group.by = 'RNA_snn_res.0.5', features= c('Podxl', 'Pecam1'))
DimPlot(seu, group.by = 'global.cluster', label = T, label.box = T)
#seu$global.cluster <- as.character(seu$RNA_snn_res.0.1)
seu$global.cluster[seu$global.cluster %in% c('0', '3', '6', '12')] <- 'B cells'
seu$global.cluster[seu$global.cluster %in% c('1', '2', '9', '7')] <- 'T/NK cells'
seu$global.cluster[seu$global.cluster %in% c('4')] <- 'Myeloid cells'
seu$global.cluster[seu$RNA_snn_res.0.5 %in% c('13')] <- 'NK cells'
seu$global.cluster[seu$global.cluster %in% c('8')] <- 'Neutrophils'
seu$global.cluster[seu$global.cluster %in% c('5')] <- 'Plasma cells'
seu <- seu[,!seu$global.cluster %in% c('10', '11')]
#removed <- seu[,seu$global.cluster %in% c('10', '11')]
#saveRDS(removed, file = 'Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_removed_populations.RDS')
de_dotplot(seu = seu, metadata = 'global.cluster', out = 'Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS', n_marks = 10, min_pct = 0.1)
```
# Myeloid cell clustering
## Load and save objects
```{r}
myl <- readRDS("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_myeloid.RDS")
#saveRDS(myl, "Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_myeloid.RDS")
```
## Object generation
```{r}
myl <- seu[,seu$global.cluster2 == 'Myeloid cells']
```
## Processing scRNA-seq data
```{r}
# run this in the console!
myl <- seu_pp1(myl, out="Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_myeloid", remove_doublets = F, feature_subset = T, batch_id = 'orig.ident', reduction = 'pca', harmony = F, seurat_integration = F, normalize = T, test_npcs = 100, assay = 'RNA')
```
## Identify clusters
```{r}
marker_plotting(seu = myl, group.by = 'RNA_snn_res.0.1', features = c('Cd68', 'Thbs1', 'Clec9a', 'Clec10a', 'Csf1r', 'Cd14', 'Fcgr3', 'Lyz2', 'Cd3e', 'Cd19', 'C1qa', 'C1qb', 'C1qc'))
marks <- de_dotplot(myl, metadata = 'RNA_snn_res.0.1', out = "Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_myeloid")
myl$global.cluster2 <- as.character(myl$RNA_snn_res.0.1)
myl$global.cluster2[myl$global.cluster2 %in% c('0', '1', '4')] <- 'Mon/Macs'
myl$global.cluster2[myl$global.cluster2 %in% c('2', '3')] <- 'Dendritic cells'
DimPlot(myl, group.by = 'global.cluster2')
```
## Transfer myeloid annotations to global
```{r}
# assigning monocyte/macrophage populations
monmac <- colnames(myl)[myl$global.cluster2 == 'Mon/Macs']
seu$global.cluster2[colnames(seu) %in% monmac] <- 'Mon/Mac'
# assigning dendritic cell populations
dcs <- colnames(myl)[myl$global.cluster2 == 'Dendritic cells']
seu$global.cluster2[colnames(seu) %in% dcs] <- 'Dendritic cells'
table(seu$global.cluster2)
```
# T cell scRNA-seq prep
## Load and save objects
```{r}
tcells <- readRDS("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_tcells.RDS")
#saveRDS(tcells, "Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_tcells.RDS")
```
## Object generation
```{r}
tcells <- seu[,seu$global.cluster == 'T/NK cells']
```
## Processing scRNA-seq data
```{r}
# run this in the console!
tcells <- seu_pp1(tcells, out="Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_tcells.RDS", remove_doublets = F, feature_subset = F, batch_id = 'orig.ident', reduction = 'pca', harmony = F, seurat_integration = F, normalize = T, test_npcs = 100, assay = 'RNA')
```
## Identify clusters
```{r}
DimPlot(tcells, group.by = 'RNA_snn_res.0.2')
# identifying Tregs
marker_plotting(tcells, features = c('Foxp3', 'Il2ra', 'Nt5e', 'Nrp1', 'Cd4'), group.by = 'RNA_snn_res.0.4') # cluster 1
# identifying Tfh cells
marker_plotting(tcells, features = c('Cxcr5', 'Pdcd1', 'Bcl6', 'Icos', 'Sh2d1a', 'Cd40lg'), group.by = 'RNA_snn_res.0.4') # cluster 2
# identifying CD4 T cells
marker_plotting(tcells, features = c('Cd4'), group.by = 'RNA_snn_res.0.4') # cluster 1, 2, 4
# identifying CD8 T cells
marker_plotting(tcells, features = c('Cd8a'), group.by = 'RNA_snn_res.0.4') # cluster 0, 3, 5, 8, 10
# identifying T cells in general
marker_plotting(tcells, features = 'Cd3e', group.by = 'RNA_snn_res.0.4')
# identifying memory T cells
marker_plotting(tcells, features = c('Cd44', 'Sell', 'Il7r', 'Il2rb', 'Klrg1', 'Cd69'), group.by = 'RNA_snn_res.0.4') # no clear population
# identifying Th17 T cells
marker_plotting(tcells, group.by = 'RNA_snn_res.0.4', features = c('Rorc', 'Il17a', 'Il17f', 'Il23r', 'Il22', 'Batf', 'Ccr6', 'Il1r1'))
tcells$global.cluster2 <- as.character(tcells$RNA_snn_res.0.4)
DimPlot(tcells, group.by = 'global.cluster2')
tcells$global.cluster2[tcells$global.cluster2 %in% c('0', '3', '5', '8', '10')] <- 'CD8 T cells'
tcells$global.cluster2[tcells$global.cluster2 %in% c('2', '4')] <- 'CD4 T cells'
tcells$global.cluster2[tcells$global.cluster2 %in% c('1')] <- 'Tregs'
tcells$global.cluster2[tcells$global.cluster2 == c('6')] <- 'Unassigned T:6'
tcells$global.cluster2[tcells$global.cluster2 == c('7')] <- 'Unassigned T:7'
tcells$global.cluster2[tcells$global.cluster2 == c('9')] <- 'Unassigned T:9'
tcell_marks <- de_dotplot(seu = tcells, metadata = 'global.cluster2', out = 'Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_tcells')
```
## Transfer T annotations to global
```{r}
# remove high stress T cell cluster 6 from global.cluster2 from t cells and from seurat object
t_remove <- colnames(tcells)[tcells$global.cluster2 == 'Unassigned T:6']
seu <- seu[,!colnames(seu) %in% t_remove]
tcells <- tcells[,!colnames(tcells) %in% t_remove]
#seu$global.cluster2 <- seu$global.cluster
# assigning Tregs
tregs <- colnames(tcells)[tcells$global.cluster2 == 'Tregs']
seu$global.cluster2[colnames(seu) %in% tregs] <- 'Tregs'
# assigning CD4 T cells
cd4 <- colnames(tcells)[tcells$global.cluster2 == 'CD4 T cells']
seu$global.cluster2[colnames(seu) %in% cd4] <- 'CD4 T cells'
# assigning CD8 T cells
cd8 <- colnames(tcells)[tcells$global.cluster2 == 'CD8 T cells']
seu$global.cluster2[colnames(seu) %in% cd8] <- 'CD8 T cells'
# removing a high mitochondrial cell percentage population
remove <- colnames(tcells)[tcells$global.cluster2 == 'Unassigned T:6']
seu <- seu[,!colnames(seu) %in% remove]
DimPlot(seu, group.by = 'global.cluster2')
#seu$global.cluster2[seu$global.cluster2 == 'T cells'] <- 'Unassigned T cells'
```
# B cell scRNA-seq prep
## Load and save objects
```{r}
bcells <- readRDS("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_bcells.RDS")
#saveRDS(bcells, "Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_bcells.RDS")
```
## Object generation
```{r}
bcells <- seu[,seu$global.cluster == 'B cells']
```
## Processing scRNA-seq data
```{r}
bcells <- seu_pp1(bcells, out="Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_bcells.RDS", remove_doublets = F, feature_subset = F, batch_id = 'orig.ident', reduction = 'pca', harmony = F, seurat_integration = F, normalize = T, test_npcs = 100, assay = 'RNA')
```
## Identify clusters
```{r}
# identifying follicular B cells
marker_plotting(bcells, features = c('Cd45ra', 'Cd19', 'Ighd', 'Cd38', 'Cr2', 'Fcer2a', 'Cd22', 'Pax5'), group.by = 'RNA_snn_res.0.2')
# identifying marginal zone B cells
marker_plotting(bcells, features = c('Cd1d1', 'Ighm', 'Cd9', 'Cd22', 'Ebf1', 'E2A', 'Slc22a2'), group.by = 'RNA_snn_res.0.2')
# identifying B1 B cells
marker_plotting(bcells, features = c('Cd5', 'Spn', 'Itgam', 'Sdc1'), group.by = 'RNA_snn_res.0.2') # cluster 5
# identifying transitional/immature B cells
marker_plotting(bcells, features = c('Cd93', 'Cd24a', 'BR2', 'Tnfrsf13b'), group.by = 'RNA_snn_res.0.2')
# germinal center b cells
marker_plotting(bcells, features = c('Fas', 'PNA', 'Tnfrsf13c', 'Bcl6', 'Ebf1'), group.by = 'RNA_snn_res.0.2')
# memory B cells
marker_plotting(tcells, features = c('Cd80', 'Nt5e', 'Pdcd1lg2', 'Cd38', 'Cd84', 'Cd86', 'Pbx1', 'Spib'), group.by = 'RNA_snn_res.0.2')
bcells$global.cluster2[bcells$RNA_snn_res.2.1 == 28] <- 'Myeloid contamination'
bcells$global.cluster2[bcells$RNA_snn_res.2.1 %in% c(24, 27)] <- 'T cell contamination'
```
## Transfer B annotations to global
```{r}
# assigning myeloid cells back to the proper
my_contam <- colnames(bcells)[bcells$global.cluster2 == 'Myeloid contamination']
seu$global.cluster2[colnames(seu) %in% my_contam] <- 'Myeloid cells'
t_contam <- colnames(bcells)[bcells$global.cluster2 == 'T cell contamination']
seu$global.cluster2[colnames(seu) %in% t_contam] <- 'T cells'
# removing clusters that seem to be T cells
t_not_b <- colnames(bcells)[bcells$RNA_snn_res.3 %in% c(32, 35)]
seu$global.cluster2[colnames(seu) %in% t_not_b] <- 'T cells'
bcells <- bcells[, !bcells$RNA_snn_res.3 %in% c(32, 35)]
```
# Visium prep
## Load and save objects
```{r}
st <- readRDS(file = "Z:\\Computational_Toxicology\\Athena\\SpaceRanger_testruns\\v2_athena_test\\Kidney_out\\kidney_visium_seurat.RDS")
#saveRDS(st, file = "Z:\\Computational_Toxicology\\Athena\\SpaceRanger_testruns\\v2_athena_test\\Kidney_out\\kidney_visium_seurat.RDS")
```
## Pre-processing Visium
```{r}
seu <- visium_pp(in_dir = "Z:\\Computational_Toxicology\\Athena\\SpaceRanger_testruns\\v2_athena_test\\Kidney_out\\outs", h5_name = "filtered_feature_bc_matrix.h5", out_dir = "Z:\\Computational_Toxicology\\Athena\\SpaceRanger_testruns\\v2_athena_test\\Kidney_out\\")
```
# SCDC
## Load in
```{r}
# single cell object load in
seu <- readRDS("Z:/Computational_Toxicology/Athena/Mouse_scRNAseq/Kimmel_et_al_2019/Spleen/kimmel_seurat.RDS")
st <- readRDS(file = "Z:\\Computational_Toxicology\\Athena\\SpaceRanger_testruns\\v2_athena_test\\Kidney_out\\kidney_visium_seurat.RDS")
```
## SCDC run
```{r}
#sc_ref <- seu
#st_query <- st
#sc_meta <- 'global.cluster2'
#out <- 'C:\\Users\\GOLFIAX\\OneDrive - AbbVie Inc (O365)\\Desktop\\'
st <- scdc_decon(sc_ref = seu, st_query = st, sc_meta = 'global.cluster2', out = 'Z:\\Computational_Toxicology\\Athena\\SpaceRanger_testruns\\v2_athena_test\\outputs\\')
```
# SPOTclean prep
Two parts of 10x Space Ranger output files are required as input to `SpotClean`: the raw gene-by-spot count matrix, and the slide metadata. In this example, you can download and unzip the [Feature / cell matrix (raw)](https://cf.10xgenomics.com/samples/spatial-exp/1.0.0/V1_Adult_Mouse_Brain/V1_Adult_Mouse_Brain_raw_feature_bc_matrix.tar.gz) and [Spatial imaging data](https://cf.10xgenomics.com/samples/spatial-exp/1.0.0/V1_Adult_Mouse_Brain/V1_Adult_Mouse_Brain_spatial.tar.gz) from [V1_Adult_Mouse_Brain](https://support.10xgenomics.com/spatial-gene-expression/datasets/1.0.0/V1_Adult_Mouse_Brain). You will get a folder `raw_feature_bc_matrix` containing `barcodes.tsv.gz`, `features.tsv.gz`, `matrix.mtx.gz`, and a folder `spatial` containing `aligned_fiducials.jpg`, `detected_tissue_image.jpg`, `tissue_hires_image.png`, `tissue_lowres_image.png`, `tissue_positions_list.csv`, `scalefactors_json.json`. The former folder contains the raw gene-by-spot count matrix, and the latter contains slide metadata like slide images and spot IDs and positions.
```{r}
library(SpotClean)
spatial_dir <- '/Volumes/hqdinh2/Projects/RawData_FromUWBiotech/HNCVisium_2022-05-05/CK17-5_outs/'
list.files(spatial_dir)
hnc_raw <- read10xRaw("/Volumes/hqdinh2/Projects/RawData_FromUWBiotech/HNCVisium_2022-05-05/CK17-5_outs/")
hnc_slide_info <- read10xSlide(tissue_csv_file=file.path(spatial_dir, "tissue_positions_list.csv"), tissue_img_file = file.path(spatial_dir,
"tissue_lowres_image.png"),
scale_factor_file = file.path(spatial_dir,
"scalefactors_json.json"))
str(hnc_slide_info)
slide_obj <- createSlide(hnc_raw, hnc_slide_info)
slide_obj
visualizeSlide(slide_obj)
visualizeLabel(slide_obj,"tissue")
metadata(slide_obj)$slide$total_counts <- colSums(hnc_raw)
visualizeHeatmap(slide_obj,"total_counts")
visualizeHeatmap(slide_obj,"LAMP3")
visualizeHeatmap(slide_obj,"CXCL9")
saveRDS(slide_obj, paste(spatial_dir, 'slide_obj.RDS', sep = ''))
decon_ck17_5_seurat <- readRDS(paste(spatial_dir, 'decon_ck17_5_seurat.RDS', sep = ''))
decon_ck17_5_seurat
names(metadata(decon_ck17_5_seurat ))
summary(metadata(decon_ck17_5_seurat )$contamination_rate)
arcScore(slide_obj)
decon_ck17_5_seurat <- convertToSeurat(decon_ck17_5_seurat ,image_dir = spatial_dir)
saveRDS(slide_obj, paste(spatial_dir, 'decon_ck17_5_seurat.RDS', sep = ''))
```