Skip to content
Snippets Groups Projects

Figures valentina

Merged Susheel Busi requested to merge figures_valentina into master
Files
5
+ 91
0
#!/usr/bin/Rscript
## LOG FILE
sink(file=file(snakemake@log[[1]], open="wt"), type="message")
## NOTE
# Plot RGI statistics
## IMPORT
suppressMessages(library(testit))
suppressMessages(library(UpSetR))
suppressMessages(library(ggplot2))
suppressMessages(library(reshape2))
# custom
source(snakemake@params$utils)
## DATA
stats <- read.csv(
file=snakemake@input$stats,
sep="\t",
header=TRUE,
stringsAsFactors=FALSE,
check.names=FALSE
)
# reshape
stats_melted <- reshape2::melt(stats, id.vars=c("label", "type"), variable.name="tool", value.name="count")
# change names
stats_melted$tool <- ASM_TOOL_NAMES[as.character(stats_melted$tool)]
## PLOT
plots <- list()
for(dtype in unique(stats_melted$type)){
dtype_df <- stats_melted[stats_melted$type == dtype,]
plots[[dtype]] <-
ggplot(data=dtype_df, aes(x=tool, y=count, fill=tool)) +
geom_col() +
scale_fill_manual(values=ASM_TOOL_COLORS$notmeth, guide="legend") +
facet_wrap(vars(label), ncol=round(sqrt(length(unique(dtype_df$label)))), scales="free_y") +
labs(
# title="",
# subtitle="",
x="",
y=RGI_NAMES$type[dtype]
) +
theme_bw() +
theme(
# legend
legend.title=element_blank(),
# grid
panel.grid=element_blank(),
# strip
strip.background=element_rect(fill="white"),
strip.text=element_text(size=9, color="black"),
# axes
axis.title=element_text(size=12, color="black"),
axis.text.y=element_text(size=9, color="black"),
axis.text.x=element_text(size=9, color="black", angle=90, vjust=0.5, hjust=1)
)
}
# Total counts
stats_melted_aro <- stats_melted[stats_melted$type == dtype,]
stats_melted_aro <- aggregate(stats_melted_aro$count, by=list(tool=stats_melted_aro$tool), FUN=sum)
plots[["total"]] <-
ggplot(data=stats_melted_aro, aes(x=tool, y=x, fill=tool)) +
geom_col() +
scale_fill_manual(values=ASM_TOOL_COLORS$notmeth, guide="legend") +
labs(
# title="",
# subtitle="",
x="",
y="Total hits"
) +
theme_bw() +
theme(
# legend
legend.title=element_blank(),
# grid
panel.grid=element_blank(),
# strip
strip.background=element_rect(fill="white"),
strip.text=element_text(size=9, color="black"),
# axes
axis.title=element_text(size=12, color="black"),
axis.text.y=element_text(size=9, color="black"),
axis.text.x=element_text(size=9, color="black", angle=90, vjust=0.5, hjust=1)
)
## PDF
pdf(snakemake@output$pdf, width=snakemake@params$width, height=snakemake@params$height)
for(pp in plots){ print(pp) }
dev.off()
Loading