-
Notifications
You must be signed in to change notification settings - Fork 0
/
classifyCells_v1.R
112 lines (74 loc) · 3.57 KB
/
classifyCells_v1.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
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)
}
print(paste0("Loading object from : ",args$dataset))
object<-readRDS(args$dataset)
print("Convert Seurat into Monocle")
monocle.object<-Seurat2Monocle(object)
print("Add Cell Type Message")
cth <- newCellTypeHierarchy()
cth <-addCellType(cth,cell_type_name="T Cells",
classify_func=function(x){ x["CCR6",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="B Cells",
classify_func=function(x){ x["CD28",] > 0 & x["CD38",] > 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 & x["CD38",] > 0 },
parent_cell_type_name="T Cells")
cth <-addCellType(cth,cell_type_name="TCR alpha-gama T Cells",
classify_func=function(x){ x["CXCR5",] > 0 & x["HLA-DRA",] > 0 },
parent_cell_type_name="T Cells")
cth <-addCellType(cth,cell_type_name="CD8+ Memory T Cells",
classify_func=function(x){ x["HLA-DRA",] > 0 },
parent_cell_type_name="CD8+ T Cells")
cth <-addCellType(cth,cell_type_name="CD4+ Effector Memory T Cells",
classify_func=function(x){ x["HLA-DRA",] > 0 & x["CCR6",] > 0 },
parent_cell_type_name="CD4+ T Cells")
cth <-addCellType(cth,cell_type_name="CD4+ Navie/Effector T Cells",
classify_func=function(x){ x["ICOS",] > 0 },
parent_cell_type_name="CD4+ T Cells")
cth <-addCellType(cth,cell_type_name="CD4+ Treg-type Cells",
classify_func=function(x){ x["CCR6",] > 0 },
parent_cell_type_name="CD4+ T Cells")
cth <-addCellType(cth,cell_type_name="CD8+ Tc17-type Cells",
classify_func=function(x){ x["CXCR3",] > 0 },
parent_cell_type_name="CD8+ T Cells")
cth <-addCellType(cth,cell_type_name="NKT Cells",
classify_func=function(x){ x["CXCR3",] > 0 & x["CCR6",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="Plasmablasts",
classify_func=function(x){ x["CCR6",] > 0 & x["CD28",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="Basophils",
classify_func=function(x){ x["CCR7",] > 0 & x["LILRB1",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="CXCR3+ Cells",
classify_func=function(x){ x["CXCR3",] > 0 },
parent_cell_type_name="root")
cth <-addCellType(cth,cell_type_name="CXCR3+ Dendritic Cells",
classify_func=function(x){ x["CXCR5",] > 0 & x["CD38",] > 0 },
parent_cell_type_name="CXCR3+ Cells")
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,file=args$dataset)
print("Successfully Done")