Commit 6eb4eac9 authored by Valentina Galata's avatar Valentina Galata
Browse files

figures: fix for mmseqs2 upsetr plots using cowplot (issue #127)

parent 2c899e7f
......@@ -8,10 +8,11 @@ sink(file=file(snakemake@log[[1]], open="wt"), type=c("output", "message"))
############################## LIBS
suppressMessages(library(testit)) # assertions
suppressMessages(library(dplyr)) # tables
suppressMessages(library(patchwork)) # combine plots
suppressMessages(library(ggplotify)) # for as.ggplot
# suppressMessages(library(grid)) # to combine upsetr plots
# suppressMessages(library(gridExtra)) # to combine upsetr plots
# suppressMessages(library(patchwork)) # combine plots
# suppressMessages(library(ggplotify)) # for as.ggplot
suppressMessages(library(grid)) # to combine upsetr plots
suppressMessages(library(gridExtra)) # to combine upsetr plots
suppressMessages(library(cowplot))
# custom
source(snakemake@params$const)
......@@ -40,36 +41,36 @@ for(sname in names(snakemake@config$samples)){
############################## PLOT
# individual plots
FIGS <- list()
for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <-
as.ggplot(plot_mmseqs2_overlap(TABS[[sname]])) +
labs(title=SAMPLE_NAMES[sname]) +
theme(plot.title=element_text(size=16, face="bold"))
}
# combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) #+ plot_annotation(tag_levels='A')
# PDF
pdf(snakemake@output$pdf, width=20, height=12)
print(FIGS_ALL)
dev.off()
# # individual plots
# # solution for how to combine upsetR plots: https://stackoverflow.com/questions/57457651/upsetr-manually-order-set-intersections-to-align-multiple-upset-plots
# FIGS <- list()
# for(sname in names(snakemake@config$samples)){
# FIGS[[sname]] <- plot_mmseqs2_overlap(TABS[[sname]])
# print(FIGS[[sname]])
# grid.text(SAMPLE_NAMES[sname], x=0.05, y=0.95, gp=gpar(fontsize=16, fontface="bold"))
# grid.edit('arrange', name=sname)
# vp <- grid.grab()
# FIGS[[sname]] <- vp
# FIGS[[sname]] <-
# as.ggplot(plot_mmseqs2_overlap(TABS[[sname]])) +
# labs(title=SAMPLE_NAMES[sname]) +
# theme(plot.title=element_text(size=16, face="bold"))
# }
# # combine plots
# FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) #+ plot_annotation(tag_levels='A')
# # PDF
# pdf(snakemake@output$pdf, width=20, height=12)
# grid.arrange(grobs = FIGS, nrow=2)
# dev.off()
\ No newline at end of file
# print(FIGS_ALL)
# dev.off()
# individual plots
FIGS <- list()
for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <- plot_mmseqs2_overlap(TABS[[sname]])
# NOTE: the barplot w/ set sizes is not meaningful, therefore plot only the intersection sizes and the matrix
FIGS[[sname]] <- cowplot::plot_grid(
FIGS[[sname]]$Main_bar, FIGS[[sname]]$Matrix,
nrow=2, align='hv', rel_heights = c(3,1), rel_widths = c(2,3),
labels=SAMPLE_NAMES[sname], label_fontface = "bold"
)
}
# PDF
pdf(snakemake@output$pdf, width=20, height=12)
grid.arrange(grobs = FIGS, nrow=2)
dev.off()
\ No newline at end of file
......@@ -19,4 +19,5 @@ dependencies:
- r-upsetr=1.4.0
- r-viridis=0.5.1
- r-patchwork=1.1.1
- r-ggplotify=0.0.5
\ No newline at end of file
- r-ggplotify=0.0.5
- r-cowplot
\ No newline at end of file
......@@ -656,9 +656,9 @@ plot_mmseqs2_overlap <- function(df, topN=20){
decreasing=TRUE,
# titles
mainbar.y.label="Total number of proteins\nin clusters",
sets.x.label="Total number of proteins\nper assembly",
sets.x.label="Ignore this statistic:\nit is not meaningful",
# text size: intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars
text.scale=c(2, 1.6, 1.8, 1.3, 2, 1),
text.scale=c(2, 2, 1.8, 1.3, 2, 1.3),
# ratio between matrix plot and main bar plot
mb.ratio=c(0.6,0.4),
# highlight those w/ only one set
......
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