Hierarchical annotation of immune cells in scRNA-Seq data based on ssGSEA algorithm. Fork for large datasets with QOL improvements.
at main 1.3 kB view raw
1#' @title scImmuCC_main 2#' @description Calculation of gene enrichment scores and annotate cell type 3#' @details Input takes a count, genelist and filename, returns a data frame 4#' with cell annotation 5#' @param count Matrix with cell unique barcodes as column names and gene 6#' names as row names 7#' @param genematrix Data frame with cell types as column names 8#' @param ssGSEA_result Data frame, scImmuCC return result 9#' @param filename Custom file name, char 10#' @return Data frame with cell annotation 11#' @import GSVA 12#' @importFrom GSVA gsva 13 14scImmuCC_main <- function(count, genematrix, filename) { 15 genelist <- as.list(genematrix) 16 genelist <- lapply(genelist, function(x) x[!is.na(x)]) 17 18 ssgsea <- ssgseaParam( 19 count, 20 genelist 21 ) 22 23 ssgsea_score <- gsva(ssgsea) 24 score <- t(ssgsea_score) 25 26 barcodes <- c() 27 celltype <- c() 28 for (i in 1:length(score[, 1])) { 29 a1 <- score[i, ] 30 b1 <- as.data.frame(a1) 31 b1$celltype <- rownames(b1) 32 f <- b1[which(b1[, 1] == max(b1[, 1])), ] 33 barcodes <- c(barcodes, rownames(score)[i]) 34 celltype <- c(celltype, rownames(f)) 35 } 36 37 ssGSEA_result <- data.frame(barcodes = barcodes, cell_type = celltype) 38 head(ssGSEA_result) 39 write.csv(ssGSEA_result, paste(filename, "_scImmuCC_label.csv", sep = "")) 40}