Skip to content

Instantly share code, notes, and snippets.

@kieranrcampbell
Created May 3, 2017 14:07
Show Gist options
  • Save kieranrcampbell/8a78c1b1fb777ebeca1293133c58280c to your computer and use it in GitHub Desktop.
Save kieranrcampbell/8a78c1b1fb777ebeca1293133c58280c to your computer and use it in GitHub Desktop.
Gene ontology enrichment analysis with Goseq
# A function that takes a set of genes and a background list and goes through the
# steps in goseq to output the enriched list
library(goseq)
#' Run all steps for a goseq analysis
#'
#' @param genes The genes "differentially expressed" or in the condition
#' @param all_genes The background gene set
#' @param genome The genome of genes and all_genes, e.g. mm10 or hg19
#' @param test_cats The test categories, any combination of GO:BP, GO:CC, or GO:MF
#' @return The output of a call to \code{Goseq}
go_analysis <- function(genes, all_genes, genome = "mm10", test_cats = "GO:BP") {
lgl <- 1 * (all_genes %in% genes)
names(lgl) <- all_genes
pwf <- nullp(lgl, genome, "ensGene")
go <- goseq(pwf, genome, "ensGene", test.cats = test_cats)
return(go)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment