-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdetect_doublets.R
executable file
·57 lines (38 loc) · 1.83 KB
/
detect_doublets.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
### Doublet Finder on PBMC chord data
#### Ravneet Kaur
#### 05/10/2021
library(Seurat)
library(DoubletFinder)
load("pbmc_obj_list.rda")
for(i in 1:length(pbmc_obj_list)){
# sample name
pbmc.list <- pbmc_obj_list[i]
filename <- names(pbmc.list)
print(filename)
pbmc.seurat <- pbmc.list[[1]]
doublet.seurat <- pbmc.list[[1]]
## Pre-process Seurat object (standard)
doublet.seurat <- NormalizeData(doublet.seurat)
doublet.seurat <- ScaleData(doublet.seurat)
doublet.seurat<- SCTransform(doublet.seurat, assay = 'RNA', new.assay.name = 'SCT',variable.features.n = 3000)
doublet.seurat <- RunPCA(doublet.seurat)
## pK Identification
sweep.res.doublet <- paramSweep_v3(doublet.seurat, PCs = 1:30, sct =TRUE)
sweep.stats.doublet <- summarizeSweep(sweep.res.doublet, GT = FALSE)
bcmvn.doublet <- find.pK(sweep.stats.doublet)
pK <- bcmvn.doublet$pK[which.max(bcmvn.doublet$BCmetric)]
pK <- as.numeric(levels(pK))[pK]
EDFR=0.075
homotypic.prop <- modelHomotypic([email protected]$predicted.celltype.l2)
nExp_poi <- round(EDFR*nrow([email protected]))
nExp_poi.adj <- round(nExp_poi*(1-homotypic.prop))
doublet.seurat <- doubletFinder_v3(doublet.seurat, PCs = 1:30, pN = 0.25, pK = pK, nExp = nExp_poi.adj,
reuse.pANN = FALSE, sct = TRUE)
class <- paste('DF.classifications', 0.25, pK, nExp_poi, sep = '_')
[email protected][['DoubletClass']] <- [email protected][[class]]
## Put doublet annotations into "original.seurat"
[email protected][['DoubletClass']] <- [email protected][['DoubletClass']]
## REMOVE DOUBLETS in original.seurat, I didn't do this because I wanted to visualize the doublets in a UMAP.
pbmc_obj_list[[i]] <- original.seurat
}
save(pbmc_obj_list,file="pbmc_obj_list_rm_doublet.rda")