#!/usr/bin/Rscript # Figure: QUAST statistics ############################## LOG 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 # custom source(snakemake@params$const) source(snakemake@params$utils) ############################## CONFIG # assemblers ASM_NAMES_CONFIG <- c( snakemake@config$assemblers$lr, snakemake@config$assemblers$sr, snakemake@config$assemblers$hy ) ASM_TOOL_NAMES <- ASM_TOOL_NAMES[ASM_NAMES_CONFIG] ASM_TOOL_COLORS <- ASM_TOOL_COLORS[ASM_NAMES_CONFIG]; names(ASM_TOOL_COLORS) <- ASM_TOOL_NAMES[names(ASM_TOOL_COLORS)] ASM_TOOL_SHAPES <- ASM_TOOL_SHAPES[ASM_NAMES_CONFIG]; names(ASM_TOOL_SHAPES) <- ASM_TOOL_NAMES[names(ASM_TOOL_SHAPES)] ############################## DATA # individual tables TABS <- list() for(sname in names(snakemake@config$samples)){ testit::assert(sname %in% names(snakemake@input)) TABS[[sname]] <- read_prodigal_gcounts(snakemake@input[[sname]]) } ############################## STATS print("STATS: Number of total proteins: max vs min:") for(sname in names(snakemake@config$samples)){ print(sprintf( "STATS: Sample %s: %s vs %s = %d / %d = %.2f", sname, TABS[[sname]]$tool[which.max(TABS[[sname]]$total)], TABS[[sname]]$tool[which.min(TABS[[sname]]$total)], max(TABS[[sname]]$total), min(TABS[[sname]]$total), max(TABS[[sname]]$total) / min(TABS[[sname]]$total) )) } ############################## PLOT # 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] ) } # combine plots FIGS_ALL <- Reduce("+", FIGS) + plot_layout(ncol=2) # PDF pdf(snakemake@output$pdf, width=20, height=14) print(FIGS_ALL) dev.off()