-
Notifications
You must be signed in to change notification settings - Fork 1
/
PreProcessing.R
513 lines (431 loc) · 30.5 KB
/
PreProcessing.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
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
507
508
509
510
511
512
513
#########################################################
## RNA, MULTI-seq and SCMK Pre-Processing for 8-donor, ##
## 7-donor, Zheng et al, and BD PBMC +/- CD3/CD28 data ##
## Chris McGinnis, Gartner Lab, UCSF, 06/26/2020 ########
#########################################################
library(Seurat)
library(deMULTIplex)
library(DoubletFinder)
##################
## 8-Donor PBMC ##
##################
## Step 1: Define putative cell IDs -------------------------------------------------------------------------------------------------------------------------------------------------------------------
data_l1 <- Read10X('./raw_feature_bc_matrix_L1/')
cell.counts <- Matrix::colSums(data_l1)
cellIDs_l1 <- colnames(data_l1)[which(cell.counts >= 250)] ## 5,001 cells
data_l2 <- Read10X('./raw_feature_bc_matrix_L2/')
cell.counts <- Matrix::colSums(data_l2)
cellIDs_l2 <- colnames(data_l2)[which(cell.counts >= 250)] ## 4,326 cells
data_l3 <- Read10X('./raw_feature_bc_matrix_L3/')
cell.counts <- Matrix::colSums(data_l3)
cellIDs_l3 <- colnames(data_l3)[which(cell.counts >= 250)] ## 5,159 cells
data_l4 <- Read10X('./raw_feature_bc_matrix_L4/')
cell.counts <- Matrix::colSums(data_l4)
cellIDs_l4 <- colnames(data_l4)[which(cell.counts >= 250)] ## 5,867 cells
## Step 2: Align MULTI-seq and HashTag FASTQs ---------------------------------------------------------------------------------------------------------------------------------------------------------
## MULTI-seq
readTable_l2_multi <- MULTIseq.preProcess(R1="TGACCA_S2_L001_R1_001.fastq.gz",
R2="TGACCA_S2_L001_R2_001.fastq.gz",
cellIDs = cellIDs_l2, cell=c(1,16), umi=c(17,28), tag=c(1,8))
readTable_l3_multi <- MULTIseq.preProcess(R1="ACAGTG_S3_L001_R1_001.fastq.gz",
R2="ACAGTG_S3_L001_R2_001.fastq.gz",
cellIDs = cellIDs_l3, cell=c(1,16), umi=c(17,28), tag=c(1,8))
bar.ref <- read.csv("LMOlist.csv", header=F, stringsAsFactors=F)
bar.ref <- bar.ref[9:16,1]
barTable_l2_multi <- MULTIseq.align(readTable_l2_multi, cellIDs_l2, bar.ref)
barTable_l3_multi <- MULTIseq.align(readTable_l3_multi, cellIDs_l3, bar.ref)
## Cell Hashing
readTable_l2_hash <- MULTIseq.preProcess_beta(R1='SL-2792-06_e06_S12_L002_R1_001.fastq.gz',
R2='SL-2792-06_e06_S12_L002_R2_001.fastq.gz',
cellIDs = cellIDs_l2, cell=c(1,16), umi=c(17,26), tag=c(26,70))
readTable_l3_hash <- MULTIseq.preProcess_beta(R1='SL-2792-07_e07_S13_L002_R1_001.fastq.gz',
R2='SL-2792-07_e07_S13_L002_R2_001.fastq.gz',
cellIDs = cellIDs_l3, cell=c(1,16), umi=c(17,26), tag=c(26,70))
bar.ref_hash <- c("ATTCAAGGGCAGCCGCGTCACGATTGGATACGACTGTTGGACCGG",
"TGGATGGGATAAGTGCGTGATGGACCGAAGGGACCTCGTGGCCGG",
"CGGCTCGTGCTGCGTCGTCTCAAGTCCAGAAACTCCGTGTATCCT",
"ATTGGGAGGCTTTCGTACCGCTGCCGCCACCAGGTGATACCCGCT",
"GTGATCCGCGCAGGCACACATACCGACTCAGATGGGTTGTCCAGG",
"GCAGCCGGCGTCGTACGAGGCACAGCGGAGACTAGATGAGGCCCC",
"CGCGTCCAATTTCCGAAGCCCCGCCCTAGGAGTTCCCCTGCGTGC",
"GCCCATTCATTGCACCCGCCAGTGATCGACCCTAGTGGAGCTAAG")
barTable_l2_hash <- MULTIseq.align_BD(readTable_l2_hash, cellIDs_l2, bar.ref_hash)
barTable_l3_hash <- MULTIseq.align_BD(readTable_l3_hash, cellIDs_l3, bar.ref_hash)
## Sample classification workflow continued in "SampleClassification.R"
## Step 3: Remove uninformative genes in read-depth normalized data -----------------------------------------------------------------------------------------------------------------------------------
data_aggr <- Read10X('/Volumes/MULTIseq_1/SLNR_PBMC/aggrSL/outs/raw_feature_bc_matrix/')
cellIDs <- c(cellIDs_l1,cellIDs_l2,cellIDs_l3,cellIDs_l4)
data_aggr <- data_aggr[,cellIDs]
gene.counts <- Matrix::rowSums(data_aggr)
data_aggr <- data_aggr[which(gene.counts >= 3), ]
## Step 4: Pre-process Seurat object ------------------------------------------------------------------------------------------------------------------------------------------------------------------
seu_pbmc_raw <- CreateSeuratObject(data_aggr)
mito.genes <- grep("^MT-", rownames(seu_pbmc_raw@assays$RNA@counts), value = TRUE)
percent.mito <- Matrix::colSums(seu_pbmc_raw@assays$RNA@counts[mito.genes, ]) / Matrix::colSums(seu_pbmc_raw@assays$RNA@counts)
[email protected][,"PercentMito"] <- percent.mito
seu_pbmc_raw <- SCTransform(seu_pbmc_raw)
seu_pbmc_raw <- RunPCA(seu_pbmc_raw)
seu_pbmc_raw <- RunUMAP(seu_pbmc_raw, dims = 1:13)
seu_pbmc_raw <- FindNeighbors(seu_pbmc_raw, dims = 1:13)
seu_pbmc_raw <- FindClusters(seu_pbmc_raw, resolution = 1.0)
## Step 5: Remove low-quality cells (high pMito, low nUMI) --------------------------------------------------------------------------------------------------------------------------------------------
'%ni%' <- Negate('%in%')
seu_pbmc_raw_2 <- SubsetData(seu_pbmc_raw, cells=rownames([email protected])[which([email protected] %ni% c(4,10,13,18:20,23,24))]) # Remove 3726 cells
seu_pbmc_raw_2 <- SCTransform(seu_pbmc_raw_2)
seu_pbmc_raw_2 <- RunPCA(seu_pbmc_raw_2)
seu_pbmc_raw_2 <- RunUMAP(seu_pbmc_raw_2, dims = 1:12)
seu_pbmc_raw_2 <- FindNeighbors(seu_pbmc_raw_2, dims = 1:12)
seu_pbmc_raw_2 <- FindClusters(seu_pbmc_raw_2, resolution = 1.0)
## Step 6: Before applying DoubletFinder, subset data by lane -----------------------------------------------------------------------------------------------------------------------------------------
[email protected][,"LaneID"] <- rep(1, nrow([email protected]))
[email protected][grep("-2", rownames([email protected])), "LaneID"] <- 2
[email protected][grep("-3", rownames([email protected])), "LaneID"] <- 3
[email protected][grep("-4", rownames([email protected])), "LaneID"] <- 4
## Lane 1
seu_pbmc_raw_l1 <- SubsetData(seu_pbmc_raw_2, cells=rownames([email protected])[which([email protected]$LaneID == 1)])
seu_pbmc_raw_l1 <- SCTransform(seu_pbmc_raw_l1)
seu_pbmc_raw_l1 <- RunPCA(seu_pbmc_raw_l1)
seu_pbmc_raw_l1 <- RunUMAP(seu_pbmc_raw_l1, dims = 1:10)
seu_pbmc_raw_l1 <- FindNeighbors(seu_pbmc_raw_l1, dims = 1:10)
seu_pbmc_raw_l1 <- FindClusters(seu_pbmc_raw_l1, resolution = 0.5)
## Lane 2
seu_pbmc_raw_l2 <- SubsetData(seu_pbmc_raw_2, cells=rownames([email protected])[which([email protected]$LaneID == 2)])
seu_pbmc_raw_l2 <- SCTransform(seu_pbmc_raw_l2)
seu_pbmc_raw_l2 <- RunPCA(seu_pbmc_raw_l2)
seu_pbmc_raw_l2 <- RunUMAP(seu_pbmc_raw_l2, dims = 1:11)
seu_pbmc_raw_l2 <- FindNeighbors(seu_pbmc_raw_l2, dims = 1:11)
seu_pbmc_raw_l2 <- FindClusters(seu_pbmc_raw_l2, resolution = 0.5)
## Lane 3
seu_pbmc_raw_l3 <- SubsetData(seu_pbmc_raw_2, cells=rownames([email protected])[which([email protected]$LaneID == 3)])
seu_pbmc_raw_l3 <- SCTransform(seu_pbmc_raw_l3)
seu_pbmc_raw_l3 <- RunPCA(seu_pbmc_raw_l3)
seu_pbmc_raw_l3 <- RunUMAP(seu_pbmc_raw_l3, dims = 1:13)
seu_pbmc_raw_l3 <- FindNeighbors(seu_pbmc_raw_l3, dims = 1:13)
seu_pbmc_raw_l3 <- FindClusters(seu_pbmc_raw_l3, resolution = 0.5)
## Lane 4
seu_pbmc_raw_l4 <- SubsetData(seu_pbmc_raw_2, cells=rownames([email protected])[which([email protected]$LaneID == 4)])
seu_pbmc_raw_l4 <- SCTransform(seu_pbmc_raw_l4)
seu_pbmc_raw_l4 <- RunPCA(seu_pbmc_raw_l4)
seu_pbmc_raw_l4 <- RunUMAP(seu_pbmc_raw_l4, dims = 1:10)
seu_pbmc_raw_l4 <- FindNeighbors(seu_pbmc_raw_l4, dims = 1:10)
seu_pbmc_raw_l4 <- FindClusters(seu_pbmc_raw_l4, resolution = 1.0)
## Step 7: Identify heterotypic doublets in each lane using DoubletFinder -----------------------------------------------------------------------------------------------------------------------------
## Lane 1
sweep.res.list_pbmc_l1 <- paramSweep_v3(seu_pbmc_raw_l1, PCs = 1:10, sct = TRUE)
sweep.stats_pbmc_l1 <- summarizeSweep(sweep.res.list_pbmc_l1, GT = FALSE)
bcmvn_pbmc_l1 <- find.pK(sweep.stats_pbmc_l1)
homotypic.prop.l1 <- modelHomotypic([email protected])
nExp_poi.l1 <- round(0.04*nrow([email protected]))
nExp_poi.adj.l1 <- round(nExp_poi.l1*(1-homotypic.prop.l1))
seu_pbmc_raw_l1 <- doubletFinder_v3(seu_pbmc_raw_l1, PCs = 1:10, pN = 0.25, pK = 0.01, nExp = nExp_poi.adj.l1, reuse.pANN = FALSE, sct=T)
## Lane 2
sweep.res.list_pbmc_l2 <- paramSweep_v3(seu_pbmc_raw_l2, PCs = 1:11, sct = TRUE)
sweep.stats_pbmc_l2 <- summarizeSweep(sweep.res.list_pbmc_l2, GT = FALSE)
bcmvn_pbmc_l2 <- find.pK(sweep.stats_pbmc_l2)
homotypic.prop.l2 <- modelHomotypic([email protected])
nExp_poi.l2 <- round(0.04*nrow([email protected]))
nExp_poi.adj.l2 <- round(nExp_poi.l2*(1-homotypic.prop.l2))
seu_pbmc_raw_l2 <- doubletFinder_v3(seu_pbmc_raw_l2, PCs = 1:11, pN = 0.25, pK = 0.01, nExp = nExp_poi.adj.l2, reuse.pANN = FALSE, sct=T)
## Lane 3
sweep.res.list_pbmc_l3 <- paramSweep_v3(seu_pbmc_raw_l3, PCs = 1:13, sct = TRUE)
sweep.stats_pbmc_l3 <- summarizeSweep(sweep.res.list_pbmc_l3, GT = TRUE, GT.calls = final.calls_l3_temp)
bcmvn_pbmc_l3 <- find.pK(sweep.stats_pbmc_l3)
homotypic.prop.l3 <- modelHomotypic([email protected])
nExp_poi.l3 <- round(0.04*nrow([email protected]))
nExp_poi.adj.l3 <- round(nExp_poi.l3*(1-homotypic.prop.l3))
seu_pbmc_raw_l3 <- doubletFinder_v3(seu_pbmc_raw_l3, PCs = 1:11, pN = 0.25, pK = 0.01, nExp = nExp_poi.adj.l3, reuse.pANN = FALSE, sct=T)
## Lane 4
sweep.res.list_pbmc_l4 <- paramSweep_v3(seu_pbmc_raw_l4, PCs = 1:10, sct = TRUE)
sweep.stats_pbmc_l4 <- summarizeSweep(sweep.res.list_pbmc_l4, GT = FALSE)
bcmvn_pbmc_l4 <- find.pK(sweep.stats_pbmc_l4)
homotypic.prop.l4 <- modelHomotypic([email protected])
nExp_poi.l4 <- round(0.04*nrow([email protected]))
nExp_poi.adj.l4 <- round(nExp_poi.l4*(1-homotypic.prop.l4))
seu_pbmc_raw_l4 <- doubletFinder_v3(seu_pbmc_raw_l4, PCs = 1:10, pN = 0.25, pK = 0.01, nExp = nExp_poi.adj.l4, reuse.pANN = FALSE, sct=T)
## Step 8: Remove doublets, pre-process cleaned merged Seurat object ----------------------------------------------------------------------------------------------------------------------------------
df.doublets <- c(rownames([email protected])[which([email protected]$DF.classifications_0.25_0.01_133 == "Doublet")],
rownames([email protected])[which([email protected]$DF.classifications_0.25_0.01_132 == "Doublet")],
rownames([email protected])[which([email protected]$DF.classifications_0.25_0.01_148 == "Doublet")],
rownames([email protected])[which([email protected]$DF.classifications_0.25_0.01_168 == "Doublet")])
[email protected][,"DF"] <- rep("Singlet")
[email protected][df.doublets,"DF"] <- "Doublet"
seu_pbmc_clean <- SubsetData(seu_pbmc_raw_2, cells=rownames([email protected])[which([email protected]$DF == "Singlet")])
seu_pbmc_clean <- SCTransform(seu_pbmc_clean)
seu_pbmc_clean <- RunPCA(seu_pbmc_clean)
seu_pbmc_clean <- RunUMAP(seu_pbmc_clean, dims = 1:12)
seu_pbmc_clean <- FindNeighbors(seu_pbmc_clean, dims = 1:12)
seu_pbmc_clean <- FindClusters(seu_pbmc_clean, resolution = 1.5)
## Step 9: Annotate Cell Types ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[email protected][,"CellType"] <- rep("unknown", nrow([email protected]))
[email protected]$CellType[which([email protected] %in% c(8,21))] <- "B"
[email protected]$CellType[which([email protected] %in% c(2,14,24))] <- "NK"
[email protected]$CellType[which([email protected] %in% c(4,6,15,16))] <- "CD14Mono"
[email protected]$CellType[which([email protected] == 20)] <- "DC"
[email protected]$CellType[which([email protected] == 25)] <- "pDC"
[email protected]$CellType[which([email protected] %in% c(13,22))] <- "CD16Mono"
[email protected]$CellType[which([email protected] %in% c(0,1,3,5,7,9,12,17,18,23))] <- "CD4T"
[email protected]$CellType[which([email protected] %in% c(10,11,19))] <- "CD8T"
## Step 10: Subset Ficoll-prepped PBMCs and CD4+ T-cells ----------------------------------------------------------------------------------------------------------------------------------------------
seu_pbmc_ficoll <- SubsetData(seu_pbmc_clean, cells = rownames([email protected])[which([email protected]$Donor %in% c("A","B","C"))])
seu_pbmc_ficoll <- SCTransform(seu_pbmc_ficoll)
seu_pbmc_ficoll <- RunPCA(seu_pbmc_ficoll)
seu_pbmc_ficoll <- RunUMAP(seu_pbmc_ficoll, dims = 1:12)
seu_pbmc_ficoll <- FindNeighbors(seu_pbmc_ficoll, dims = 1:12)
seu_pbmc_ficoll <- FindClusters(seu_pbmc_ficoll, resolution = 0.8)
seu_CD4T_ficoll <- SubsetData(seu_pbmc_clean, cells = rownames([email protected])[which([email protected]$CellType == "CD4T" & [email protected]$Donor %in% c("A","B","C"))])
seu_CD4T_ficoll <- SCTransform(seu_CD4T_ficoll)
seu_CD4T_ficoll <- RunPCA(seu_CD4T_ficoll)
seu_CD4T_ficoll <- RunUMAP(seu_CD4T_ficoll, dims = 1:25)
seu_CD4T_ficoll <- FindNeighbors(seu_CD4T_ficoll, dims = 1:25)
seu_CD4T_ficoll <- FindClusters(seu_CD4T_ficoll, resolution = 1.0)
## Step 11: Define CD4+ T-cell subtypes ---------------------------------------------------------------------------------------------------------------------------------------------------------------
[email protected][,"CD4Tsubset"] <- rep("unknown")
[email protected]$CD4Tsubset[which([email protected] %in% c(0,2,6,10,11))] <- "Activated"
[email protected]$CD4Tsubset[which([email protected] %in% c(1,3,5,7:9))] <- "Memory"
[email protected]$CD4Tsubset[which([email protected] == 4)] <- "Naive"
######################
## Zheng et al PBMC ##
######################
## Step 1: Remove uninformative genes and cell BCs from read-depth normalized Zheng et al (Nat Comm, 2017) dataset ------------------------------------------------------------------------------------
data_zheng <- Read10X('/Users/gartnerlab/Desktop/SLNR_PBMC/REVIEW/zheng/raw_feature_bc_matrix/')
cell.counts <- Matrix::colSums(data_zheng)
data_zheng <- data_zheng[,which(cell.counts >= 250)]
gene.counts <- Matrix::rowSums(data_zheng)
data_zheng <- data_zheng[which(gene.counts > 3), ]
## Step 2: Pre-process Seurat object, remove high %Mito cells -----------------------------------------------------------------------------------------------------------------------------------------
seu_zheng <- CreateSeuratObject(data_zheng)
seu_zheng <- SCTransform(seu_zheng)
seu_zheng <- RunPCA(seu_zheng)
seu_zheng <- RunUMAP(seu_zheng, dims = 1:21)
seu_zheng <- FindNeighbors(seu_zheng, dims = 1:21)
seu_zheng <- FindClusters(seu_zheng, resolution = 0.5)
mito.genes <- grep("MT-", rownames(seu_zheng@assays$RNA@counts), value = TRUE)
percent.mito <- Matrix::colSums(seu_zheng@assays$RNA@counts[mito.genes, ]) / Matrix::colSums(seu_zheng@assays$RNA@counts)
[email protected][,"PercentMito"] <- percent.mito
seu_zheng_2 <- SubsetData(seu_zheng, cells=rownames([email protected])[which([email protected] != 9)])
seu_zheng_2 <- SCTransform(seu_zheng_2)
seu_zheng_2 <- RunPCA(seu_zheng_2)
seu_zheng_2 <- RunUMAP(seu_zheng_2, dims = 1:20)
seu_zheng_2 <- FindNeighbors(seu_zheng_2, dims = 1:20)
seu_zheng_2 <- FindClusters(seu_zheng_2, resolution = 0.5)
[email protected][,"LaneID"] <- 1L
[email protected]$LaneID[grep("-2",rownames([email protected]))] <- 2
[email protected]$LaneID[grep("-3",rownames([email protected]))] <- 3
## Step 3: Before applying DoubletFinder, subset data by lane -----------------------------------------------------------------------------------------------------------------------------------------
seu_zheng_XY <- SubsetData(seu_zheng_2, cells=rownames([email protected])[which([email protected]$LaneID == 1)])
seu_zheng_XY <- SCTransform(seu_zheng_XY)
seu_zheng_XY <- RunPCA(seu_zheng_XY)
seu_zheng_XY <- RunUMAP(seu_zheng_XY, dims = 1:18)
seu_zheng_XY <- FindNeighbors(seu_zheng_XY, dims = 1:18)
seu_zheng_XY <- FindClusters(seu_zheng_XY, resolution = 0.5)
seu_zheng_X <- SubsetData(seu_zheng_2, cells=rownames([email protected])[which([email protected]$LaneID == 2)])
seu_zheng_X <- SCTransform(seu_zheng_X)
seu_zheng_X <- RunPCA(seu_zheng_X)
seu_zheng_X <- RunUMAP(seu_zheng_X, dims = 1:16)
seu_zheng_X <- FindNeighbors(seu_zheng_X, dims = 1:16)
seu_zheng_X <- FindClusters(seu_zheng_X, resolution = 0.5)
seu_zheng_Y <- SubsetData(seu_zheng_2, cells=rownames([email protected])[which([email protected]$LaneID == 3)])
seu_zheng_Y <- SCTransform(seu_zheng_Y)
seu_zheng_Y <- RunPCA(seu_zheng_Y)
seu_zheng_Y <- RunUMAP(seu_zheng_Y, dims = 1:18)
seu_zheng_Y <- FindNeighbors(seu_zheng_Y, dims = 1:18)
seu_zheng_Y <- FindClusters(seu_zheng_Y, resolution = 0.5)
## Step 4: Identify heterotypic doublets in each lane using DoubletFinder -----------------------------------------------------------------------------------------------------------------------------
sweep.res.list_X <- paramSweep_v3(seu_zheng_X, PCs = 1:16, sct = TRUE)
sweep.stats_X <- summarizeSweep(sweep.res.list_X, GT = FALSE)
bcmvn_X <- find.pK(sweep.stats_X)
nExp_poi <- round(0.07*nrow([email protected]))
seu_zheng_X <- doubletFinder_v3(seu_zheng_X, PCs = 1:16, pN = 0.25, pK = 0.07, nExp = nExp_poi, reuse.pANN = FALSE, sct = TRUE)
sweep.res.list_Y <- paramSweep_v3(seu_zheng_Y, PCs = 1:18, sct = TRUE)
sweep.stats_Y <- summarizeSweep(sweep.res.list_Y, GT = FALSE)
bcmvn_Y <- find.pK(sweep.stats_Y)
nExp_poi <- round(0.07*nrow([email protected]))
seu_zheng_Y <- doubletFinder_v3(seu_zheng_Y, PCs = 1:18, pN = 0.25, pK = 0.09, nExp = nExp_poi, reuse.pANN = FALSE, sct = TRUE)
sweep.res.list_XY <- paramSweep_v3(seu_zheng_XY, PCs = 1:18, sct = TRUE)
sweep.stats_XY <- summarizeSweep(sweep.res.list_XY, GT = FALSE)
bcmvn_XY <- find.pK(sweep.stats_XY)
nExp_poi <- round(0.07*nrow([email protected]))
seu_zheng_XY <- doubletFinder_v3(seu_zheng_XY, PCs = 1:18, pN = 0.25, pK = 0.08, nExp = nExp_poi, reuse.pANN = FALSE, sct = TRUE)
## Step 5: Record DoubletFinder results, remove doublets (also souporcell), and low-frequency cell types ---------------------------------------------------------------------------------------------
[email protected][,"DF"] <- rep("unknown")
[email protected][rownames([email protected]),"DF"] <- [email protected]$DF.classifications_0.25_0.07_556
[email protected][rownames([email protected]),"DF"] <- [email protected]$DF.classifications_0.25_0.09_681
[email protected][rownames([email protected]),"DF"] <- [email protected]$DF.classifications_0.25_0.08_595
seu_zheng_clean <- SubsetData(seu_zheng_2, cells=rownames([email protected])[which([email protected]$DF == "Singlet")])
seu_zheng_clean <- SCTransform(seu_zheng_clean)
seu_zheng_clean <- RunPCA(seu_zheng_clean)
seu_zheng_clean <- RunUMAP(seu_zheng_clean, dims = 1:21)
seu_zheng_clean <- FindNeighbors(seu_zheng_clean, dims = 1:21)
seu_zheng_clean <- FindClusters(seu_zheng_clean, resolution = 0.75)
seu_zheng_clean <- SubsetData(seu_zheng_clean, cells=rownames([email protected])[which([email protected]$CellType != "low_frequency" & [email protected]$Donor != "Doublet")])
seu_zheng_clean <- SCTransform(seu_zheng_clean)
seu_zheng_clean <- RunPCA(seu_zheng_clean)
seu_zheng_clean <- RunUMAP(seu_zheng_clean, dims = 1:16)
seu_zheng_clean <- FindNeighbors(seu_zheng_clean, dims = 1:16)
seu_zheng_clean <- FindClusters(seu_zheng_clean, resolution = 0.5)
## Step 6: Annotate cell types ------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[email protected][,"CellType"] <- rep("low_frequency")
[email protected]$CellType[which([email protected] %in% c(0:2,4,5,11,18))] <- "CD4T"
[email protected]$CellType[which([email protected] %in% c(3,10,17))] <- "CD8T"
[email protected]$CellType[which([email protected] == 8)] <- "NK"
[email protected]$CellType[which([email protected] == 16)] <- "Platelet"
[email protected]$CellType[which([email protected] %in% c(7,9))] <- "CD14Mono"
[email protected]$CellType[which([email protected] == 12)] <- "CD16Mono"
[email protected]$CellType[which([email protected] == 13)] <- "DC"
[email protected]$CellType[which([email protected] %in% c(6,14))] <- "B"
## Step 7: Subset CD4+ T-cells, define subtypes -------------------------------------------------------------------------------------------------------------------------------------------------------
seu_zheng_CD4T <- SubsetData(seu_zheng_clean, cells=rownames([email protected])[which([email protected]$CellType == "CD4T")])
seu_zheng_CD4T <- SCTransform(seu_zheng_CD4T)
seu_zheng_CD4T <- RunPCA(seu_zheng_CD4T)
seu_zheng_CD4T <- RunUMAP(seu_zheng_CD4T, dims = 1:20)
seu_zheng_CD4T <- FindNeighbors(seu_zheng_CD4T, dims = 1:20)
seu_zheng_CD4T <- FindClusters(seu_zheng_CD4T, resolution = 0.75)
[email protected][,"Subtype"] <- rep("memory")
[email protected]$Subtype[which([email protected] %in% c(0,1,3))] <- "activated"
[email protected]$Subtype[which([email protected] %in% c(5,7))] <- "naive"
##################
## 7-Donor PBMC ##
##################
## Step 1: Remove uninformative genes and cell BCs ----------------------------------------------------------------------------------------------------------------------------------------------------
rna.raw <- Read10X('.')
cell.counts <- Matrix::colSums(rna.raw)
rna.raw <- rna.raw[, which(cell.counts >= 250)]
gene.counts <- Matrix::rowSums(rna.raw)
rna.raw <- rna.raw[which(gene.counts > 3), ]
## Step 2: Pre-process Seurat object, remove high %Mito cells -----------------------------------------------------------------------------------------------------------------------------------------
seu_gh <- CreateSeuratObject(rna.raw)
seu_gh <- NormalizeData(seu_gh)
seu_gh <- ScaleData(seu_gh)
seu_gh <- FindVariableFeatures(seu_gh, selection.method = "vst", nfeatures = 2000)
seu_gh <- RunPCA(seu_gh)
seu_gh <- RunUMAP(seu_gh, dims=1:18)
seu_gh <- FindNeighbors(seu_gh, dims=1:18)
seu_gh <- FindClusters(seu_gh, resolution = 1.0)
mito.genes <- grep("^MT-", rownames(seu_gh@assays$RNA@counts), value = TRUE)
percent.mito <- Matrix::colSums(seu_gh@assays$RNA@counts[mito.genes, ]) / Matrix::colSums(seu_gh@assays$RNA@counts)
[email protected][,"PercentMito"] <- percent.mito
seu_gh <- SubsetData(seu_gh, cells=rownames([email protected])[which([email protected] %ni% c(4,8))])
seu_gh <- NormalizeData(seu_gh)
seu_gh <- ScaleData(seu_gh)
seu_gh <- FindVariableFeatures(seu_gh, selection.method = "vst", nfeatures = 2000)
seu_gh <- RunPCA(seu_gh)
seu_gh <- RunUMAP(seu_gh, dims=1:16)
seu_gh <- FindNeighbors(seu_gh, dims=1:16)
seu_gh <- FindClusters(seu_gh, resolution = 1.0)
seu_gh <- SubsetData(seu_gh, cells=rownames([email protected])[which([email protected] != 11)])
seu_gh <- NormalizeData(seu_gh)
seu_gh <- ScaleData(seu_gh)
seu_gh <- FindVariableFeatures(seu_gh, selection.method = "vst", nfeatures = 2000)
seu_gh <- RunPCA(seu_gh)
seu_gh <- RunUMAP(seu_gh, dims=1:13)
seu_gh <- FindNeighbors(seu_gh, dims=1:13)
seu_gh <- FindClusters(seu_gh, resolution = 0.5)
## Sample classification workflow continued in "SampleClassification.R"
## Step 3: Remove doublets defined by SCMK classifications --------------------------------------------------------------------------------------------------------------------------------------------
seu_gh <- SubsetData(seu_gh, cells=rownames([email protected])[which([email protected]$class != "Doublet")])
seu_gh <- NormalizeData(seu_gh)
seu_gh <- ScaleData(seu_gh)
seu_gh <- FindVariableFeatures(seu_gh, selection.method = "vst", nfeatures = 2000)
seu_gh <- RunPCA(seu_gh)
seu_gh <- RunUMAP(seu_gh, dims=1:17)
seu_gh <- FindNeighbors(seu_gh, dims=1:17)
seu_gh <- FindClusters(seu_gh, resolution = 0.5)
## Step 4: Annotate PBMC cell types -------------------------------------------------------------------------------------------------------------------------------------------------------------------
[email protected][,'CellType'] <- rep("unknown")
[email protected]$CellType[which([email protected] %in% 0:2)] <-"CD4T"
[email protected]$CellType[which([email protected] == 3)] <-"CD8T"
[email protected]$CellType[which([email protected] == 4)] <-"CMono"
[email protected]$CellType[which([email protected] == 5)] <-"B"
[email protected]$CellType[which([email protected] %in% c(6,7))] <-"NK"
[email protected]$CellType[which([email protected] == 8)] <-"NCMono"
[email protected]$CellType[which([email protected] == 9)] <-"DC"
[email protected]$CellType[which([email protected] == 11)] <-"Platelet"
[email protected]$CellType[which([email protected] == 12)] <-"MKI67+T"
## Step 5: Subset CD4+ T-cells, annotate subtypes -----------------------------------------------------------------------------------------------------------------------------------------------------
seu_gh_cd4t <- SubsetData(seu_gh, cells=rownames([email protected])[which([email protected] %in% 0:2)])
seu_gh_cd4t <- NormalizeData(seu_gh_cd4t)
seu_gh_cd4t <- ScaleData(seu_gh_cd4t)
seu_gh_cd4t <- FindVariableFeatures(seu_gh_cd4t, selection.method = "vst", nfeatures = 2000)
seu_gh_cd4t <- RunPCA(seu_gh_cd4t)
seu_gh_cd4t <- RunUMAP(seu_gh_cd4t, dims=1:15)
seu_gh_cd4t <- FindNeighbors(seu_gh_cd4t, dims=1:15)
seu_gh_cd4t <- FindClusters(seu_gh_cd4t, resolution = 0.5)
[email protected][,'subset'] <- rep("activated")
[email protected]$subset[which([email protected] == 1)] <- "memory"
[email protected]$subset[which([email protected] == 3)] <- "naive"
#########################
## BD PBMC +/- CD/CD28 ##
#########################
## Step 1: Load raw gene expression (long-format) -----------------------------------------------------------------------------------------------------------------------------------------------------
rna.BD.raw <- read.table("Combined_BD-Demo-WTA-AbSeq-SMK_Expression_Data.st", header=T, stringsAsFactors = F)
rna.BD.raw <- rna.BD.raw[,c(1,2,7)]
colnames(rna.BD.raw) <- c("Cell","Gene","Count")
cellIDs <- unique(rna.BD.raw$Cell)
geneIDs <- unique(rna.BD.raw$Gene)
## Step 2: Convert to sparse, wide matrix) ------------------------------------------------------------------------------------------------------------------------------------------------------------
library(Matrix)
raw.mat.BD <- matrix(0L, nrow=length(geneIDs), ncol=length(cellIDs))
raw.mat.BD <- Matrix(raw.mat.BD, sparse = TRUE)
rownames(raw.mat.BD) <- geneIDs; colnames(raw.mat.BD) <- cellIDs
x <- 0
for (i in cellIDs) {
ind <- which(rna.BD.raw$Cell == i)
x <- x + 1
print(paste(x, "out of 5665", sep=" "))
raw.mat.BD[rna.BD.raw$Gene[ind],x] <- rna.BD.raw$Count[ind]
rna.BD.raw <- rna.BD.raw[-ind, ]
}
## Step 3: Remove uninformative genes and CITE-seq Ab counts) -----------------------------------------------------------------------------------------------------------------------------------------
gene.counts <- Matrix::rowSums(raw.mat.BD)
raw.mat.BD <- raw.mat.BD[which(gene.counts > 3), ]
ind <- grep("pAb",rownames(raw.mat.BD))
raw.mat.BD <- raw.mat.BD[-ind, ]
seu_bd <- CreateSeuratObject(raw.mat.BD)
seu_bd <- NormalizeData(seu_bd)
seu_bd <- ScaleData(seu_bd)
seu_bd <- FindVariableFeatures(seu_bd, selection.method = "vst", nfeatures = 2000)
seu_bd <- RunPCA(seu_bd)
seu_bd <- RunUMAP(seu_bd, dims=1:17)
seu_bd <- FindNeighbors(seu_bd, dims=1:17)
seu_bd <- FindClusters(seu_bd, resolution = 0.25)
mito.genes <- grep("^MT-", rownames(seu_bd@assays$RNA@counts), value = TRUE)
percent.mito <- Matrix::colSums(seu_bd@assays$RNA@counts[mito.genes, ]) / Matrix::colSums(seu_bd@assays$RNA@counts)
[email protected][,"PercentMito"] <- percent.mito
## Step 4: Remove low-quality cells) ------------------------------------------------------------------------------------------------------------------------------------------------------------------
cells.to.remove <- rownames([email protected])[which([email protected] == 10)]
cells.to.remove <- c(cells.to.remove, rownames([email protected])[which([email protected]$PercentMito >= 0.25)])
ind <- which(rownames([email protected]) %in% cells.to.remove)
cells.to.keep <- rownames([email protected])[-ind]
seu_bd <- SubsetData(seu_bd, cells=cells.to.keep)
seu_bd <- NormalizeData(seu_bd)
seu_bd <- ScaleData(seu_bd)
seu_bd <- FindVariableFeatures(seu_bd, selection.method = "vst", nfeatures = 2000)
seu_bd <- RunPCA(seu_bd)
seu_bd <- RunUMAP(seu_bd, dims=1:17)
seu_bd <- FindNeighbors(seu_bd, dims=1:17)
seu_bd <- FindClusters(seu_bd, resolution = 0.25)
## Step 5: Read in BD SCMK classifications, remove doublets) ------------------------------------------------------------------------------------------------------------------------------------------
temp <- read.csv('BD-Demo-WTA-AbSeq-SMK_Sample_Tag_Calls.csv')
rownames(temp) <- temp[,1]
[email protected][,"class"] <- temp[rownames([email protected]), "Sample_Tag"]
seu_bd <- SubsetData(seu_bd, cells=rownames([email protected])[which([email protected]$class != "Multiplet")])
seu_bd <- NormalizeData(seu_bd)
seu_bd <- ScaleData(seu_bd)
seu_bd <- FindVariableFeatures(seu_bd, selection.method = "vst", nfeatures = 2000)
seu_bd <- RunPCA(seu_bd)
seu_bd <- RunUMAP(seu_bd, dims=1:17)
seu_bd <- FindNeighbors(seu_bd, dims=1:17)
seu_bd <- FindClusters(seu_bd, resolution = 1.0)
## Step 6: Annotate cells) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
[email protected][,'CellType'] <- rep("unknown")
[email protected]$CellType[which([email protected] == 0)] <-"CD4T_rest"
[email protected]$CellType[which([email protected] %in% c(1,2,9))] <-"CD4T_stim"
[email protected]$CellType[which([email protected] == 5)] <-"CD8T"
[email protected]$CellType[which([email protected] == 10)] <-"NK_rest"
[email protected]$CellType[which([email protected] %in% c(4,12))] <-"NK_stim"
[email protected]$CellType[which([email protected] %in% c(3,8,11,13))] <-"RBC"
[email protected]$CellType[which([email protected] == 6)] <-"Monocyte"
[email protected]$CellType[which([email protected] %in% c(15,17))] <-"Macrophage"
[email protected]$CellType[which([email protected] == 7)] <-"B"
[email protected]$CellType[which([email protected] == 14)] <-"Granulocyte"
[email protected]$CellType[which([email protected] == 16)] <-"Neutrophil"