-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifyCells_v2.R
72 lines (48 loc) · 2.01 KB
/
classifyCells_v2.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
library(Seurat)
library(monocle)
library(stringr)
library(argparse)
source("utils.R")
print("...configure parameters...")
parser <- ArgumentParser(description='Process some tasks')
parser$add_argument("--dataset",
type="character",
default=NULL,
help="The path of objects")
args<-parser$parse_args()
updateSeurat<-function(object,meta.data=NULL){
object<-AddMetaData(object,
metadata=meta.data)
return(object)
}
model<-paste0("pretrain","/",args$dataset,"/","model","/","object.rds")
print(paste0("Loading object from : ",args$dataset))
object<-readRDS(model)
print("Convert Seurat into Monocle")
monocle.object<-Seurat2Monocle(object)
print("Add Cell Type Message")
cth <- newCellTypeHierarchy()
cth <-addCellType(cth,cell_type_name="B Cells",
classify_func=function(x){ x["PTPRC",]>0 & x["CD19",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="T Cells",
classify_func=function(x){ x["PTPRC",] > 0 & x["CD3D",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="CD8+ T Cells",
classify_func=function(x){ x["CD8A",] > 0 },
parent_cell_type_name="T Cells")
cth <-addCellType(cth,cell_type_name="CD4+ T Cells",
classify_func=function(x){ x["CD4",] > 0 },
parent_cell_type_name="T Cells")
cth <-addCellType(cth,cell_type_name="Treg Cells",
classify_func=function(x){ x["FOXP3",] > 0},
parent_cell_type_name="CD4+ T Cells")
cth <-addCellType(cth,cell_type_name="Myeloid Cells",
classify_func=function(x){ x["PTPRC",] > 0 & x["CD19",]==0 & x["CD3D",]==0 & x["NCAM1",]==0 & x["ITGAM",] > 0 },
parent_cell_type_name="root")
monocle.object<-classifyCells(monocle.object,cth)
print("Update Seurat object")
new.meta.data<-pData(monocle.object)[,"CellType",drop=FALSE]
object<-updateSeurat(object,new.meta.data)
saveRDS(object,model)
print("Successfully Done")