Skip to content
Snippets Groups Projects

Figures valentina

Merged Susheel Busi requested to merge figures_valentina into master
Files
4
+ 46
0
#!/usr/bin/Rscript
## LOG FILE
sink(file=file(snakemake@log[[1]], open="wt"), type="message")
## NOTE
# Plot CRISPR statistics
## IMPORT
suppressMessages(library(testit))
suppressMessages(library(UpSetR))
suppressMessages(library(ggplot2))
# custom
source(snakemake@params$utils)
## DATA
stats <- read.csv(
file=snakemake@input$stats,
sep="\t",
header=TRUE,
stringsAsFactors=FALSE,
check.names=FALSE
)
# change names
stats$crispr_tool <- CRISPR_TOOL_NAMES[stats$crispr_tool]
stats$asm_tool <- ASM_TOOL_NAMES[stats$asm_tool]
## PLOT: UpSetR + PDF
plot_upsetr <- function(df, asm_tool){
asm_sets <- lapply(
CRISPR_TOOL_NAMES,
function(x){ unique(unlist(df[df$asm_tool==asm_tool & df$crispr_tool == x,"seq_id"])) }
)
names(asm_sets) <- CRISPR_TOOL_NAMES[names(asm_sets)]
UpSetR::upset(data=UpSetR::fromList(asm_sets), order.by="degree", decreasing=FALSE)
}
# NOTE:
# For an unknown reason creating and saving multiple plots using a for-loop or sapply did not work - the PDF was empty.
# Creating a PDF per plot in a for-loop or using sapply did not work either - each PDF was empty.
pdf(snakemake@output$pdf, width=snakemake@params$width, height=snakemake@params$height)
plot_upsetr(stats, "Flye")
plot_upsetr(stats, "MEGAHIT")
plot_upsetr(stats, "metaSPAdes")
plot_upsetr(stats, "metaSPAdes (H)")
dev.off()
\ No newline at end of file
Loading