1 Introduction

SBGNview has collected pathway data and gene sets from the following databases: Reactome, PANTHER Pathway, SMPDB, MetaCyc and MetaCrop. These gene sets can be used for pathway enrichment analysis.

In this vignette, we will show you a complete pathway analysis workflow based on GAGE + SBGNview. Similar workflows have been documented in the gage package using GAGE + Pathview.

2 Citation

Please cite the following papers when using the open-source SBGNview package. This will help the project and our team:

Luo W, Brouwer C. Pathview: an R/Biocondutor package for pathway-based data integration and visualization. Bioinformatics, 2013, 29(14):1830-1831, doi: 10.1093/bioinformatics/btt285

Please also cite the GAGE paper when using the gage package:

Luo W, Friedman M, etc. GAGE: generally applicable gene set enrichment for pathway analysis. BMC Bioinformatics, 2009, 10, pp. 161, doi: 10.1186/1471-2105-10-161

3 Installation and quick start

Please see the Quick Start tutorial for installation instructions and quick start examples.

4 Complete pathway analysis + visualization workflow

In this example, we analyze a RNA-Seq dataset of IFNg KO mice vs wild type mice. It contains normalized RNA-seq gene expression data described in Greer, Renee L., Xiaoxi Dong, et al, 2016.

4.1 Load the gene (RNA-seq) data

The RNA abundance data was quantile normalized and log2 transformed, stored in a “SummarizedExperiment” object. SBGNview input user data (gene.data or cpd.data) can be either a numeric matrix or a vector, like those in pathview. In addition, it can be a “SummarizedExperiment” object, which is commonly used in BioConductor packages.

library(SBGNview)
library(SummarizedExperiment)
data("IFNg", "pathways.info")
count.data <- assays(IFNg)$counts
head(count.data)
wt.cols <- which(IFNg$group == "wt")
ko.cols <- which(IFNg$group == "ko")

4.2 Gene sets from SBGNview pathway collection

4.2.1 Load gene set for mouse with ENSEMBL gene IDs

ensembl.pathway <- sbgn.gsets(id.type = "ENSEMBL",
                              species = "mmu",
                              mol.type = "gene",
                              output.pathway.name = TRUE
                              )
head(ensembl.pathway[[2]])

4.2.2 Pathway or gene set analysis using GAGE

if(!requireNamespace("gage", quietly = TRUE)) {
  BiocManager::install("gage", update = FALSE)
}

library(gage)
degs <- gage(exprs = count.data,
           gsets = ensembl.pathway,
           ref = wt.cols,
           samp = ko.cols,
           compare = "paired" #"as.group"
           )
head(degs$greater)[,3:5]
head(degs$less)[,3:5]
down.pathways <- row.names(degs$less)[1:10]
head(down.pathways)

4.3 Visualize perturbations in top SBGN pathways

4.3.1 Calculate fold changes or gene perturbations

The abundance values were log2 transformed. Here we calculate the fold change of IFNg KO group v.s. WT group.

ensembl.koVsWt <- count.data[,ko.cols]-count.data[,wt.cols]
head(ensembl.koVsWt)

#alternatively, we can also calculate mean fold changes per gene, which corresponds to gage analysis above with compare="as.group"
mean.wt <- apply(count.data[,wt.cols] ,1 ,"mean")
head(mean.wt)
mean.ko <- apply(count.data[,ko.cols],1,"mean")
head(mean.ko)
# The abundance values were on log scale. Hence fold change is their difference.
ensembl.koVsWt.m <- mean.ko - mean.wt

4.3.2 Visualize pathway perturbations by SBNGview

#load the SBGNview pathway collection, which may takes a few seconds.
data(sbgn.xmls)
down.pathways <- sapply(strsplit(down.pathways,"::"), "[", 1)
head(down.pathways)
sbgnview.obj <- SBGNview(
    gene.data = ensembl.koVsWt,
    gene.id.type = "ENSEMBL",
    input.sbgn = down.pathways[1:2],#can be more than 2 pathways
    output.file = "ifn.sbgnview.less",
    show.pathway.name = TRUE,
    max.gene.value = 2,
    min.gene.value = -2,
    mid.gene.value = 0,
    node.sum = "mean",
    output.format = c("png"),
    
    font.size = 2.3,
    org = "mmu",
    
    text.length.factor.complex = 3,
    if.scale.compartment.font.size = TRUE,
    node.width.adjust.factor.compartment = 0.04 
)
sbgnview.obj
\label{fig:ifng}SBGNview graph of the most down-regulated pathways in IFNg KO experiment

Figure 4.1: SBGNview graph of the most down-regulated pathways in IFNg KO experiment

\label{fig:ifna}SBGNview graph of the second most down-regulated pathways in IFNg KO experiment

Figure 4.2: SBGNview graph of the second most down-regulated pathways in IFNg KO experiment

4.4 SBGNview with SummarizedExperiment object

The ‘cancer.ds’ is a microarray dataset from a breast cancer study. The dataset was adopted from gage package and processed into a SummarizedExperiment object. It is used to demo SBGNview’s visualization ability.

data("cancer.ds")
sbgnview.obj <- SBGNview(
    gene.data = cancer.ds,
    gene.id.type = "ENTREZID",
    input.sbgn = "R-HSA-877300",
    output.file = "demo.SummarizedExperiment",
    show.pathway.name = TRUE,
    max.gene.value = 1,
    min.gene.value = -1,
    mid.gene.value = 0,
    node.sum = "mean",
    output.format = c("png"),
    
    font.size = 2.3,
    org = "hsa",
    
    text.length.factor.complex = 3,
    if.scale.compartment.font.size = TRUE,
    node.width.adjust.factor.compartment = 0.04
   )
sbgnview.obj
\label{fig:cancerds}SBGNview of a cancer dataset gse16873

Figure 4.3: SBGNview of a cancer dataset gse16873

5 Session Info

sessionInfo()
## R version 4.2.1 (2022-06-23)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.5 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.16-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.16-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_GB              LC_COLLATE=C              
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] gage_2.48.0                 SummarizedExperiment_1.28.0
##  [3] Biobase_2.58.0              GenomicRanges_1.50.0       
##  [5] GenomeInfoDb_1.34.0         IRanges_2.32.0             
##  [7] S4Vectors_0.36.0            BiocGenerics_0.44.0        
##  [9] MatrixGenerics_1.10.0       matrixStats_0.62.0         
## [11] SBGNview_1.12.0             SBGNview.data_1.11.0       
## [13] pathview_1.38.0             knitr_1.40                 
## 
## loaded via a namespace (and not attached):
##  [1] KEGGgraph_1.58.0       Rcpp_1.0.9             lattice_0.20-45       
##  [4] GO.db_3.16.0           png_0.1-7              rsvg_2.3.2            
##  [7] Biostrings_2.66.0      digest_0.6.30          R6_2.5.1              
## [10] RSQLite_2.2.18         evaluate_0.17          highr_0.9             
## [13] httr_1.4.4             Rdpack_2.4             zlibbioc_1.44.0       
## [16] rlang_1.0.6            Rgraphviz_2.42.0       jquerylib_0.1.4       
## [19] blob_1.2.3             Matrix_1.5-1           rmarkdown_2.17        
## [22] stringr_1.4.1          igraph_1.3.5           RCurl_1.98-1.9        
## [25] bit_4.0.4              DelayedArray_0.24.0    compiler_4.2.1        
## [28] xfun_0.34              pkgconfig_2.0.3        htmltools_0.5.3       
## [31] KEGGREST_1.38.0        GenomeInfoDbData_1.2.9 bookdown_0.29         
## [34] XML_3.99-0.12          crayon_1.5.2           bitops_1.0-7          
## [37] rbibutils_2.2.9        grid_4.2.1             jsonlite_1.8.3        
## [40] DBI_1.1.3              magrittr_2.0.3         graph_1.76.0          
## [43] cli_3.4.1              stringi_1.7.8          cachem_1.0.6          
## [46] XVector_0.38.0         xml2_1.3.3             bslib_0.4.0           
## [49] vctrs_0.5.0            org.Hs.eg.db_3.16.0    tools_4.2.1           
## [52] bit64_4.0.5            fastmap_1.1.0          yaml_2.3.6            
## [55] AnnotationDbi_1.60.0   memoise_2.0.1          sass_0.4.2