Skip to content
Snippets Groups Projects
Commit 46d37f8c authored by Holger Brandl's avatar Holger Brandl
Browse files

moved utility cp functions into commons

parent bfd2dad5
No related branches found
No related tags found
No related merge requests found
#!/usr/bin/env Rscript
#+ echo=FALSE, error=F
# cd
suppressMessages(require(docopt))
## todo use textual input here for ease of use
doc <- '
Perform an enrichment analysis for a set of genes
Usage:gsea_enrichment.R[options] <sorted_gene_lists_tsv> <group_col>
Usage:gsea_enrichment.R[options] <sorted_gene_lists_tsv>
Options:
--list_id_col Column containing the grouping variable to speparate different lists [default: ]
......@@ -23,10 +20,11 @@ opts <- docopt(doc, commandArgs(TRUE)) ## does not work when spining
devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.27/R/core_commons.R")
devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.27/R/ggplot_commons.R")
devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/v1.27/R/bio/diffex_commons.R")
## todo relase and use proper version here
devtools::source_url("https://raw.githubusercontent.com/holgerbrandl/datautils/master/R/bio/diffex_commons.R")
loadpack(knitr)
loadpack(DT)
#loadpack(DT)
#loadpack(clusterProfiler)
......@@ -41,7 +39,8 @@ loadpack(DT)
## load the data
geneLists <- read_tsv(opts$sorted_gene_lists_tsv)
group_col=opts$group_col
#group_col=opts$group_col
group_col="contrast"
geneLists %<>% group_by_(.dots=group_col)
#geneLists %<>% filter(cluster %in% c("cluster_1", "cluster_2"))
......@@ -68,46 +67,10 @@ vec2df(unlist(opts)) %>% filter(!str_detect(name, "^[<-]")) %>% kable()
listLabels <- geneLists %>% select(-ensembl_gene_id) %>% distinct
listLabels %<>% transform(list_label=do.call(paste, c(listLabels, sep="__")))
geneLists %>% inner_join(listLabels) %>%
ggplot(aes(list_label)) +
geom_bar() +
coord_flip() +
ggtitle("gene list sizes to be tested for term enrichment") +
ylab("")
## 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))
}
}
stopifnot(unlen(count(geneLists)$n) == 1) # make sure that all input lists have the same length (to avoid that just degs are provided as input
count(geneLists) %>% kable()
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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment