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)){
xlim <- NULL
FIGS[[sname]] <-
plot_barrnap(TABS[[sname]]) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
labs(title=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
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF
pdf(snakemake@output$pdf, width=20, height=20)
pdf(snakemake@output$pdf, width=20, height=14)
print(FIGS_ALL)
dev.off()
\ No newline at end of file
......@@ -42,17 +42,28 @@ FIGS <- list()
for(sname in names(snakemake@config$samples)){
xlim <- NULL
FIGS[[sname]] <- plot_diamondDB_density(TABS[[sname]], col="qs_len_ratio", xlim=c(0, 3)) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
)
FIGS[[sname]] <-
plot_diamondDB_density(TABS[[sname]], col="qs_len_ratio", xlim=c(0, 3)) +
labs(title=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
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF
pdf(snakemake@output$pdf, width=20, height=20)
pdf(snakemake@output$pdf, width=20, height=14)
print(FIGS_ALL)
dev.off()
\ No newline at end of file
......@@ -77,7 +77,11 @@ custom_theme <-
theme(
panel.grid.major=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
......@@ -117,7 +121,7 @@ p_cov <-
x=c(5547, 5547, 5780), y=c(2, -5, -5),
label=levels(metat_cov_seqs$variable),
hjust=c("left", "left", "right"),
size=4
size=5
) +
# colors
scale_fill_manual(values=aa_colors) +
......
......@@ -44,23 +44,40 @@ for(sname in names(snakemake@config$samples)){
TABS[[sname]] %>%
filter(variable=="mapped_pct") %>%
plot_mappability() +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
labs(title=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
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# 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(snakemake@output$pdf, width=20, height=14)
pdf(snakemake@output$pdf, width=20, height=10)
print(FIGS_ALL)
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)
dev.off()
\ No newline at end of file
......@@ -51,13 +51,14 @@ for(sname in names(snakemake@config$samples)){
scale="none",
cluster_rows=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
)
) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
labs(title=SAMPLE_NAMES[sname]) +
theme(
plot.title=element_text(size=16, face="bold")
)
}
......
......@@ -10,6 +10,8 @@ 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
# custom
source(snakemake@params$const)
......@@ -43,16 +45,31 @@ FIGS <- list()
for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <-
as.ggplot(plot_mmseqs2_overlap(TABS[[sname]])) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[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=14)
pdf(snakemake@output$pdf, width=20, height=12)
print(FIGS_ALL)
dev.off()
\ No newline at end of file
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
# }
# # 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)){
# individual plots
FIGS <- list()
for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <- plot_prodigal2(TABS[[sname]]) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
)
FIGS[[sname]] <-
plot_prodigal2(TABS[[sname]]) +
labs(title=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
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF
pdf(snakemake@output$pdf, width=20, height=14)
pdf(snakemake@output$pdf, width=20, height=8)
print(FIGS_ALL)
dev.off()
\ No newline at end of file
......@@ -40,17 +40,32 @@ for(sname in names(snakemake@config$samples)){
# individual plots
FIGS <- list()
for(sname in names(snakemake@config$samples)){
FIGS[[sname]] <- plot_quast(TABS[[sname]]) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
)
FIGS[[sname]] <-
plot_quast(TABS[[sname]]) +
labs(title=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
FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2)
# PDF
pdf(snakemake@output$pdf, width=20, height=20)
pdf(snakemake@output$pdf, width=20, height=14)
print(FIGS_ALL)
dev.off()
\ No newline at end of file
......@@ -9,7 +9,8 @@ sink(file=file(snakemake@log[[1]], open="wt"), type=c("output", "message"))
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
# custom
source(snakemake@params$const)
......@@ -47,27 +48,36 @@ FIGS_o <- list()
for(sname in names(TABS)){
FIGS_c[[sname]] <-
plot_rgi_counts_total(proc_rgi(TABS[[sname]])$aggr) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
)
FIGS_o[[sname]] <-
as.ggplot(plot_rgi_overlap(TABS[[sname]], "strict", "ARO")) +
labs(
title=LETTERS[which(names(TABS) == sname)],
subtitle=SAMPLE_NAMES[sname]
labs(title=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")
)
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
FIGS_ALL_c <- Reduce("+", FIGS_c) + plot_layout(ncol=3)
FIGS_ALL_o <- Reduce("+", FIGS_o) + plot_layout(ncol=3)
# PDF
pdf(snakemake@output$pdf_c, width=30, height=7)
pdf(snakemake@output$pdf_c, width=20, height=5)
print(FIGS_ALL_c)
dev.off()
pdf(snakemake@output$pdf_o, width=30, height=7)
print(FIGS_ALL_o)
pdf(snakemake@output$pdf_o, width=20, height=5)
grid.arrange(grobs=FIGS_o, ncol=3)
dev.off()
\ No newline at end of file
......@@ -503,9 +503,11 @@ plot_rgi_overlap <- function(df, ctype, col){
# number of sets to plot
nsets=length(ASM_TOOL_NAMES),
# 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.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
# set.metadata=list(
# data=data.frame(
......@@ -653,10 +655,12 @@ plot_mmseqs2_overlap <- function(df, topN=20){
order.by="freq",
decreasing=TRUE,
# titles
mainbar.y.label="Total number of proteins in clusters",
sets.x.label="Total number of proteins per assembly",
mainbar.y.label="Total number of proteins\nin clusters",
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.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
queries=c(
# 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