Commit cf633248 authored by Holger Brandl's avatar Holger Brandl

use load_pack more consistently; started cp-utils

parent aa5ad2a4
......@@ -2,7 +2,7 @@
#library(Biostrings, quietly=T)
#require_auto(BiocGenerics x
#loadpack(Biostrings)
#load_pack(Biostrings)
## install Biostrings if not yet there
install_package("Biostrings")
......
install_package(clusterProfiler)
## todo move to diffex commons
guess_cp_species <- function(ensIds){
an_id <-ensIds[1]
if(str_detect(an_id, "ENSG")){
return("human")
}else if(str_detect(an_id, "ENSMUSG")){
return("mouse")
}else if(str_detect(an_id, "ENSDARG")){
return("zebrafish")
}else if(str_detect(an_id, "FBgn")){
return("fly")
}else{
stop(paste("could not clusterProfiler species name from ", an_id))
}
}
guess_anno_db <- function(ensIds){
an_id <-ensIds[1]
if(str_detect(an_id, "ENSG")){
return("org.Hs.eg.db")
}else if(str_detect(an_id, "ENSMUSG")){
return("org.Mm.eg.db")
}else if(str_detect(an_id, "ENSDARG")){
return("org.Dr.eg.db")
}else if(str_detect(an_id, "FBgn")){
return("org.Dm.eg.db")
}else{
stop(paste("could not anno db mart from ", an_id))
}
}
#source("http://bioconductor.org/biocLite.R")
#biocLite("org.Mm.eg.db")
#biocLite("org.Hs.eg.db")
#biocLite("org.Dr.eg.db")
#biocLite("org.Dm.eg.db")
#biocLite("KEGG.db")
load_pack(ReactomePA)
cp_test <- function(geneIds){
# DEBUG geneIds <- glMapped %>% filter(cluster %in% c("cluster_9")) %$% entrez_gene_id %>% as.integer
# DEBUG geneIds <- head(glMapped,30)$entrez_gene_id
# geneIds=.$entrez_gene_id
if(length(geneIds)>1500){
geneIds <- sample(geneIds) %>% head(1500)
}
echo("testing", length(geneIds), " genes for enrichment")
# PANTHER10_ontology <- read.delim("http://data.pantherdb.org/PANTHER10.0/ontology/Protein_Class_7.0")
# browser()
# pantherResults <- enricher(gene = geneIds, organism = cpSpecies, qvalueCutoff = qCutoff, readable = TRUE, TERM2GENE = PANTHER10_ontology) %>% summary()
keggResults <- clusterProfiler::enrichKEGG(gene = geneIds, organism = cpSpecies, qvalueCutoff = qCutoff, use_internal_data=T) %>% summary()
reactomeResults <- enrichPathway(gene = geneIds, organism = cpSpecies, qvalueCutoff = qCutoff) %>% summary()
goResultsCC <- clusterProfiler::enrichGO(gene = geneIds, OrgDb = annoDb, qvalueCutoff = qCutoff, ont = "CC") %>% summary()
goResultsMF <- clusterProfiler::enrichGO(gene = geneIds, OrgDb = annoDb, qvalueCutoff = qCutoff, ont = "MF") %>% summary()
goResultsBP <- clusterProfiler::enrichGO(gene = geneIds, OrgDb = annoDb, qvalueCutoff = qCutoff, ont = "BP") %>% summary()
#cp-bug: if no pathways are enriched odd strucuture is retured ##todo file issue
if(!("data.frame" %in% class(keggResults))) keggResults <- filter(goResultsBP, Description="foobar")
enrResults <- bind_rows(
mutate(keggResults, ontology="kegg"),
mutate(reactomeResults, ontology="reactome"),
mutate(goResultsBP, ontology="go_bp"),
mutate(goResultsMF, ontology="go_mf"),
mutate(goResultsCC, ontology="go_cc")
)
enrResults
# echo("numResults", nrow(enrResults))
}
## example
if(F){
someGenes = c("") ## todo continue
cpSpecies <- guess_cp_species(someGenes)
annoDb <- guess_anno_db(someGenes) # e.g. "org.Hs.eg.db"
enrResults <- cp_test(someGenes)
## or for grouped data
#enrResults <- quote(glMapped %>% do(cp_test(.$entrez_gene_id))) %>% cache_it(paste0("enrdata_", digest(glMapped)))
## test custom ontology
#enrichrFile_TFchip = "/projects/bioinfo/holger/data/enrichr_datasets/ENCODE_TF_ChIP-seq_2015.txt"
#tfChipOnt <- convert_enrichr_cp(enrichrFile_TFchip)
}
\ No newline at end of file
......@@ -31,7 +31,7 @@ options(gsubfn.engine = "R")
## automatic package installation
require_auto <- function(x){
warning("require_auto is deprecated, use loadpack() instead")
warning("require_auto is deprecated, use load_pack() instead")
x <- as.character(substitute(x))
......@@ -75,7 +75,7 @@ load_pack <- function(x, warn_conflicts=T){
install_package(x)
## load it using a library function so that loadpack errors if package is still not ins
## load it using a library function so that load_pack errors if package is still not ins
eval(parse(text=paste("library(", x, ", quietly=T, warn.conflicts=", warn_conflicts, ")", sep="")))
}
......@@ -86,7 +86,7 @@ loadpack <- function(x, warn_conflicts=T){
install_package(x)
## load it using a library function so that loadpack errors if package is still not ins
## load it using a library function so that load_pack errors if package is still not ins
eval(parse(text=paste("library(", x, ", quietly=T, warn.conflicts=", warn_conflicts, ")", sep="")))
}
......@@ -100,34 +100,34 @@ check_version = function(pkg_name, min_version) {
########################################################################################################################
## load core packages
loadpack(plyr)
loadpack(stringr)
loadpack(reshape2)
#loadpack(reshape2, quietly=T, warn_conflicts=F)
load_pack(plyr)
load_pack(stringr)
load_pack(reshape2)
#load_pack(reshape2, quietly=T, warn_conflicts=F)
## load on purpose after plyr
loadpack(dplyr, warn_conflicts=F)
loadpack(magrittr, warn_conflicts=F)
loadpack(tidyr, warn_conflicts=F)
load_pack(dplyr, warn_conflicts=F)
load_pack(magrittr, warn_conflicts=F)
load_pack(tidyr, warn_conflicts=F)
## needed for caching
loadpack(digest)
loadpack(readr)
suppressWarnings(loadpack(readxl)) ## supress differring build number
#loadpack(readxl) ## supress differring build number
load_pack(digest)
load_pack(readr)
suppressWarnings(load_pack(readxl)) ## supress differring build number
#load_pack(readxl) ## supress differring build number
## common plotting requirements since they are omnipresent
loadpack(ggplot2)
loadpack(scales, warn_conflicts=F)
loadpack(grid)
load_pack(ggplot2)
load_pack(scales, warn_conflicts=F)
load_pack(grid)
## for table exploration without using Rstudio
loadpack(DT)
load_pack(DT)
## moved into datatable_commons because replaced almost everywhere with dplyr
#loadpack(data.table)
#load_pack(data.table)
......@@ -461,6 +461,6 @@ assert <- function (expr, error) {
}
### table rendering
table_browser <- function(df){
datatable(df, filter = "bottom", extensions = 'Buttons', options = list( dom = 'Bfrtip', buttons = c('copy', 'csv', 'excel')))
table_browser <- function(df, ...){
datatable(df, filter = "bottom", extensions = 'Buttons', options = list( dom = 'Bfrtip', buttons = c('copy', 'csv', 'excel')), ...)
}
......@@ -2,8 +2,8 @@
#library(ggplot2)
#library(reshape2)
require_auto(ggdendro)
require_auto(grid)
load_pack(ggdendro)
load_pack(grid)
## Adopted from http://cwcode.wordpress.com/2013/01/30/ggheatmap-version-2/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment