+153
R/scImmuCC.R
+153
R/scImmuCC.R
···
1
+
#' @title scImmuCC_Layered.
2
+
#' @description Creating Hierarchical_annotation for scRNA-Seq data immune cell.
3
+
#' @details Input takes a cells-genes matrix with cell unique barcodes as column names and gene names as row names and returns the cells annotation.
4
+
#' @param count a matrix with cell unique barcodes as column names and gene names as row names .
5
+
#' @param Non_Immune Whether non-immune cells are included in the matrix.
6
+
#' @return Data frames with the barcodes and cell types, and some maps.
7
+
#' @import GSVA
8
+
#' @importFrom GSVA gsva
9
+
#' @import Matrix
10
+
#' @export
11
+
#' @examples test_data
12
+
#' library(GSVA)
13
+
#' library(Seurat)
14
+
15
+
scImmuCC_Layered <- function(count,Non_Immune=TRUE){
16
+
17
+
# if (!requireNamespace("GSVA", quietly = TRUE)) {
18
+
BiocManager::install("GSVA")
19
+
# }
20
+
# if (!requireNamespace("Seurat", quietly = TRUE)){
21
+
install.packages("Seurat")
22
+
# }
23
+
data("./data/layer1_genelist.rda",package="scImmuCC")
24
+
data("./data/Tcell_genelist.rda",package="scImmuCC")
25
+
data("./data/Bcell_genelist.rda",package="scImmuCC")
26
+
data("./data/DC_genelist.rda",package="scImmuCC")
27
+
data("./data/NK_genelist.rda",package="scImmuCC")
28
+
data("./data/Monocyte_genelist.rda",package="scImmuCC")
29
+
data("./data/Macrophage_genelist.rda",package="scImmuCC")
30
+
data("./data/ILC_genelist.rda",package="scImmuCC")
31
+
data("./data/CD4_genelist.rda",package="scImmuCC")
32
+
data("./data/CD8_genelist.rda",package="scImmuCC")
33
+
data("./data/layer0_genelist.rda",package="scImmuCC")
34
+
35
+
36
+
if(Non_Immune==TRUE){
37
+
38
+
layer0_result <- scImmuCC_main(count,layer0_genelist,"Layer0")
39
+
immune <- layer0_result[which(layer0_result[,2]=="Immune"),]
40
+
count_immune <- count[,immune[,1]]
41
+
ssGSEA_result <- scImmuCC_main(count_immune,layer1_genelist,"Layer1")
42
+
seurat_result <- seurat_Heatmap(count,layer1_genelist,ssGSEA_result,"Layer1")
43
+
44
+
}else{
45
+
46
+
ssGSEA_result <- scImmuCC_main(count,layer1_genelist,"Layer1")
47
+
seurat_result <- seurat_Heatmap(count,layer1_genelist,ssGSEA_result,"Layer1")
48
+
}
49
+
50
+
cell_type <- unique(ssGSEA_result[,2])
51
+
52
+
if("Tcell" %in% cell_type){
53
+
sub_ssGSEA_Tcell <- ssGSEA_result[which(ssGSEA_result[,2]=="Tcell"),]
54
+
sub_count_Tcell <- count[,sub_ssGSEA_Tcell[,1]]
55
+
sub_count_Tcell <- as.matrix(sub_count_Tcell)
56
+
ssGSEA_Tcell <- scImmuCC_main(sub_count_Tcell,Tcell_genelist,"Layer2_Tcell")
57
+
seurat_Tcell <- seurat_Heatmap(sub_count_Tcell,Tcell_genelist,ssGSEA_Tcell,"Layer2_Tcell")
58
+
59
+
cell_type2 <- unique(ssGSEA_Tcell[,2])
60
+
61
+
if("CD4_T" %in% cell_type){
62
+
sub_ssGSEA_CD4 <- ssGSEA_Tcell[which(ssGSEA_Tcell[,2]=="CD4_T"),]
63
+
sub_count_CD4 <- count[,sub_ssGSEA_CD4[,1]]
64
+
sub_count_CD4 <- as.matrix(sub_count_CD4)
65
+
ssGSEA_CD4 <- scImmuCC_main(sub_count_CD4,CD4_genelist,"Layer3_CD4")
66
+
cells <- length(sub_count_CD4[2,])
67
+
if(cells>50){
68
+
seurat_CD4 <- seurat_Heatmap(sub_count_CD4,CD4_genelist,ssGSEA_CD4,"Layer3_CD4")
69
+
}
70
+
71
+
}
72
+
73
+
74
+
if("CD8_T" %in% cell_type){
75
+
sub_ssGSEA_CD8 <- ssGSEA_Tcell[which(ssGSEA_Tcell[,2]=="CD8_T"),]
76
+
sub_count_CD8 <- count[,sub_ssGSEA_CD8[,1]]
77
+
sub_count_CD8 <- as.matrix(sub_count_CD8)
78
+
ssGSEA_CD8 <- scImmuCC_main(sub_count_CD8,CD8_genelist,"Layer3_CD4")
79
+
cells <- length(sub_count_CD8[2,])
80
+
if(cells>50){
81
+
seurat_CD8 <- seurat_Heatmap(sub_count_CD8,CD8_genelist,ssGSEA_CD8,"Layer3_CD8")
82
+
}
83
+
84
+
}
85
+
}
86
+
87
+
if("Bcell" %in% cell_type){
88
+
sub_ssGSEA_Bcell <- ssGSEA_result[which(ssGSEA_result[,2]=="Bcell"),]
89
+
sub_count_Bcell <- count[,sub_ssGSEA_Bcell[,1]]
90
+
sub_count_Bcell <- as.matrix(sub_count_Bcell)
91
+
ssGSEA_Bcell <- scImmuCC_main(sub_count_Bcell,Bcell_genelist,"Layer2_Bcell")
92
+
cells <- length(sub_count_Bcell[2,])
93
+
if(cells>50){
94
+
seurat_Bcell <- seurat_Heatmap(sub_count_Bcell,Bcell_genelist,ssGSEA_Bcell,"Layer2_Bcell")
95
+
}
96
+
}
97
+
98
+
if("DC" %in% cell_type){
99
+
sub_ssGSEA_DC <- ssGSEA_result[which(ssGSEA_result[,2]=="DC"),]
100
+
sub_count_DC <- count[,sub_ssGSEA_DC[,1]]
101
+
sub_count_DC <- as.matrix(sub_count_DC)
102
+
ssGSEA_DC <- scImmuCC_main(sub_count_DC,DC_genelist,"Layer2_DC")
103
+
cells <- length(sub_count_DC[2,])
104
+
if(cells>50){
105
+
seurat_DC <- seurat_Heatmap(sub_count_DC,DC_genelist,ssGSEA_DC,"Layer2_DC")
106
+
}
107
+
108
+
}
109
+
110
+
if("NK" %in% cell_type){
111
+
sub_ssGSEA_NK <- ssGSEA_result[which(ssGSEA_result[,2]=="NK"),]
112
+
sub_count_NK <- count[,sub_ssGSEA_NK[,1]]
113
+
sub_count_NK <- as.matrix(sub_count_NK)
114
+
ssGSEA_NK <- scImmuCC_main(sub_count_NK,NK_genelist,"Layer2_NK")
115
+
cells <- length(sub_count_NK[2,])
116
+
if(cells>50){
117
+
seurat_NK <- seurat_Heatmap(sub_count_NK,NK_genelist,ssGSEA_NK,"Layer2_NK")
118
+
}
119
+
}
120
+
121
+
if("Monocyte" %in% cell_type){
122
+
sub_ssGSEA_Mono <- ssGSEA_result[which(ssGSEA_result[,2]=="Monocyte"),]
123
+
sub_count_Mono <- count[,sub_ssGSEA_Mono[,1]]
124
+
sub_count_Mono <- as.matrix(sub_count_Mono)
125
+
ssGSEA_Mono <- scImmuCC_main(sub_count_Mono,Monocyte_genelist,"Layer2_Monocyte")
126
+
cells <- length(sub_count_Mono[2,])
127
+
if(cells>50){
128
+
seurat_Mono <- seurat_Heatmap(sub_count_Mono,Monocyte_genelist,ssGSEA_Mono,"Layer2_Monocyte")
129
+
}
130
+
}
131
+
132
+
if("Macrophage" %in% cell_type){
133
+
sub_ssGSEA_Mac <- ssGSEA_result[which(ssGSEA_result[,2]=="Macrophage"),]
134
+
sub_count_Mac <- count[,sub_ssGSEA_Mac[,1]]
135
+
sub_count_Mac <- as.matrix(sub_count_Mac)
136
+
ssGSEA_Mac <- scImmuCC_main(sub_count_Mac,Macrophage_genelist,"Layer2_Macrophage")
137
+
cells <- length(sub_count_Mac[2,])
138
+
if(cells>50){
139
+
seurat_Mac <- seurat_Heatmap(sub_count_Mac,Macrophage_genelist,ssGSEA_Mac,"Layer2_Macrophage")
140
+
}
141
+
}
142
+
143
+
if("ILC" %in% cell_type){
144
+
sub_ssGSEA_ILC <- ssGSEA_result[which(ssGSEA_result[,2]=="ILC"),]
145
+
sub_count_ILC <- count[,sub_ssGSEA_ILC[,1]]
146
+
sub_count_ILC <- as.matrix(sub_count_ILC)
147
+
ssGSEA_ILC <- scImmuCC_main(sub_count_ILC,ILC_genelist,"Layer2_ILC")
148
+
cells <- length(sub_count_ILC[2,])
149
+
if(cells>50){
150
+
seurat_ILC <- seurat_Heatmap(sub_count_ILC,ILC_genelist,ssGSEA_ILC,"Layer2_ILC")
151
+
}
152
+
}
153
+
}