Closed nina-hahn closed 3 months ago
So you basically would like to have a plot in which the ratios (e.g. 9/81
) are displayed as fraction (0.111
)?
First of all, I don't know why the function dotplot
seems to sometimes plot ratios, and other times fractions...
Yet, a simple (but not a really elegant) solution would be to first manually convert the ratios to fractions before plotting. This is just adding a single line of code:
ego.combined@compareClusterResult$GeneRatio <- sapply( strsplit(ego.combined@compareClusterResult$GeneRatio, "/"),
function(x) as.numeric(x[1])/as.numeric(x[2]) )
Example:
> library(clusterProfiler)
> library(enrichplot)
> library(org.Hs.eg.db)
>
> data(geneList, package="DOSE")
> genes.up <- names(geneList)[geneList > 2]
> genes.down <- names(geneList)[geneList < -2]
>
>
> up <- enrichGO(gene = genes.up,
+ universe = names(geneList),
+ OrgDb = org.Hs.eg.db,
+ ont = "ALL",
+ pAdjustMethod = "BH",
+ pvalueCutoff = 0.05,
+ qvalueCutoff = 0.05,
+ readable = TRUE)
>
>
> down <- enrichGO(gene = genes.down,
+ universe = names(geneList),
+ OrgDb = org.Hs.eg.db,
+ ont = "ALL",
+ pAdjustMethod = "BH",
+ pvalueCutoff = 0.05,
+ qvalueCutoff = 0.05,
+ readable = TRUE)
>
>
> ego.up <- pairwise_termsim(up, showCategory=30)
> ego.up <-simplify(ego.up, cutoff=0.7, by="p.adjust", select_fun=min)
>
>
> ego.down <- pairwise_termsim(down, showCategory=30)
> ego.down <-simplify(ego.down, cutoff=0.7, by="p.adjust", select_fun=min)
>
> ego.list<-list("activated"=ego.up, "suppressed"=ego.down)
> ego.combined <- merge_result(ego.list)
>
>
> ## plot with ratio
> dotplot(ego.combined,split="Cluster", showCategory=15, x="GeneRatio",
+ size= "count", font.size=7, label_format=10) +
+ facet_grid(.~Cluster) +
+ ggtitle("GO ORA, displaying ratios")
>
>
> ## manually convert ratios into fractions
> ego.combined@compareClusterResult$GeneRatio <- sapply( strsplit(ego.combined@compareClusterResult$GeneRatio, "/"),
+ function(x) as.numeric(x[1])/as.numeric(x[2]) )
>
> ## plot with fraction
> dotplot(ego.combined,split="Cluster", showCategory=15, x="GeneRatio",
+ size= "count", font.size=7, label_format=10) +
+ facet_grid(.~Cluster) +
+ ggtitle("GO ORA, displaying fractions")
>
should be fixed with https://github.com/YuLab-SMU/enrichplot/commit/17e42c43cc51e6b657e9a7428f9b3bc569094ae9.
Thanks a lot. It might be a silly question: How can I update to that version? Updating in R Studio, even with devtools leads to vresion 1.24.2.
Best, Nina
As you can see here the latest version of enrichplot
at the Bioconductor 'release' repository is 1.24.2
.
You can see here that the latest fix incorporated into 1.24.2
is dated July 19, 2024. If you click on the commit you indeed see that the fix for 'your' problem hasn't been incorporated/propagated yet. This is expected because propagation to the Bioconductor repository usually takes a couple of days.
What I usually do is install directly from GitHub. See below. This makes sure you are using the latest of the latest of a package...
BiocManager::install(c('YuLab-SMU/enrichplot'), force=TRUE)
Note that this is synonym to installing a development package, and installing from Github / a dev package may sometimes break the functionality of a package... If so, you should revert back to the release version of a package, and install the development version of Bioconductor in a separate instance of a dev version of R (along your 'working' installation). Yet, don't worry: this isn't the case for enrichplot
; you can just install it from GitHub.
Hi Guido,
thanks. It seems that I am still doing something wrong. Here is my history. enrichplot is still the 1.24.2 versiond and the dotplot with the previous gene ratio as fraction.
Thanks for your support.
Best Nina
1) Make sure that all your R
sessions and R-studio
are closed.
2) Open a new, fresh R
session, and run BiocManager::install(c('YuLab-SMU/enrichplot'), force=TRUE)
. Nothing more, nothing less!
3) Check by running packageVersion("enrichplot")
.
4) Rerun all your code.
You will need to do this in a fresh R
session, because otherwise the library may be already loaded, and this will prevent updating (since its files are locked)!
The same applies if multiple R
sessions are open; if in one of them enrichplot
is loaded (by library()
), then it can not be updated in any R
session...
Also, be sure to check all messages that are reported after installing from GitHub using BiocManager::install
!
I tried and got this warnings
1: In untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers
2: In untar2(tarfile, files, list, exdir, restore_times) :
skipping pax global extended headers
3: In i.p(...) :
Installation des Pakets ‘C:/Temp/RtmpcBEQIn/file3d741d946737/enrichplot_1.25.1.001.tar.gz’ hatte Exit-Status ungleich 0
I then tried to install the packages manually refering to the given path C:/Temp/RtmpcBEQIn/file3d741d946737/. After that I got the message
Error: Error installing package 'enrichplot':
======================================
* installing *source* package 'enrichplot' ...
** using staged installation
** R
** byte-compile and prepare package for lazy loading
Fehler in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
Namensraum 'DOSE' 3.30.2 ist geladen, aber >= 3.31.2 wird benötigt
Ruft auf: <Anonymous> ... namespaceImportFrom -> asNamespace -> loadNamespace
Ausführung angehalten
ERROR: lazy loading failed for package 'enrichplot'
I then tried solving it the identical way you suggested with enrichplot using
BiocManager::install(c('YuLab-SMU/DOSE'), force=TRUE)
Again, installation was not possible, I figured out the path, tried to install that one manually but then stopped at
Fehler in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]) :
Namensraum 'GOSemSim' 2.30.0 ist geladen, aber >= 2.31.1 wird benötigt
It seems to be an endless try to update various packages and no successfull automatic installation. How can I try to solve it? I am sorry, that I an not so experienced with developping versions yet.
Best Nina
PS. Continuing with GoSemSim: leads to error
* installing *source* package 'GOSemSim' ...
** using staged installation
** libs
g++ -std=gnu++17 -I"C:/PROGRA~1/R/R-44~1.0/include" -DNDEBUG -I'C:/Users/.........renv/library/windows/R-4.4/x86_64-w64-mingw32/Rcpp/include' -I"c:/rtools44/x86_64-w64-mingw32.static.posix/include" -O2 -Wall -mfpmath=sse -msse2 -mstackrealign -c ICmethod.cpp -o ICmethod.o
/bin/sh: line 1: g++: command not found
make: *** [C:/PROGRA~1/R/R-44~1.0/etc/x64/Makeconf:296: ICmethod.o] Error 127
ERROR: compilation failed for package 'GOSemSim'
* removing 'C:/Users/........../renv/staging/1/GOSemSim'
install of package 'GOSemSim' failed [error code 1]
Yes, this 'dependency hell' you are experiencing is typical when you go outside the recommended route (which is only installing packages that are part of the same Bioconductor release, and not to mix release and development packages). Yet, you have a good reason to do so, thus hang on...!
I could reproduce the dependency requirements on my system. Also, since GOSemSim
couldn't be installed on your (Windows?!) system, it seems you are missing RTools
.
Therefore:
0) c;lose all R
and R-studio
sessions
1) download and install RTools 4.4
from: https://cran.r-project.org/bin/windows/Rtools/
2) restart R
, and run BiocManager::install(c('yulab.utils'), force=TRUE)
. By doing so, you update yulab.utils
to its latest version; packageVersion("yulab.utils")
should return ‘0.1.6’
.
If prompted for it by BiocManager::install()
, be sure to update all other packages as well!
3) now install GOsemSim
from GitHub by BiocManager::install(c('YuLab-SMU/GOSemSim'), force=TRUE)
. Check: packageVersion("GOSemSim")
should return ‘2.31.1’
.
4) continue with DOSE
: BiocManager::install(c('YuLab-SMU/DOSE'), force=TRUE)
. Check: packageVersion("DOSE")
gives ‘3.31.3’
.
5) finally install enrichplot
: BiocManager::install(c('YuLab-SMU/enrichplot'), force=TRUE)
. Check: packageVersion("enrichplot")
gives ‘1.25.1.1’
.
It is working! Thank you @guidohooiveld , for guiding me through. I would have never managed without your support.
Best,
Dear all,
in some dotplots the GeneRatio is presented as a number.
After applying pairwise_termsim and simplify, it is presented as a fraction.
How can I change the plots to show always a number as GeneRatio? Both plots originate from CompareCluster results.
Here is the code of the second plot . The first just skips the pairwise_termsim and simplify functions `ego.down<-enrichGO(gene= DEGs.down$ENSEMBL, OrgDb = organism, ont= "All", pAdjustMethod = "BH", pvalueCutoff = 0.05, qvalueCutoff = 0.05, keyType = "ENSEMBL", readable = TRUE)
ego.down<-pairwise_termsim(ego.down, showCategory=30) ego.down<-simplify(ego.down,cutoff=0.7, by="p.adjust", select_fun=min)
ego.up<-enrichGO(gene= DEGs.up$ENSEMBL, OrgDb = organism, ont= "All", pAdjustMethod = "BH", pvalueCutoff = 0.05, qvalueCutoff = 0.05, keyType = "ENSEMBL", readable = TRUE)
ego.up<-pairwise_termsim(ego.up, showCategory=30) ego.up<-simplify(ego.up,cutoff=0.7, by="p.adjust", select_fun=min)
ego.list<-list("activated"=ego.up, "suppressed"=ego.down) ego.combined<-merge_result(ego.list)
options(enrichplot.colours = c("#009E73","#f0e442"))
dotplot(ego.combined,split="Cluster", showCategory=15, x="GeneRatio", size= "count", font.size=10, label_format=60) + facet_grid(.~Cluster)+ ggtitle("GO ORA") `
Best, Nina