├── .Rbuildignore ├── .gitignore ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── R ├── irGSEA.barplot.R ├── irGSEA.bubble.R ├── irGSEA.density.scatterplot.R ├── irGSEA.densityheatmap.R ├── irGSEA.halfvlnplot.R ├── irGSEA.heatmap.R ├── irGSEA.hub.R ├── irGSEA.integrate.R ├── irGSEA.merge.R ├── irGSEA.ridgeplot.R ├── irGSEA.score.R ├── irGSEA.subset.R ├── irGSEA.upset.R ├── irGSEA.vlnplot.R ├── utils-pipe.R └── utils-tidy-eval.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── docs ├── 404.html ├── LICENSE-text.html ├── LICENSE.html ├── authors.html ├── bootstrap-toc.css ├── bootstrap-toc.js ├── docsearch.css ├── docsearch.js ├── index.html ├── link.svg ├── pkgdown.css ├── pkgdown.js ├── pkgdown.yml └── reference │ ├── Rplot001.png │ ├── figures │ ├── README-unnamed-chunk-10-1.png │ ├── README-unnamed-chunk-11-1.png │ ├── README-unnamed-chunk-12-1.png │ ├── README-unnamed-chunk-13-1.png │ ├── README-unnamed-chunk-14-1.png │ ├── README-unnamed-chunk-3-1.png │ ├── README-unnamed-chunk-6-1.png │ ├── README-unnamed-chunk-7-1.png │ ├── README-unnamed-chunk-8-1.png │ └── README-unnamed-chunk-9-1.png │ ├── index.html │ ├── irGSEA.barplot.html │ ├── irGSEA.bubble.html │ ├── irGSEA.density.scatterplot.html │ ├── irGSEA.densityheatmap.html │ ├── irGSEA.halfvlnplot.html │ ├── irGSEA.heatmap.html │ ├── irGSEA.integrate.html │ ├── irGSEA.ridgeplot.html │ ├── irGSEA.score.html │ ├── irGSEA.upset.html │ └── pipe.html ├── inst └── python │ ├── gsva.py │ ├── ssgsea.py │ └── viper.py ├── irGSEA.Rproj └── man ├── figures ├── Abstrast.jpg ├── README-unnamed-chunk-10-1.png ├── README-unnamed-chunk-11-1.png ├── README-unnamed-chunk-12-1.png ├── README-unnamed-chunk-13-1.png ├── README-unnamed-chunk-14-1.png ├── README-unnamed-chunk-15-1.png ├── README-unnamed-chunk-16-1.png ├── README-unnamed-chunk-17-1.png ├── README-unnamed-chunk-18-1.png ├── README-unnamed-chunk-19-1.png ├── README-unnamed-chunk-19-2.png ├── README-unnamed-chunk-20-1.png ├── README-unnamed-chunk-20-2.png ├── README-unnamed-chunk-3-1.png ├── README-unnamed-chunk-5-1.png ├── README-unnamed-chunk-6-1.png ├── README-unnamed-chunk-7-1.png ├── README-unnamed-chunk-8-1.png ├── README-unnamed-chunk-9-1.png ├── figure3.png └── figure4.png ├── irGSEA.barplot.Rd ├── irGSEA.bubble.Rd ├── irGSEA.density.scatterplot.Rd ├── irGSEA.densityheatmap.Rd ├── irGSEA.halfvlnplot.Rd ├── irGSEA.heatmap.Rd ├── irGSEA.hub.Rd ├── irGSEA.integrate.Rd ├── irGSEA.merge.Rd ├── irGSEA.ridgeplot.Rd ├── irGSEA.score.Rd ├── irGSEA.subset.Rd ├── irGSEA.upset.Rd ├── irGSEA.vlnplot.Rd ├── pipe.Rd └── tidyeval.Rd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^.*\.Rproj$ 2 | ^\.Rproj\.user$ 3 | ^LICENSE\.md$ 4 | ^README\.Rmd$ 5 | ^_pkgdown\.yml$ 6 | ^docs$ 7 | ^pkgdown$ 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # docs 2 | .Rproj.user 3 | .Rhistory 4 | .Rdata 5 | .httr-oauth 6 | .DS_Store 7 | # docs 8 | docs 9 | -------------------------------------------------------------------------------- /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: irGSEA 2 | Type: Package 3 | Title: The integration of single cell rank-based gene set enrichment analysis 4 | Version: 3.3.2 5 | Author: Chuiqin Fan 6 | Author@R: person("Chuiqin", "Fan", role = c('aut', 'cre'), email = '19cqfan@alumni.stu.edu.cn') 7 | Maintainer: Chuiqin Fan <19cqfan@stu.edu.cn> 8 | Description: The integration of single cell rank-based gene set enrichment analysis. 9 | Meanwhile, you are easy to visualize the results. 10 | License: MIT + file LICENSE 11 | Encoding: UTF-8 12 | LazyData: true 13 | RoxygenNote: 7.2.3 14 | Imports: 15 | AUCell, 16 | ComplexHeatmap, 17 | decoupleR, 18 | dplyr, 19 | gghalves, 20 | ggplotify, 21 | ggridges, 22 | ggsci, 23 | ggtree, 24 | GSVA, 25 | magrittr, 26 | msigdbr, 27 | Nebulosa, 28 | rlang (>= 0.4.11), 29 | RobustRankAggreg, 30 | Seurat, 31 | singscore, 32 | stringr, 33 | plyr, 34 | UCell 35 | URL: https://github.com/chuiqin/irGSEA 36 | BugReports: https://github.com/chuiqin/irGSEA/issues 37 | Suggests: 38 | aplot, 39 | BiocManager, 40 | BiocParallel, 41 | circlize, 42 | cowplot, 43 | devtools, 44 | data.table, 45 | doParallel, 46 | doRNG, 47 | fgsea, 48 | gficf, 49 | ggplot2, 50 | grDevices, 51 | ggfun, 52 | GSEABase, 53 | irlba, 54 | Matrix, 55 | methods, 56 | pagoda2, 57 | pointr, 58 | purrr, 59 | RcppML, 60 | readr, 61 | reshape2, 62 | reticulate, 63 | roxygen2, 64 | RMTstat, 65 | scde, 66 | SeuratDisk, 67 | SeuratObject, 68 | SummarizedExperiment, 69 | tidytree, 70 | tidyr, 71 | tibble, 72 | tidyselect, 73 | VAM, 74 | VISION, 75 | viper, 76 | sargent, 77 | sparseMatrixStats 78 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2021 2 | COPYRIGHT HOLDER: Chuiqin Fan 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2021 Chuiqin Fan 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | # Generated by roxygen2: do not edit by hand 2 | 3 | export("%>%") 4 | export(":=") 5 | export(.data) 6 | export(as_label) 7 | export(as_name) 8 | export(enquo) 9 | export(enquos) 10 | export(irGSEA.barplot) 11 | export(irGSEA.bubble) 12 | export(irGSEA.density.scatterplot) 13 | export(irGSEA.densityheatmap) 14 | export(irGSEA.halfvlnplot) 15 | export(irGSEA.heatmap) 16 | export(irGSEA.hub) 17 | export(irGSEA.integrate) 18 | export(irGSEA.merge) 19 | export(irGSEA.ridgeplot) 20 | export(irGSEA.score) 21 | export(irGSEA.subset) 22 | export(irGSEA.upset) 23 | export(irGSEA.vlnplot) 24 | importFrom(magrittr,"%>%") 25 | importFrom(rlang,":=") 26 | importFrom(rlang,.data) 27 | importFrom(rlang,as_label) 28 | importFrom(rlang,as_name) 29 | importFrom(rlang,enquo) 30 | importFrom(rlang,enquos) 31 | -------------------------------------------------------------------------------- /R/irGSEA.barplot.R: -------------------------------------------------------------------------------- 1 | 2 | #' Stacked bar plot 3 | #' 4 | #' Easy to show analysis results by stacked bar plot 5 | #' 6 | #' @param object A list after perform \code{\link{irGSEA.integrate}} 7 | #' @param method A vector. It should be one or more of the followling : AUCell, 8 | #' UCell, singscore, ssgsea or RRA. Default all methods when it is set to NULL. 9 | #' @param significance.color A vector. Default "c("#D0DFE6FF","#f87669")" when 10 | #' it is set to NULL. 11 | #' @param color.cluster A vector. Default "ggsci::pal_igv()(the number of colnames 12 | #' of enrichment score matrix)" when it is set to NULL. 13 | #' @param color.method A vector. Default "ggsci::pal_igv()(the number of methods 14 | #' )" when it is set to NULL. 15 | #' @param cluster.levels A vector equal to the number of clusters. 16 | #' 17 | #' 18 | #' @return stacked bar plot 19 | #' @export 20 | #' 21 | #' @examples 22 | #' \dontrun{ 23 | #' # load PBMC dataset by R package SeuratData 24 | #' library(Seurat) 25 | #' library(SeuratData) 26 | #' # download 3k PBMCs from 10X Genomics 27 | #' InstallData("pbmc3k") 28 | #' data("pbmc3k.final") 29 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 30 | #' 31 | #' # Seurat object 32 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 33 | #' slot = "data", msigdb = T, species = "Homo sapiens", 34 | #' category = "H", geneid = "symbol", 35 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 36 | #' 37 | #' # Integrated analysis 38 | #' result.dge <- irGSEA.integrate(object = pbmc3k.final, 39 | #' group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 40 | #' method = c("AUCell","UCell","singscore","ssgsea")) 41 | #' 42 | #' irGSEA.barplot.plot1 <- irGSEA.barplot(object = result.dge) 43 | #' 44 | #' } 45 | #' 46 | irGSEA.barplot <- function(object = NULL, method = NULL, 47 | significance.color = NULL, 48 | color.cluster = NULL, color.method = NULL, 49 | cluster.levels = NULL){ 50 | # pretreatment 51 | if (! purrr::is_list(object)) { 52 | stop("object should be a list.") 53 | } 54 | if (! all(method %in% names(object))) { 55 | stop("`method` should be one or more of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2, RRA.") 56 | } 57 | cluster <- NULL 58 | direction <- NULL 59 | pvalue <- NULL 60 | cell <- NULL 61 | Name <- NULL 62 | geneset <- NULL 63 | proportion <- NULL 64 | anno.cluster <- NULL 65 | anno.method <- NULL 66 | 67 | if (purrr::is_null(method)){ method <- names(object) } 68 | 69 | for (i in method) { 70 | if (i != "RRA"){ 71 | object[i] <- object[i] %>% purrr::map( ~.x %>% dplyr::rename(pvalue = p_val_adj)) 72 | } 73 | } 74 | 75 | 76 | # matrix 77 | sig.genesets.barplot <- list() 78 | for (i in seq_along(names(object[method]))) { 79 | sig.genesets.barplot[[i]] <- object[method][[names(object[method])[i]]] %>% 80 | dplyr::mutate(cell = stringr::str_c(cluster, direction, sep = "_")) %>% 81 | dplyr::select(c("Name", "pvalue", "cell")) %>% 82 | dplyr::mutate(pvalue = dplyr::if_else(pvalue < 0.05, "significant","no significant")) %>% 83 | tidyr::spread(cell, pvalue, fill = "no significant") %>% 84 | tidyr::gather(cell, pvalue, -Name) %>% 85 | dplyr::mutate(direction = stringr::str_extract(cell, pattern = "up|down"), 86 | cluster = stringr::str_remove(cell, pattern = "_up|_down"), 87 | method = names(object[method])[i]) %>% 88 | dplyr::mutate(geneset = dplyr::if_else(pvalue == "no significant", "no significant", direction)) 89 | } 90 | 91 | sig.genesets.barplot <- do.call(rbind, sig.genesets.barplot) %>% 92 | dplyr::group_by(cluster, method, geneset) %>% 93 | dplyr::summarise(proportion = dplyr::n()) %>% 94 | dplyr::mutate(cell = paste0(cluster, "_", method), 95 | method = factor(method, levels = names(object))) %>% 96 | dplyr::arrange(cluster, method) %>% 97 | dplyr::mutate(cell = factor(cell, levels = unique(cell))) %>% 98 | dplyr::filter(method %in% tidyselect::all_of(method)) 99 | 100 | # set levels of cluster 101 | if (! purrr::is_null(cluster.levels)) { 102 | sig.genesets.barplot <- sig.genesets.barplot %>% 103 | dplyr::mutate(cluster = factor(cluster, levels = cluster.levels)) %>% 104 | dplyr::arrange(cluster) %>% 105 | dplyr::mutate(cell = factor(cell, levels = unique(cell))) 106 | } 107 | 108 | # set color 109 | if (purrr::is_null(significance.color)) { 110 | significance.color <- c("#4575B4","#D0DFE6FF","#D73027") 111 | } 112 | # middle plot 113 | barplot.middle <- ggplot2::ggplot(sig.genesets.barplot , ggplot2::aes(cell, proportion, fill = geneset))+ 114 | ggplot2::geom_bar(stat = "identity", position = "fill")+ 115 | ggplot2::theme_bw()+ 116 | ggplot2::guides(fill = ggplot2::guide_legend(title = "Significance"))+ 117 | ggplot2::scale_fill_manual(values = significance.color)+ 118 | ggplot2::theme(panel.grid = ggplot2::element_blank(), 119 | axis.ticks.x = ggplot2::element_blank(), 120 | axis.text.x = ggplot2::element_blank(), 121 | axis.title.x = ggplot2::element_blank())+ 122 | ggplot2::ylab("Proportion") + 123 | ggplot2::scale_y_continuous(expand = c(0,0)) 124 | # set color 125 | significance.down.up.color <- c(significance.color[1],significance.color[3]) 126 | 127 | # above color 128 | barplot.above <- sig.genesets.barplot %>% 129 | dplyr::filter(geneset != "no significant") %>% 130 | ggplot2::ggplot(ggplot2::aes(cell, proportion, fill = geneset)) + 131 | ggplot2::geom_bar(stat = "identity", colour = "white") + 132 | ggplot2::theme_classic() + 133 | ggplot2::theme(panel.grid = ggplot2::element_blank(), 134 | axis.ticks.x = ggplot2::element_blank(), 135 | axis.text.x = ggplot2::element_blank(), 136 | axis.title.x = ggplot2::element_blank(), 137 | legend.position = "none") + 138 | ggplot2::ylab("Count") + 139 | ggplot2::scale_fill_manual(values = significance.down.up.color) + 140 | ggplot2::geom_text(ggplot2::aes(label = proportion), color = "white", 141 | position = ggplot2::position_stack(vjust = 0.5), size = 3) 142 | # set color 143 | if (purrr::is_null(color.cluster)) { 144 | color.cluster <- ggsci::pal_igv()(length(unique(sig.genesets.barplot$cluster))) 145 | } 146 | # below picture 147 | labels.cluster <- sig.genesets.barplot %>% 148 | dplyr::mutate(anno.cluster = "Cluster") %>% 149 | ggplot2::ggplot(ggplot2::aes(cell, y = anno.cluster, fill = cluster)) + 150 | ggplot2::geom_tile() + 151 | ggplot2::scale_fill_manual(values = color.cluster, name = "Cluster") + 152 | ggplot2::scale_y_discrete(position = "right") + 153 | ggplot2::theme_minimal() + 154 | ggplot2::theme(axis.text.x = ggplot2::element_blank(), 155 | axis.ticks.x = ggplot2::element_blank(), 156 | panel.grid = ggplot2::element_blank()) + 157 | ggplot2::labs(x = NULL, y = NULL) 158 | # set color 159 | if (purrr::is_null(color.method)) { 160 | color.method <- ggsci::pal_igv()(length(unique(sig.genesets.barplot$method))) 161 | } 162 | # below picture 163 | labels.method <- sig.genesets.barplot %>% 164 | dplyr::mutate(anno.method = "Method") %>% 165 | ggplot2::ggplot(ggplot2::aes(cell, y = anno.method, fill = method)) + 166 | ggplot2::geom_tile() + 167 | ggplot2::scale_fill_manual(values = color.method, name = "Method") + 168 | ggplot2::scale_y_discrete(position = "right") + 169 | ggplot2::theme_minimal() + 170 | ggplot2::theme(axis.text.x = ggplot2::element_blank(), 171 | axis.ticks.x = ggplot2::element_blank(), 172 | panel.grid = ggplot2::element_blank()) + 173 | ggplot2::labs(x = NULL, y = NULL) 174 | # combine all plots 175 | sig.genesets.bar.plot <- barplot.middle %>% 176 | aplot::insert_top(barplot.above, height = 1) %>% 177 | aplot::insert_bottom(labels.method, height = .1) %>% 178 | aplot::insert_bottom(labels.cluster, height = .1) 179 | sig.genesets.bar.plot <- ggplotify::as.ggplot(sig.genesets.bar.plot) 180 | return(sig.genesets.bar.plot) 181 | 182 | } 183 | 184 | 185 | 186 | -------------------------------------------------------------------------------- /R/irGSEA.bubble.R: -------------------------------------------------------------------------------- 1 | #' Bubble plot 2 | #' 3 | #' Easy to show analysis results by bubble plot 4 | #' 5 | #' @param object A list after perform \code{\link{irGSEA.integrate}} 6 | #' @param method A character. It should be one of the followling : AUCell, UCell, 7 | #' singscore, ssgsea or RRA. Default RRA. 8 | #' @param top The top gene sets. Default 50. 9 | #' @param show.geneset A vector including special gene sets. Default NULL. 10 | #' @param cluster.color A vector. Default "ggsci::pal_igv()(the number of colnames 11 | #' of enrichment score matrix)" when it is set to NULL. 12 | #' @param direction.color A vector. Default "c("#4575B4","#D73027")" when it 13 | #' is set to NULL. 14 | #' @param significance.color A vector. Default "c("#D0DFE6FF","#f87669")" when 15 | #' it is set to NULL. 16 | #' @param cluster_rows Whether to make cluster on rows. Defaul True. 17 | #' @param cluster.levels A vector equal to the number of clusters. 18 | #' 19 | #' @return bubble plot 20 | #' @export 21 | #' 22 | #' @examples 23 | #' \dontrun{ 24 | #' # load PBMC dataset by R package SeuratData 25 | #' library(Seurat) 26 | #' library(SeuratData) 27 | #' # download 3k PBMCs from 10X Genomics 28 | #' InstallData("pbmc3k") 29 | #' data("pbmc3k.final") 30 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 31 | #' 32 | #' # Seurat object 33 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 34 | #' slot = "data", msigdb = T, species = "Homo sapiens", 35 | #' category = "H", geneid = "symbol", 36 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 37 | #' 38 | #' # Integrated analysis 39 | #' result.dge <- irGSEA.integrate(object = pbmc3k.final, 40 | #' group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 41 | #' method = c("AUCell","UCell","singscore","ssgsea")) 42 | #' 43 | #' irGSEA.bubble.plot1 <- irGSEA.bubble(object = result.dge, 44 | #' method = "RRA", top = 50) 45 | #' irGSEA.bubble.plot2 <- irGSEA.bubble(object = result.dge, 46 | #' method = "ssgsea", top = 50) 47 | #' 48 | #' } 49 | #' 50 | #' 51 | #' 52 | irGSEA.bubble <- function(object = NULL, method = "RRA", 53 | top = 50, show.geneset = NULL, 54 | cluster.color = NULL, direction.color = NULL, 55 | significance.color = NULL, 56 | cluster_rows = T, cluster.levels = NULL){ 57 | # pretreatment 58 | cluster <- NULL 59 | direction <- NULL 60 | cell <- NULL 61 | pvalue <- NULL 62 | Name <- NULL 63 | significance <- NULL 64 | anno.cluster <- NULL 65 | anno.direction <- NULL 66 | value <- NULL 67 | 68 | if (! purrr::is_list(object)) { 69 | stop("object should be a list.") 70 | } 71 | if ((! all(method %in% names(object))) | (length(method) > 1) | (purrr::is_null(method))) { 72 | stop("`method` should be one of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2, RRA.") 73 | } 74 | pvalue <- NULL 75 | if (method %in% names(object)[! names(object) == "RRA"]) { 76 | object[method] <- object[method] %>% purrr::map( ~.x %>% dplyr::rename(pvalue = p_val_adj)) 77 | } 78 | 79 | # matrix 80 | 81 | sig.genesets.bubble <- object[[method]] %>% 82 | dplyr::mutate(cell = stringr::str_c(cluster, direction, sep = "_")) %>% 83 | dplyr::select(c("Name", "pvalue", "cell")) %>% 84 | dplyr::mutate(pvalue = dplyr::case_when( pvalue < 0.0001 ~ "< 0.0001", 85 | pvalue < 0.001 ~ "< 0.001", 86 | pvalue < 0.01 ~ "< 0.01", 87 | pvalue < 0.05 ~ "< 0.05", 88 | pvalue >= 0.05 ~ ">= 0.05", 89 | TRUE ~ NA_character_)) %>% 90 | dplyr::mutate(Name = factor(Name, levels = unique(Name))) %>% 91 | tidyr::spread(cell, pvalue, fill = ">= 0.05") %>% 92 | tibble::column_to_rownames(var = "Name") 93 | 94 | 95 | if (length(unique(object[[method]]$cluster)) != 0.5*ncol(sig.genesets.bubble)) { 96 | cell.name <- c(stringr::str_c(unique(object[[method]]$cluster), c("up"), sep = "_"), 97 | stringr::str_c(unique(object[[method]]$cluster), c("down"), sep = "_")) 98 | cell.name <- cell.name[!cell.name %in% colnames(sig.genesets.bubble)] 99 | for (i in cell.name) { 100 | sig.genesets.bubble <- sig.genesets.bubble %>% 101 | dplyr::mutate(!!rlang::sym(i):= ">= 0.05") 102 | sig.genesets.bubble <- sig.genesets.bubble[, sort(colnames(sig.genesets.bubble))] 103 | } 104 | 105 | } 106 | 107 | # top rows or custom genesets 108 | if (purrr::is_null(show.geneset)) { 109 | sig.genesets.bubble <- sig.genesets.bubble %>% dplyr::slice_head(n = top) 110 | }else{ 111 | sig.genesets.bubble <- sig.genesets.bubble[rownames(sig.genesets.bubble) %in% show.geneset, ] 112 | sig.genesets.bubble <- sig.genesets.bubble[intersect(show.geneset, rownames(sig.genesets.bubble)), ] 113 | 114 | if (purrr::is_null(sig.genesets.bubble)) { 115 | stop("All genesets of `show.geneset` are not in the `method`.") 116 | } 117 | if (! all(show.geneset %in% rownames(sig.genesets.bubble))) { 118 | a <- show.geneset[! show.geneset %in% rownames(sig.genesets.bubble)] 119 | message(paste0("Some genesets of `show.geneset` are not in the `method` : ",a)) 120 | } 121 | } 122 | 123 | # continue to edit matrix 124 | sig.genesets.bubble <- sig.genesets.bubble %>% 125 | tibble::rownames_to_column(var = "Name") %>% 126 | tidyr::gather(cell, pvalue, -Name) %>% 127 | dplyr::mutate(direction = stringr::str_extract(cell, pattern = "up|down"), 128 | anno.direction = "Direction", 129 | cluster = stringr::str_remove(cell, pattern = "_up|_down"), 130 | anno.cluster = "Cluster", 131 | pvalue = factor(pvalue, levels = rev(levels(factor(pvalue)))), 132 | significance = dplyr::if_else(pvalue == ">= 0.05", "no significant", "significant")) %>% 133 | dplyr::mutate(value = dplyr::if_else(significance == "no significant", 0, 1)) 134 | 135 | # set levels of cluster 136 | if (! purrr::is_null(cluster.levels)) { 137 | sig.genesets.bubble <- sig.genesets.bubble %>% 138 | dplyr::mutate(cluster = factor(cluster, levels = cluster.levels)) %>% 139 | dplyr::arrange(cluster) %>% 140 | dplyr::mutate(cell = factor(cell, levels = unique(cell))) 141 | } 142 | 143 | 144 | 145 | # set color 146 | if (purrr::is_null(cluster.color)) { 147 | cluster.color <- ggsci::pal_igv()(length(unique(sig.genesets.bubble$cluster))) 148 | } 149 | # above picture 150 | labels.cluster <- sig.genesets.bubble %>% 151 | ggplot2::ggplot(ggplot2::aes(cell, y = anno.cluster, fill = cluster)) + 152 | ggplot2::geom_tile() + 153 | ggplot2::scale_fill_manual(values = cluster.color, name = "Cluster") + 154 | ggplot2::scale_y_discrete(position = "right") + 155 | ggplot2::theme_minimal() + 156 | ggplot2::theme(axis.text.x = ggplot2::element_blank(), 157 | axis.ticks.x = ggplot2::element_blank(), 158 | panel.grid = ggplot2::element_blank()) + 159 | ggplot2::labs(x = NULL, y = NULL) 160 | 161 | # set color 162 | if (purrr::is_null(direction.color)) { 163 | direction.color <- c("#4575B4","#D73027") 164 | } 165 | # above picture 166 | labels.direction <- sig.genesets.bubble %>% 167 | ggplot2::ggplot(ggplot2::aes(cell, y = anno.direction, fill = direction)) + 168 | ggplot2::geom_tile() + 169 | ggplot2::scale_fill_manual(values = direction.color, name = "Direction") + 170 | ggplot2::scale_y_discrete(position = "right") + 171 | ggplot2::theme_minimal() + 172 | ggplot2::theme(axis.text.x = ggplot2::element_blank(), 173 | axis.ticks.x = ggplot2::element_blank(), 174 | panel.grid = ggplot2::element_blank()) + 175 | ggplot2::labs(x = NULL, y = NULL) 176 | 177 | # set color 178 | if (purrr::is_null(significance.color)) { 179 | significance.color <- c("#D0DFE6FF","#f87669") 180 | } 181 | # middle picture 182 | bubble.plot <- ggplot2::ggplot(sig.genesets.bubble, ggplot2::aes(x = cell, y = Name))+ 183 | ggplot2::geom_point(ggplot2::aes(size = pvalue, color = significance))+ 184 | ggplot2::scale_color_manual(values = significance.color, name = method)+ 185 | ggplot2::theme_bw()+ 186 | ggplot2::theme(panel.grid = ggplot2::element_blank(), 187 | axis.text.x = ggplot2::element_blank(), 188 | axis.ticks.x = ggplot2::element_blank(), 189 | axis.text.y = ggplot2::element_text(size = 8))+ 190 | ggplot2::labs(x=NULL,y=NULL)+ 191 | ggplot2::guides(size = ggplot2::guide_legend(title = "P Value")) + 192 | ggplot2::scale_size_manual(values = c(1,1.5,2,2.5,3)) 193 | 194 | # bulid ggtree matrix 195 | sig.genesets.bubble.matrix <- sig.genesets.bubble %>% 196 | dplyr::select(c(Name, cell, value)) %>% 197 | dplyr::mutate(Name = factor(Name, levels = unique(Name))) %>% 198 | tidyr::spread(cell, value) %>% 199 | tibble::column_to_rownames(var = "Name") 200 | 201 | # row tree 202 | phr <- ggtree::ggtree(stats::hclust(stats::dist(sig.genesets.bubble.matrix))) 203 | # combine tree 204 | if (cluster_rows == T) { 205 | sig.genesets.bubble.plot <- bubble.plot %>% 206 | aplot::insert_left(phr, width=.1) %>% 207 | aplot::insert_top(labels.direction, height = .05) %>% 208 | aplot::insert_top(labels.cluster, height = .05) 209 | }else{ 210 | sig.genesets.bubble.plot <- bubble.plot %>% 211 | aplot::insert_top(labels.direction, height = .05) %>% 212 | aplot::insert_top(labels.cluster, height = .05) 213 | } 214 | sig.genesets.bubble.plot <- ggplotify::as.ggplot(sig.genesets.bubble.plot) 215 | return(sig.genesets.bubble.plot) 216 | 217 | } 218 | 219 | -------------------------------------------------------------------------------- /R/irGSEA.density.scatterplot.R: -------------------------------------------------------------------------------- 1 | #' Density Scatter plot 2 | #' 3 | #' Easy to the data distribution by density scatter plot 4 | #' 5 | #' @param object A Seurat after perform \code{\link{irGSEA.score}} 6 | #' @param method A character. It should be one of the followling : AUCell, 7 | #' UCell, singscore, ssgsea. 8 | #' @param show.geneset A character. It should be one of the rownames of 9 | #' enrichment score matrix. 10 | #' @param reduction A character. It can not be empty and should be calculated 11 | #' in advance. 12 | #' @param ... More parameters pass to \code{\link[Nebulosa]{plot_density}} 13 | #' 14 | #' @return density scatter plot 15 | #' @export 16 | #' 17 | #' @examples 18 | #' \dontrun{ 19 | #' # load PBMC dataset by R package SeuratData 20 | #' library(Seurat) 21 | #' library(SeuratData) 22 | #' # download 3k PBMCs from 10X Genomics 23 | #' InstallData("pbmc3k") 24 | #' data("pbmc3k.final") 25 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 26 | #' 27 | #' # Seurat object 28 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 29 | #' slot = "data", msigdb = T, species = "Homo sapiens", 30 | #' category = "H", geneid = "symbol", 31 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 32 | #' 33 | #' irGSEA.density.scatterplot1 <- irGSEA.density.scatterplot(object = pbmc3k.final, 34 | #' method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE", 35 | #' reduction = "umap") 36 | #' irGSEA.density.scatterplot2 <- irGSEA.density.scatterplot(object = pbmc3k.final, 37 | #' method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING", 38 | #' reduction = "umap") 39 | #' 40 | #' } 41 | #' 42 | #' 43 | irGSEA.density.scatterplot <- function(object = NULL, method = NULL, 44 | show.geneset = NULL, reduction = "umap", 45 | ...){ 46 | # pretreatment 47 | if ((! all(method %in% Seurat::Assays(object))) | (length(method) > 1) | (purrr::is_null(method))) { 48 | stop("`method` should be one of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2.") 49 | } 50 | 51 | if ((! all(reduction %in% Seurat::Reductions(object))) | (length(reduction) > 1) | (purrr::is_null(reduction))) { 52 | stop("`reductions` can not be empty and should be calculated in advance.") 53 | } 54 | 55 | # geneset 56 | if (purrr::is_null(show.geneset)) { 57 | stop("`show.geneset` can not be empty.") 58 | }else{ 59 | custom.geneset <- show.geneset[show.geneset %in% rownames(object[[method]])] 60 | if (purrr::is_null(custom.geneset)) { 61 | stop("All genesets of `show.geneset` are not in the `method`.") 62 | } 63 | if (! all(show.geneset %in% rownames(object[[method]]))) { 64 | a <- show.geneset[! show.geneset %in% rownames(object[[method]])] 65 | message(paste0("Following genesets of `show.geneset` are not in such `method` : ",a)) 66 | } 67 | } 68 | 69 | # plot 70 | SeuratObject::DefaultAssay(object) <- method 71 | scores.scatterplot <- Nebulosa::plot_density(object, 72 | features = custom.geneset, 73 | slot = "scale.data", 74 | reduction = reduction, 75 | method = "wkde", 76 | joint = T, 77 | ...) + 78 | ggplot2::ggtitle(paste0(method, ": ", custom.geneset))+ 79 | ggplot2::theme(plot.title = ggplot2::element_text(size = 10, hjust = 0.5), 80 | axis.title = ggplot2::element_text(size = 10)) 81 | 82 | return(scores.scatterplot) 83 | 84 | } 85 | -------------------------------------------------------------------------------- /R/irGSEA.densityheatmap.R: -------------------------------------------------------------------------------- 1 | #' Density heatmap 2 | #' 3 | #' Easy to show the data distribution by density heatmap 4 | #' 5 | #' @param object A Seurat after perform \code{\link{irGSEA.score}} 6 | #' @param method A character. It should be one of the followling : AUCell, 7 | #' UCell, singscore, ssgsea. 8 | #' @param show.geneset A character. It should be one of the rownames of 9 | #' enrichment score matrix. 10 | #' @param group.by Default ident when it is set to NULL. You can specify other 11 | #' column of metadata. 12 | #' @param heatmap_width Width of the whole heatmap (including heatmap 13 | #' components), default 12. 14 | #' @param heatmap_height Heigh of the whole heatmap (including heatmap 15 | #' components), default 12. 16 | #' @param cluster.levels A vector equal to the number of clusters. 17 | #' @param ... More parameters pass to \code{\link[ComplexHeatmap]{densityHeatmap}} 18 | #' 19 | #' @return density heatmap 20 | #' @export 21 | #' 22 | #' @examples 23 | #' 24 | #' \dontrun{ 25 | #' # load PBMC dataset by R package SeuratData 26 | #' library(Seurat) 27 | #' library(SeuratData) 28 | #' # download 3k PBMCs from 10X Genomics 29 | #' InstallData("pbmc3k") 30 | #' data("pbmc3k.final") 31 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 32 | #' 33 | #' # Seurat object 34 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 35 | #' slot = "data", msigdb = T, species = "Homo sapiens", 36 | #' category = "H", geneid = "symbol", 37 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 38 | #' 39 | #' irGSEA.densityheatmap.plot1 <- irGSEA.densityheatmap(object = pbmc3k.final, 40 | #' method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 41 | #' irGSEA.densityheatmap.plot2 <- irGSEA.densityheatmap(object = pbmc3k.final, 42 | #' method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 43 | #' 44 | #' } 45 | #' 46 | irGSEA.densityheatmap <- function(object = NULL, method = NULL, 47 | show.geneset = NULL, group.by = NULL, 48 | heatmap_width = 12, heatmap_height = 12, 49 | cluster.levels = NULL, ...){ 50 | # pretreatment 51 | ident <- NULL 52 | if ((! all(method %in% Seurat::Assays(object))) | (length(method) > 1) | (purrr::is_null(method))) { 53 | stop("`method` should be one of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2.") 54 | } 55 | # group 56 | if (purrr::is_null(group.by)) { 57 | anno.ident <- SeuratObject::Idents(object) 58 | }else{ 59 | object <- SeuratObject::SetIdent(object, value = group.by) 60 | anno.ident <- SeuratObject::Idents(object) 61 | } 62 | # factors are sorted alphabetically 63 | anno.ident <- as.factor(as.character(anno.ident)) 64 | # set levels of cluster 65 | if (! purrr::is_null(cluster.levels)) { 66 | anno.ident <- factor(anno.ident, levels = cluster.levels) 67 | } 68 | SeuratObject::Idents(object) <- anno.ident 69 | 70 | # geneset 71 | if (purrr::is_null(show.geneset)) { 72 | stop("`show.geneset` can not be empty.") 73 | }else{ 74 | custom.geneset <- show.geneset[show.geneset %in% rownames(object[[method]])] 75 | if (purrr::is_null(custom.geneset)) { 76 | stop("All genesets of `show.geneset` are not in the `method`.") 77 | } 78 | if (! all(show.geneset %in% rownames(object[[method]]))) { 79 | a <- show.geneset[! show.geneset %in% rownames(object[[method]])] 80 | message(paste0("Following genesets of `show.geneset` are not in such `method` : ",a)) 81 | } 82 | } 83 | 84 | # plot 85 | scores.densityheatmap <- Seurat::VlnPlot(object = object, 86 | assay = method, 87 | slot = "data", 88 | group.by = group.by, 89 | features = custom.geneset, 90 | pt.size = 0, 91 | fill.by = "ident") 92 | scores.densityheatmap <- scores.densityheatmap$data %>% 93 | dplyr::group_split(ident, .keep = F) %>% 94 | purrr::set_names(levels(scores.densityheatmap$data$ident)) %>% 95 | purrr::map(~ .x %>% dplyr::pull(.)) 96 | 97 | 98 | scores.densityheatmap <- ComplexHeatmap::densityHeatmap(scores.densityheatmap, 99 | title = paste0(method,"'s Distribution"), 100 | ylab = custom.geneset, 101 | title_gp = grid::gpar(fontsize = 9), 102 | ylab_gp = grid::gpar(fontsize = 8), 103 | tick_label_gp = grid::gpar(fontsize = 9), 104 | column_names_gp = grid::gpar(fontsize = 9), 105 | column_names_rot = 45, 106 | show_heatmap_legend = T, 107 | heatmap_width = grid::unit(heatmap_width, "cm"), 108 | heatmap_height = grid::unit(heatmap_height, "cm"), 109 | ...) 110 | scores.densityheatmap <- ggplotify::as.ggplot( 111 | grid::grid.grabExpr(ComplexHeatmap::draw(scores.densityheatmap))) 112 | 113 | return(scores.densityheatmap) 114 | 115 | } 116 | 117 | 118 | -------------------------------------------------------------------------------- /R/irGSEA.halfvlnplot.R: -------------------------------------------------------------------------------- 1 | #' Half vlnplot 2 | #' 3 | #' Easy to show the data distribution by half vlnplot 4 | #' 5 | #' @param object A Seurat after perform \code{\link{irGSEA.score}} 6 | #' @param method A character. It should be one of the followling : AUCell, 7 | #' UCell, singscore, ssgsea. 8 | #' @param show.geneset A character. It should be one of the rownames of 9 | #' enrichment score matrix. 10 | #' @param group.by Default ident when it is set to NULL. You can specify other 11 | #' column of metadata. 12 | #' @param color.cluster A vector. Default "ggsci::pal_igv()(the number of colnames 13 | #' of enrichment score matrix)" when it is set to NULL. 14 | #' @param cluster.levels A vector equal to the number of clusters. 15 | #' 16 | #' @return half vlnplot 17 | #' @export 18 | #' 19 | #' @examples 20 | #' \dontrun{ 21 | #' # load PBMC dataset by R package SeuratData 22 | #' library(Seurat) 23 | #' library(SeuratData) 24 | #' # download 3k PBMCs from 10X Genomics 25 | #' InstallData("pbmc3k") 26 | #' data("pbmc3k.final") 27 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 28 | #' 29 | #' # Seurat object 30 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 31 | #' slot = "data", msigdb = T, species = "Homo sapiens", 32 | #' category = "H", geneid = "symbol", 33 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 34 | #' 35 | #' irGSEA.halfvlnplot.plot1 <- irGSEA.halfvlnplot(object = pbmc3k.final, 36 | #' method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 37 | #' irGSEA.halfvlnplot.plot2 <- irGSEA.halfvlnplot(object = pbmc3k.final, 38 | #' method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 39 | #' 40 | #' 41 | #' } 42 | #' 43 | irGSEA.halfvlnplot <- function(object = NULL, method = NULL, 44 | show.geneset = NULL, group.by = NULL, 45 | color.cluster = NULL, cluster.levels = NULL){ 46 | # pretreatment 47 | ident <- NULL 48 | geneset <- NULL 49 | if ((! all(method %in% Seurat::Assays(object))) | (length(method) > 1) | (purrr::is_null(method))) { 50 | stop("`method` should be one of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2.") 51 | } 52 | 53 | # group 54 | if (purrr::is_null(group.by)) { 55 | anno.ident <- SeuratObject::Idents(object) 56 | }else{ 57 | object <- SeuratObject::SetIdent(object, value = group.by) 58 | anno.ident <- SeuratObject::Idents(object) 59 | } 60 | # factors are sorted alphabetically 61 | anno.ident <- as.factor(as.character(anno.ident)) 62 | # set levels of cluster 63 | if (! purrr::is_null(cluster.levels)) { 64 | anno.ident <- factor(anno.ident, levels = cluster.levels) 65 | } 66 | SeuratObject::Idents(object) <- anno.ident 67 | 68 | # set colors 69 | if (purrr::is_null(color.cluster)) { 70 | color.cluster <- ggsci::pal_igv()(length(levels(object))) 71 | } 72 | 73 | # geneset 74 | if (purrr::is_null(show.geneset)) { 75 | stop("`show.geneset` can not be empty.") 76 | }else{ 77 | custom.geneset <- show.geneset[show.geneset %in% rownames(object[[method]])] 78 | if (purrr::is_null(custom.geneset)) { 79 | stop("All genesets of `show.geneset` are not in the `method`.") 80 | } 81 | if (! all(show.geneset %in% rownames(object[[method]]))) { 82 | a <- show.geneset[! show.geneset %in% rownames(object[[method]])] 83 | message(paste0("Following genesets of `show.geneset` are not in such `method` : ",a)) 84 | } 85 | } 86 | 87 | # plot 88 | scores.vlnplot <- Seurat::VlnPlot(object = object, 89 | assay = method, 90 | slot = "data", 91 | group.by = group.by, 92 | cols = color.cluster, 93 | features = custom.geneset, 94 | pt.size = 0, 95 | fill.by = "ident") + 96 | ggplot2::theme(axis.title.x = ggplot2::element_blank())+ 97 | ggplot2::guides(fill = ggplot2::guide_legend(title = "Cluster")) 98 | 99 | scores.vlnplot <- scores.vlnplot$data 100 | scores.vlnplot <- scores.vlnplot %>% 101 | dplyr::rename(c("geneset" = tidyselect::all_of(custom.geneset))) %>% 102 | ggplot2::ggplot(ggplot2::aes(x = ident, y = geneset, fill = ident), colour = "white") + 103 | gghalves::geom_half_boxplot(side = "r", outlier.color = NA,errorbar.draw = TRUE)+ 104 | gghalves::geom_half_violin() + 105 | ggplot2::theme_classic() + 106 | ggplot2::scale_fill_manual(values = color.cluster)+ 107 | ggplot2::ylab(paste0(method, " scores")) + 108 | ggplot2::xlab("") + 109 | ggplot2::ggtitle(custom.geneset) + 110 | ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5), 111 | title = ggplot2::element_text(size =12), 112 | axis.text.x = ggplot2::element_text(vjust = 0.5, hjust = 0.5, angle = 45))+ 113 | ggplot2::guides(fill = ggplot2::guide_legend(title = "Cluster")) 114 | 115 | return(scores.vlnplot) 116 | 117 | } 118 | 119 | 120 | -------------------------------------------------------------------------------- /R/irGSEA.hub.R: -------------------------------------------------------------------------------- 1 | #' Calculate the hub gene of the geneset 2 | #' 3 | #' Easy to calculate the hub gene of the geneset based on the correlation between 4 | #' the geneset's score and the expression or rank of gene included in the geneset 5 | #' 6 | #' @param object A Seurat after perform \code{\link{irGSEA.score}} 7 | #' @param assay Name of assay to calculate the correction. Default RNA. 8 | #' @param slot Default data. 9 | #' @param method A character. 10 | #' @param show.geneset A character. 11 | #' @param ncores Default 4. 12 | #' @param type expression or rank. Default rank. Calculate the correlation between 13 | #' the geneset's score and the rank of gene included in the geneset while the 14 | #' type is rank. Calculate the correlation between the geneset's score and the 15 | #' expression of gene included in the geneset while the type is expression. 16 | #' @param maxRank Maximum number of genes to rank per cell; above this rank, 17 | #' a given gene is considered as not expressed. Default 2000. 18 | #' @param top The number of top-ranked positively correlated genes in each method 19 | #' is displayed in a heatmap. 20 | #' @param correlation.color A vector. 21 | #' @param method.color A vector. Default "ggsci::pal_png()(the number of 22 | #' methods)" when it is set to NULL. 23 | #' @return list includes hub_result and hub_plot 24 | #' @export 25 | #' 26 | #' @examples 27 | #' \dontrun{ 28 | #' # load PBMC dataset by R package SeuratData 29 | #' library(Seurat) 30 | #' library(SeuratData) 31 | #' # download 3k PBMCs from 10X Genomics 32 | #' InstallData("pbmc3k") 33 | #' data("pbmc3k.final") 34 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 35 | #' 36 | #' # Seurat object 37 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 38 | #' slot = "data", msigdb = T, species = "Homo sapiens", 39 | #' category = "H", geneid = "symbol", 40 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 41 | #' 42 | #' hub.result <- irGSEA.hub(object = pbmc3k.final, assay = "RNA", slot = "data", 43 | #' method = c("AUCell","UCell","singscore", "ssgsea"), 44 | #' show.geneset = c("HALLMARK-INFLAMMATORY-RESPONSE", "HALLMARK-APOPTOSIS"), 45 | #' ncores = 4, type = "rank", maxRank = 2000, top = 5, 46 | #' correlation.color = c("#0073c2","white","#efc000"), method.color = NULL) 47 | #' 48 | #' head(hub.result$hub_result) 49 | #' hub.result$hub_plot$`HALLMARK-APOPTOSIS` 50 | #' hub.result$hub_plot$`HALLMARK-INFLAMMATORY-RESPONSE` 51 | #' 52 | #' 53 | #' } 54 | #' 55 | irGSEA.hub <- function(object = NULL, assay = "RNA", slot = "data", 56 | method = NULL, show.geneset = NULL, 57 | ncores = 4, type = "rank", maxRank = 2000, top = 5, 58 | correlation.color = c("#0073c2","white","#efc000"), 59 | method.color = NULL){ 60 | 61 | method.data <- lapply(method, function(i){ 62 | message(i) 63 | # method 64 | tryCatch({ 65 | 66 | # All the genesets are not on the assay 67 | if (all(show.geneset %in% rownames(object[[i]])) == F) { 68 | message(paste0("All the genesets: ", show.geneset, " are not on the assay: ", 69 | i, ".")) 70 | return(NULL) 71 | } 72 | 73 | show.geneset.before <- length(show.geneset) 74 | show.geneset.new <- show.geneset[show.geneset %in% rownames(object[[i]])] 75 | show.geneset.after <- length(show.geneset) 76 | 77 | # Some genesets are not on the assay 78 | if (show.geneset.before > show.geneset.after) { 79 | message(paste0("Some genesets: ", show.geneset[!show.geneset %in% show.geneset.new], 80 | " are not on the assay: ", i, ".")) 81 | } 82 | 83 | # geneset matrix 84 | geneset.data <- SeuratObject::GetAssayData(object[[i]], slot = "scale.data")[show.geneset.new, , drop=F] 85 | 86 | cor.geneset <- lapply(show.geneset.new, function(x){ 87 | message(x) 88 | 89 | # the target gene of geneset 90 | if (class(object[[i]])[1] == "Assay5") { 91 | gene <- object[[i]]@meta.data 92 | rownames(gene) <- rownames(object[[i]]) 93 | gene <- gene[x, "target.gene"] 94 | }else{ 95 | gene <- object[[i]]@meta.features[x, "target.gene"] 96 | } 97 | 98 | # if target gene of geneset is null 99 | if (gene == "") { 100 | message(paste0("Please check the column `target.gene` in meta.data or meta.features of", 101 | " the geneset `", x, "` in the assay `", i, "`. It maybe empty.")) 102 | return(NULL) 103 | } 104 | 105 | gene <- stringr::str_remove_all(gene, pattern = "\\+$|-$") 106 | gene <- stringr::str_split(gene, pattern = ", ")[[1]] 107 | 108 | # gene expression matrix or gene rank matrix 109 | if (type == "rank") { 110 | expression.data <- UCell::StoreRankings_UCell(matrix = SeuratObject::GetAssayData(object[[assay]], slot = slot), 111 | maxRank = maxRank, 112 | ncores = ncores) 113 | expression.data <- as.matrix(expression.data)[gene, , drop=F] 114 | }else{ 115 | expression.data <- SeuratObject::GetAssayData(object[[assay]], slot = slot)[gene, , drop=F] 116 | } 117 | 118 | # calcute correlation 119 | cor.list <- lapply(gene, function(k){ 120 | #message(k) 121 | test <- stats::cor.test(as.numeric(expression.data[k, ]), 122 | as.numeric(geneset.data[x, ]), 123 | type = "spearman") 124 | cor.data <- data.frame(method = i, 125 | geneset = x, 126 | gene = k, 127 | correlation = test$estimate, 128 | p.value = test$p.value) 129 | return(cor.data) 130 | }) 131 | cor.list <- do.call(rbind, cor.list) 132 | return(cor.list) 133 | 134 | }) 135 | cor.geneset <- do.call(rbind, cor.geneset) 136 | return(cor.geneset) 137 | 138 | }, error = function(e) { 139 | cat("Error: ", conditionMessage(e), "\n") 140 | }) 141 | 142 | }) 143 | method.data <- do.call(rbind, method.data) 144 | method.data$geneset <- factor(method.data$geneset, levels = show.geneset) 145 | method.data$method <- factor(method.data$method, levels = method) 146 | geneset <- NULL 147 | method.data2 <- method.data %>% 148 | dplyr::group_split(geneset, .keep = T) %>% 149 | purrr::set_names(levels(method.data$geneset)) 150 | 151 | # draw 152 | method.data2 <- lapply(method.data2, function(method.data3){ 153 | 154 | 155 | method <- NULL 156 | Module <- NULL 157 | correlation <- NULL 158 | p.value <- NULL 159 | gene <- NULL 160 | pvalue <- NULL 161 | Variable <- NULL 162 | Value <- NULL 163 | text <- NULL 164 | Method <- NULL 165 | 166 | method.data3 <- method.data3 %>% 167 | dplyr::group_by(method) %>% 168 | dplyr::arrange(dplyr::desc(correlation)) %>% 169 | dplyr::slice_head(n = top) 170 | 171 | method.data3 <- method.data3 %>% 172 | dplyr::mutate(pvalue = p.value, Value = correlation, 173 | Variable = gene, Module = method) %>% 174 | dplyr::mutate(pvalue = dplyr::case_when(pvalue < 1e-04 ~ "****", 175 | pvalue < 0.001 ~ "***", 176 | pvalue < 0.01 ~ "**", 177 | pvalue <= 0.05 ~ "*", 178 | pvalue > 0.05 ~ "", 179 | TRUE ~ NA_character_)) 180 | 181 | method.data3$Value <- round(method.data3$Value, 2) 182 | method.data3$text <- NULL 183 | # text 184 | for (i in 1:nrow(method.data3)) { 185 | if (method.data3$pvalue[i]=="") { 186 | method.data3$text[i] <- method.data3$Value[i] 187 | }else{ 188 | method.data3$text[i] <- paste0(method.data3$Value[i], "\n", "(", method.data3$pvalue[i], ")" ) 189 | } 190 | 191 | } 192 | 193 | 194 | # plot 195 | p.heatmap <- ggplot2::ggplot(method.data3, ggplot2::aes(x = Module, y = Variable, fill = Value)) + 196 | ggplot2::geom_tile(color = "black") + 197 | ggplot2::geom_text(ggplot2::aes(label = text), color = "black", show.legend = T)+ 198 | ggplot2::scale_fill_gradientn(colours = grDevices::colorRampPalette(correlation.color)(100))+ 199 | ggplot2::theme(panel.background = ggplot2::element_blank(), 200 | panel.grid.major = ggplot2::element_blank(), 201 | panel.grid.minor = ggplot2::element_blank(), 202 | axis.ticks = ggplot2::element_blank(), 203 | axis.text.x.bottom = ggplot2::element_blank())+ 204 | ggplot2::xlab("")+ 205 | ggplot2::ylab("")+ 206 | ggplot2::labs(fill = "Correlation")+ 207 | Seurat::NoLegend() 208 | 209 | # label 210 | if (is.null(method.color)) { 211 | method.color <- ggsci::pal_npg()(length(unique(method.data3$Module))) 212 | } 213 | p.label <- method.data3 %>% 214 | dplyr::mutate(Method = "Method") %>% 215 | ggplot2::ggplot(ggplot2::aes(Module, y = Method, fill = Module)) + 216 | ggplot2::ylab("Method")+ 217 | ggplot2::geom_tile() + 218 | ggplot2::scale_fill_manual(values = method.color, name = "Method") + 219 | ggplot2::scale_y_discrete(position = "left") + 220 | ggplot2::theme_minimal() + 221 | ggplot2::theme(axis.text.x = ggplot2::element_blank(), 222 | axis.ticks.x = ggplot2::element_blank(), 223 | panel.grid = ggplot2::element_blank(), 224 | axis.text.y = ggplot2::element_text(angle = 0, size =10, vjust = 0.5), 225 | axis.title.x = ggplot2::element_blank(), 226 | axis.title.y = ggplot2::element_blank())+ 227 | Seurat::NoLegend() 228 | 229 | p <- p.heatmap %>% aplot::insert_top(p.label, height = 0.1) 230 | p <- ggplotify::as.ggplot(p) + 231 | ggplot2::ggtitle(unique(method.data3$geneset))+ 232 | ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5)) 233 | 234 | # make legend 235 | col_fun <- circlize::colorRamp2(c(stats::fivenum(method.data3$Value)[1], 236 | stats::fivenum(method.data3$Value)[3], 237 | stats::fivenum(method.data3$Value)[5]), 238 | correlation.color) 239 | 240 | lgd.method <- ComplexHeatmap::Legend(labels = levels(factor(method.data3$Module)), 241 | title = "Method", 242 | legend_gp = grid::gpar(fill = method.color)) 243 | 244 | 245 | lgd.cor <- ComplexHeatmap::Legend(col_fun = col_fun, title = "Correlation") 246 | 247 | 248 | lgd.p <- ComplexHeatmap::Legend(pch = c("*", "**", "***", "****"), 249 | type = "points", 250 | labels = c("<= 0.05", "< 0.01", "< 0.001", "< 0.0001"), 251 | title = "Spearman's P Value") 252 | 253 | heatmap.legend <- ComplexHeatmap::packLegend(lgd.method, lgd.cor, lgd.p, 254 | direction = "vertical", 255 | column_gap = grid::unit(1, "cm")) 256 | heatmap.legend <- grid::grid.grabExpr(ComplexHeatmap::draw(heatmap.legend)) %>% 257 | ggplotify::as.ggplot() 258 | 259 | p <- cowplot::plot_grid(p, heatmap.legend, rel_widths = c(1,0.1)) 260 | 261 | return(p) 262 | 263 | }) 264 | 265 | result <- list() 266 | result[["hub_result"]] <- method.data 267 | result[["hub_plot"]] <- method.data2 268 | return(result ) 269 | 270 | } 271 | 272 | 273 | -------------------------------------------------------------------------------- /R/irGSEA.merge.R: -------------------------------------------------------------------------------- 1 | #' Merge the enrichment score assay 2 | #' 3 | #' Merge the enrichment score assay among various Seurat objects 4 | #' 5 | #' @param object.x Seurat object (V4 or V5). 6 | #' @param object.y The list includes various Seurat objects. The verison of 7 | #' Seurat object should be the same as the version of object.x. 8 | #' @param method A vector. Default c("AUCell", "UCell", "singscore", "ssgsea", 9 | #' "JASMINE", "viper"). 10 | #' @param overwrite Default True. The same geneset name exists in two gene scoring 11 | #' matrices, the newly added geneset will overwrite the previous geneset if 12 | #' the overwrite is true. The newly added geneset will be forcibly renamed 13 | #' as "geneset's name + serial number" if the overwrite is false. 14 | #' 15 | #' @return Seurat object including score matrix. 16 | #' @export 17 | #' 18 | #' @examples 19 | #' \dontrun{ 20 | #' # load PBMC dataset by R package SeuratData 21 | # # devtools::install_github('satijalab/seurat-data') 22 | #' library(Seurat) 23 | #' library(SeuratData) 24 | #' # download 3k PBMCs from 10X Genomics 25 | #' InstallData("pbmc3k") 26 | #' library(Seurat) 27 | #' 28 | #' library(RcppML) 29 | #' library(irGSEA) 30 | #' library(tidyverse) 31 | #' library(clusterProfiler) 32 | #' data("pbmc3k.final") 33 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 34 | #' 35 | #' # download gmt file 36 | #' gmt_url1 <- "https://data.broadinstitute.org/" 37 | #' gmt_url2 <- "gsea-msigdb/msigdb/release/2023.2.Hs/", 38 | #' gmt_url3 <- "h.all.v2023.2.Hs.symbols.gmt" 39 | #' gmt_url <- paste0(gmt_url1, gmt_url2, gmt_url3) 40 | #' local_gmt <- "./h.all.v2023.2.Hs.symbols.gmt" 41 | #' download.file(gmt_url , local_gmt) 42 | #' msigdb <- clusterProfiler::read.gmt("./h.all.v2023.2.Hs.symbols.gmt") 43 | #' 44 | #' # convert to list[hallmarker] required by irGSEA package 45 | #' msigdb$term <- factor(msigdb$term) 46 | #' msigdb <- msigdb %>% 47 | #' dplyr::group_split(term, .keep = F) %>% 48 | #' purrr::map( ~.x %>% dplyr::pull(gene) %>% unique(.)) %>% 49 | #' purrr::set_names(levels(msigdb$term)) 50 | #' 51 | #' pbmc3k.final1 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 52 | #' custom = T, geneset = msigdb[1:25], 53 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 54 | #' kcdf = 'Gaussian') 55 | #' pbmc3k.final2 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 56 | #' custom = T, geneset = msigdb[26:50], 57 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 58 | #' kcdf = 'Gaussian') 59 | #' 60 | #' pbmc3k.final3 <- irGSEA.merge(object.x = pbmc3k.final1, 61 | #' object.y = pbmc3k.final2, 62 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 63 | #' overwrite = T) 64 | #' 65 | #' } 66 | #' 67 | irGSEA.merge <- function(object.x = NULL, object.y = NULL, 68 | method = c("AUCell", "UCell", "singscore", 69 | "ssgsea","JASMINE", "viper"), 70 | overwrite = T 71 | ){ 72 | # create a list 73 | if (length(object.y) == 1) { 74 | object.y <- list(object.y) 75 | } 76 | 77 | # work 78 | for (k in method) { 79 | 80 | for (i in seq_along(object.y)) { 81 | 82 | # acts.x 83 | acts.x <- tryCatch({ 84 | acts.x <- SeuratObject::GetAssayData(object.x, assay = k, slot = "scale.data") 85 | }, error = function(e) { 86 | acts.x <- NULL 87 | }) 88 | 89 | # acts.y 90 | acts.y <- tryCatch({ 91 | acts.y <- SeuratObject::GetAssayData(object.y[[i]], assay = k, slot = "scale.data") 92 | }, error = function(e) { 93 | acts.y <- NULL 94 | }) 95 | 96 | # next 97 | if (is.null(acts.x) & is.null(acts.y)) { 98 | next 99 | } 100 | 101 | 102 | 103 | # merge, if overwrite, or renames the same geneset 104 | if (overwrite) { 105 | index.intersect <- !rownames(acts.x) %in% rownames(acts.y) 106 | acts <- rbind(acts.x[index.intersect,], acts.y) 107 | 108 | 109 | }else{ 110 | index.intersect <- match(rownames(acts.x), rownames(acts.y)) 111 | if (any(!is.na(index.intersect))) { 112 | index.intersect2 <- index.intersect[!is.na(index.intersect)] 113 | rownames(acts.y)[index.intersect2] <- paste0(rownames(acts.y)[index.intersect2], "-", i) 114 | acts <- rbind(acts.x, acts.y) 115 | }else{ 116 | acts <- rbind(acts.x, acts.y) 117 | } 118 | 119 | 120 | } 121 | 122 | if (is.null(acts)) { next } 123 | 124 | 125 | # if version 126 | version <- tryCatch({ 127 | # if v5 or v3 128 | if (class(object.x[[k]])[1] == "Assay5") { 129 | options(Seurat.object.assay.version = "v5") 130 | version <- "v5" 131 | }else{ 132 | options(Seurat.object.assay.version = "v3") 133 | version <- "v3" 134 | } 135 | }, error = function(e) { 136 | version <- tryCatch({ 137 | # if v5 or v3 138 | if (class(object.y[[i]][[k]])[1] == "Assay5") { 139 | options(Seurat.object.assay.version = "v5") 140 | version <- "v5" 141 | }else{ 142 | options(Seurat.object.assay.version = "v3") 143 | version <- "v3" 144 | } 145 | }, error = function(e) { 146 | options(Seurat.object.assay.version = "v3") 147 | version <- "v3" 148 | }) 149 | }) 150 | 151 | # if verison of Assay same 152 | tryCatch({ 153 | if (class(object.x[[k]])[1] != class(object.y[[i]][[k]])[1]) { 154 | message(paste0("The Seurat/Assay versions of the object.x and object.y: ", 155 | i, 156 | " are inconsistent. \n", 157 | "We convert object.y: ", 158 | i, 159 | " from ", 160 | class(object.y[[i]][[k]])[1], 161 | " to ", 162 | class(object.x[[k]])[1], 163 | " .")) 164 | 165 | # convert 166 | if (class(object.y[[i]][[k]])[1] == "Assay5") { 167 | object.y[[i]][[k]] <- methods::as(object = object.y[[i]][[k]], Class = "Assay") 168 | }else{ 169 | object.y[[i]][[k]] <- methods::as(object = object.y[[i]][[k]], Class = "Assay5") 170 | } 171 | } 172 | }, error = function(e) { 173 | # print("") 174 | }) 175 | 176 | 177 | 178 | 179 | # meta.features 180 | # object.x 181 | 182 | if (is.null(acts.x)) { 183 | object.x.meta.features <- NULL 184 | }else{ 185 | if (purrr::is_empty(object.x[[k]]@meta.features)) { 186 | if (version == "v3") { 187 | object.x.meta.features <- data.frame(geneset = rownames(object.x[[k]]), 188 | target.gene = "") 189 | }else{ 190 | object.x.meta.features <- data.frame(geneset = rownames(object.x[[k]]), 191 | target.gene = "") %>% 192 | tibble::column_to_rownames(var = "geneset") 193 | } 194 | 195 | }else{ 196 | if (version == "v3") { 197 | object.x.meta.features <- object.x[[k]]@meta.features %>% 198 | tibble::rownames_to_column(var = "geneset") 199 | }else{ 200 | object.x.meta.features <- object.x[[k]]@meta.features 201 | } 202 | } 203 | if (overwrite) { 204 | index.intersect <- !rownames(acts.x) %in% rownames(acts.y) 205 | object.x.meta.features <- object.x.meta.features[index.intersect, ] 206 | 207 | } 208 | } 209 | 210 | 211 | 212 | # object.y 213 | 214 | if (is.null(acts.y)) { 215 | object.y.meta.features <- NULL 216 | }else{ 217 | if (purrr::is_empty(object.y[[i]][[k]]@meta.features)) { 218 | 219 | if (version == "v3") { 220 | object.y.meta.features <- data.frame(geneset = rownames(object.y[[i]][[k]]), 221 | target.gene = "") 222 | }else{ 223 | object.y.meta.features <- data.frame(geneset = rownames(object.y[[i]][[k]]), 224 | target.gene = "") %>% 225 | tibble::column_to_rownames(var = "geneset") 226 | } 227 | object.y.meta.features$geneset <- rownames(acts.y) 228 | 229 | }else{ 230 | if (version == "v3") { 231 | object.y.meta.features <- object.y[[i]][[k]]@meta.features %>% 232 | tibble::rownames_to_column(var = "geneset") 233 | }else{ 234 | object.y.meta.features <- object.y[[i]][[k]]@meta.features 235 | } 236 | object.y.meta.features$geneset <- rownames(acts.y) 237 | } 238 | 239 | } 240 | 241 | 242 | 243 | 244 | if (is.null(object.x.meta.features) & is.null(object.y.meta.features) ) { 245 | next 246 | } 247 | 248 | 249 | 250 | # add matrix meta.features 251 | 252 | object.x[[k]] <- SeuratObject::CreateAssayObject(counts = acts) 253 | object.x <- SeuratObject::SetAssayData(object.x, slot = "scale.data", 254 | new.data = acts, 255 | assay = k) 256 | if (utils::packageVersion("Seurat") >= "5.0.0") { 257 | object.x[[k]]$counts <- NULL} 258 | 259 | 260 | 261 | if (version == "v3") { 262 | object.x[[k]]@meta.features <- as.data.frame(rbind(object.x.meta.features, 263 | object.y.meta.features)) %>% 264 | tibble::column_to_rownames(var = "geneset") 265 | 266 | }else{ 267 | object.x[[k]]@meta.features <- rbind(object.x.meta.features, 268 | object.y.meta.features) 269 | 270 | } 271 | 272 | rm(acts) 273 | gc() 274 | 275 | 276 | message(paste0("Finish merge ", k, " scores of object.y: ", i)) 277 | 278 | } 279 | 280 | } 281 | 282 | 283 | return(object.x) 284 | 285 | } 286 | 287 | 288 | -------------------------------------------------------------------------------- /R/irGSEA.ridgeplot.R: -------------------------------------------------------------------------------- 1 | #' Ridge plot 2 | #' Easy to show the data distribution by ridge plot 3 | #' @param object A Seurat after perform \code{\link{irGSEA.score}} 4 | #' @param method A character. It should be one of the followling : AUCell, 5 | #' UCell, singscore, ssgsea. 6 | #' @param show.geneset A character. It should be one of the rownames of 7 | #' enrichment score matrix. 8 | #' @param group.by Default ident when it is set to NULL. You can specify other 9 | #' column of metadata. 10 | #' @param color.cluster A vector. Default "ggsci::pal_igv()(the number of colnames 11 | #' of enrichment score matrix)" when it is set to NULL. 12 | #' @param cluster.levels A vector equal to the number of clusters. 13 | #' @param ... More parameters pass to \code{\link[ggridges]{geom_density_ridges}} 14 | #' 15 | #' @return ridge plot 16 | #' @export 17 | #' 18 | #' @examples 19 | #' 20 | #' \dontrun{ 21 | #' # load PBMC dataset by R package SeuratData 22 | #' library(Seurat) 23 | #' library(SeuratData) 24 | #' # download 3k PBMCs from 10X Genomics 25 | #' InstallData("pbmc3k") 26 | #' data("pbmc3k.final") 27 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 28 | #' 29 | #' # Seurat object 30 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 31 | #' slot = "data", msigdb = T, species = "Homo sapiens", 32 | #' category = "H", geneid = "symbol", 33 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 34 | #' 35 | #' irGSEA.ridgeplot.plot1 <- irGSEA.ridgeplot(object = pbmc3k.final, 36 | #' method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 37 | #' irGSEA.ridgeplot.plot2 <- irGSEA.ridgeplot(object = pbmc3k.final, 38 | #' method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 39 | #' 40 | #' } 41 | #' 42 | irGSEA.ridgeplot <- function(object = NULL, method = NULL, 43 | show.geneset = NULL, group.by = NULL, 44 | color.cluster = NULL, cluster.levels = NULL, ...){ 45 | # pretreatment 46 | ident <- NULL 47 | geneset <- NULL 48 | if ((! all(method %in% Seurat::Assays(object))) | (length(method) > 1) | (purrr::is_null(method))) { 49 | stop("`method` should be one of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2.") 50 | } 51 | 52 | # group 53 | if (purrr::is_null(group.by)) { 54 | anno.ident <- SeuratObject::Idents(object) 55 | }else{ 56 | object <- SeuratObject::SetIdent(object, value = group.by) 57 | anno.ident <- SeuratObject::Idents(object) 58 | } 59 | # factors are sorted alphabetically 60 | anno.ident <- as.factor(as.character(anno.ident)) 61 | # set levels of cluster 62 | if (! purrr::is_null(cluster.levels)) { 63 | anno.ident <- factor(anno.ident, levels = cluster.levels) 64 | } 65 | SeuratObject::Idents(object) <- anno.ident 66 | 67 | # set colors 68 | if (purrr::is_null(color.cluster)) { 69 | color.cluster <- ggsci::pal_igv()(length(levels(object))) 70 | } 71 | 72 | # geneset 73 | if (purrr::is_null(show.geneset)) { 74 | stop("`show.geneset` can not be empty.") 75 | }else{ 76 | custom.geneset <- show.geneset[show.geneset %in% rownames(object[[method]])] 77 | if (purrr::is_null(custom.geneset)) { 78 | stop("All genesets of `show.geneset` are not in the `method`.") 79 | } 80 | if (! all(show.geneset %in% rownames(object[[method]]))) { 81 | a <- show.geneset[! show.geneset %in% rownames(object[[method]])] 82 | message(paste0("Following genesets of `show.geneset` are not in such `method` : ",a)) 83 | } 84 | } 85 | 86 | # plot 87 | scores.ridgeplot <- Seurat::RidgePlot(object = object, 88 | assay = method, 89 | slot = "scale.data", 90 | group.by = group.by, 91 | cols = color.cluster, 92 | features = custom.geneset, 93 | fill.by = "ident") + 94 | ggplot2::theme(axis.title.y = ggplot2::element_blank(), 95 | plot.title = ggplot2::element_text(hjust = 0.5), 96 | axis.title.x = ggplot2::element_text(hjust = 0.5), 97 | panel.grid = ggplot2::element_blank())+ 98 | ggplot2::guides(fill = ggplot2::guide_legend(title = "Cluster")) 99 | 100 | scores.ridgeplot <- scores.ridgeplot$data %>% 101 | dplyr::rename(c("geneset" = tidyselect::all_of(custom.geneset))) %>% 102 | ggplot2::ggplot(ggplot2::aes(x = geneset, y = ident, fill = ident)) + 103 | ggridges::geom_density_ridges(jittered_points=TRUE, scale = .95, rel_min_height = .01, 104 | point_shape = "|", point_size = 3, size = 0.25, 105 | position = ggridges::position_points_jitter(height = 0), ...) + 106 | ggplot2::scale_y_discrete(expand = c(.01, 0), name = "Cluster") + 107 | ggplot2::scale_x_continuous(expand = c(0, 0), name = paste0(method, " scores")) + 108 | ggplot2::scale_fill_manual(values = color.cluster) + 109 | ggplot2::guides(fill = ggplot2::guide_legend( 110 | title="Cluster", 111 | override.aes = list(fill = color.cluster, color = NA, point_color = NA))) + 112 | ggplot2::ggtitle(custom.geneset) + 113 | ggridges::theme_ridges(center = TRUE)+ 114 | ggplot2::theme(plot.title = ggplot2::element_text(hjust = 0.5, size = 12), 115 | axis.title = ggplot2::element_text(size = 12)) 116 | 117 | 118 | return(scores.ridgeplot) 119 | 120 | } 121 | 122 | -------------------------------------------------------------------------------- /R/irGSEA.subset.R: -------------------------------------------------------------------------------- 1 | #' Subset the enrichment score matrix 2 | #' 3 | #' Subset the enrichment score matrix 4 | #' 5 | #' @param object Seurat object (V4 or V5). 6 | #' @param features Vector. The geneset want to subset. 7 | #' @param invert If filp the geneset want to subset. 8 | #' @param method A vector. Default c("AUCell", "UCell", "singscore", "ssgsea", 9 | #' "JASMINE", "viper"). 10 | #' 11 | #' 12 | #' @return Seurat object including score matrix. 13 | #' @export 14 | #' 15 | #' @examples 16 | #' \dontrun{ 17 | #' # load PBMC dataset by R package SeuratData 18 | # # devtools::install_github('satijalab/seurat-data') 19 | #' library(Seurat) 20 | #' library(SeuratData) 21 | #' # download 3k PBMCs from 10X Genomics 22 | #' InstallData("pbmc3k") 23 | #' library(Seurat) 24 | #' 25 | #' library(RcppML) 26 | #' library(irGSEA) 27 | #' library(tidyverse) 28 | #' library(clusterProfiler) 29 | #' data("pbmc3k.final") 30 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 31 | #' 32 | #' # download gmt file 33 | #' gmt_url1 <- "https://data.broadinstitute.org/" 34 | #' gmt_url2 <- "gsea-msigdb/msigdb/release/2023.2.Hs/", 35 | #' gmt_url3 <- "h.all.v2023.2.Hs.symbols.gmt" 36 | #' gmt_url <- paste0(gmt_url1, gmt_url2, gmt_url3) 37 | #' local_gmt <- "./h.all.v2023.2.Hs.symbols.gmt" 38 | #' download.file(gmt_url , local_gmt) 39 | #' msigdb <- clusterProfiler::read.gmt("./h.all.v2023.2.Hs.symbols.gmt") 40 | #' 41 | #' # convert to list[hallmarker] required by irGSEA package 42 | #' msigdb$term <- factor(msigdb$term) 43 | #' msigdb <- msigdb %>% 44 | #' dplyr::group_split(term, .keep = F) %>% 45 | #' purrr::map( ~.x %>% dplyr::pull(gene) %>% unique(.)) %>% 46 | #' purrr::set_names(levels(msigdb$term)) 47 | #' 48 | #' pbmc3k.final1 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 49 | #' custom = T, geneset = msigdb[1:25], 50 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 51 | #' kcdf = 'Gaussian') 52 | #' pbmc3k.final2 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 53 | #' custom = T, geneset = msigdb[26:50], 54 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 55 | #' kcdf = 'Gaussian') 56 | #' 57 | #' pbmc3k.final3 <- irGSEA.merge(object.x = pbmc3k.final1, 58 | #' object.y = pbmc3k.final2, 59 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 60 | #' overwrite = T) 61 | #' pbmc3k.final4 <- irGSEA.subset(object = pbmc3k.final3, 62 | #' features = rownames(pbmc3k.final3[["AUCell"]])[1:25], 63 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 64 | #' invert = F) 65 | #' } 66 | #' 67 | irGSEA.subset <- function(object = NULL, 68 | features = NULL, 69 | invert = F, 70 | method = c("AUCell", "UCell", "singscore", 71 | "ssgsea","JASMINE", "viper") 72 | ){ 73 | 74 | # work 75 | for (k in method) { 76 | # if v5 or v3 77 | if (class(object)[1] == "Assay5") { 78 | options(Seurat.object.assay.version = "v5") 79 | version <- "v5" 80 | }else{ 81 | options(Seurat.object.assay.version = "v3") 82 | version <- "v3" 83 | } 84 | if (invert) { 85 | features <- rownames(object[[k]])[!rownames(object[[k]]) %in% features] 86 | } 87 | 88 | object[[k]] <- subset(object[[k]], features = features) 89 | 90 | } 91 | 92 | 93 | return(object) 94 | 95 | } 96 | 97 | 98 | -------------------------------------------------------------------------------- /R/irGSEA.upset.R: -------------------------------------------------------------------------------- 1 | #' Upset plot 2 | #' 3 | #' Easy to show analysis results by upset plot 4 | #' 5 | #' @param object A list after perform \code{\link{irGSEA.integrate}} 6 | #' @param method A character. It should be one of the followling : AUCell, UCell, 7 | #' singscore, ssgsea or RRA. Default RRA. 8 | #' @param upset.width Width of the whole upset plot. Default 13. 9 | #' @param upset.height Height of the whole upset plot. Default 7. 10 | #' @param title.size The fointsize of rownames. Default 10. 11 | #' @param text.size The fointsize of rownames. Default 9. 12 | #' @param cluster.color A vector. Default "ggsci::pal_igv()(the number of colnames 13 | #' of enrichment score matrix)" when it is set to NULL. 14 | #' @param bar.color A character. Default "black" when it is set to NULL. 15 | #' @param cluster.levels A vector equal to the number of clusters. 16 | #' @param mode A character. It should be one of the followling : distinct, 17 | #' intersect, or union. Default distinct. It represents the mode for forming 18 | #' the combination set. see Mode section \url{https://jokergoo.github.io/ComplexHeatmap-reference/book/upset-plot.html} 19 | #' for details. 20 | #' @param set.size The minimal combination set size. Default 1. 21 | #' @param set.degree A vector. Show all combination sets when it set to NULL. 22 | #' It would show different combination set when it is set to different number. 23 | #' For example, it only show the interactions among two cluster or three cluster 24 | #' when it's set to 2 or 3. 25 | #' @param table.generate Deault FALSE. It will output a list including all 26 | #' combination sets and their gene sets when it set to TRUE. 27 | #' @param ... More parameters pass to \code{\link[ComplexHeatmap]{UpSet}} 28 | #' 29 | #' @return upset plot or list 30 | #' @export 31 | #' 32 | #' @examples 33 | #' \dontrun{ 34 | #' # load PBMC dataset by R package SeuratData 35 | #' library(Seurat) 36 | #' library(SeuratData) 37 | #' # download 3k PBMCs from 10X Genomics 38 | #' InstallData("pbmc3k") 39 | #' data("pbmc3k.final") 40 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 41 | #' 42 | #' # Seurat object 43 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 44 | #' slot = "data", msigdb = T, species = "Homo sapiens", 45 | #' category = "H", geneid = "symbol", 46 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 47 | #' 48 | #' # Integrated analysis 49 | #' result.dge <- irGSEA.integrate(object = pbmc3k.final, 50 | #' group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 51 | #' method = c("AUCell","UCell","singscore","ssgsea")) 52 | #' 53 | #' irGSEA.upset.plot1 <- irGSEA.upset(object = result.dge, method = "RRA") 54 | #' irGSEA.upset.plot2 <- irGSEA.upset(object = result.dge, method = "ssgsea") 55 | #' 56 | #' } 57 | #' 58 | #' 59 | 60 | irGSEA.upset <- function(object = NULL, method = "RRA", 61 | upset.width = 13, upset.height = 7, 62 | title.size = 10, text.size = 9, 63 | cluster.color = NULL, bar.color = "black", 64 | cluster.levels = NULL, mode = "distinct", 65 | set.size = 1, set.degree = NULL, table.generate = F, 66 | ...){ 67 | # pretreatment 68 | if (! purrr::is_list(object)) { 69 | stop("object should be a list.") 70 | } 71 | if ((! all(method %in% names(object))) | (length(method) > 1) | (purrr::is_null(method))) { 72 | stop("`method` should be one of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2, RRA.") 73 | } 74 | pvalue <- NULL 75 | if (method %in% names(object)[! names(object) == "RRA"]) { 76 | object[method] <- object[method] %>% purrr::map( ~.x %>% dplyr::rename(pvalue = p_val_adj)) 77 | } 78 | # matrix 79 | cluster <- NULL 80 | sig.genesets.upset <- object[[method]] %>% 81 | dplyr::filter(pvalue < 0.05) %>% 82 | dplyr::select(c("Name","cluster")) 83 | sig.genesets.upset.names <- levels(factor(as.character(sig.genesets.upset$cluster))) 84 | if (purrr::is_null(cluster.color)) { 85 | cluster.color <- ggsci::pal_igv()(length(sig.genesets.upset.names)) 86 | } 87 | 88 | sig.genesets.upset <- sig.genesets.upset %>% 89 | dplyr::group_split(cluster,.keep = F) %>% 90 | purrr::set_names(sig.genesets.upset.names) 91 | sig.genesets.upset <- lapply(sig.genesets.upset, function(x){x <- x$Name}) 92 | # set levels of cluster 93 | if (! purrr::is_null(cluster.levels)) { 94 | sig.genesets.upset <- sig.genesets.upset[cluster.levels] 95 | } 96 | 97 | # matrix 98 | m <- ComplexHeatmap::make_comb_mat(sig.genesets.upset, mode = mode) 99 | # degree 100 | if (purrr::is_null(set.degree)) { 101 | m <- m[ComplexHeatmap::comb_degree(m) > 0] 102 | }else{ 103 | m <- m[ComplexHeatmap::comb_degree(m) %in% c(set.degree)] 104 | } 105 | # set size 106 | m <- m[ComplexHeatmap::comb_size(m) >= set.size] 107 | 108 | # set levels of cluster 109 | ss <- ComplexHeatmap::set_size(m) 110 | if (! purrr::is_null(cluster.levels)) { 111 | cluster.order <- cluster.levels 112 | }else{ 113 | cluster.order <- order(ss) 114 | } 115 | 116 | # table 117 | if (table.generate == T) { 118 | comb.list <- lapply(ComplexHeatmap::comb_name(m), function(i){ComplexHeatmap::extract_comb(m, i)}) 119 | names(comb.list) <- ComplexHeatmap::comb_name(m, readable = TRUE) 120 | return(comb.list) 121 | } 122 | # plot 123 | cs <- ComplexHeatmap::comb_size(m) 124 | ht <- ComplexHeatmap::UpSet(m, 125 | bg_col = "#D0DFE6FF", 126 | heatmap_width = grid::unit(upset.width, "cm"), 127 | heatmap_height = grid::unit(upset.height, "cm"), 128 | column_title = method, 129 | column_title_gp = grid::gpar(fontsize = title.size), 130 | set_order = cluster.order, 131 | comb_order = order(ComplexHeatmap::comb_degree(m), -cs), 132 | top_annotation = ComplexHeatmap::HeatmapAnnotation( 133 | "Intersections" = ComplexHeatmap::anno_barplot(cs, 134 | ylim = c(0, max(cs)*1.1), 135 | border = FALSE, 136 | gp = grid::gpar(color = bar.color), 137 | height = grid::unit(2, "cm") 138 | ), 139 | annotation_name_side = "left", 140 | annotation_name_rot = 90, 141 | annotation_name_gp = grid::gpar(fontsize = text.size)), 142 | left_annotation = ComplexHeatmap::rowAnnotation( 143 | "Counts" = ComplexHeatmap::anno_barplot(-ss, baseline = 0, 144 | axis_param = list(at = c(0, -500, -1000, -1500), 145 | labels = c(0, 500, 1000, 1500), 146 | labels_rot = 0), 147 | border = FALSE, 148 | gp = grid::gpar(fill = cluster.color), 149 | width = grid::unit(1.5, "cm")), annotation_name_gp = grid::gpar(fontsize = text.size), 150 | set_name = ComplexHeatmap::anno_text(ComplexHeatmap::set_name(m), 151 | location = 0.5, 152 | just = "center", 153 | gp = grid::gpar(fontsize = text.size), 154 | width = ComplexHeatmap::max_text_width(text = ComplexHeatmap::set_name(m), 155 | gp = grid::gpar(fontsize = text.size)) + grid::unit(1, "mm"))), 156 | right_annotation = NULL, 157 | show_row_names = FALSE, ...) 158 | 159 | plot_upset <- function(){ 160 | ht <- ComplexHeatmap::draw(ht) 161 | od <- ComplexHeatmap::column_order(ht) 162 | ComplexHeatmap::decorate_annotation("Intersections", { 163 | grid::grid.text(cs[od], x = seq_along(cs), y = grid::unit(cs[od], "native") + grid::unit(2, "pt"), 164 | default.units = "native", just = c("left", "bottom"), 165 | gp = grid::gpar(fontsize = 6, col = "black"), rot = 45) 166 | }) 167 | 168 | } 169 | 170 | upset.plot <- grid::grid.grabExpr(plot_upset()) %>% 171 | ggplotify::as.ggplot() 172 | return(upset.plot) 173 | } 174 | 175 | -------------------------------------------------------------------------------- /R/irGSEA.vlnplot.R: -------------------------------------------------------------------------------- 1 | #' Half vlnplot 2 | #' 3 | #' Easy to show the data distribution by half vlnplot 4 | #' 5 | #' @param object A Seurat after perform \code{\link{irGSEA.score}} 6 | #' @param method A character. It should be one or more of the followling : AUCell, 7 | #' UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, 8 | #' plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2. 9 | #' @param show.geneset A character. It should be one of the rownames of 10 | #' enrichment score matrix. 11 | #' @param group.by Default ident when it is set to NULL. You can specify other 12 | #' column of metadata. 13 | #' @param color.cluster A vector. Default "ggsci::pal_igv()(the number of colnames 14 | #' of enrichment score matrix)" when it is set to NULL. 15 | #' @param cluster.levels A vector equal to the number of clusters. 16 | #' 17 | #' @return vlnplot 18 | #' @export 19 | #' 20 | #' @examples 21 | #' \dontrun{ 22 | #' # load PBMC dataset by R package SeuratData 23 | #' library(Seurat) 24 | #' library(SeuratData) 25 | #' # download 3k PBMCs from 10X Genomics 26 | #' InstallData("pbmc3k") 27 | #' data("pbmc3k.final") 28 | #' pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 29 | #' 30 | #' # Seurat object 31 | #' pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 32 | #' slot = "data", msigdb = T, species = "Homo sapiens", 33 | #' category = "H", geneid = "symbol", 34 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 35 | #' 36 | #' irGSEA.vlnplot.plot1 <- irGSEA.vlnplot(object = pbmc3k.final, 37 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 38 | #' show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 39 | #' irGSEA.vlnplot.plot2 <- irGSEA.vlnplot(object = pbmc3k.final, 40 | #' method = c("AUCell", "UCell", "singscore", "ssgsea"), 41 | #' show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 42 | #' 43 | #' 44 | #' } 45 | #' 46 | irGSEA.vlnplot <- function(object = NULL, method = NULL, 47 | show.geneset = NULL, group.by = NULL, 48 | color.cluster = NULL, cluster.levels = NULL){ 49 | # pretreatment 50 | ident <- NULL 51 | geneset <- NULL 52 | if ((! all(method %in% Seurat::Assays(object))) |(purrr::is_null(method))) { 53 | stop("`method` should be one or more of the followling : AUCell, UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2.") 54 | } 55 | 56 | # group 57 | if (purrr::is_null(group.by)) { 58 | anno.ident <- SeuratObject::Idents(object) 59 | }else{ 60 | object <- SeuratObject::SetIdent(object, value = group.by) 61 | anno.ident <- SeuratObject::Idents(object) 62 | } 63 | # factors are sorted alphabetically 64 | anno.ident <- as.factor(as.character(anno.ident)) 65 | # set levels of cluster 66 | if (! purrr::is_null(cluster.levels)) { 67 | anno.ident <- factor(anno.ident, levels = cluster.levels) 68 | } 69 | SeuratObject::Idents(object) <- anno.ident 70 | 71 | # set colors 72 | if (purrr::is_null(color.cluster)) { 73 | color.cluster <- ggsci::pal_igv()(length(levels(object))) 74 | } 75 | 76 | # geneset 77 | if (purrr::is_null(show.geneset)) { 78 | stop("`show.geneset` can not be empty.") 79 | } 80 | 81 | # plot 82 | for (i in method) { 83 | object@meta.data <- object@meta.data %>% 84 | dplyr::mutate(!!rlang::sym(i):= as.numeric(SeuratObject::GetAssayData(object, assay = i, slot = "scale.data")[show.geneset,])) 85 | } 86 | scores.vlnplot <- Seurat::VlnPlot(object = object, 87 | assay = "RNA", 88 | combine = T, 89 | stack = T, 90 | flip = T, 91 | group.by = group.by, 92 | cols = color.cluster, 93 | features = method, 94 | pt.size = 0, 95 | fill.by = "ident")+ 96 | ggplot2::ggtitle(show.geneset)+ 97 | ggplot2::theme(axis.title.x = ggplot2::element_blank(), 98 | plot.title = ggplot2::element_text(hjust = 0.5), 99 | title = ggplot2::element_text(size =12), 100 | axis.text.x = ggplot2::element_text(vjust = 0.5, hjust = 0.5, angle = 45))+ 101 | ggplot2::guides(fill = ggplot2::guide_legend(title = "Cluster")) 102 | 103 | 104 | return(scores.vlnplot) 105 | 106 | } 107 | 108 | 109 | -------------------------------------------------------------------------------- /R/utils-pipe.R: -------------------------------------------------------------------------------- 1 | #' Pipe operator 2 | #' 3 | #' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 4 | #' 5 | #' @name %>% 6 | #' @rdname pipe 7 | #' @keywords internal 8 | #' @export 9 | #' @importFrom magrittr %>% 10 | #' @usage lhs \%>\% rhs 11 | #' @param lhs A value or the magrittr placeholder. 12 | #' @param rhs A function call using the magrittr semantics. 13 | #' @return The result of calling `rhs(lhs)`. 14 | NULL 15 | -------------------------------------------------------------------------------- /R/utils-tidy-eval.R: -------------------------------------------------------------------------------- 1 | #' Tidy eval helpers 2 | #' 3 | #' @description 4 | #' This page lists the tidy eval tools reexported in this package from 5 | #' rlang. To learn about using tidy eval in scripts and packages at a 6 | #' high level, see the [dplyr programming 7 | #' vignette](https://dplyr.tidyverse.org/articles/programming.html) 8 | #' and the [ggplot2 in packages 9 | #' vignette](https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html). 10 | #' The [Metaprogramming 11 | #' section](https://adv-r.hadley.nz/metaprogramming.html) of [Advanced 12 | #' R](https://adv-r.hadley.nz) may also be useful for a deeper dive. 13 | #' 14 | #' * The tidy eval operators `{{`, `!!`, and `!!!` are syntactic 15 | #' constructs which are specially interpreted by tidy eval functions. 16 | #' You will mostly need `{{`, as `!!` and `!!!` are more advanced 17 | #' operators which you should not have to use in simple cases. 18 | #' 19 | #' The curly-curly operator `{{` allows you to tunnel data-variables 20 | #' passed from function arguments inside other tidy eval functions. 21 | #' `{{` is designed for individual arguments. To pass multiple 22 | #' arguments contained in dots, use `...` in the normal way. 23 | #' 24 | #' ``` 25 | #' my_function <- function(data, var, ...) { 26 | #' data %>% 27 | #' group_by(...) %>% 28 | #' summarise(mean = mean({{ var }})) 29 | #' } 30 | #' ``` 31 | #' 32 | #' * [enquo()] and [enquos()] delay the execution of one or several 33 | #' function arguments. The former returns a single expression, the 34 | #' latter returns a list of expressions. Once defused, expressions 35 | #' will no longer evaluate on their own. They must be injected back 36 | #' into an evaluation context with `!!` (for a single expression) and 37 | #' `!!!` (for a list of expressions). 38 | #' 39 | #' ``` 40 | #' my_function <- function(data, var, ...) { 41 | #' # Defuse 42 | #' var <- enquo(var) 43 | #' dots <- enquos(...) 44 | #' 45 | #' # Inject 46 | #' data %>% 47 | #' group_by(!!!dots) %>% 48 | #' summarise(mean = mean(!!var)) 49 | #' } 50 | #' ``` 51 | #' 52 | #' In this simple case, the code is equivalent to the usage of `{{` 53 | #' and `...` above. Defusing with `enquo()` or `enquos()` is only 54 | #' needed in more complex cases, for instance if you need to inspect 55 | #' or modify the expressions in some way. 56 | #' 57 | #' * The `.data` pronoun is an object that represents the current 58 | #' slice of data. If you have a variable name in a string, use the 59 | #' `.data` pronoun to subset that variable with `[[`. 60 | #' 61 | #' ``` 62 | #' my_var <- "disp" 63 | #' mtcars %>% summarise(mean = mean(.data[[my_var]])) 64 | #' ``` 65 | #' 66 | #' * Another tidy eval operator is `:=`. It makes it possible to use 67 | #' glue and curly-curly syntax on the LHS of `=`. For technical 68 | #' reasons, the R language doesn't support complex expressions on 69 | #' the left of `=`, so we use `:=` as a workaround. 70 | #' 71 | #' ``` 72 | #' my_function <- function(data, var, suffix = "foo") { 73 | #' # Use `{{` to tunnel function arguments and the usual glue 74 | #' # operator `{` to interpolate plain strings. 75 | #' data %>% 76 | #' summarise("{{ var }}_mean_{suffix}" := mean({{ var }})) 77 | #' } 78 | #' ``` 79 | #' 80 | #' * Many tidy eval functions like `dplyr::mutate()` or 81 | #' `dplyr::summarise()` give an automatic name to unnamed inputs. If 82 | #' you need to create the same sort of automatic names by yourself, 83 | #' use `as_label()`. For instance, the glue-tunnelling syntax above 84 | #' can be reproduced manually with: 85 | #' 86 | #' ``` 87 | #' my_function <- function(data, var, suffix = "foo") { 88 | #' var <- enquo(var) 89 | #' prefix <- as_label(var) 90 | #' data %>% 91 | #' summarise("{prefix}_mean_{suffix}" := mean(!!var)) 92 | #' } 93 | #' ``` 94 | #' 95 | #' Expressions defused with `enquo()` (or tunnelled with `{{`) need 96 | #' not be simple column names, they can be arbitrarily complex. 97 | #' `as_label()` handles those cases gracefully. If your code assumes 98 | #' a simple column name, use `as_name()` instead. This is safer 99 | #' because it throws an error if the input is not a name as expected. 100 | #' 101 | #' @md 102 | #' @name tidyeval 103 | #' @keywords internal 104 | #' @importFrom rlang enquo enquos .data := as_name as_label 105 | #' @aliases enquo enquos .data := as_name as_label 106 | #' @export enquo enquos .data := as_name as_label 107 | NULL 108 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/_pkgdown.yml -------------------------------------------------------------------------------- /docs/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Page not found (404) • irGSEA 9 | 10 | 11 | 12 | 13 | 14 | 15 | 19 | 20 | 21 | 22 | 23 |
24 |
58 | 59 | 60 | 61 | 62 |
63 |
64 | 67 | 68 | Content not found. Please use links in the navbar. 69 | 70 |
71 | 72 | 76 | 77 |
78 | 79 | 80 | 81 | 92 |
93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | -------------------------------------------------------------------------------- /docs/LICENSE-text.html: -------------------------------------------------------------------------------- 1 | 2 | License • irGSEA 6 | 7 | 8 |
9 |
37 | 38 | 39 | 40 |
41 |
42 | 45 | 46 |
YEAR: 2021
47 | COPYRIGHT HOLDER: Chuiqin Fan
48 | 
49 | 50 |
51 | 52 | 55 | 56 |
57 | 58 | 59 | 60 |
69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /docs/LICENSE.html: -------------------------------------------------------------------------------- 1 | 2 | MIT License • irGSEA 6 | 7 | 8 |
9 |
37 | 38 | 39 | 40 |
41 |
42 | 45 | 46 |
47 | 48 |

Copyright (c) 2021 Chuiqin Fan

49 |

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

50 |

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

51 |

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

52 |
53 | 54 |
55 | 56 | 59 | 60 |
61 | 62 | 63 | 64 |
73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /docs/authors.html: -------------------------------------------------------------------------------- 1 | 2 | Authors and Citation • irGSEA 6 | 7 | 8 |
9 |
37 | 38 | 39 | 40 |
41 |
42 |
43 | 46 | 47 | 48 |
  • 49 |

    Chuiqin Fan. Maintainer. 50 |

    51 |
  • 52 |
53 |
54 |
55 |

Citation

56 | Source: DESCRIPTION 57 |
58 |
59 | 60 | 61 |

Fan C (2024). 62 | irGSEA: The integration of single cell rank-based gene set enrichment analysis. 63 | R package version 3.2.2, https://github.com/chuiqin/irGSEA. 64 |

65 |
@Manual{,
66 |   title = {irGSEA: The integration of single cell rank-based gene set enrichment analysis},
67 |   author = {Chuiqin Fan},
68 |   year = {2024},
69 |   note = {R package version 3.2.2},
70 |   url = {https://github.com/chuiqin/irGSEA},
71 | }
72 | 73 |
74 | 75 |
76 | 77 | 78 | 79 |
88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.css: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | 6 | /* modified from https://github.com/twbs/bootstrap/blob/94b4076dd2efba9af71f0b18d4ee4b163aa9e0dd/docs/assets/css/src/docs.css#L548-L601 */ 7 | 8 | /* All levels of nav */ 9 | nav[data-toggle='toc'] .nav > li > a { 10 | display: block; 11 | padding: 4px 20px; 12 | font-size: 13px; 13 | font-weight: 500; 14 | color: #767676; 15 | } 16 | nav[data-toggle='toc'] .nav > li > a:hover, 17 | nav[data-toggle='toc'] .nav > li > a:focus { 18 | padding-left: 19px; 19 | color: #563d7c; 20 | text-decoration: none; 21 | background-color: transparent; 22 | border-left: 1px solid #563d7c; 23 | } 24 | nav[data-toggle='toc'] .nav > .active > a, 25 | nav[data-toggle='toc'] .nav > .active:hover > a, 26 | nav[data-toggle='toc'] .nav > .active:focus > a { 27 | padding-left: 18px; 28 | font-weight: bold; 29 | color: #563d7c; 30 | background-color: transparent; 31 | border-left: 2px solid #563d7c; 32 | } 33 | 34 | /* Nav: second level (shown on .active) */ 35 | nav[data-toggle='toc'] .nav .nav { 36 | display: none; /* Hide by default, but at >768px, show it */ 37 | padding-bottom: 10px; 38 | } 39 | nav[data-toggle='toc'] .nav .nav > li > a { 40 | padding-top: 1px; 41 | padding-bottom: 1px; 42 | padding-left: 30px; 43 | font-size: 12px; 44 | font-weight: normal; 45 | } 46 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 47 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 48 | padding-left: 29px; 49 | } 50 | nav[data-toggle='toc'] .nav .nav > .active > a, 51 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 52 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 53 | padding-left: 28px; 54 | font-weight: 500; 55 | } 56 | 57 | /* from https://github.com/twbs/bootstrap/blob/e38f066d8c203c3e032da0ff23cd2d6098ee2dd6/docs/assets/css/src/docs.css#L631-L634 */ 58 | nav[data-toggle='toc'] .nav > .active > ul { 59 | display: block; 60 | } 61 | -------------------------------------------------------------------------------- /docs/bootstrap-toc.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * Bootstrap Table of Contents v0.4.1 (http://afeld.github.io/bootstrap-toc/) 3 | * Copyright 2015 Aidan Feldman 4 | * Licensed under MIT (https://github.com/afeld/bootstrap-toc/blob/gh-pages/LICENSE.md) */ 5 | (function() { 6 | 'use strict'; 7 | 8 | window.Toc = { 9 | helpers: { 10 | // return all matching elements in the set, or their descendants 11 | findOrFilter: function($el, selector) { 12 | // http://danielnouri.org/notes/2011/03/14/a-jquery-find-that-also-finds-the-root-element/ 13 | // http://stackoverflow.com/a/12731439/358804 14 | var $descendants = $el.find(selector); 15 | return $el.filter(selector).add($descendants).filter(':not([data-toc-skip])'); 16 | }, 17 | 18 | generateUniqueIdBase: function(el) { 19 | var text = $(el).text(); 20 | var anchor = text.trim().toLowerCase().replace(/[^A-Za-z0-9]+/g, '-'); 21 | return anchor || el.tagName.toLowerCase(); 22 | }, 23 | 24 | generateUniqueId: function(el) { 25 | var anchorBase = this.generateUniqueIdBase(el); 26 | for (var i = 0; ; i++) { 27 | var anchor = anchorBase; 28 | if (i > 0) { 29 | // add suffix 30 | anchor += '-' + i; 31 | } 32 | // check if ID already exists 33 | if (!document.getElementById(anchor)) { 34 | return anchor; 35 | } 36 | } 37 | }, 38 | 39 | generateAnchor: function(el) { 40 | if (el.id) { 41 | return el.id; 42 | } else { 43 | var anchor = this.generateUniqueId(el); 44 | el.id = anchor; 45 | return anchor; 46 | } 47 | }, 48 | 49 | createNavList: function() { 50 | return $(''); 51 | }, 52 | 53 | createChildNavList: function($parent) { 54 | var $childList = this.createNavList(); 55 | $parent.append($childList); 56 | return $childList; 57 | }, 58 | 59 | generateNavEl: function(anchor, text) { 60 | var $a = $(''); 61 | $a.attr('href', '#' + anchor); 62 | $a.text(text); 63 | var $li = $('
  • '); 64 | $li.append($a); 65 | return $li; 66 | }, 67 | 68 | generateNavItem: function(headingEl) { 69 | var anchor = this.generateAnchor(headingEl); 70 | var $heading = $(headingEl); 71 | var text = $heading.data('toc-text') || $heading.text(); 72 | return this.generateNavEl(anchor, text); 73 | }, 74 | 75 | // Find the first heading level (`

    `, then `

    `, etc.) that has more than one element. Defaults to 1 (for `

    `). 76 | getTopLevel: function($scope) { 77 | for (var i = 1; i <= 6; i++) { 78 | var $headings = this.findOrFilter($scope, 'h' + i); 79 | if ($headings.length > 1) { 80 | return i; 81 | } 82 | } 83 | 84 | return 1; 85 | }, 86 | 87 | // returns the elements for the top level, and the next below it 88 | getHeadings: function($scope, topLevel) { 89 | var topSelector = 'h' + topLevel; 90 | 91 | var secondaryLevel = topLevel + 1; 92 | var secondarySelector = 'h' + secondaryLevel; 93 | 94 | return this.findOrFilter($scope, topSelector + ',' + secondarySelector); 95 | }, 96 | 97 | getNavLevel: function(el) { 98 | return parseInt(el.tagName.charAt(1), 10); 99 | }, 100 | 101 | populateNav: function($topContext, topLevel, $headings) { 102 | var $context = $topContext; 103 | var $prevNav; 104 | 105 | var helpers = this; 106 | $headings.each(function(i, el) { 107 | var $newNav = helpers.generateNavItem(el); 108 | var navLevel = helpers.getNavLevel(el); 109 | 110 | // determine the proper $context 111 | if (navLevel === topLevel) { 112 | // use top level 113 | $context = $topContext; 114 | } else if ($prevNav && $context === $topContext) { 115 | // create a new level of the tree and switch to it 116 | $context = helpers.createChildNavList($prevNav); 117 | } // else use the current $context 118 | 119 | $context.append($newNav); 120 | 121 | $prevNav = $newNav; 122 | }); 123 | }, 124 | 125 | parseOps: function(arg) { 126 | var opts; 127 | if (arg.jquery) { 128 | opts = { 129 | $nav: arg 130 | }; 131 | } else { 132 | opts = arg; 133 | } 134 | opts.$scope = opts.$scope || $(document.body); 135 | return opts; 136 | } 137 | }, 138 | 139 | // accepts a jQuery object, or an options object 140 | init: function(opts) { 141 | opts = this.helpers.parseOps(opts); 142 | 143 | // ensure that the data attribute is in place for styling 144 | opts.$nav.attr('data-toggle', 'toc'); 145 | 146 | var $topContext = this.helpers.createChildNavList(opts.$nav); 147 | var topLevel = this.helpers.getTopLevel(opts.$scope); 148 | var $headings = this.helpers.getHeadings(opts.$scope, topLevel); 149 | this.helpers.populateNav($topContext, topLevel, $headings); 150 | } 151 | }; 152 | 153 | $(function() { 154 | $('nav[data-toggle="toc"]').each(function(i, el) { 155 | var $nav = $(el); 156 | Toc.init($nav); 157 | }); 158 | }); 159 | })(); 160 | -------------------------------------------------------------------------------- /docs/docsearch.js: -------------------------------------------------------------------------------- 1 | $(function() { 2 | 3 | // register a handler to move the focus to the search bar 4 | // upon pressing shift + "/" (i.e. "?") 5 | $(document).on('keydown', function(e) { 6 | if (e.shiftKey && e.keyCode == 191) { 7 | e.preventDefault(); 8 | $("#search-input").focus(); 9 | } 10 | }); 11 | 12 | $(document).ready(function() { 13 | // do keyword highlighting 14 | /* modified from https://jsfiddle.net/julmot/bL6bb5oo/ */ 15 | var mark = function() { 16 | 17 | var referrer = document.URL ; 18 | var paramKey = "q" ; 19 | 20 | if (referrer.indexOf("?") !== -1) { 21 | var qs = referrer.substr(referrer.indexOf('?') + 1); 22 | var qs_noanchor = qs.split('#')[0]; 23 | var qsa = qs_noanchor.split('&'); 24 | var keyword = ""; 25 | 26 | for (var i = 0; i < qsa.length; i++) { 27 | var currentParam = qsa[i].split('='); 28 | 29 | if (currentParam.length !== 2) { 30 | continue; 31 | } 32 | 33 | if (currentParam[0] == paramKey) { 34 | keyword = decodeURIComponent(currentParam[1].replace(/\+/g, "%20")); 35 | } 36 | } 37 | 38 | if (keyword !== "") { 39 | $(".contents").unmark({ 40 | done: function() { 41 | $(".contents").mark(keyword); 42 | } 43 | }); 44 | } 45 | } 46 | }; 47 | 48 | mark(); 49 | }); 50 | }); 51 | 52 | /* Search term highlighting ------------------------------*/ 53 | 54 | function matchedWords(hit) { 55 | var words = []; 56 | 57 | var hierarchy = hit._highlightResult.hierarchy; 58 | // loop to fetch from lvl0, lvl1, etc. 59 | for (var idx in hierarchy) { 60 | words = words.concat(hierarchy[idx].matchedWords); 61 | } 62 | 63 | var content = hit._highlightResult.content; 64 | if (content) { 65 | words = words.concat(content.matchedWords); 66 | } 67 | 68 | // return unique words 69 | var words_uniq = [...new Set(words)]; 70 | return words_uniq; 71 | } 72 | 73 | function updateHitURL(hit) { 74 | 75 | var words = matchedWords(hit); 76 | var url = ""; 77 | 78 | if (hit.anchor) { 79 | url = hit.url_without_anchor + '?q=' + escape(words.join(" ")) + '#' + hit.anchor; 80 | } else { 81 | url = hit.url + '?q=' + escape(words.join(" ")); 82 | } 83 | 84 | return url; 85 | } 86 | -------------------------------------------------------------------------------- /docs/link.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 8 | 12 | 13 | -------------------------------------------------------------------------------- /docs/pkgdown.css: -------------------------------------------------------------------------------- 1 | /* Sticky footer */ 2 | 3 | /** 4 | * Basic idea: https://philipwalton.github.io/solved-by-flexbox/demos/sticky-footer/ 5 | * Details: https://github.com/philipwalton/solved-by-flexbox/blob/master/assets/css/components/site.css 6 | * 7 | * .Site -> body > .container 8 | * .Site-content -> body > .container .row 9 | * .footer -> footer 10 | * 11 | * Key idea seems to be to ensure that .container and __all its parents__ 12 | * have height set to 100% 13 | * 14 | */ 15 | 16 | html, body { 17 | height: 100%; 18 | } 19 | 20 | body { 21 | position: relative; 22 | } 23 | 24 | body > .container { 25 | display: flex; 26 | height: 100%; 27 | flex-direction: column; 28 | } 29 | 30 | body > .container .row { 31 | flex: 1 0 auto; 32 | } 33 | 34 | footer { 35 | margin-top: 45px; 36 | padding: 35px 0 36px; 37 | border-top: 1px solid #e5e5e5; 38 | color: #666; 39 | display: flex; 40 | flex-shrink: 0; 41 | } 42 | footer p { 43 | margin-bottom: 0; 44 | } 45 | footer div { 46 | flex: 1; 47 | } 48 | footer .pkgdown { 49 | text-align: right; 50 | } 51 | footer p { 52 | margin-bottom: 0; 53 | } 54 | 55 | img.icon { 56 | float: right; 57 | } 58 | 59 | /* Ensure in-page images don't run outside their container */ 60 | .contents img { 61 | max-width: 100%; 62 | height: auto; 63 | } 64 | 65 | /* Fix bug in bootstrap (only seen in firefox) */ 66 | summary { 67 | display: list-item; 68 | } 69 | 70 | /* Typographic tweaking ---------------------------------*/ 71 | 72 | .contents .page-header { 73 | margin-top: calc(-60px + 1em); 74 | } 75 | 76 | dd { 77 | margin-left: 3em; 78 | } 79 | 80 | /* Section anchors ---------------------------------*/ 81 | 82 | a.anchor { 83 | display: none; 84 | margin-left: 5px; 85 | width: 20px; 86 | height: 20px; 87 | 88 | background-image: url(./link.svg); 89 | background-repeat: no-repeat; 90 | background-size: 20px 20px; 91 | background-position: center center; 92 | } 93 | 94 | h1:hover .anchor, 95 | h2:hover .anchor, 96 | h3:hover .anchor, 97 | h4:hover .anchor, 98 | h5:hover .anchor, 99 | h6:hover .anchor { 100 | display: inline-block; 101 | } 102 | 103 | /* Fixes for fixed navbar --------------------------*/ 104 | 105 | .contents h1, .contents h2, .contents h3, .contents h4 { 106 | padding-top: 60px; 107 | margin-top: -40px; 108 | } 109 | 110 | /* Navbar submenu --------------------------*/ 111 | 112 | .dropdown-submenu { 113 | position: relative; 114 | } 115 | 116 | .dropdown-submenu>.dropdown-menu { 117 | top: 0; 118 | left: 100%; 119 | margin-top: -6px; 120 | margin-left: -1px; 121 | border-radius: 0 6px 6px 6px; 122 | } 123 | 124 | .dropdown-submenu:hover>.dropdown-menu { 125 | display: block; 126 | } 127 | 128 | .dropdown-submenu>a:after { 129 | display: block; 130 | content: " "; 131 | float: right; 132 | width: 0; 133 | height: 0; 134 | border-color: transparent; 135 | border-style: solid; 136 | border-width: 5px 0 5px 5px; 137 | border-left-color: #cccccc; 138 | margin-top: 5px; 139 | margin-right: -10px; 140 | } 141 | 142 | .dropdown-submenu:hover>a:after { 143 | border-left-color: #ffffff; 144 | } 145 | 146 | .dropdown-submenu.pull-left { 147 | float: none; 148 | } 149 | 150 | .dropdown-submenu.pull-left>.dropdown-menu { 151 | left: -100%; 152 | margin-left: 10px; 153 | border-radius: 6px 0 6px 6px; 154 | } 155 | 156 | /* Sidebar --------------------------*/ 157 | 158 | #pkgdown-sidebar { 159 | margin-top: 30px; 160 | position: -webkit-sticky; 161 | position: sticky; 162 | top: 70px; 163 | } 164 | 165 | #pkgdown-sidebar h2 { 166 | font-size: 1.5em; 167 | margin-top: 1em; 168 | } 169 | 170 | #pkgdown-sidebar h2:first-child { 171 | margin-top: 0; 172 | } 173 | 174 | #pkgdown-sidebar .list-unstyled li { 175 | margin-bottom: 0.5em; 176 | } 177 | 178 | /* bootstrap-toc tweaks ------------------------------------------------------*/ 179 | 180 | /* All levels of nav */ 181 | 182 | nav[data-toggle='toc'] .nav > li > a { 183 | padding: 4px 20px 4px 6px; 184 | font-size: 1.5rem; 185 | font-weight: 400; 186 | color: inherit; 187 | } 188 | 189 | nav[data-toggle='toc'] .nav > li > a:hover, 190 | nav[data-toggle='toc'] .nav > li > a:focus { 191 | padding-left: 5px; 192 | color: inherit; 193 | border-left: 1px solid #878787; 194 | } 195 | 196 | nav[data-toggle='toc'] .nav > .active > a, 197 | nav[data-toggle='toc'] .nav > .active:hover > a, 198 | nav[data-toggle='toc'] .nav > .active:focus > a { 199 | padding-left: 5px; 200 | font-size: 1.5rem; 201 | font-weight: 400; 202 | color: inherit; 203 | border-left: 2px solid #878787; 204 | } 205 | 206 | /* Nav: second level (shown on .active) */ 207 | 208 | nav[data-toggle='toc'] .nav .nav { 209 | display: none; /* Hide by default, but at >768px, show it */ 210 | padding-bottom: 10px; 211 | } 212 | 213 | nav[data-toggle='toc'] .nav .nav > li > a { 214 | padding-left: 16px; 215 | font-size: 1.35rem; 216 | } 217 | 218 | nav[data-toggle='toc'] .nav .nav > li > a:hover, 219 | nav[data-toggle='toc'] .nav .nav > li > a:focus { 220 | padding-left: 15px; 221 | } 222 | 223 | nav[data-toggle='toc'] .nav .nav > .active > a, 224 | nav[data-toggle='toc'] .nav .nav > .active:hover > a, 225 | nav[data-toggle='toc'] .nav .nav > .active:focus > a { 226 | padding-left: 15px; 227 | font-weight: 500; 228 | font-size: 1.35rem; 229 | } 230 | 231 | /* orcid ------------------------------------------------------------------- */ 232 | 233 | .orcid { 234 | font-size: 16px; 235 | color: #A6CE39; 236 | /* margins are required by official ORCID trademark and display guidelines */ 237 | margin-left:4px; 238 | margin-right:4px; 239 | vertical-align: middle; 240 | } 241 | 242 | /* Reference index & topics ----------------------------------------------- */ 243 | 244 | .ref-index th {font-weight: normal;} 245 | 246 | .ref-index td {vertical-align: top; min-width: 100px} 247 | .ref-index .icon {width: 40px;} 248 | .ref-index .alias {width: 40%;} 249 | .ref-index-icons .alias {width: calc(40% - 40px);} 250 | .ref-index .title {width: 60%;} 251 | 252 | .ref-arguments th {text-align: right; padding-right: 10px;} 253 | .ref-arguments th, .ref-arguments td {vertical-align: top; min-width: 100px} 254 | .ref-arguments .name {width: 20%;} 255 | .ref-arguments .desc {width: 80%;} 256 | 257 | /* Nice scrolling for wide elements --------------------------------------- */ 258 | 259 | table { 260 | display: block; 261 | overflow: auto; 262 | } 263 | 264 | /* Syntax highlighting ---------------------------------------------------- */ 265 | 266 | pre, code, pre code { 267 | background-color: #f8f8f8; 268 | color: #333; 269 | } 270 | pre, pre code { 271 | white-space: pre-wrap; 272 | word-break: break-all; 273 | overflow-wrap: break-word; 274 | } 275 | 276 | pre { 277 | border: 1px solid #eee; 278 | } 279 | 280 | pre .img, pre .r-plt { 281 | margin: 5px 0; 282 | } 283 | 284 | pre .img img, pre .r-plt img { 285 | background-color: #fff; 286 | } 287 | 288 | code a, pre a { 289 | color: #375f84; 290 | } 291 | 292 | a.sourceLine:hover { 293 | text-decoration: none; 294 | } 295 | 296 | .fl {color: #1514b5;} 297 | .fu {color: #000000;} /* function */ 298 | .ch,.st {color: #036a07;} /* string */ 299 | .kw {color: #264D66;} /* keyword */ 300 | .co {color: #888888;} /* comment */ 301 | 302 | .error {font-weight: bolder;} 303 | .warning {font-weight: bolder;} 304 | 305 | /* Clipboard --------------------------*/ 306 | 307 | .hasCopyButton { 308 | position: relative; 309 | } 310 | 311 | .btn-copy-ex { 312 | position: absolute; 313 | right: 0; 314 | top: 0; 315 | visibility: hidden; 316 | } 317 | 318 | .hasCopyButton:hover button.btn-copy-ex { 319 | visibility: visible; 320 | } 321 | 322 | /* headroom.js ------------------------ */ 323 | 324 | .headroom { 325 | will-change: transform; 326 | transition: transform 200ms linear; 327 | } 328 | .headroom--pinned { 329 | transform: translateY(0%); 330 | } 331 | .headroom--unpinned { 332 | transform: translateY(-100%); 333 | } 334 | 335 | /* mark.js ----------------------------*/ 336 | 337 | mark { 338 | background-color: rgba(255, 255, 51, 0.5); 339 | border-bottom: 2px solid rgba(255, 153, 51, 0.3); 340 | padding: 1px; 341 | } 342 | 343 | /* vertical spacing after htmlwidgets */ 344 | .html-widget { 345 | margin-bottom: 10px; 346 | } 347 | 348 | /* fontawesome ------------------------ */ 349 | 350 | .fab { 351 | font-family: "Font Awesome 5 Brands" !important; 352 | } 353 | 354 | /* don't display links in code chunks when printing */ 355 | /* source: https://stackoverflow.com/a/10781533 */ 356 | @media print { 357 | code a:link:after, code a:visited:after { 358 | content: ""; 359 | } 360 | } 361 | 362 | /* Section anchors --------------------------------- 363 | Added in pandoc 2.11: https://github.com/jgm/pandoc-templates/commit/9904bf71 364 | */ 365 | 366 | div.csl-bib-body { } 367 | div.csl-entry { 368 | clear: both; 369 | } 370 | .hanging-indent div.csl-entry { 371 | margin-left:2em; 372 | text-indent:-2em; 373 | } 374 | div.csl-left-margin { 375 | min-width:2em; 376 | float:left; 377 | } 378 | div.csl-right-inline { 379 | margin-left:2em; 380 | padding-left:1em; 381 | } 382 | div.csl-indent { 383 | margin-left: 2em; 384 | } 385 | -------------------------------------------------------------------------------- /docs/pkgdown.js: -------------------------------------------------------------------------------- 1 | /* http://gregfranko.com/blog/jquery-best-practices/ */ 2 | (function($) { 3 | $(function() { 4 | 5 | $('.navbar-fixed-top').headroom(); 6 | 7 | $('body').css('padding-top', $('.navbar').height() + 10); 8 | $(window).resize(function(){ 9 | $('body').css('padding-top', $('.navbar').height() + 10); 10 | }); 11 | 12 | $('[data-toggle="tooltip"]').tooltip(); 13 | 14 | var cur_path = paths(location.pathname); 15 | var links = $("#navbar ul li a"); 16 | var max_length = -1; 17 | var pos = -1; 18 | for (var i = 0; i < links.length; i++) { 19 | if (links[i].getAttribute("href") === "#") 20 | continue; 21 | // Ignore external links 22 | if (links[i].host !== location.host) 23 | continue; 24 | 25 | var nav_path = paths(links[i].pathname); 26 | 27 | var length = prefix_length(nav_path, cur_path); 28 | if (length > max_length) { 29 | max_length = length; 30 | pos = i; 31 | } 32 | } 33 | 34 | // Add class to parent
  • , and enclosing
  • if in dropdown 35 | if (pos >= 0) { 36 | var menu_anchor = $(links[pos]); 37 | menu_anchor.parent().addClass("active"); 38 | menu_anchor.closest("li.dropdown").addClass("active"); 39 | } 40 | }); 41 | 42 | function paths(pathname) { 43 | var pieces = pathname.split("/"); 44 | pieces.shift(); // always starts with / 45 | 46 | var end = pieces[pieces.length - 1]; 47 | if (end === "index.html" || end === "") 48 | pieces.pop(); 49 | return(pieces); 50 | } 51 | 52 | // Returns -1 if not found 53 | function prefix_length(needle, haystack) { 54 | if (needle.length > haystack.length) 55 | return(-1); 56 | 57 | // Special case for length-0 haystack, since for loop won't run 58 | if (haystack.length === 0) { 59 | return(needle.length === 0 ? 0 : -1); 60 | } 61 | 62 | for (var i = 0; i < haystack.length; i++) { 63 | if (needle[i] != haystack[i]) 64 | return(i); 65 | } 66 | 67 | return(haystack.length); 68 | } 69 | 70 | /* Clipboard --------------------------*/ 71 | 72 | function changeTooltipMessage(element, msg) { 73 | var tooltipOriginalTitle=element.getAttribute('data-original-title'); 74 | element.setAttribute('data-original-title', msg); 75 | $(element).tooltip('show'); 76 | element.setAttribute('data-original-title', tooltipOriginalTitle); 77 | } 78 | 79 | if(ClipboardJS.isSupported()) { 80 | $(document).ready(function() { 81 | var copyButton = ""; 82 | 83 | $("div.sourceCode").addClass("hasCopyButton"); 84 | 85 | // Insert copy buttons: 86 | $(copyButton).prependTo(".hasCopyButton"); 87 | 88 | // Initialize tooltips: 89 | $('.btn-copy-ex').tooltip({container: 'body'}); 90 | 91 | // Initialize clipboard: 92 | var clipboardBtnCopies = new ClipboardJS('[data-clipboard-copy]', { 93 | text: function(trigger) { 94 | return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); 95 | } 96 | }); 97 | 98 | clipboardBtnCopies.on('success', function(e) { 99 | changeTooltipMessage(e.trigger, 'Copied!'); 100 | e.clearSelection(); 101 | }); 102 | 103 | clipboardBtnCopies.on('error', function() { 104 | changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); 105 | }); 106 | }); 107 | } 108 | })(window.jQuery || window.$) 109 | -------------------------------------------------------------------------------- /docs/pkgdown.yml: -------------------------------------------------------------------------------- 1 | pandoc: 2.19.2 2 | pkgdown: 2.0.7 3 | pkgdown_sha: ~ 4 | articles: {} 5 | last_built: 2024-01-02T04:35Z 6 | 7 | -------------------------------------------------------------------------------- /docs/reference/Rplot001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/Rplot001.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /docs/reference/figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/docs/reference/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /docs/reference/index.html: -------------------------------------------------------------------------------- 1 | 2 | Function reference • irGSEA 6 | 7 | 8 |
    9 |
    37 | 38 | 39 | 40 |
    41 |
    42 | 45 | 46 | 50 | 53 | 54 | 57 | 58 | 61 | 62 | 65 | 66 | 69 | 70 | 73 | 74 | 77 | 78 | 81 | 82 | 85 | 87 | 90 | 91 | 94 | 95 | 98 | 99 |
    47 |

    All functions

    48 |

    49 |
    51 |

    irGSEA.barplot()

    52 |

    Stacked bar plot

    55 |

    irGSEA.bubble()

    56 |

    Bubble plot

    59 |

    irGSEA.density.scatterplot()

    60 |

    Density Scatter plot

    63 |

    irGSEA.densityheatmap()

    64 |

    Density heatmap

    67 |

    irGSEA.halfvlnplot()

    68 |

    Half vlnplot

    71 |

    irGSEA.heatmap()

    72 |

    Heatmap plot

    75 |

    irGSEA.hub()

    76 |

    Calculate the hub gene of the geneset

    79 |

    irGSEA.integrate()

    80 |

    Integrate differential gene set calculated by all enrichment score matrixes

    83 |

    irGSEA.ridgeplot()

    84 |

    Ridge plot 86 | Easy to show the data distribution by ridge plot

    88 |

    irGSEA.score()

    89 |

    Calculate enrichment scores from scRNA-seq data

    92 |

    irGSEA.upset()

    93 |

    Upset plot

    96 |

    irGSEA.vlnplot()

    97 |

    Half vlnplot

    100 | 101 | 104 |
    105 | 106 | 107 |
    110 | 111 |
    112 |

    Site built with pkgdown 2.0.7.

    113 |
    114 | 115 |
    116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /docs/reference/irGSEA.density.scatterplot.html: -------------------------------------------------------------------------------- 1 | 2 | Density Scatter plot — irGSEA.density.scatterplot • irGSEA 6 | 7 | 8 |
    9 |
    37 | 38 | 39 | 40 |
    41 |
    42 | 47 | 48 |
    49 |

    Easy to the data distribution by density scatter plot

    50 |
    51 | 52 |
    53 |
    irGSEA.density.scatterplot(
     54 |   object = NULL,
     55 |   method = NULL,
     56 |   show.geneset = NULL,
     57 |   reduction = "umap",
     58 |   ...
     59 | )
    60 |
    61 | 62 |
    63 |

    Arguments

    64 |
    object
    65 |

    A Seurat after perform irGSEA.score

    66 | 67 | 68 |
    method
    69 |

    A character. It should be one of the followling : AUCell, 70 | UCell, singscore, ssgsea.

    71 | 72 | 73 |
    show.geneset
    74 |

    A character. It should be one of the rownames of 75 | enrichment score matrix.

    76 | 77 | 78 |
    reduction
    79 |

    A character. It can not be empty and should be calculated 80 | in advance.

    81 | 82 | 83 |
    ...
    84 |

    More parameters pass to plot_density

    85 | 86 |
    87 |
    88 |

    Value

    89 | 90 | 91 |

    density scatter plot

    92 |
    93 | 94 |
    95 |

    Examples

    96 |
    if (FALSE) {
     97 | # load PBMC dataset by R package SeuratData
     98 | library(Seurat)
     99 | library(SeuratData)
    100 | # download 3k PBMCs from 10X Genomics
    101 | InstallData("pbmc3k")
    102 | data("pbmc3k.final")
    103 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final)
    104 | 
    105 | # Seurat object
    106 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA",
    107 | slot = "data", msigdb = T, species = "Homo sapiens",
    108 | category = "H", geneid = "symbol",
    109 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian')
    110 | 
    111 | irGSEA.density.scatterplot1 <- irGSEA.density.scatterplot(object = pbmc3k.final,
    112 | method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE",
    113 | reduction = "umap")
    114 | irGSEA.density.scatterplot2 <- irGSEA.density.scatterplot(object = pbmc3k.final,
    115 | method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING",
    116 | reduction = "umap")
    117 | 
    118 | }
    119 | 
    120 | 
    121 | 
    122 |
    123 |
    124 | 127 |
    128 | 129 | 130 |
    133 | 134 |
    135 |

    Site built with pkgdown 2.0.7.

    136 |
    137 | 138 |
    139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | -------------------------------------------------------------------------------- /docs/reference/irGSEA.halfvlnplot.html: -------------------------------------------------------------------------------- 1 | 2 | Half vlnplot — irGSEA.halfvlnplot • irGSEA 6 | 7 | 8 |
    9 |
    37 | 38 | 39 | 40 |
    41 |
    42 | 47 | 48 |
    49 |

    Easy to show the data distribution by half vlnplot

    50 |
    51 | 52 |
    53 |
    irGSEA.halfvlnplot(
     54 |   object = NULL,
     55 |   method = NULL,
     56 |   show.geneset = NULL,
     57 |   group.by = NULL,
     58 |   color.cluster = NULL,
     59 |   cluster.levels = NULL
     60 | )
    61 |
    62 | 63 |
    64 |

    Arguments

    65 |
    object
    66 |

    A Seurat after perform irGSEA.score

    67 | 68 | 69 |
    method
    70 |

    A character. It should be one of the followling : AUCell, 71 | UCell, singscore, ssgsea.

    72 | 73 | 74 |
    show.geneset
    75 |

    A character. It should be one of the rownames of 76 | enrichment score matrix.

    77 | 78 | 79 |
    group.by
    80 |

    Default ident when it is set to NULL. You can specify other 81 | column of metadata.

    82 | 83 | 84 |
    color.cluster
    85 |

    A vector. Default "ggsci::pal_igv()(the number of colnames 86 | of enrichment score matrix)" when it is set to NULL.

    87 | 88 | 89 |
    cluster.levels
    90 |

    A vector equal to the number of clusters.

    91 | 92 |
    93 |
    94 |

    Value

    95 | 96 | 97 |

    half vlnplot

    98 |
    99 | 100 |
    101 |

    Examples

    102 |
    if (FALSE) {
    103 | # load PBMC dataset by R package SeuratData
    104 | library(Seurat)
    105 | library(SeuratData)
    106 | # download 3k PBMCs from 10X Genomics
    107 | InstallData("pbmc3k")
    108 | data("pbmc3k.final")
    109 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final)
    110 | 
    111 | # Seurat object
    112 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA",
    113 | slot = "data", msigdb = T, species = "Homo sapiens",
    114 | category = "H", geneid = "symbol",
    115 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian')
    116 | 
    117 | irGSEA.halfvlnplot.plot1 <- irGSEA.halfvlnplot(object = pbmc3k.final,
    118 | method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE")
    119 | irGSEA.halfvlnplot.plot2 <- irGSEA.halfvlnplot(object = pbmc3k.final,
    120 | method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING")
    121 | 
    122 | 
    123 | }
    124 | 
    125 | 
    126 |
    127 |
    128 | 131 |
    132 | 133 | 134 |
    137 | 138 |
    139 |

    Site built with pkgdown 2.0.7.

    140 |
    141 | 142 |
    143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | -------------------------------------------------------------------------------- /docs/reference/pipe.html: -------------------------------------------------------------------------------- 1 | 2 | Pipe operator — %>% • irGSEA 6 | 7 | 8 |
    9 |
    37 | 38 | 39 | 40 |
    41 |
    42 | 47 | 48 |
    49 |

    See magrittr::%>% for details.

    50 |
    51 | 52 |
    53 |
    lhs %>% rhs
    54 |
    55 | 56 |
    57 |

    Arguments

    58 |
    lhs
    59 |

    A value or the magrittr placeholder.

    60 | 61 | 62 |
    rhs
    63 |

    A function call using the magrittr semantics.

    64 | 65 |
    66 |
    67 |

    Value

    68 | 69 | 70 |

    The result of calling `rhs(lhs)`.

    71 |
    72 | 73 |
    74 | 77 |
    78 | 79 | 80 |
    83 | 84 |
    85 |

    Site built with pkgdown 2.0.7.

    86 |
    87 | 88 |
    89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | -------------------------------------------------------------------------------- /inst/python/gsva.py: -------------------------------------------------------------------------------- 1 | # import 2 | import os 3 | import pandas as pd 4 | import numpy as np 5 | import scanpy as sc 6 | import decoupler as dc 7 | import argparse 8 | from scipy.sparse import csr_matrix 9 | 10 | # Parse the parameters passed in 11 | parser = argparse.ArgumentParser(description=' ') 12 | parser.add_argument('--kcdf', type=str, default = None) 13 | parser.add_argument('--min_n', type=int, default = None) 14 | parser.add_argument('--seed', type=int, default = None) 15 | 16 | args = parser.parse_args() 17 | 18 | # assign 19 | kcdf = args.kcdf 20 | min_n = args.min_n 21 | seed = args.seed 22 | 23 | 24 | 25 | # def function 26 | adata = sc.read_h5ad("./temp.h5ad") 27 | geneset = pd.read_csv("./geneset.csv") 28 | 29 | # dc.run_gsva(mat=adata, net=geneset, source='source', 30 | # target='target', 31 | # kcdf=kcdf, 32 | # min_n=min_n, 33 | # seed=seed, 34 | # use_raw=False) 35 | 36 | # # output result 37 | # adata.obsm['gsva_estimate'].to_csv('./matrix.py.result.csv') 38 | 39 | 40 | if isinstance(adata.X, csr_matrix): 41 | data = pd.DataFrame.sparse.from_spmatrix(adata.X) 42 | elif isinstance(adata.X, np.ndarray): 43 | data = pd.DataFrame(adata.X) 44 | else: 45 | raise ValueError("Unsupported data type for adata.X") 46 | 47 | 48 | data.index=adata.obs.index 49 | data.columns=adata.var.index 50 | 51 | acts=dc.run_gsva( 52 | mat=data, 53 | net=geneset, 54 | source='source', 55 | target='target', 56 | verbose=True, 57 | use_raw=False 58 | ) 59 | 60 | acts.to_csv('./matrix.py.result.csv') 61 | 62 | 63 | -------------------------------------------------------------------------------- /inst/python/ssgsea.py: -------------------------------------------------------------------------------- 1 | # import 2 | import scanpy as sc 3 | import pandas as pd 4 | import numpy as np 5 | import gseapy as gp 6 | import argparse 7 | from scipy.sparse import csr_matrix 8 | 9 | # Parse the parameters passed in 10 | parser = argparse.ArgumentParser(description=' ') 11 | parser.add_argument('--min_size', type=int, default = None) 12 | parser.add_argument('--max_size', type=int, default = None) 13 | parser.add_argument('--seed', type=int, default = None) 14 | parser.add_argument('--threads', type=int, default = None) 15 | 16 | args = parser.parse_args() 17 | 18 | # assign 19 | min_size = args.min_size 20 | max_size = args.max_size 21 | seed = args.seed 22 | threads = args.threads 23 | 24 | # def function 25 | adata = sc.read_h5ad("./temp.h5ad") 26 | 27 | if isinstance(adata.X, csr_matrix): 28 | data = pd.DataFrame.sparse.from_spmatrix(adata.X) 29 | elif isinstance(adata.X, np.ndarray): 30 | data = pd.DataFrame(adata.X) 31 | else: 32 | raise ValueError("Unsupported data type for adata.X") 33 | 34 | 35 | 36 | data.index=adata.obs.index 37 | data.columns=adata.var.index 38 | data = data.T 39 | 40 | geneset = pd.read_csv("./geneset.csv") 41 | 42 | gene_sets = geneset.groupby('source')['target'].apply(list).to_dict() 43 | 44 | ss = gp.ssgsea(data= data, 45 | gene_sets=gene_sets, 46 | outdir=None, 47 | sample_norm_method='rank', # choose 'custom' will only use the raw value of `data` 48 | no_plot=True, 49 | threads=threads, 50 | seed=seed, 51 | min_size=min_size, 52 | max_size=max_size) 53 | 54 | nes = ss.res2d.pivot(index='Term', columns='Name', values='ES') 55 | # output result 56 | nes.to_csv('./matrix.py.result.csv') 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /inst/python/viper.py: -------------------------------------------------------------------------------- 1 | # import 2 | import os 3 | import pandas as pd 4 | import numpy as np 5 | import scanpy as sc 6 | import decoupler as dc 7 | import argparse 8 | from scipy.sparse import csr_matrix 9 | 10 | # Parse the parameters passed in 11 | parser = argparse.ArgumentParser(description=' ') 12 | parser.add_argument('--kcdf', type=str, default = None) 13 | parser.add_argument('--min_n', type=int, default = None) 14 | parser.add_argument('--seed', type=int, default = None) 15 | 16 | args = parser.parse_args() 17 | 18 | # assign 19 | kcdf = args.kcdf 20 | min_n = args.min_n 21 | seed = args.seed 22 | 23 | 24 | 25 | # def function 26 | adata = sc.read_h5ad("./temp.h5ad") 27 | geneset = pd.read_csv("./geneset.csv") 28 | 29 | dc.run_viper( 30 | mat=adata, 31 | net=geneset, 32 | source='source', 33 | target='target', 34 | verbose=True, 35 | use_raw=False 36 | ) 37 | 38 | 39 | # output result 40 | adata.obsm['viper_estimate'].to_csv('./matrix.py.result.csv') 41 | 42 | -------------------------------------------------------------------------------- /irGSEA.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: Default 4 | SaveWorkspace: Default 5 | AlwaysSaveHistory: Default 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | StripTrailingWhitespace: Yes 17 | 18 | BuildType: Package 19 | PackageUseDevtools: Yes 20 | PackageInstallArgs: --no-multiarch --with-keep.source 21 | -------------------------------------------------------------------------------- /man/figures/Abstrast.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/Abstrast.jpg -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-10-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-10-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-11-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-11-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-12-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-12-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-13-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-13-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-14-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-14-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-15-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-15-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-16-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-16-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-17-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-17-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-18-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-18-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-19-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-19-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-19-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-19-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-20-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-20-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-20-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-20-2.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-3-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-3-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-5-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-5-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-6-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-6-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-7-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-7-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-8-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-8-1.png -------------------------------------------------------------------------------- /man/figures/README-unnamed-chunk-9-1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/README-unnamed-chunk-9-1.png -------------------------------------------------------------------------------- /man/figures/figure3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/figure3.png -------------------------------------------------------------------------------- /man/figures/figure4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/chuiqin/irGSEA/e411feca4ecece57d287f192bf7521a28a2cc5d4/man/figures/figure4.png -------------------------------------------------------------------------------- /man/irGSEA.barplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.barplot.R 3 | \name{irGSEA.barplot} 4 | \alias{irGSEA.barplot} 5 | \title{Stacked bar plot} 6 | \usage{ 7 | irGSEA.barplot( 8 | object = NULL, 9 | method = NULL, 10 | significance.color = NULL, 11 | color.cluster = NULL, 12 | color.method = NULL, 13 | cluster.levels = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A list after perform \code{\link{irGSEA.integrate}}} 18 | 19 | \item{method}{A vector. It should be one or more of the followling : AUCell, 20 | UCell, singscore, ssgsea or RRA. Default all methods when it is set to NULL.} 21 | 22 | \item{significance.color}{A vector. Default "c("#D0DFE6FF","#f87669")" when 23 | it is set to NULL.} 24 | 25 | \item{color.cluster}{A vector. Default "ggsci::pal_igv()(the number of colnames 26 | of enrichment score matrix)" when it is set to NULL.} 27 | 28 | \item{color.method}{A vector. Default "ggsci::pal_igv()(the number of methods 29 | )" when it is set to NULL.} 30 | 31 | \item{cluster.levels}{A vector equal to the number of clusters.} 32 | } 33 | \value{ 34 | stacked bar plot 35 | } 36 | \description{ 37 | Easy to show analysis results by stacked bar plot 38 | } 39 | \examples{ 40 | \dontrun{ 41 | # load PBMC dataset by R package SeuratData 42 | library(Seurat) 43 | library(SeuratData) 44 | # download 3k PBMCs from 10X Genomics 45 | InstallData("pbmc3k") 46 | data("pbmc3k.final") 47 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 48 | 49 | # Seurat object 50 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 51 | slot = "data", msigdb = T, species = "Homo sapiens", 52 | category = "H", geneid = "symbol", 53 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 54 | 55 | # Integrated analysis 56 | result.dge <- irGSEA.integrate(object = pbmc3k.final, 57 | group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 58 | method = c("AUCell","UCell","singscore","ssgsea")) 59 | 60 | irGSEA.barplot.plot1 <- irGSEA.barplot(object = result.dge) 61 | 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /man/irGSEA.bubble.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.bubble.R 3 | \name{irGSEA.bubble} 4 | \alias{irGSEA.bubble} 5 | \title{Bubble plot} 6 | \usage{ 7 | irGSEA.bubble( 8 | object = NULL, 9 | method = "RRA", 10 | top = 50, 11 | show.geneset = NULL, 12 | cluster.color = NULL, 13 | direction.color = NULL, 14 | significance.color = NULL, 15 | cluster_rows = T, 16 | cluster.levels = NULL 17 | ) 18 | } 19 | \arguments{ 20 | \item{object}{A list after perform \code{\link{irGSEA.integrate}}} 21 | 22 | \item{method}{A character. It should be one of the followling : AUCell, UCell, 23 | singscore, ssgsea or RRA. Default RRA.} 24 | 25 | \item{top}{The top gene sets. Default 50.} 26 | 27 | \item{show.geneset}{A vector including special gene sets. Default NULL.} 28 | 29 | \item{cluster.color}{A vector. Default "ggsci::pal_igv()(the number of colnames 30 | of enrichment score matrix)" when it is set to NULL.} 31 | 32 | \item{direction.color}{A vector. Default "c("#4575B4","#D73027")" when it 33 | is set to NULL.} 34 | 35 | \item{significance.color}{A vector. Default "c("#D0DFE6FF","#f87669")" when 36 | it is set to NULL.} 37 | 38 | \item{cluster_rows}{Whether to make cluster on rows. Defaul True.} 39 | 40 | \item{cluster.levels}{A vector equal to the number of clusters.} 41 | } 42 | \value{ 43 | bubble plot 44 | } 45 | \description{ 46 | Easy to show analysis results by bubble plot 47 | } 48 | \examples{ 49 | \dontrun{ 50 | # load PBMC dataset by R package SeuratData 51 | library(Seurat) 52 | library(SeuratData) 53 | # download 3k PBMCs from 10X Genomics 54 | InstallData("pbmc3k") 55 | data("pbmc3k.final") 56 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 57 | 58 | # Seurat object 59 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 60 | slot = "data", msigdb = T, species = "Homo sapiens", 61 | category = "H", geneid = "symbol", 62 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 63 | 64 | # Integrated analysis 65 | result.dge <- irGSEA.integrate(object = pbmc3k.final, 66 | group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 67 | method = c("AUCell","UCell","singscore","ssgsea")) 68 | 69 | irGSEA.bubble.plot1 <- irGSEA.bubble(object = result.dge, 70 | method = "RRA", top = 50) 71 | irGSEA.bubble.plot2 <- irGSEA.bubble(object = result.dge, 72 | method = "ssgsea", top = 50) 73 | 74 | } 75 | 76 | 77 | 78 | } 79 | -------------------------------------------------------------------------------- /man/irGSEA.density.scatterplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.density.scatterplot.R 3 | \name{irGSEA.density.scatterplot} 4 | \alias{irGSEA.density.scatterplot} 5 | \title{Density Scatter plot} 6 | \usage{ 7 | irGSEA.density.scatterplot( 8 | object = NULL, 9 | method = NULL, 10 | show.geneset = NULL, 11 | reduction = "umap", 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{object}{A Seurat after perform \code{\link{irGSEA.score}}} 17 | 18 | \item{method}{A character. It should be one of the followling : AUCell, 19 | UCell, singscore, ssgsea.} 20 | 21 | \item{show.geneset}{A character. It should be one of the rownames of 22 | enrichment score matrix.} 23 | 24 | \item{reduction}{A character. It can not be empty and should be calculated 25 | in advance.} 26 | 27 | \item{...}{More parameters pass to \code{\link[Nebulosa]{plot_density}}} 28 | } 29 | \value{ 30 | density scatter plot 31 | } 32 | \description{ 33 | Easy to the data distribution by density scatter plot 34 | } 35 | \examples{ 36 | \dontrun{ 37 | # load PBMC dataset by R package SeuratData 38 | library(Seurat) 39 | library(SeuratData) 40 | # download 3k PBMCs from 10X Genomics 41 | InstallData("pbmc3k") 42 | data("pbmc3k.final") 43 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 44 | 45 | # Seurat object 46 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 47 | slot = "data", msigdb = T, species = "Homo sapiens", 48 | category = "H", geneid = "symbol", 49 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 50 | 51 | irGSEA.density.scatterplot1 <- irGSEA.density.scatterplot(object = pbmc3k.final, 52 | method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE", 53 | reduction = "umap") 54 | irGSEA.density.scatterplot2 <- irGSEA.density.scatterplot(object = pbmc3k.final, 55 | method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING", 56 | reduction = "umap") 57 | 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /man/irGSEA.densityheatmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.densityheatmap.R 3 | \name{irGSEA.densityheatmap} 4 | \alias{irGSEA.densityheatmap} 5 | \title{Density heatmap} 6 | \usage{ 7 | irGSEA.densityheatmap( 8 | object = NULL, 9 | method = NULL, 10 | show.geneset = NULL, 11 | group.by = NULL, 12 | heatmap_width = 12, 13 | heatmap_height = 12, 14 | cluster.levels = NULL, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{object}{A Seurat after perform \code{\link{irGSEA.score}}} 20 | 21 | \item{method}{A character. It should be one of the followling : AUCell, 22 | UCell, singscore, ssgsea.} 23 | 24 | \item{show.geneset}{A character. It should be one of the rownames of 25 | enrichment score matrix.} 26 | 27 | \item{group.by}{Default ident when it is set to NULL. You can specify other 28 | column of metadata.} 29 | 30 | \item{heatmap_width}{Width of the whole heatmap (including heatmap 31 | components), default 12.} 32 | 33 | \item{heatmap_height}{Heigh of the whole heatmap (including heatmap 34 | components), default 12.} 35 | 36 | \item{cluster.levels}{A vector equal to the number of clusters.} 37 | 38 | \item{...}{More parameters pass to \code{\link[ComplexHeatmap]{densityHeatmap}}} 39 | } 40 | \value{ 41 | density heatmap 42 | } 43 | \description{ 44 | Easy to show the data distribution by density heatmap 45 | } 46 | \examples{ 47 | 48 | \dontrun{ 49 | # load PBMC dataset by R package SeuratData 50 | library(Seurat) 51 | library(SeuratData) 52 | # download 3k PBMCs from 10X Genomics 53 | InstallData("pbmc3k") 54 | data("pbmc3k.final") 55 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 56 | 57 | # Seurat object 58 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 59 | slot = "data", msigdb = T, species = "Homo sapiens", 60 | category = "H", geneid = "symbol", 61 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 62 | 63 | irGSEA.densityheatmap.plot1 <- irGSEA.densityheatmap(object = pbmc3k.final, 64 | method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 65 | irGSEA.densityheatmap.plot2 <- irGSEA.densityheatmap(object = pbmc3k.final, 66 | method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 67 | 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /man/irGSEA.halfvlnplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.halfvlnplot.R 3 | \name{irGSEA.halfvlnplot} 4 | \alias{irGSEA.halfvlnplot} 5 | \title{Half vlnplot} 6 | \usage{ 7 | irGSEA.halfvlnplot( 8 | object = NULL, 9 | method = NULL, 10 | show.geneset = NULL, 11 | group.by = NULL, 12 | color.cluster = NULL, 13 | cluster.levels = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A Seurat after perform \code{\link{irGSEA.score}}} 18 | 19 | \item{method}{A character. It should be one of the followling : AUCell, 20 | UCell, singscore, ssgsea.} 21 | 22 | \item{show.geneset}{A character. It should be one of the rownames of 23 | enrichment score matrix.} 24 | 25 | \item{group.by}{Default ident when it is set to NULL. You can specify other 26 | column of metadata.} 27 | 28 | \item{color.cluster}{A vector. Default "ggsci::pal_igv()(the number of colnames 29 | of enrichment score matrix)" when it is set to NULL.} 30 | 31 | \item{cluster.levels}{A vector equal to the number of clusters.} 32 | } 33 | \value{ 34 | half vlnplot 35 | } 36 | \description{ 37 | Easy to show the data distribution by half vlnplot 38 | } 39 | \examples{ 40 | \dontrun{ 41 | # load PBMC dataset by R package SeuratData 42 | library(Seurat) 43 | library(SeuratData) 44 | # download 3k PBMCs from 10X Genomics 45 | InstallData("pbmc3k") 46 | data("pbmc3k.final") 47 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 48 | 49 | # Seurat object 50 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 51 | slot = "data", msigdb = T, species = "Homo sapiens", 52 | category = "H", geneid = "symbol", 53 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 54 | 55 | irGSEA.halfvlnplot.plot1 <- irGSEA.halfvlnplot(object = pbmc3k.final, 56 | method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 57 | irGSEA.halfvlnplot.plot2 <- irGSEA.halfvlnplot(object = pbmc3k.final, 58 | method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 59 | 60 | 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /man/irGSEA.heatmap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.heatmap.R 3 | \name{irGSEA.heatmap} 4 | \alias{irGSEA.heatmap} 5 | \title{Heatmap plot} 6 | \usage{ 7 | irGSEA.heatmap( 8 | object = NULL, 9 | method = "RRA", 10 | top = 50, 11 | show.geneset = NULL, 12 | cluster_rows = T, 13 | significance.color = NULL, 14 | cluster.color = NULL, 15 | direction.color = NULL, 16 | rowname.fointsize = 7, 17 | heatmap.width = 17, 18 | heatmap.heigh = 13, 19 | cluster.levels = NULL, 20 | ... 21 | ) 22 | } 23 | \arguments{ 24 | \item{object}{A list after perform \code{\link{irGSEA.integrate}}} 25 | 26 | \item{method}{A character. It should be one of the followling : AUCell, UCell, 27 | singscore, ssgsea or RRA. Default RRA.} 28 | 29 | \item{top}{The top gene sets. Default 50.} 30 | 31 | \item{show.geneset}{A vector including special gene sets. Default NULL.} 32 | 33 | \item{cluster_rows}{Whether to make cluster on rows. Defaul True.} 34 | 35 | \item{significance.color}{A vector. Default "c("#D0DFE6FF","#f87669")" when 36 | it is set to NULL.} 37 | 38 | \item{cluster.color}{A vector. Default "ggsci::pal_igv()(the number of colnames 39 | of enrichment score matrix)" when it is set to NULL.} 40 | 41 | \item{direction.color}{A vector. Default "c("#4575B4","#D73027")" when it 42 | is set to NULL.} 43 | 44 | \item{rowname.fointsize}{The fointsize of rownames. Default 7.} 45 | 46 | \item{heatmap.width}{Width of the whole heatmap (including heatmap 47 | components), default 17.} 48 | 49 | \item{heatmap.heigh}{Height of the whole heatmap (including heatmap 50 | components), default 13.} 51 | 52 | \item{cluster.levels}{A vector equal to the number of clusters.} 53 | 54 | \item{...}{More parameters pass to \code{\link[ComplexHeatmap]{Heatmap}}} 55 | } 56 | \value{ 57 | heatmap plot 58 | } 59 | \description{ 60 | Easy to show analysis results by heatmap plot 61 | } 62 | \examples{ 63 | \dontrun{ 64 | # load PBMC dataset by R package SeuratData 65 | library(Seurat) 66 | library(SeuratData) 67 | # download 3k PBMCs from 10X Genomics 68 | InstallData("pbmc3k") 69 | data("pbmc3k.final") 70 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 71 | 72 | # Seurat object 73 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 74 | slot = "data", msigdb = T, species = "Homo sapiens", 75 | category = "H", geneid = "symbol", 76 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 77 | 78 | # Integrated analysis 79 | result.dge <- irGSEA.integrate(object = pbmc3k.final, 80 | group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 81 | method = c("AUCell","UCell","singscore","ssgsea")) 82 | 83 | irGSEA.heatmap.plot1 <- irGSEA.heatmap(object = result.dge, method = "RRA", 84 | top = 50, show.geneset = NULL) 85 | 86 | irGSEA.heatmap.plot2 <- irGSEA.heatmap(object = result.dge, method = "ssgsea", 87 | top = 50, show.geneset = NULL) 88 | 89 | } 90 | 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /man/irGSEA.hub.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.hub.R 3 | \name{irGSEA.hub} 4 | \alias{irGSEA.hub} 5 | \title{Calculate the hub gene of the geneset} 6 | \usage{ 7 | irGSEA.hub( 8 | object = NULL, 9 | assay = "RNA", 10 | slot = "data", 11 | method = NULL, 12 | show.geneset = NULL, 13 | ncores = 4, 14 | type = "rank", 15 | maxRank = 2000, 16 | top = 5, 17 | correlation.color = c("#0073c2", "white", "#efc000"), 18 | method.color = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{object}{A Seurat after perform \code{\link{irGSEA.score}}} 23 | 24 | \item{assay}{Name of assay to calculate the correction. Default RNA.} 25 | 26 | \item{slot}{Default data.} 27 | 28 | \item{method}{A character.} 29 | 30 | \item{show.geneset}{A character.} 31 | 32 | \item{ncores}{Default 4.} 33 | 34 | \item{type}{expression or rank. Default rank. Calculate the correlation between 35 | the geneset's score and the rank of gene included in the geneset while the 36 | type is rank. Calculate the correlation between the geneset's score and the 37 | expression of gene included in the geneset while the type is expression.} 38 | 39 | \item{maxRank}{Maximum number of genes to rank per cell; above this rank, 40 | a given gene is considered as not expressed. Default 2000.} 41 | 42 | \item{top}{The number of top-ranked positively correlated genes in each method 43 | is displayed in a heatmap.} 44 | 45 | \item{correlation.color}{A vector.} 46 | 47 | \item{method.color}{A vector. Default "ggsci::pal_png()(the number of 48 | methods)" when it is set to NULL.} 49 | } 50 | \value{ 51 | list includes hub_result and hub_plot 52 | } 53 | \description{ 54 | Easy to calculate the hub gene of the geneset based on the correlation between 55 | the geneset's score and the expression or rank of gene included in the geneset 56 | } 57 | \examples{ 58 | \dontrun{ 59 | # load PBMC dataset by R package SeuratData 60 | library(Seurat) 61 | library(SeuratData) 62 | # download 3k PBMCs from 10X Genomics 63 | InstallData("pbmc3k") 64 | data("pbmc3k.final") 65 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 66 | 67 | # Seurat object 68 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 69 | slot = "data", msigdb = T, species = "Homo sapiens", 70 | category = "H", geneid = "symbol", 71 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 72 | 73 | hub.result <- irGSEA.hub(object = pbmc3k.final, assay = "RNA", slot = "data", 74 | method = c("AUCell","UCell","singscore", "ssgsea"), 75 | show.geneset = c("HALLMARK-INFLAMMATORY-RESPONSE", "HALLMARK-APOPTOSIS"), 76 | ncores = 4, type = "rank", maxRank = 2000, top = 5, 77 | correlation.color = c("#0073c2","white","#efc000"), method.color = NULL) 78 | 79 | head(hub.result$hub_result) 80 | hub.result$hub_plot$`HALLMARK-APOPTOSIS` 81 | hub.result$hub_plot$`HALLMARK-INFLAMMATORY-RESPONSE` 82 | 83 | 84 | } 85 | 86 | } 87 | -------------------------------------------------------------------------------- /man/irGSEA.integrate.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.integrate.R 3 | \name{irGSEA.integrate} 4 | \alias{irGSEA.integrate} 5 | \title{Integrate differential gene set calculated by all enrichment score matrixes} 6 | \usage{ 7 | irGSEA.integrate( 8 | object = NULL, 9 | group.by = NULL, 10 | metadata = NULL, 11 | col.name = NULL, 12 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 13 | p.value = "p_val_adj" 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{Seurat object including enrichment score matrixes.} 18 | 19 | \item{group.by}{Default ident when it set to NULL. You can specify other 20 | columns of metadata.} 21 | 22 | \item{metadata}{A vector add to this Seurat object, and then it is set as 23 | the ident of Seurat object to perform differential gene sets analysis.} 24 | 25 | \item{col.name}{A name for metadata.} 26 | 27 | \item{method}{A vector to select enrichment score matrixes. Default all 28 | enrichment score matrixes} 29 | 30 | \item{p.value}{p_val_adj or p_val. The gene sets with statistical significance 31 | in different scoring methods were filtered based on the p_val_adj or p_val 32 | and then RRA analysis was performed. Default p_val_adj.} 33 | } 34 | \value{ 35 | A list including the differential gene sets calculated by enrichment 36 | score matrixes through wlicox test. Gene sets with adjusted p value < 0.05 37 | are regarded as statistically significant. Meanwhile, significant differential 38 | gene sets are integrated and the results are saved in a data frame named RRA. 39 | Among them, Gene sets with p value < 0.05 are statistically significant and 40 | common differential in all gene sets enrichment analysis methods. 41 | } 42 | \description{ 43 | Wlicox test is perform to all enrichment score matrixes and gene sets with 44 | adjusted p value < 0.05 are used to integrated through RRA. 45 | } 46 | \examples{ 47 | \dontrun{ 48 | # load PBMC dataset by R package SeuratData 49 | library(Seurat) 50 | library(SeuratData) 51 | # download 3k PBMCs from 10X Genomics 52 | InstallData("pbmc3k") 53 | data("pbmc3k.final") 54 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 55 | 56 | # Seurat object 57 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 58 | slot = "data", msigdb = T, species = "Homo sapiens", 59 | category = "H", geneid = "symbol", 60 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 61 | 62 | # Integrated analysis 63 | result.dge <- irGSEA.integrate(object = pbmc3k.final, 64 | group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 65 | method = c("AUCell","UCell","singscore","ssgsea")) 66 | 67 | result.dge2 <- irGSEA.integrate(object = pbmc3k.final, group.by = NULL, 68 | metadata = pbmc3k.final$seurat_annotations, col.name = "ident", 69 | method = c("AUCell","UCell","singscore","ssgsea")) 70 | 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /man/irGSEA.merge.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.merge.R 3 | \name{irGSEA.merge} 4 | \alias{irGSEA.merge} 5 | \title{Merge the enrichment score assay} 6 | \usage{ 7 | irGSEA.merge( 8 | object.x = NULL, 9 | object.y = NULL, 10 | method = c("AUCell", "UCell", "singscore", "ssgsea", "JASMINE", "viper"), 11 | overwrite = T 12 | ) 13 | } 14 | \arguments{ 15 | \item{object.x}{Seurat object (V4 or V5).} 16 | 17 | \item{object.y}{The list includes various Seurat objects. The verison of 18 | Seurat object should be the same as the version of object.x.} 19 | 20 | \item{method}{A vector. Default c("AUCell", "UCell", "singscore", "ssgsea", 21 | "JASMINE", "viper").} 22 | 23 | \item{overwrite}{Default True. The same geneset name exists in two gene scoring 24 | matrices, the newly added geneset will overwrite the previous geneset if 25 | the overwrite is true. The newly added geneset will be forcibly renamed 26 | as "geneset's name + serial number" if the overwrite is false.} 27 | } 28 | \value{ 29 | Seurat object including score matrix. 30 | } 31 | \description{ 32 | Merge the enrichment score assay among various Seurat objects 33 | } 34 | \examples{ 35 | \dontrun{ 36 | # load PBMC dataset by R package SeuratData 37 | library(Seurat) 38 | library(SeuratData) 39 | # download 3k PBMCs from 10X Genomics 40 | InstallData("pbmc3k") 41 | library(Seurat) 42 | 43 | library(RcppML) 44 | library(irGSEA) 45 | library(tidyverse) 46 | library(clusterProfiler) 47 | data("pbmc3k.final") 48 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 49 | 50 | # download gmt file 51 | gmt_url1 <- "https://data.broadinstitute.org/" 52 | gmt_url2 <- "gsea-msigdb/msigdb/release/2023.2.Hs/", 53 | gmt_url3 <- "h.all.v2023.2.Hs.symbols.gmt" 54 | gmt_url <- paste0(gmt_url1, gmt_url2, gmt_url3) 55 | local_gmt <- "./h.all.v2023.2.Hs.symbols.gmt" 56 | download.file(gmt_url , local_gmt) 57 | msigdb <- clusterProfiler::read.gmt("./h.all.v2023.2.Hs.symbols.gmt") 58 | 59 | # convert to list[hallmarker] required by irGSEA package 60 | msigdb$term <- factor(msigdb$term) 61 | msigdb <- msigdb \%>\% 62 | dplyr::group_split(term, .keep = F) \%>\% 63 | purrr::map( ~.x \%>\% dplyr::pull(gene) \%>\% unique(.)) \%>\% 64 | purrr::set_names(levels(msigdb$term)) 65 | 66 | pbmc3k.final1 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 67 | custom = T, geneset = msigdb[1:25], 68 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 69 | kcdf = 'Gaussian') 70 | pbmc3k.final2 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 71 | custom = T, geneset = msigdb[26:50], 72 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 73 | kcdf = 'Gaussian') 74 | 75 | pbmc3k.final3 <- irGSEA.merge(object.x = pbmc3k.final1, 76 | object.y = pbmc3k.final2, 77 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 78 | overwrite = T) 79 | 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /man/irGSEA.ridgeplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.ridgeplot.R 3 | \name{irGSEA.ridgeplot} 4 | \alias{irGSEA.ridgeplot} 5 | \title{Ridge plot 6 | Easy to show the data distribution by ridge plot} 7 | \usage{ 8 | irGSEA.ridgeplot( 9 | object = NULL, 10 | method = NULL, 11 | show.geneset = NULL, 12 | group.by = NULL, 13 | color.cluster = NULL, 14 | cluster.levels = NULL, 15 | ... 16 | ) 17 | } 18 | \arguments{ 19 | \item{object}{A Seurat after perform \code{\link{irGSEA.score}}} 20 | 21 | \item{method}{A character. It should be one of the followling : AUCell, 22 | UCell, singscore, ssgsea.} 23 | 24 | \item{show.geneset}{A character. It should be one of the rownames of 25 | enrichment score matrix.} 26 | 27 | \item{group.by}{Default ident when it is set to NULL. You can specify other 28 | column of metadata.} 29 | 30 | \item{color.cluster}{A vector. Default "ggsci::pal_igv()(the number of colnames 31 | of enrichment score matrix)" when it is set to NULL.} 32 | 33 | \item{cluster.levels}{A vector equal to the number of clusters.} 34 | 35 | \item{...}{More parameters pass to \code{\link[ggridges]{geom_density_ridges}}} 36 | } 37 | \value{ 38 | ridge plot 39 | } 40 | \description{ 41 | Ridge plot 42 | Easy to show the data distribution by ridge plot 43 | } 44 | \examples{ 45 | 46 | \dontrun{ 47 | # load PBMC dataset by R package SeuratData 48 | library(Seurat) 49 | library(SeuratData) 50 | # download 3k PBMCs from 10X Genomics 51 | InstallData("pbmc3k") 52 | data("pbmc3k.final") 53 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 54 | 55 | # Seurat object 56 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 57 | slot = "data", msigdb = T, species = "Homo sapiens", 58 | category = "H", geneid = "symbol", 59 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 60 | 61 | irGSEA.ridgeplot.plot1 <- irGSEA.ridgeplot(object = pbmc3k.final, 62 | method = "UCell", show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 63 | irGSEA.ridgeplot.plot2 <- irGSEA.ridgeplot(object = pbmc3k.final, 64 | method = "ssgsea", show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 65 | 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /man/irGSEA.subset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.subset.R 3 | \name{irGSEA.subset} 4 | \alias{irGSEA.subset} 5 | \title{Subset the enrichment score matrix} 6 | \usage{ 7 | irGSEA.subset( 8 | object = NULL, 9 | features = NULL, 10 | invert = F, 11 | method = c("AUCell", "UCell", "singscore", "ssgsea", "JASMINE", "viper") 12 | ) 13 | } 14 | \arguments{ 15 | \item{object}{Seurat object (V4 or V5).} 16 | 17 | \item{features}{Vector. The geneset want to subset.} 18 | 19 | \item{invert}{If filp the geneset want to subset.} 20 | 21 | \item{method}{A vector. Default c("AUCell", "UCell", "singscore", "ssgsea", 22 | "JASMINE", "viper").} 23 | } 24 | \value{ 25 | Seurat object including score matrix. 26 | } 27 | \description{ 28 | Subset the enrichment score matrix 29 | } 30 | \examples{ 31 | \dontrun{ 32 | # load PBMC dataset by R package SeuratData 33 | library(Seurat) 34 | library(SeuratData) 35 | # download 3k PBMCs from 10X Genomics 36 | InstallData("pbmc3k") 37 | library(Seurat) 38 | 39 | library(RcppML) 40 | library(irGSEA) 41 | library(tidyverse) 42 | library(clusterProfiler) 43 | data("pbmc3k.final") 44 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 45 | 46 | # download gmt file 47 | gmt_url1 <- "https://data.broadinstitute.org/" 48 | gmt_url2 <- "gsea-msigdb/msigdb/release/2023.2.Hs/", 49 | gmt_url3 <- "h.all.v2023.2.Hs.symbols.gmt" 50 | gmt_url <- paste0(gmt_url1, gmt_url2, gmt_url3) 51 | local_gmt <- "./h.all.v2023.2.Hs.symbols.gmt" 52 | download.file(gmt_url , local_gmt) 53 | msigdb <- clusterProfiler::read.gmt("./h.all.v2023.2.Hs.symbols.gmt") 54 | 55 | # convert to list[hallmarker] required by irGSEA package 56 | msigdb$term <- factor(msigdb$term) 57 | msigdb <- msigdb \%>\% 58 | dplyr::group_split(term, .keep = F) \%>\% 59 | purrr::map( ~.x \%>\% dplyr::pull(gene) \%>\% unique(.)) \%>\% 60 | purrr::set_names(levels(msigdb$term)) 61 | 62 | pbmc3k.final1 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 63 | custom = T, geneset = msigdb[1:25], 64 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 65 | kcdf = 'Gaussian') 66 | pbmc3k.final2 <- irGSEA.score(object = pbmc3k.final, assay = "RNA", slot = "data", 67 | custom = T, geneset = msigdb[26:50], 68 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 69 | kcdf = 'Gaussian') 70 | 71 | pbmc3k.final3 <- irGSEA.merge(object.x = pbmc3k.final1, 72 | object.y = pbmc3k.final2, 73 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 74 | overwrite = T) 75 | pbmc3k.final4 <- irGSEA.subset(object = pbmc3k.final3, 76 | features = rownames(pbmc3k.final3[["AUCell"]])[1:25], 77 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 78 | invert = F) 79 | } 80 | 81 | } 82 | -------------------------------------------------------------------------------- /man/irGSEA.upset.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.upset.R 3 | \name{irGSEA.upset} 4 | \alias{irGSEA.upset} 5 | \title{Upset plot} 6 | \usage{ 7 | irGSEA.upset( 8 | object = NULL, 9 | method = "RRA", 10 | upset.width = 13, 11 | upset.height = 7, 12 | title.size = 10, 13 | text.size = 9, 14 | cluster.color = NULL, 15 | bar.color = "black", 16 | cluster.levels = NULL, 17 | mode = "distinct", 18 | set.size = 1, 19 | set.degree = NULL, 20 | table.generate = F, 21 | ... 22 | ) 23 | } 24 | \arguments{ 25 | \item{object}{A list after perform \code{\link{irGSEA.integrate}}} 26 | 27 | \item{method}{A character. It should be one of the followling : AUCell, UCell, 28 | singscore, ssgsea or RRA. Default RRA.} 29 | 30 | \item{upset.width}{Width of the whole upset plot. Default 13.} 31 | 32 | \item{upset.height}{Height of the whole upset plot. Default 7.} 33 | 34 | \item{title.size}{The fointsize of rownames. Default 10.} 35 | 36 | \item{text.size}{The fointsize of rownames. Default 9.} 37 | 38 | \item{cluster.color}{A vector. Default "ggsci::pal_igv()(the number of colnames 39 | of enrichment score matrix)" when it is set to NULL.} 40 | 41 | \item{bar.color}{A character. Default "black" when it is set to NULL.} 42 | 43 | \item{cluster.levels}{A vector equal to the number of clusters.} 44 | 45 | \item{mode}{A character. It should be one of the followling : distinct, 46 | intersect, or union. Default distinct. It represents the mode for forming 47 | the combination set. see Mode section \url{https://jokergoo.github.io/ComplexHeatmap-reference/book/upset-plot.html} 48 | for details.} 49 | 50 | \item{set.size}{The minimal combination set size. Default 1.} 51 | 52 | \item{set.degree}{A vector. Show all combination sets when it set to NULL. 53 | It would show different combination set when it is set to different number. 54 | For example, it only show the interactions among two cluster or three cluster 55 | when it's set to 2 or 3.} 56 | 57 | \item{table.generate}{Deault FALSE. It will output a list including all 58 | combination sets and their gene sets when it set to TRUE.} 59 | 60 | \item{...}{More parameters pass to \code{\link[ComplexHeatmap]{UpSet}}} 61 | } 62 | \value{ 63 | upset plot or list 64 | } 65 | \description{ 66 | Easy to show analysis results by upset plot 67 | } 68 | \examples{ 69 | \dontrun{ 70 | # load PBMC dataset by R package SeuratData 71 | library(Seurat) 72 | library(SeuratData) 73 | # download 3k PBMCs from 10X Genomics 74 | InstallData("pbmc3k") 75 | data("pbmc3k.final") 76 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 77 | 78 | # Seurat object 79 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 80 | slot = "data", msigdb = T, species = "Homo sapiens", 81 | category = "H", geneid = "symbol", 82 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 83 | 84 | # Integrated analysis 85 | result.dge <- irGSEA.integrate(object = pbmc3k.final, 86 | group.by = "seurat_annotations", metadata = NULL, col.name = NULL, 87 | method = c("AUCell","UCell","singscore","ssgsea")) 88 | 89 | irGSEA.upset.plot1 <- irGSEA.upset(object = result.dge, method = "RRA") 90 | irGSEA.upset.plot2 <- irGSEA.upset(object = result.dge, method = "ssgsea") 91 | 92 | } 93 | 94 | 95 | } 96 | -------------------------------------------------------------------------------- /man/irGSEA.vlnplot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/irGSEA.vlnplot.R 3 | \name{irGSEA.vlnplot} 4 | \alias{irGSEA.vlnplot} 5 | \title{Half vlnplot} 6 | \usage{ 7 | irGSEA.vlnplot( 8 | object = NULL, 9 | method = NULL, 10 | show.geneset = NULL, 11 | group.by = NULL, 12 | color.cluster = NULL, 13 | cluster.levels = NULL 14 | ) 15 | } 16 | \arguments{ 17 | \item{object}{A Seurat after perform \code{\link{irGSEA.score}}} 18 | 19 | \item{method}{A character. It should be one or more of the followling : AUCell, 20 | UCell, singscore, ssgsea, JASMINE, VAM, scSE, VISION, gficf, GSVA, zscore, 21 | plage, wmean, wsum, mdt, viper, GSVApy, AddModuleScore, pagoda2.} 22 | 23 | \item{show.geneset}{A character. It should be one of the rownames of 24 | enrichment score matrix.} 25 | 26 | \item{group.by}{Default ident when it is set to NULL. You can specify other 27 | column of metadata.} 28 | 29 | \item{color.cluster}{A vector. Default "ggsci::pal_igv()(the number of colnames 30 | of enrichment score matrix)" when it is set to NULL.} 31 | 32 | \item{cluster.levels}{A vector equal to the number of clusters.} 33 | } 34 | \value{ 35 | vlnplot 36 | } 37 | \description{ 38 | Easy to show the data distribution by half vlnplot 39 | } 40 | \examples{ 41 | \dontrun{ 42 | # load PBMC dataset by R package SeuratData 43 | library(Seurat) 44 | library(SeuratData) 45 | # download 3k PBMCs from 10X Genomics 46 | InstallData("pbmc3k") 47 | data("pbmc3k.final") 48 | pbmc3k.final <- SeuratObject::UpdateSeuratObject(pbmc3k.final) 49 | 50 | # Seurat object 51 | pbmc3k.final <- irGSEA.score(object = pbmc3k.final, assay = "RNA", 52 | slot = "data", msigdb = T, species = "Homo sapiens", 53 | category = "H", geneid = "symbol", 54 | method = c("AUCell", "UCell", "singscore", "ssgsea"), kcdf = 'Gaussian') 55 | 56 | irGSEA.vlnplot.plot1 <- irGSEA.vlnplot(object = pbmc3k.final, 57 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 58 | show.geneset = "HALLMARK-INFLAMMATORY-RESPONSE") 59 | irGSEA.vlnplot.plot2 <- irGSEA.vlnplot(object = pbmc3k.final, 60 | method = c("AUCell", "UCell", "singscore", "ssgsea"), 61 | show.geneset = "HALLMARK-IL6-JAK-STAT3-SIGNALING") 62 | 63 | 64 | } 65 | 66 | } 67 | -------------------------------------------------------------------------------- /man/pipe.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-pipe.R 3 | \name{\%>\%} 4 | \alias{\%>\%} 5 | \title{Pipe operator} 6 | \usage{ 7 | lhs \%>\% rhs 8 | } 9 | \arguments{ 10 | \item{lhs}{A value or the magrittr placeholder.} 11 | 12 | \item{rhs}{A function call using the magrittr semantics.} 13 | } 14 | \value{ 15 | The result of calling `rhs(lhs)`. 16 | } 17 | \description{ 18 | See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. 19 | } 20 | \keyword{internal} 21 | -------------------------------------------------------------------------------- /man/tidyeval.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utils-tidy-eval.R 3 | \name{tidyeval} 4 | \alias{tidyeval} 5 | \alias{enquo} 6 | \alias{enquos} 7 | \alias{.data} 8 | \alias{:=} 9 | \alias{as_name} 10 | \alias{as_label} 11 | \title{Tidy eval helpers} 12 | \description{ 13 | This page lists the tidy eval tools reexported in this package from 14 | rlang. To learn about using tidy eval in scripts and packages at a 15 | high level, see the \href{https://dplyr.tidyverse.org/articles/programming.html}{dplyr programming vignette} 16 | and the \href{https://ggplot2.tidyverse.org/articles/ggplot2-in-packages.html}{ggplot2 in packages vignette}. 17 | The \href{https://adv-r.hadley.nz/metaprogramming.html}{Metaprogramming section} of \href{https://adv-r.hadley.nz}{Advanced R} may also be useful for a deeper dive. 18 | \itemize{ 19 | \item The tidy eval operators \verb{\{\{}, \verb{!!}, and \verb{!!!} are syntactic 20 | constructs which are specially interpreted by tidy eval functions. 21 | You will mostly need \verb{\{\{}, as \verb{!!} and \verb{!!!} are more advanced 22 | operators which you should not have to use in simple cases. 23 | 24 | The curly-curly operator \verb{\{\{} allows you to tunnel data-variables 25 | passed from function arguments inside other tidy eval functions. 26 | \verb{\{\{} is designed for individual arguments. To pass multiple 27 | arguments contained in dots, use \code{...} in the normal way. 28 | 29 | \if{html}{\out{
    }}\preformatted{my_function <- function(data, var, ...) \{ 30 | data \%>\% 31 | group_by(...) \%>\% 32 | summarise(mean = mean(\{\{ var \}\})) 33 | \} 34 | }\if{html}{\out{
    }} 35 | \item \code{\link[=enquo]{enquo()}} and \code{\link[=enquos]{enquos()}} delay the execution of one or several 36 | function arguments. The former returns a single expression, the 37 | latter returns a list of expressions. Once defused, expressions 38 | will no longer evaluate on their own. They must be injected back 39 | into an evaluation context with \verb{!!} (for a single expression) and 40 | \verb{!!!} (for a list of expressions). 41 | 42 | \if{html}{\out{
    }}\preformatted{my_function <- function(data, var, ...) \{ 43 | # Defuse 44 | var <- enquo(var) 45 | dots <- enquos(...) 46 | 47 | # Inject 48 | data \%>\% 49 | group_by(!!!dots) \%>\% 50 | summarise(mean = mean(!!var)) 51 | \} 52 | }\if{html}{\out{
    }} 53 | 54 | In this simple case, the code is equivalent to the usage of \verb{\{\{} 55 | and \code{...} above. Defusing with \code{enquo()} or \code{enquos()} is only 56 | needed in more complex cases, for instance if you need to inspect 57 | or modify the expressions in some way. 58 | \item The \code{.data} pronoun is an object that represents the current 59 | slice of data. If you have a variable name in a string, use the 60 | \code{.data} pronoun to subset that variable with \code{[[}. 61 | 62 | \if{html}{\out{
    }}\preformatted{my_var <- "disp" 63 | mtcars \%>\% summarise(mean = mean(.data[[my_var]])) 64 | }\if{html}{\out{
    }} 65 | \item Another tidy eval operator is \verb{:=}. It makes it possible to use 66 | glue and curly-curly syntax on the LHS of \code{=}. For technical 67 | reasons, the R language doesn't support complex expressions on 68 | the left of \code{=}, so we use \verb{:=} as a workaround. 69 | 70 | \if{html}{\out{
    }}\preformatted{my_function <- function(data, var, suffix = "foo") \{ 71 | # Use `\{\{` to tunnel function arguments and the usual glue 72 | # operator `\{` to interpolate plain strings. 73 | data \%>\% 74 | summarise("\{\{ var \}\}_mean_\{suffix\}" := mean(\{\{ var \}\})) 75 | \} 76 | }\if{html}{\out{
    }} 77 | \item Many tidy eval functions like \code{dplyr::mutate()} or 78 | \code{dplyr::summarise()} give an automatic name to unnamed inputs. If 79 | you need to create the same sort of automatic names by yourself, 80 | use \code{as_label()}. For instance, the glue-tunnelling syntax above 81 | can be reproduced manually with: 82 | 83 | \if{html}{\out{
    }}\preformatted{my_function <- function(data, var, suffix = "foo") \{ 84 | var <- enquo(var) 85 | prefix <- as_label(var) 86 | data \%>\% 87 | summarise("\{prefix\}_mean_\{suffix\}" := mean(!!var)) 88 | \} 89 | }\if{html}{\out{
    }} 90 | 91 | Expressions defused with \code{enquo()} (or tunnelled with \verb{\{\{}) need 92 | not be simple column names, they can be arbitrarily complex. 93 | \code{as_label()} handles those cases gracefully. If your code assumes 94 | a simple column name, use \code{as_name()} instead. This is safer 95 | because it throws an error if the input is not a name as expected. 96 | } 97 | } 98 | \keyword{internal} 99 | --------------------------------------------------------------------------------