Last updated: 2021-01-27
Checks: 7 0
Knit directory: muse/
This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.
Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.
Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.
The command set.seed(20200712)
was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.
Great job! Recording the operating system, R version, and package versions is critical for reproducibility.
Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.
Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.
Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.
The results in this page were generated with repository version 687a6ca. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.
Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish
or wflow_git_commit
). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:
Ignored files:
Ignored: .DS_Store
Ignored: .Rhistory
Ignored: .Rproj.user/
Ignored: analysis/.Rhistory
Untracked files:
Untracked: analysis/linear_regression.Rmd
Untracked: data/gencode.v36.annotation.gtf.gz
Unstaged changes:
Modified: .gitignore
Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.
These are the previous versions of the repository in which changes were made to the R Markdown (analysis/go_enrichment.Rmd
) and HTML (docs/go_enrichment.html
) files. If you’ve configured a remote Git repository (see ?wflow_git_remote
), click on the hyperlinks in the table below to view the files as they were in that past version.
File | Version | Author | Date | Message |
---|---|---|---|---|
Rmd | 687a6ca | davetang | 2021-01-27 | Gene Ontology Enrichment Analysis |
The Gene Ontology Enrichment Analysis (GOEA) is a typical analysis carried out on transcriptome data. Online tools for performing a GOEA include DAVID, Enrichr, and PANTHER just to name a few. While web-based tools are easy to use, it becomes tedious when you have to analyse (or re-analyse) lots of datasets. Therefore, it is preferable to use a programmatic approach and in this post we will check out some Bioconductor packages that allow to perform a GOEA.
First install the following packages, if necessary, and then load them.
if (!requireNamespace("BiocManager", quietly = TRUE))
install.packages("BiocManager")
my_packages <- c("clusterProfiler",
"GOstats",
"GO.db",
"org.Hs.eg.db")
to_install <- my_packages[!my_packages %in% installed.packages()]
BiocManager::install(pkgs = to_install)
# load all packages and suppress output of sapply
invisible(sapply(my_packages, library, character.only = TRUE))
Create a positive control where the gene set are composed of genes that are all associated with GO:0007411
(axon guidance); we will use the org.Hs.eg.db
package to achieve this based on the vignette.
Methods that can be applied to AnnotationDbi
objects such as org.Hs.eg.db
include: columns
, keytypes
, keys
, and select
.
Use columns
to find out what data can be retrived using select
.
columns(org.Hs.eg.db)
[1] "ACCNUM" "ALIAS" "ENSEMBL" "ENSEMBLPROT" "ENSEMBLTRANS"
[6] "ENTREZID" "ENZYME" "EVIDENCE" "EVIDENCEALL" "GENENAME"
[11] "GO" "GOALL" "IPI" "MAP" "OMIM"
[16] "ONTOLOGY" "ONTOLOGYALL" "PATH" "PFAM" "PMID"
[21] "PROSITE" "REFSEQ" "SYMBOL" "UCSCKG" "UNIGENE"
[26] "UNIPROT"
Use keytypes
to find out what fields we can use as keys to query the database.
keytypes(org.Hs.eg.db)
[1] "ACCNUM" "ALIAS" "ENSEMBL" "ENSEMBLPROT" "ENSEMBLTRANS"
[6] "ENTREZID" "ENZYME" "EVIDENCE" "EVIDENCEALL" "GENENAME"
[11] "GO" "GOALL" "IPI" "MAP" "OMIM"
[16] "ONTOLOGY" "ONTOLOGYALL" "PATH" "PFAM" "PMID"
[21] "PROSITE" "REFSEQ" "SYMBOL" "UCSCKG" "UNIGENE"
[26] "UNIPROT"
Select all genes with GO:0007411
.
go_to_entrez <- select(org.Hs.eg.db,
keys = "GO:0007411",
columns = "ENTREZID",
keytype = "GO")
'select()' returned 1:many mapping between keys and columns
axon_gene <- unique(go_to_entrez$ENTREZID)
length(axon_gene)
[1] 205
To perform the GOEA we need to create a gene background called the universe
and we will use all genes with a GO term. Normally the universe
should be the list of genes that were actually assayed in your transcriptome analysis.
all_go_terms <- keys(org.Hs.eg.db, keytype = "GO")
all_go <- select(org.Hs.eg.db, keys = all_go_terms, columns = c("ENTREZID", "GO"), keytype = "GO")
'select()' returned 1:many mapping between keys and columns
universe <- unique(all_go$ENTREZID)
length(universe)
[1] 20488
The function hyperGTest
will perform the GOEA based on a set of parameters; in this example, we are testing for the over-representation of biological process (BP) terms and using a p-value cutoff of 0.001 or less.
params <- new('GOHyperGParams',
geneIds = axon_gene,
universeGeneIds = universe,
ontology = 'BP',
pvalueCutoff = 0.001,
conditional = FALSE,
testDirection = 'over',
annotation = "org.Hs.eg.db"
)
my_test <- hyperGTest(params)
my_test
Gene to GO BP test for over-representation
4723 GO BP ids tested (1069 have p < 0.001)
Selected gene set size: 205
Gene universe size: 18670
Annotation package: org.Hs.eg
Use summary
to get a summary of the results. The summary contains the GOID
, Pvalue
, OddsRatio
, ExpCount
, Count
, and Size
.
ExpCount
is the expected countCount
is how many instances of that term were actually observed in your gene listSize
is the number that could have been found in your gene list if every instance had turned uphead(summary(my_test))
GOBPID Pvalue OddsRatio ExpCount Count Size
1 GO:0007409 0.00000e+00 Inf 5.138725 205 468
2 GO:0007411 0.00000e+00 Inf 3.030530 205 276
3 GO:0048667 0.00000e+00 Inf 6.401446 205 583
4 GO:0061564 0.00000e+00 Inf 5.643814 205 514
5 GO:0097485 0.00000e+00 Inf 3.041510 205 277
6 GO:0006935 6.87054e-316 Inf 7.071237 205 644
Term
1 axonogenesis
2 axon guidance
3 cell morphogenesis involved in neuron differentiation
4 axon development
5 neuron projection guidance
6 chemotaxis
GO terms associated to axons are enriched as expected. Note that the Count
and Size
for GO:0007411 is not identical even though we had selected all genes associated with GO:0007411.
If we manually select Entrez gene IDs using org.Hs.egGO
, we still get the same list of genes, so I’m not sure how the size is calculated by hyperGTest
.
my_df <- as.data.frame(org.Hs.egGO)
my_idx <- my_df$go_id == "GO:0007411"
length(unique(my_df[my_idx, "gene_id"])) == length(axon_gene)
[1] TRUE
We can use the biomaRt
package for converting between different gene identifiers and in this example, we will convert Ensembl gene IDs to Entrez gene IDs.
if (!"biomaRt" %in% installed.packages()){
BiocManager::install("biomaRt")
}
library("biomaRt")
We will fetch every Ensembl gene ID and randomly select 10 IDs to convert into Entrez gene IDs.
ensembl <- useMart("ensembl", dataset="hsapiens_gene_ensembl")
my_chr <- c(1:22, 'M', 'X', 'Y')
my_ensembl_gene <- getBM(attributes = 'ensembl_gene_id',
filters = 'chromosome_name',
values = my_chr,
mart = ensembl)
head(my_ensembl_gene)
ensembl_gene_id
1 ENSG00000223972
2 ENSG00000227232
3 ENSG00000278267
4 ENSG00000243485
5 ENSG00000284332
6 ENSG00000237613
Select 10 Ensembl gene IDs.
set.seed(1984)
to_convert <- sample(x = my_ensembl_gene$ensembl_gene_id, size = 10, replace = FALSE)
Now to convert the IDs.
to_entrez <- getBM(attributes = c('ensembl_gene_id', 'entrezgene_id'),
filters = 'ensembl_gene_id',
values = to_convert,
mart = ensembl)
to_entrez
ensembl_gene_id entrezgene_id
1 ENSG00000124568 6568
2 ENSG00000131400 9476
3 ENSG00000212191 NA
4 ENSG00000225315 NA
5 ENSG00000228658 NA
6 ENSG00000256659 101927694
7 ENSG00000257890 NA
8 ENSG00000267552 NA
9 ENSG00000280344 NA
10 ENSG00000281133 NA
Note that not all Ensembl IDs have Entrez IDs. We can find out how many Ensembl IDs do not have Entrez IDs.
my_entrez_gene <- getBM(attributes = c('ensembl_gene_id', 'entrezgene_id'),
filters = 'ensembl_gene_id',
values = my_ensembl_gene,
mart = ensembl)
table(is.na(my_entrez_gene$entrezgene_id))
FALSE TRUE
25628 35099
35099 out of 60727 Ensembl gene IDs do not have corresponding Entrez gene IDs. To learn more about the missing Entrez ID values from the Ensembl conversion see this useful post on BioStars.
sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
locale:
[1] en_AU.UTF-8/en_AU.UTF-8/en_AU.UTF-8/C/en_AU.UTF-8/en_AU.UTF-8
attached base packages:
[1] stats4 parallel stats graphics grDevices utils datasets
[8] methods base
other attached packages:
[1] biomaRt_2.44.4 org.Hs.eg.db_3.11.4 GO.db_3.11.4
[4] GOstats_2.54.0 graph_1.66.0 Category_2.54.0
[7] Matrix_1.3-2 AnnotationDbi_1.50.3 IRanges_2.22.2
[10] S4Vectors_0.26.1 Biobase_2.48.0 BiocGenerics_0.34.0
[13] clusterProfiler_3.16.1 workflowr_1.6.2
loaded via a namespace (and not attached):
[1] fgsea_1.14.0 colorspace_2.0-0 ellipsis_0.3.1
[4] ggridges_0.5.3 rprojroot_2.0.2 qvalue_2.20.0
[7] fs_1.5.0 rstudioapi_0.13 farver_2.0.3
[10] urltools_1.7.3 graphlayouts_0.7.1 ggrepel_0.9.1
[13] bit64_4.0.5 scatterpie_0.1.5 xml2_1.3.2
[16] splines_4.0.3 cachem_1.0.1 GOSemSim_2.14.2
[19] knitr_1.30 polyclip_1.10-0 jsonlite_1.7.2
[22] annotate_1.66.0 dbplyr_2.0.0 ggforce_0.3.2
[25] BiocManager_1.30.10 compiler_4.0.3 httr_1.4.2
[28] rvcheck_0.1.8 assertthat_0.2.1 fastmap_1.1.0
[31] later_1.1.0.1 tweenr_1.0.1 htmltools_0.5.1.1
[34] prettyunits_1.1.1 tools_4.0.3 igraph_1.2.6
[37] gtable_0.3.0 glue_1.4.2 reshape2_1.4.4
[40] DO.db_2.9 dplyr_1.0.3 rappdirs_0.3.1
[43] fastmatch_1.1-0 Rcpp_1.0.6 enrichplot_1.8.1
[46] vctrs_0.3.6 ggraph_2.0.4 xfun_0.20
[49] stringr_1.4.0 lifecycle_0.2.0 XML_3.99-0.5
[52] DOSE_3.14.0 europepmc_0.4 MASS_7.3-53
[55] scales_1.1.1 tidygraph_1.2.0 hms_1.0.0
[58] promises_1.1.1 RBGL_1.64.0 RColorBrewer_1.1-2
[61] curl_4.3 yaml_2.2.1 memoise_2.0.0
[64] gridExtra_2.3 ggplot2_3.3.3 downloader_0.4
[67] triebeard_0.3.0 stringi_1.5.3 RSQLite_2.2.3
[70] genefilter_1.70.0 BiocParallel_1.22.0 rlang_0.4.10
[73] pkgconfig_2.0.3 bitops_1.0-6 evaluate_0.14
[76] lattice_0.20-41 purrr_0.3.4 cowplot_1.1.1
[79] bit_4.0.4 tidyselect_1.1.0 AnnotationForge_1.30.1
[82] GSEABase_1.50.1 plyr_1.8.6 magrittr_2.0.1
[85] R6_2.5.0 generics_0.1.0 DBI_1.1.1
[88] withr_2.4.1 pillar_1.4.7 whisker_0.4
[91] survival_3.2-7 RCurl_1.98-1.2 tibble_3.0.5
[94] crayon_1.3.4 BiocFileCache_1.12.1 rmarkdown_2.6
[97] viridis_0.5.1 progress_1.2.2 grid_4.0.3
[100] data.table_1.13.6 Rgraphviz_2.32.0 blob_1.2.1
[103] git2r_0.28.0 digest_0.6.27 xtable_1.8-4
[106] tidyr_1.1.2 httpuv_1.5.5 gridGraphics_0.5-1
[109] openssl_1.4.3 munsell_0.5.0 viridisLite_0.3.0
[112] ggplotify_0.0.5 askpass_1.1