Commit 2c899e7f authored by Valentina Galata's avatar Valentina Galata
Browse files

figures: updated fig scripts (and some func.s in utils.R) to optimize figs for...

figures: updated fig scripts (and some func.s in utils.R) to optimize figs for submission (issue #127)
parent 64ffc22d
...@@ -62,16 +62,30 @@ for(sname in names(snakemake@config$samples)){ ...@@ -62,16 +62,30 @@ for(sname in names(snakemake@config$samples)){
xlim <- NULL xlim <- NULL
FIGS[[sname]] <- FIGS[[sname]] <-
plot_barrnap(TABS[[sname]]) + plot_barrnap(TABS[[sname]]) +
labs( labs(title=SAMPLE_NAMES[sname]) +
title=LETTERS[which(names(TABS) == sname)], theme(
subtitle=SAMPLE_NAMES[sname] plot.title=element_text(size=16, face="bold"),
plot.subtitle=element_text(size=16, face="italic"),
# legend
legend.title=element_text(size=16, face="bold"),
legend.text=element_text(size=16),
# strip
strip.text=element_text(size=14),
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black")
) )
# remove axis labels for first sub-plots (4 plots in a 2x2 layout)
if(which(names(SAMPLE_NAMES) == sname) < 3){
FIGS[[sname]] <- FIGS[[sname]] + theme(axis.text.x=element_blank())
}
} }
# combine plots # combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF # PDF
pdf(snakemake@output$pdf, width=20, height=20) pdf(snakemake@output$pdf, width=20, height=14)
print(FIGS_ALL) print(FIGS_ALL)
dev.off() dev.off()
\ No newline at end of file
...@@ -42,17 +42,28 @@ FIGS <- list() ...@@ -42,17 +42,28 @@ FIGS <- list()
for(sname in names(snakemake@config$samples)){ for(sname in names(snakemake@config$samples)){
xlim <- NULL xlim <- NULL
FIGS[[sname]] <- plot_diamondDB_density(TABS[[sname]], col="qs_len_ratio", xlim=c(0, 3)) + FIGS[[sname]] <-
labs( plot_diamondDB_density(TABS[[sname]], col="qs_len_ratio", xlim=c(0, 3)) +
title=LETTERS[which(names(TABS) == sname)], labs(title=SAMPLE_NAMES[sname]) +
subtitle=SAMPLE_NAMES[sname] theme(
) plot.title=element_text(size=16, face="bold"),
plot.subtitle=element_text(size=16, face="italic"),
# legend
legend.title=element_text(size=16, face="bold"),
legend.text=element_text(size=16),
# strip
strip.text=element_text(size=16),
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black", angle=0)
)
} }
# combine plots # combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF # PDF
pdf(snakemake@output$pdf, width=20, height=20) pdf(snakemake@output$pdf, width=20, height=14)
print(FIGS_ALL) print(FIGS_ALL)
dev.off() dev.off()
\ No newline at end of file
...@@ -77,7 +77,11 @@ custom_theme <- ...@@ -77,7 +77,11 @@ custom_theme <-
theme( theme(
panel.grid.major=element_blank(), panel.grid.major=element_blank(),
panel.grid.minor=element_blank(), panel.grid.minor=element_blank(),
legend.position="none" legend.position="none",
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black")
) )
# AA colors # AA colors
...@@ -117,7 +121,7 @@ p_cov <- ...@@ -117,7 +121,7 @@ p_cov <-
x=c(5547, 5547, 5780), y=c(2, -5, -5), x=c(5547, 5547, 5780), y=c(2, -5, -5),
label=levels(metat_cov_seqs$variable), label=levels(metat_cov_seqs$variable),
hjust=c("left", "left", "right"), hjust=c("left", "left", "right"),
size=4 size=5
) + ) +
# colors # colors
scale_fill_manual(values=aa_colors) + scale_fill_manual(values=aa_colors) +
......
...@@ -44,23 +44,40 @@ for(sname in names(snakemake@config$samples)){ ...@@ -44,23 +44,40 @@ for(sname in names(snakemake@config$samples)){
TABS[[sname]] %>% TABS[[sname]] %>%
filter(variable=="mapped_pct") %>% filter(variable=="mapped_pct") %>%
plot_mappability() + plot_mappability() +
labs( labs(title=SAMPLE_NAMES[sname]) +
title=LETTERS[which(names(TABS) == sname)], theme(
subtitle=SAMPLE_NAMES[sname] plot.title=element_text(size=16, face="bold"),
plot.subtitle=element_text(size=16, face="italic"),
# legend
legend.title=element_text(size=16, face="bold"),
legend.text=element_text(size=16),
# strip
strip.text=element_text(size=16),
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black")
) )
# remove axis labels for first sub-plots (4 plots in a 2x2 layout)
if(which(names(SAMPLE_NAMES) == sname) < 3){
FIGS[[sname]] <- FIGS[[sname]] + theme(axis.text.x=element_blank())
}
} }
# combine plots # combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# extra plot # extra plot
FIGS_gdb_metat <- TABS[["gdb_metat"]] %>% filter(variable=="mapped_pct") %>% plot_mappability() FIGS_gdb_metat <-
TABS[["gdb_metat"]] %>%
filter(variable=="mapped_pct") %>%
plot_mappability()
# PDF # PDF
pdf(snakemake@output$pdf, width=20, height=14) pdf(snakemake@output$pdf, width=20, height=10)
print(FIGS_ALL) print(FIGS_ALL)
dev.off() dev.off()
pdf(snakemake@output$pdf_gdb_metat, width=10, height=7) pdf(snakemake@output$pdf_gdb_metat, width=10, height=5)
print(FIGS_gdb_metat) print(FIGS_gdb_metat)
dev.off() dev.off()
\ No newline at end of file
...@@ -51,13 +51,14 @@ for(sname in names(snakemake@config$samples)){ ...@@ -51,13 +51,14 @@ for(sname in names(snakemake@config$samples)){
scale="none", scale="none",
cluster_rows=HCLUST[[sname]], cluster_rows=HCLUST[[sname]],
cluster_cols=HCLUST[[sname]], cluster_cols=HCLUST[[sname]],
display_numbers=TRUE, number_color="black", number_format="%.3f", fontsize_number=12, display_numbers=TRUE, number_color="black", number_format="%.3f", fontsize_number=14,
fontsize=14,
silent=TRUE silent=TRUE
) )
) + ) +
labs( labs(title=SAMPLE_NAMES[sname]) +
title=LETTERS[which(names(TABS) == sname)], theme(
subtitle=SAMPLE_NAMES[sname] plot.title=element_text(size=16, face="bold")
) )
} }
......
...@@ -10,6 +10,8 @@ suppressMessages(library(testit)) # assertions ...@@ -10,6 +10,8 @@ suppressMessages(library(testit)) # assertions
suppressMessages(library(dplyr)) # tables suppressMessages(library(dplyr)) # tables
suppressMessages(library(patchwork)) # combine plots suppressMessages(library(patchwork)) # combine plots
suppressMessages(library(ggplotify)) # for as.ggplot suppressMessages(library(ggplotify)) # for as.ggplot
# suppressMessages(library(grid)) # to combine upsetr plots
# suppressMessages(library(gridExtra)) # to combine upsetr plots
# custom # custom
source(snakemake@params$const) source(snakemake@params$const)
...@@ -43,16 +45,31 @@ FIGS <- list() ...@@ -43,16 +45,31 @@ FIGS <- list()
for(sname in names(snakemake@config$samples)){ for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <- FIGS[[sname]] <-
as.ggplot(plot_mmseqs2_overlap(TABS[[sname]])) + as.ggplot(plot_mmseqs2_overlap(TABS[[sname]])) +
labs( labs(title=SAMPLE_NAMES[sname]) +
title=LETTERS[which(names(TABS) == sname)], theme(plot.title=element_text(size=16, face="bold"))
subtitle=SAMPLE_NAMES[sname]
)
} }
# combine plots # combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) #+ plot_annotation(tag_levels='A') FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) #+ plot_annotation(tag_levels='A')
# PDF # PDF
pdf(snakemake@output$pdf, width=20, height=14) pdf(snakemake@output$pdf, width=20, height=12)
print(FIGS_ALL) print(FIGS_ALL)
dev.off() dev.off()
\ No newline at end of file
# # 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
# }
# # PDF
# pdf(snakemake@output$pdf, width=20, height=12)
# grid.arrange(grobs = FIGS, nrow=2)
# dev.off()
\ No newline at end of file
...@@ -55,17 +55,32 @@ for(sname in names(snakemake@config$samples)){ ...@@ -55,17 +55,32 @@ for(sname in names(snakemake@config$samples)){
# individual plots # individual plots
FIGS <- list() FIGS <- list()
for(sname in names(snakemake@config$samples)){ for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <- plot_prodigal2(TABS[[sname]]) + FIGS[[sname]] <-
labs( plot_prodigal2(TABS[[sname]]) +
title=LETTERS[which(names(TABS) == sname)], labs(title=SAMPLE_NAMES[sname]) +
subtitle=SAMPLE_NAMES[sname] theme(
) plot.title=element_text(size=16, face="bold"),
plot.subtitle=element_text(size=16, face="italic"),
# legend
legend.title=element_text(size=16, face="bold"),
legend.text=element_text(size=16),
# strip
strip.text=element_text(size=16),
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black")
)
# remove axis labels for first sub-plots (4 plots in a 2x2 layout)
if(which(names(SAMPLE_NAMES) == sname) < 3){
FIGS[[sname]] <- FIGS[[sname]] + theme(axis.text.x=element_blank())
}
} }
# combine plots # combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF # PDF
pdf(snakemake@output$pdf, width=20, height=14) pdf(snakemake@output$pdf, width=20, height=8)
print(FIGS_ALL) print(FIGS_ALL)
dev.off() dev.off()
\ No newline at end of file
...@@ -40,17 +40,32 @@ for(sname in names(snakemake@config$samples)){ ...@@ -40,17 +40,32 @@ for(sname in names(snakemake@config$samples)){
# individual plots # individual plots
FIGS <- list() FIGS <- list()
for(sname in names(snakemake@config$samples)){ for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <- plot_quast(TABS[[sname]]) + FIGS[[sname]] <-
labs( plot_quast(TABS[[sname]]) +
title=LETTERS[which(names(TABS) == sname)], labs(title=SAMPLE_NAMES[sname]) +
subtitle=SAMPLE_NAMES[sname] theme(
) plot.title=element_text(size=16, face="bold"),
plot.subtitle=element_text(size=16, face="italic"),
# legend
legend.title=element_text(size=16, face="bold"),
legend.text=element_text(size=16),
# strip
strip.text=element_text(size=14),
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black")
)
# remove axis labels for first sub-plots (4 plots in a 2x2 layout)
if(which(names(SAMPLE_NAMES) == sname) < 3){
FIGS[[sname]] <- FIGS[[sname]] + theme(axis.text.x=element_blank())
}
} }
# combine plots # combine plots
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF # PDF
pdf(snakemake@output$pdf, width=20, height=20) pdf(snakemake@output$pdf, width=20, height=14)
print(FIGS_ALL) print(FIGS_ALL)
dev.off() dev.off()
\ No newline at end of file
...@@ -9,7 +9,8 @@ sink(file=file(snakemake@log[[1]], open="wt"), type=c("output", "message")) ...@@ -9,7 +9,8 @@ sink(file=file(snakemake@log[[1]], open="wt"), type=c("output", "message"))
suppressMessages(library(testit)) # assertions suppressMessages(library(testit)) # assertions
suppressMessages(library(dplyr)) # tables suppressMessages(library(dplyr)) # tables
suppressMessages(library(patchwork)) # combine 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
# custom # custom
source(snakemake@params$const) source(snakemake@params$const)
...@@ -47,27 +48,36 @@ FIGS_o <- list() ...@@ -47,27 +48,36 @@ FIGS_o <- list()
for(sname in names(TABS)){ for(sname in names(TABS)){
FIGS_c[[sname]] <- FIGS_c[[sname]] <-
plot_rgi_counts_total(proc_rgi(TABS[[sname]])$aggr) + plot_rgi_counts_total(proc_rgi(TABS[[sname]])$aggr) +
labs( labs(title=SAMPLE_NAMES[sname]) +
title=LETTERS[which(names(TABS) == sname)], theme(
subtitle=SAMPLE_NAMES[sname] plot.title=element_text(size=16, face="bold"),
) plot.subtitle=element_text(size=16, face="italic"),
FIGS_o[[sname]] <- # legend
as.ggplot(plot_rgi_overlap(TABS[[sname]], "strict", "ARO")) + legend.title=element_text(size=16, face="bold"),
labs( legend.text=element_text(size=16),
title=LETTERS[which(names(TABS) == sname)], # strip
subtitle=SAMPLE_NAMES[sname] strip.text=element_text(size=14),
# axes
axis.title=element_text(size=16, color="black"),
axis.text.y=element_text(size=16, color="black"),
axis.text.x=element_text(size=16, color="black")
) )
FIGS_o[[sname]] <- plot_rgi_overlap(TABS[[sname]], "strict", "ARO")
print(FIGS_o[[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_o[[sname]] <- vp
} }
# combine plots # combine plots
FIGS_ALL_c <- Reduce("+", FIGS_c) + plot_layout(ncol=3) FIGS_ALL_c <- Reduce("+", FIGS_c) + plot_layout(ncol=3)
FIGS_ALL_o <- Reduce("+", FIGS_o) + plot_layout(ncol=3)
# PDF # PDF
pdf(snakemake@output$pdf_c, width=30, height=7) pdf(snakemake@output$pdf_c, width=20, height=5)
print(FIGS_ALL_c) print(FIGS_ALL_c)
dev.off() dev.off()
pdf(snakemake@output$pdf_o, width=30, height=7) pdf(snakemake@output$pdf_o, width=20, height=5)
print(FIGS_ALL_o) grid.arrange(grobs=FIGS_o, ncol=3)
dev.off() dev.off()
\ No newline at end of file
...@@ -503,9 +503,11 @@ plot_rgi_overlap <- function(df, ctype, col){ ...@@ -503,9 +503,11 @@ plot_rgi_overlap <- function(df, ctype, col){
# number of sets to plot # number of sets to plot
nsets=length(ASM_TOOL_NAMES), nsets=length(ASM_TOOL_NAMES),
# y-label title # y-label title
mainbar.y.label=sprintf("Intersection size (%s hits, %s)", ctype, col), mainbar.y.label=sprintf("Intersection size\n(%s hits, %s)", ctype, col),
# text size: intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars # text size: intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars
text.scale = c(1.2, 1.2, 1.2, 1.2, 1.2, 1.2)#, text.scale=c(2, 2, 1.8, 1.3, 2, 2),
# ratio between matrix plot and main bar plot
mb.ratio=c(0.65,0.35),
# colors # colors
# set.metadata=list( # set.metadata=list(
# data=data.frame( # data=data.frame(
...@@ -653,10 +655,12 @@ plot_mmseqs2_overlap <- function(df, topN=20){ ...@@ -653,10 +655,12 @@ plot_mmseqs2_overlap <- function(df, topN=20){
order.by="freq", order.by="freq",
decreasing=TRUE, decreasing=TRUE,
# titles # titles
mainbar.y.label="Total number of proteins in clusters", mainbar.y.label="Total number of proteins\nin clusters",
sets.x.label="Total number of proteins per assembly", sets.x.label="Total number of proteins\nper assembly",
# text size: intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars # text size: intersection size title, intersection size tick labels, set size title, set size tick labels, set names, numbers above bars
text.scale = c(1.2, 1.2, 1.2, 1.2, 1.2, 1), text.scale=c(2, 1.6, 1.8, 1.3, 2, 1),
# ratio between matrix plot and main bar plot
mb.ratio=c(0.6,0.4),
# highlight those w/ only one set # highlight those w/ only one set
queries=c( queries=c(
# unique proteins # unique proteins
......
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