diff --git a/DESCRIPTION b/DESCRIPTION index b1c6d328376683c603eaefd4b48bc5e4a3203497..d76ead64b84b0545741a6dfb41506636a2fb6335 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,10 +1,11 @@ Package: coGSEA Title: coGSEA : comparison of Gene Set Enrichment Analysis methods -Version: 0.0.0.9000 +Version: 0.0.1 Authors@R: person("Maxime", "Borry", email = "maxime.borry@gmail.com", role = c("aut", "cre")) Description: comparison of GSEA methods on the ranks and pvalues of genesets. Largely inspired (and contains some code) by eGSEA package. License: MIT Encoding: UTF-8 +LazyData: false Depends: R (>= 3.3.3), parallel, diff --git a/R/comparResumPlot.r b/R/comparResumPlot.r new file mode 100644 index 0000000000000000000000000000000000000000..007ce1d8488c61104429b9e9315db5066019ad1d --- /dev/null +++ b/R/comparResumPlot.r @@ -0,0 +1,10 @@ + +#' Internal function for coGSEA +#' +#' @export + +comparResumPlot = function(preparedData, savePlot = TRUE, legend = TRUE, directoryPath = directoryPath){ + print("Plotting Summary comparison Plot for all conditions") + generateSummaryPlots(comparisonSummaryData(preparedData), savePlot = savePlot, legend = legend, file.name = paste(directoryPath, "_comparison_sumplot", sep = ""), format = "pdf") + +} diff --git a/R/generateSummaryPlots.r b/R/generateSummaryPlots.r index 4a05c170a88584b1365fb527131c6f82d84dac6b..bc6a86f892573594eed8c64613e7adbf99ef6f85 100644 --- a/R/generateSummaryPlots.r +++ b/R/generateSummaryPlots.r @@ -7,6 +7,7 @@ #' @param Ybal label for Y axis (character) #' @param firstN N number of top N genes to highlight in blue (integer) #' @param savePlot Wheter to save the plot, or just display it (boolean) +#' @param legen whether to display or not the legend if savePlot = FALSE (boolean) #' @return A plot if savePlot = TRUE, else nothing #' @examples @@ -16,7 +17,7 @@ #' @export generateSummaryPlots <- function(plot.data, file.name = "resumPlot", Xlab="-log10(p-value)", - Ylab="Average Absolute logFC", format = NULL, firstN = 10, savePlot = TRUE){ + Ylab="Average Absolute logFC", format = NULL, firstN = 10, savePlot = TRUE, legend = TRUE){ if(!require(ggplot2)){ install.packages("ggplot2") require(ggplot2) @@ -116,11 +117,13 @@ name="Regulation Direction") # low="#5FE377" colour=sig.cols, vjust=-1, hjust=1) ) dev.off() } - } else { - p + geom_text(size=5, mapping=aes(x=x.data, y=y.data, + } else if (savePlot == FALSE && legend == TRUE){ + print(p + geom_text(size=5, mapping=aes(x=x.data, y=y.data, label=id), data=plot.data.sig, - colour=sig.cols, vjust=-1, hjust=1) + colour=sig.cols, vjust=-1, hjust=1)) + } else if (savePlot == FALSE && legend == FALSE){ + p } }, diff --git a/R/plots.r b/R/plots.r index b1e1499c95be4f4b94830b97220c82bf451dd0f4..5fb2f0e36307c18300159c50bd877ebf20a57e48 100644 --- a/R/plots.r +++ b/R/plots.r @@ -109,11 +109,6 @@ resumPlot2 = function(preparedData, contrCondi, savePlot = TRUE, directoryPath= } -comparResumPlot2 = function(preparedData, savePlot = TRUE, directoryPath = directoryPath){ - print("Plotting Summary comparison Plot for all conditions") - generateSummaryPlots(comparisonSummaryData(preparedData), savePlot = savePlot, file.name = paste(directoryPath, "_comparison_sumplot", sep = ""), format = "pdf") -} - cGSEAMakePlots = function(preparedData, directoryPath){ dir.create(file.path(directoryPath,"/plots/"), showWarnings = FALSE) for (condi in names(preparedData$result)){ @@ -127,5 +122,5 @@ cGSEAMakePlots = function(preparedData, directoryPath){ resumPlot2(preparedData = preparedData, contrCondi = condi, directoryPath = paste0(directoryPath,"/plots/",condi,"/")) } runTimePlot(preparedData = preparedData, directoryPath = paste0(directoryPath,"/plots/")) - comparResumPlot2(preparedData = preparedData, directoryPath = paste0(directoryPath,"/plots/")) + comparResumPlot(preparedData = preparedData, directoryPath = paste0(directoryPath,"/plots/")) } diff --git a/R/setRankDBMaker.r b/R/setRankDBMaker.r index 951f8e0eb4acd286340922261007a9dc6b399ecc..acdea8627a097648acccf621f9c4bd155ef3cf6a 100644 --- a/R/setRankDBMaker.r +++ b/R/setRankDBMaker.r @@ -1,68 +1,68 @@ -msig_to_setrankDb = function(msigdb, orga, dbname){ - # msigdb : database R object - # orga : organism name (HUMAN|MOUSE) - # dbname : Msig database name (C2|H) - i = 1 - df = data.frame(geneID = factor(), termID = factor(), termName = factor(), dbName = factor(), description = factor()) - for (name in(names(msigdb))){ - for (gene in msigdb[[name]]){ - df = rbind(df, data.frame(geneID = factor(gene), termID = factor(paste(orga,"MSigDB",dbname,i,sep = "_")), termName = factor(name), dbName = factor("MSigDB"), description = factor(""))) - } - i = i+1 - } - return(df) -} - -# #MOUSE -load(url("http://bioinf.wehi.edu.au/software/MSigDB/mouse_H_v5p2.rdata")) -load(url("http://bioinf.wehi.edu.au/software/MSigDB/mouse_c2_v5p2.rdata")) +# msig_to_setrankDb = function(msigdb, orga, dbname){ +# # msigdb : database R object +# # orga : organism name (HUMAN|MOUSE) +# # dbname : Msig database name (C2|H) +# i = 1 +# df = data.frame(geneID = factor(), termID = factor(), termName = factor(), dbName = factor(), description = factor()) +# for (name in(names(msigdb))){ +# for (gene in msigdb[[name]]){ +# df = rbind(df, data.frame(geneID = factor(gene), termID = factor(paste(orga,"MSigDB",dbname,i,sep = "_")), termName = factor(name), dbName = factor("MSigDB"), description = factor(""))) +# } +# i = i+1 +# } +# return(df) +# } # +# # #MOUSE +# load(url("http://bioinf.wehi.edu.au/software/MSigDB/mouse_H_v5p2.rdata")) +# load(url("http://bioinf.wehi.edu.au/software/MSigDB/mouse_c2_v5p2.rdata")) +# # +# # +# # #HUMAN +# load(url("http://bioinf.wehi.edu.au/software/MSigDB/human_H_v5p2.rdata")) +# load(url("http://bioinf.wehi.edu.au/software/MSigDB/human_c2_v5p2.rdata")) # -# #HUMAN -load(url("http://bioinf.wehi.edu.au/software/MSigDB/human_H_v5p2.rdata")) -load(url("http://bioinf.wehi.edu.au/software/MSigDB/human_c2_v5p2.rdata")) - - -Mm.c2.kegg.subset = c(Mm.c2[grep("KEGG",attributes(Mm.c2)$names)]) -Mm.c2.reactome.subset = c(Mm.c2[grep("REACTOME", attributes(Mm.c2)$names)]) - -Hs.c2.kegg.subset = c(Hs.c2[grep("KEGG",attributes(Hs.c2)$names)]) -Hs.c2.reactome.subset = c(Hs.c2[grep("REACTOME", attributes(Hs.c2)$names)]) - -mouse_H = msig_to_setrankDb(Mm.H, "MOUSE", "H") -mouse_C2_kegg = msig_to_setrankDb(Mm.c2.kegg.subset,"MOUSE","C2Kegg") -mouse_C2_reactome = msig_to_setrankDb(Mm.c2.reactome.subset,"MOUSE","C2Reactome") - - - -human_H = msig_to_setrankDb(Hs.H,"HUMAN","H") -human_C2_kegg = msig_to_setrankDb(Hs.c2.kegg.subset,"HUMAN","C2Kegg") -human_C2_reactome = msig_to_setrankDb(Hs.c2.reactome.subset,"HUMAN","C2Reactome") - -MusCollectionH = buildSetCollection(mouse_H, referenceSet = allMusGenes, maxSetSize = 1450) -MusCollectionC2Kegg = buildSetCollection(mouse_C2_kegg, referenceSet = allMusGenes, maxSetSize = 1450) -MusCollectionC2Reactome = buildSetCollection(mouse_C2_reactome, referenceSet = allMusGenes, maxSetSize = 1450) - -HomoCollectionH = buildSetCollection(human_H, referenceSet = allHomoGenes, maxSetSize = 1450) -HomoCollectionC2Kegg = buildSetCollection(human_C2_kegg, referenceSet = allHomoGenes, maxSetSize = 1450) -HomoCollectionC2Reactome = buildSetCollection(human_C2_reactome, referenceSet = allHomoGenes, maxSetSize = 1450) - - -save(MusCollectionH, file = "setRankMusCollection_H.RData") -save(MusCollectionC2Kegg, file = "setRankMusCollection_C2Kegg.RData") -save(MusCollectionC2Reactome, file = "setRankMusCollection_C2Reactome.RData") - -save(HomoCollectionH, file = "setRankHomoCollection_H.RData") -save(HomoCollectionC2Kegg, file = "setRankHomoCollection_C2Kegg.RData") -save(HomoCollectionC2Reactome, file = "setRankHomoCollection_C2Reactome.RData") - -# load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankHomoCollection_H.RData") -# load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankHomoCollection_C2Kegg.RData") -# load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankHomoCollection_C2Reactome.RData") # -# load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankMusCollection_H.RData") -# load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankMusCollection_C2Kegg.RData") -# load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankMusCollection_C2Reactome.RData") - -# too slow when installin package - just put the .rdata files in the /data directory -# devtools::use_data(MusCollectionH, MusCollectionC2Kegg, MusCollectionC2Reactome, HomoCollectionH, HomoCollectionC2Kegg, HomoCollectionC2Reactome, internal = TRUE, compress = "gzip", overwrite = TRUE) +# Mm.c2.kegg.subset = c(Mm.c2[grep("KEGG",attributes(Mm.c2)$names)]) +# Mm.c2.reactome.subset = c(Mm.c2[grep("REACTOME", attributes(Mm.c2)$names)]) +# +# Hs.c2.kegg.subset = c(Hs.c2[grep("KEGG",attributes(Hs.c2)$names)]) +# Hs.c2.reactome.subset = c(Hs.c2[grep("REACTOME", attributes(Hs.c2)$names)]) +# +# mouse_H = msig_to_setrankDb(Mm.H, "MOUSE", "H") +# mouse_C2_kegg = msig_to_setrankDb(Mm.c2.kegg.subset,"MOUSE","C2Kegg") +# mouse_C2_reactome = msig_to_setrankDb(Mm.c2.reactome.subset,"MOUSE","C2Reactome") +# +# +# +# human_H = msig_to_setrankDb(Hs.H,"HUMAN","H") +# human_C2_kegg = msig_to_setrankDb(Hs.c2.kegg.subset,"HUMAN","C2Kegg") +# human_C2_reactome = msig_to_setrankDb(Hs.c2.reactome.subset,"HUMAN","C2Reactome") +# +# MusCollectionH = buildSetCollection(mouse_H, referenceSet = allMusGenes, maxSetSize = 1450) +# MusCollectionC2Kegg = buildSetCollection(mouse_C2_kegg, referenceSet = allMusGenes, maxSetSize = 1450) +# MusCollectionC2Reactome = buildSetCollection(mouse_C2_reactome, referenceSet = allMusGenes, maxSetSize = 1450) +# +# HomoCollectionH = buildSetCollection(human_H, referenceSet = allHomoGenes, maxSetSize = 1450) +# HomoCollectionC2Kegg = buildSetCollection(human_C2_kegg, referenceSet = allHomoGenes, maxSetSize = 1450) +# HomoCollectionC2Reactome = buildSetCollection(human_C2_reactome, referenceSet = allHomoGenes, maxSetSize = 1450) +# +# +# save(MusCollectionH, file = "setRankMusCollection_H.RData") +# save(MusCollectionC2Kegg, file = "setRankMusCollection_C2Kegg.RData") +# save(MusCollectionC2Reactome, file = "setRankMusCollection_C2Reactome.RData") +# +# save(HomoCollectionH, file = "setRankHomoCollection_H.RData") +# save(HomoCollectionC2Kegg, file = "setRankHomoCollection_C2Kegg.RData") +# save(HomoCollectionC2Reactome, file = "setRankHomoCollection_C2Reactome.RData") +# +# # load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankHomoCollection_H.RData") +# # load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankHomoCollection_C2Kegg.RData") +# # load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankHomoCollection_C2Reactome.RData") +# # +# # load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankMusCollection_H.RData") +# # load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankMusCollection_C2Kegg.RData") +# # load("~/GitLab/DEA-DifferentialExpressionAnalysis/setRankMusCollection_C2Reactome.RData") +# +# # too slow when installin package - just put the .rdata files in the /data directory +# # devtools::use_data(MusCollectionH, MusCollectionC2Kegg, MusCollectionC2Reactome, HomoCollectionH, HomoCollectionC2Kegg, HomoCollectionC2Reactome, internal = TRUE, compress = "gzip", overwrite = TRUE)