Hierarchical annotation of immune cells in scRNA-Seq data based on ssGSEA algorithm. Fork for large datasets with QOL improvements.

Delete sc-ImmuCC.R

Changed files
-129
R
-129
R/sc-ImmuCC.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 - 13 - scImmuCC_Layered <- function(count,Non_Immune=TRUE){ 14 - 15 - # load("./data/layer1_genelist.rda") 16 - # load("./data/Tcell_genelist.rda") 17 - # load("./data/Bcell_genelist.rda") 18 - # load("./data/DC_genelist.rda") 19 - # load("./data/NK_genelist.rda") 20 - # load("./data/Monocyte_genelist.rda") 21 - # load("./data/Macrophage_genelist.rda") 22 - # load("./data/ILC_genelist.rda") 23 - # load("./data/CD4_genelist.rda") 24 - # load("./data/CD8_genelist.rda") 25 - # load("./data/layer0_genelist.rda") 26 - data("./data/layer1_genelist.rda",package="scImmuCC") 27 - data("./data/Tcell_genelist.rda",package="scImmuCC") 28 - data("./data/Bcell_genelist.rda",package="scImmuCC") 29 - data("./data/DC_genelist.rda",package="scImmuCC") 30 - data("./data/NK_genelist.rda",package="scImmuCC") 31 - data("./data/Monocyte_genelist.rda",package="scImmuCC") 32 - data("./data/Macrophage_genelist.rda",package="scImmuCC") 33 - data("./data/ILC_genelist.rda",package="scImmuCC") 34 - data("./data/CD4_genelist.rda",package="scImmuCC") 35 - data("./data/CD8_genelist.rda",package="scImmuCC") 36 - data("./data/layer0_genelist.rda",package="scImmuCC") 37 - 38 - 39 - if(Non_Immune==TRUE){ 40 - 41 - layer0_result <- scImmuCC_main(count,layer0_genelist,"Layer0") 42 - immune <- layer0_result[which(layer0_result[,2]=="Immune"),] 43 - count_immune <- count[,immune[,1]] 44 - ssGSEA_result <- scImmuCC_main(count_immune,layer1_genelist,"Layer1") 45 - seurat_result <- seurat_Heatmap(count,layer1_genelist,ssGSEA_result,"Layer1") 46 - 47 - }else{ 48 - 49 - ssGSEA_result <- scImmuCC_main(count,layer1_genelist,"Layer1") 50 - seurat_result <- seurat_Heatmap(count,layer1_genelist,ssGSEA_result,"Layer1") 51 - } 52 - 53 - cell_type <- unique(ssGSEA_result[,2]) 54 - 55 - if("Tcell" %in% cell_type){ 56 - sub_ssGSEA_Tcell <- ssGSEA_result[which(ssGSEA_result[,2]=="Tcell"),] 57 - sub_count_Tcell <- count[,sub_ssGSEA_Tcell[,1]] 58 - sub_count_Tcell <- as.matrix(sub_count_Tcell) 59 - ssGSEA_Tcell <- scImmuCC_main(sub_count_Tcell,Tcell_genelist,"Layer2_Tcell") 60 - seurat_Tcell <- seurat_Heatmap(sub_count_Tcell,Tcell_genelist,ssGSEA_Tcell,"Layer2_Tcell") 61 - 62 - cell_type2 <- unique(ssGSEA_Tcell[,2]) 63 - 64 - if("CD4_T" %in% cell_type){ 65 - sub_ssGSEA_CD4 <- ssGSEA_Tcell[which(ssGSEA_Tcell[,2]=="CD4_T"),] 66 - sub_count_CD4 <- count[,sub_ssGSEA_CD4[,1]] 67 - sub_count_CD4 <- as.matrix(sub_count_CD4) 68 - ssGSEA_CD4 <- scImmuCC_main(sub_count_CD4,CD4_genelist,"Layer3_CD4") 69 - seurat_CD4 <- seurat_Heatmap(sub_count_CD4,CD4_genelist,ssGSEA_CD4,"Layer3_CD4") 70 - } 71 - 72 - 73 - if("CD8_T" %in% cell_type){ 74 - sub_ssGSEA_CD8 <- ssGSEA_Tcell[which(ssGSEA_Tcell[,2]=="CD8_T"),] 75 - sub_count_CD8 <- count[,sub_ssGSEA_CD8[,1]] 76 - sub_count_CD8 <- as.matrix(sub_count_CD8) 77 - ssGSEA_CD8 <- scImmuCC_main(sub_count_CD8,CD8_genelist,"Layer3_CD4") 78 - seurat_CD8 <- seurat_Heatmap(sub_count_CD8,CD8_genelist,ssGSEA_CD8,"Layer3_CD8") 79 - } 80 - } 81 - 82 - if("Bcell" %in% cell_type){ 83 - sub_ssGSEA_Bcell <- ssGSEA_result[which(ssGSEA_result[,2]=="Bcell"),] 84 - sub_count_Bcell <- count[,sub_ssGSEA_Bcell[,1]] 85 - sub_count_Bcell <- as.matrix(sub_count_Bcell) 86 - ssGSEA_Bcell <- scImmuCC_main(sub_count_Bcell,Bcell_genelist,"Layer2_Bcell") 87 - seurat_Bcell <- seurat_Heatmap(sub_count_Bcell,Bcell_genelist,ssGSEA_Bcell,"Layer2_Bcell") 88 - } 89 - 90 - if("DC" %in% cell_type){ 91 - sub_ssGSEA_DC <- ssGSEA_result[which(ssGSEA_result[,2]=="DC"),] 92 - sub_count_DC <- count[,sub_ssGSEA_DC[,1]] 93 - sub_count_DC <- as.matrix(sub_count_DC) 94 - ssGSEA_DC <- scImmuCC_main(sub_count_DC,DC_genelist,"Layer2_DC") 95 - seurat_DC <- seurat_Heatmap(sub_count_DC,DC_genelist,ssGSEA_DC,"Layer2_DC") 96 - } 97 - 98 - if("NK" %in% cell_type){ 99 - sub_ssGSEA_NK <- ssGSEA_result[which(ssGSEA_result[,2]=="NK"),] 100 - sub_count_NK <- count[,sub_ssGSEA_NK[,1]] 101 - sub_count_NK <- as.matrix(sub_count_NK) 102 - ssGSEA_NK <- scImmuCC_main(sub_count_NK,NK_genelist,"Layer2_NK") 103 - seurat_NK <- seurat_Heatmap(sub_count_NK,NK_genelist,ssGSEA_NK,"Layer2_NK") 104 - } 105 - 106 - if("Monocyte" %in% cell_type){ 107 - sub_ssGSEA_Mono <- ssGSEA_result[which(ssGSEA_result[,2]=="Monocyte"),] 108 - sub_count_Mono <- count[,sub_ssGSEA_Mono[,1]] 109 - sub_count_Mono <- as.matrix(sub_count_Mono) 110 - ssGSEA_Mono <- scImmuCC_main(sub_count_Mono,Monocyte_genelist,"Layer2_Monocyte") 111 - seurat_Mono <- seurat_Heatmap(sub_count_Mono,Monocyte_genelist,ssGSEA_Mono,"Layer2_Monocyte") 112 - } 113 - 114 - if("Macrophage" %in% cell_type){ 115 - sub_ssGSEA_Mac <- ssGSEA_result[which(ssGSEA_result[,2]=="Macrophage"),] 116 - sub_count_Mac <- count[,sub_ssGSEA_Mac[,1]] 117 - sub_count_Mac <- as.matrix(sub_count_Mac) 118 - ssGSEA_Mac <- scImmuCC_main(sub_count_Mac,Macrophage_genelist,"Layer2_Macrophage") 119 - seurat_Mac <- seurat_Heatmap(sub_count_Mac,Macrophage_genelist,ssGSEA_Mac,"Layer2_Macrophage") 120 - } 121 - 122 - if("ILC" %in% cell_type){ 123 - sub_ssGSEA_ILC <- ssGSEA_result[which(ssGSEA_result[,2]=="ILC"),] 124 - sub_count_ILC <- count[,sub_ssGSEA_ILC[,1]] 125 - sub_count_ILC <- as.matrix(sub_count_ILC) 126 - ssGSEA_ILC <- scImmuCC_main(sub_count_ILC,ILC_genelist,"Layer2_ILC") 127 - seurat_ILC <- seurat_Heatmap(sub_count_ILC,ILC_genelist,ssGSEA_ILC,"Layer2_ILC") 128 - } 129 - }