Setup
Install and Load XGR
- First Install Package using the BiocManager Package (Once Per
Computer)
- This takes a little bit of time, so it would be best to install this
before the lesson!
- Follow the prompts in the command line, and do not update packages
when asked (This saves install time)
- XGR is not located on CRAN, instead it can be downloaded from the
XGR github using the bioconductor packages
if(!("BiocManager" %in% rownames(installed.packages()))) install.packages("BiocManager")
BiocManager::install("remotes", dependencies=T)
## Bioconductor version 3.17 (BiocManager 1.30.20), R 4.3.0 (2023-04-21)
## Warning: package(s) not installed when version(s) same as or greater than current; use
## `force = TRUE` to re-install: 'remotes'
## Installation paths not writeable, unable to update packages
## path: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
## packages:
## class, KernSmooth, MASS, Matrix, mgcv, nnet, spatial
## Old packages: 'BiocManager', 'broom', 'bslib', 'cachem', 'cpp11', 'curl',
## 'dbplyr', 'digest', 'evaluate', 'fs', 'future', 'gargle', 'googledrive',
## 'googlesheets4', 'haven', 'httr', 'igraph', 'jsonlite', 'jtools', 'knitr',
## 'lme4', 'MatrixModels', 'multcomp', 'mvtnorm', 'openssl', 'pkgload',
## 'polspline', 'pROC', 'processx', 'quantreg', 'Rcpp', 'readxl', 'rmarkdown',
## 'rstudioapi', 'sass', 'sys', 'testthat', 'vctrs', 'viridis', 'viridisLite',
## 'xml2'
BiocManager::install("hfang-bristol/XGR", dependencies=T)
## Bioconductor version 3.17 (BiocManager 1.30.20), R 4.3.0 (2023-04-21)
## Installing github package(s) 'hfang-bristol/XGR'
## Skipping install of 'XGR' from a github remote, the SHA1 (7b947080) has not changed since last install.
## Use `force = TRUE` to force installation
## Installation paths not writeable, unable to update packages
## path: /Library/Frameworks/R.framework/Versions/4.3-x86_64/Resources/library
## packages:
## class, KernSmooth, MASS, Matrix, mgcv, nnet, spatial
## Old packages: 'BiocManager', 'broom', 'bslib', 'cachem', 'cpp11', 'curl',
## 'dbplyr', 'digest', 'evaluate', 'fs', 'future', 'gargle', 'googledrive',
## 'googlesheets4', 'haven', 'httr', 'igraph', 'jsonlite', 'jtools', 'knitr',
## 'lme4', 'MatrixModels', 'multcomp', 'mvtnorm', 'openssl', 'pkgload',
## 'polspline', 'pROC', 'processx', 'quantreg', 'Rcpp', 'readxl', 'rmarkdown',
## 'rstudioapi', 'sass', 'sys', 'testthat', 'vctrs', 'viridis', 'viridisLite',
## 'xml2'
## reload the installed package
library(XGR)
## Loading required package: igraph
##
## Attaching package: 'igraph'
## The following objects are masked from 'package:stats':
##
## decompose, spectrum
## The following object is masked from 'package:base':
##
## union
## Loading required package: dnet
## Loading required package: supraHex
## Loading required package: hexbin
## Loading required package: ggplot2
Load Additional Packages used
- tidyverse - Data Cleaning and Plotting Tools
- kableExtra - Nicely formatted tables for rMarkdown
- RColorBrewer - Color Palettes for Plots
#install.packages('tidyverse')
#install.packages('kableExtra')
#install.packages('RColorBrewer')
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.2 ✔ readr 2.1.4
## ✔ forcats 1.0.0 ✔ stringr 1.5.0
## ✔ lubridate 1.9.2 ✔ tibble 3.2.1
## ✔ purrr 1.0.1 ✔ tidyr 1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ lubridate::%--%() masks igraph::%--%()
## ✖ dplyr::as_data_frame() masks tibble::as_data_frame(), igraph::as_data_frame()
## ✖ purrr::compose() masks igraph::compose()
## ✖ tidyr::crossing() masks igraph::crossing()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::simplify() masks igraph::simplify()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(kableExtra)
##
## Attaching package: 'kableExtra'
##
## The following object is masked from 'package:dplyr':
##
## group_rows
library(RColorBrewer)
Generate XGR Objects
Generate_XGR_list <- function(data, contrast, mygo , tree = F, l2fc ,background){
mysymbol <- data %>% dplyr::filter(FDR < 0.1, abs(L2FC) > l2fc, Treatment == contrast) %>%
dplyr::select(Symbol, FDR) %>% mutate(symbol = toupper(Symbol)) %>%
pull(symbol)
myxgr <- xEnricherGenes(data = mysymbol, ontology = mygo, background = background,ontology.algorithm = ifelse(tree == F,"none","lea"))
if(tree == F){myxgr <- try(xEnrichConciser(myxgr))}
}
xgr_list <- list(
Generate_XGR_list(contrast = mycontrasts[1], mygo = "MsigdbH", data = contrasts, l2fc = 0,background = background),
Generate_XGR_list(contrast = mycontrasts[2], mygo = "MsigdbH", data = contrasts, l2fc = 0,background = background),
Generate_XGR_list(contrast = mycontrasts[3], mygo = "MsigdbH", data = contrasts, l2fc = 0,background = background)
)
## Start at 2023-07-25 11:24:19.593127
##
## Load the ontology MsigdbH and its gene annotations (2023-07-25 11:24:19.594203) ...
## Start at 2023-07-25 11:24:19.594422
##
## 'org.Hs.egMsigdbH' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.egMsigdbH.RData) has been loaded into the working environment (at 2023-07-25 11:24:20.019346)
##
## End at 2023-07-25 11:24:20.019665
## Runtime in total is: 1 secs
## Do gene mapping from Symbols to EntrezIDs (2023-07-25 11:24:20.023773) ...
## Start at 2023-07-25 11:24:20.024428
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:21.758037)
##
## End at 2023-07-25 11:24:21.758273
## Runtime in total is: 1 secs
## human organism (2023-07-25 11:24:21.758686)
## Among 4754 symbols of input data, there are 3886 mappable via official gene symbols but 868 left unmappable
## Start at 2023-07-25 11:24:21.776261
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:23.533338)
##
## End at 2023-07-25 11:24:23.533611
## Runtime in total is: 2 secs
## human organism (2023-07-25 11:24:23.534115)
## Among 8688 symbols of input data, there are 6933 mappable via official gene symbols but 1755 left unmappable
##
## #######################################################
## 'xEnricher' is being called (2023-07-25 11:24:23.589359):
## #######################################################
## First, generate a subgraph induced (via 'all_paths' mode) by the annotation data (2023-07-25 11:24:23.59203) ...
## Next, prepare enrichment analysis (2023-07-25 11:24:23.954258) ...
## There are 3886 genes/SNPs of interest tested against 6933 genes/SNPs as the background (annotatable only? FALSE) (2023-07-25 11:24:23.954988)
## Third, perform enrichment analysis using 'fisher' test (2023-07-25 11:24:23.9596) ...
## There are 49 terms being used, each restricted within [10,2000] annotations
## Last, adjust the p-values for 48 terms (with 5 minimum overlaps) using the BH method (2023-07-25 11:24:24.245787) ...
## Start at 2023-07-25 11:24:24.271841
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:26.133479)
##
## End at 2023-07-25 11:24:26.133711
## Runtime in total is: 2 secs
## #######################################################
## 'xEnricher' has been finished (2023-07-25 11:24:26.952061)!
## #######################################################
##
## End at 2023-07-25 11:24:26.952499
## Runtime in total (xEnricherGenes): 7 secs
## Among 48 terms, there are 48 non-redundant terms
## Start at 2023-07-25 11:24:26.997363
##
## Load the ontology MsigdbH and its gene annotations (2023-07-25 11:24:26.997907) ...
## Start at 2023-07-25 11:24:26.998098
##
## 'org.Hs.egMsigdbH' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.egMsigdbH.RData) has been loaded into the working environment (at 2023-07-25 11:24:27.509564)
##
## End at 2023-07-25 11:24:27.509844
## Runtime in total is: 1 secs
## Do gene mapping from Symbols to EntrezIDs (2023-07-25 11:24:27.511948) ...
## Start at 2023-07-25 11:24:27.512233
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:29.374229)
##
## End at 2023-07-25 11:24:29.374583
## Runtime in total is: 2 secs
## human organism (2023-07-25 11:24:29.375001)
## Among 5019 symbols of input data, there are 4117 mappable via official gene symbols but 902 left unmappable
## Start at 2023-07-25 11:24:29.392623
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:31.229239)
##
## End at 2023-07-25 11:24:31.229474
## Runtime in total is: 2 secs
## human organism (2023-07-25 11:24:31.229886)
## Among 8688 symbols of input data, there are 6933 mappable via official gene symbols but 1755 left unmappable
##
## #######################################################
## 'xEnricher' is being called (2023-07-25 11:24:31.262915):
## #######################################################
## First, generate a subgraph induced (via 'all_paths' mode) by the annotation data (2023-07-25 11:24:31.26369) ...
## Next, prepare enrichment analysis (2023-07-25 11:24:31.371202) ...
## There are 4117 genes/SNPs of interest tested against 6933 genes/SNPs as the background (annotatable only? FALSE) (2023-07-25 11:24:31.371793)
## Third, perform enrichment analysis using 'fisher' test (2023-07-25 11:24:31.375062) ...
## There are 49 terms being used, each restricted within [10,2000] annotations
## Last, adjust the p-values for 48 terms (with 5 minimum overlaps) using the BH method (2023-07-25 11:24:31.690344) ...
## Start at 2023-07-25 11:24:31.72662
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:33.574457)
##
## End at 2023-07-25 11:24:33.574691
## Runtime in total is: 2 secs
## #######################################################
## 'xEnricher' has been finished (2023-07-25 11:24:34.639067)!
## #######################################################
##
## End at 2023-07-25 11:24:34.639684
## Runtime in total (xEnricherGenes): 8 secs
## Among 48 terms, there are 48 non-redundant terms
## Start at 2023-07-25 11:24:34.660349
##
## Load the ontology MsigdbH and its gene annotations (2023-07-25 11:24:34.660843) ...
## Start at 2023-07-25 11:24:34.661022
##
## 'org.Hs.egMsigdbH' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.egMsigdbH.RData) has been loaded into the working environment (at 2023-07-25 11:24:35.077352)
##
## End at 2023-07-25 11:24:35.077605
## Runtime in total is: 1 secs
## Do gene mapping from Symbols to EntrezIDs (2023-07-25 11:24:35.079492) ...
## Start at 2023-07-25 11:24:35.079721
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:36.915083)
##
## End at 2023-07-25 11:24:36.915324
## Runtime in total is: 1 secs
## human organism (2023-07-25 11:24:36.915743)
## Among 4741 symbols of input data, there are 3519 mappable via official gene symbols but 1222 left unmappable
## Start at 2023-07-25 11:24:36.93291
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:38.76152)
##
## End at 2023-07-25 11:24:38.761756
## Runtime in total is: 2 secs
## human organism (2023-07-25 11:24:38.762164)
## Among 8688 symbols of input data, there are 6933 mappable via official gene symbols but 1755 left unmappable
##
## #######################################################
## 'xEnricher' is being called (2023-07-25 11:24:38.78474):
## #######################################################
## First, generate a subgraph induced (via 'all_paths' mode) by the annotation data (2023-07-25 11:24:38.7854) ...
## Next, prepare enrichment analysis (2023-07-25 11:24:38.90665) ...
## There are 3519 genes/SNPs of interest tested against 6933 genes/SNPs as the background (annotatable only? FALSE) (2023-07-25 11:24:38.907389)
## Third, perform enrichment analysis using 'fisher' test (2023-07-25 11:24:38.923147) ...
## There are 49 terms being used, each restricted within [10,2000] annotations
## Last, adjust the p-values for 49 terms (with 5 minimum overlaps) using the BH method (2023-07-25 11:24:39.185688) ...
## Start at 2023-07-25 11:24:39.21597
##
## 'org.Hs.eg' (from http://galahad.well.ox.ac.uk/bigdata/org.Hs.eg.RData) has been loaded into the working environment (at 2023-07-25 11:24:41.073747)
##
## End at 2023-07-25 11:24:41.074141
## Runtime in total is: 2 secs
## #######################################################
## 'xEnricher' has been finished (2023-07-25 11:24:41.767023)!
## #######################################################
##
## End at 2023-07-25 11:24:41.767396
## Runtime in total (xEnricherGenes): 7 secs
## Among 49 terms, there are 49 non-redundant terms
names(xgr_list) <- mycontrasts