diff --git a/tools/plot_ragtag_paf/plot_ragtag_paf.R b/tools/plot_ragtag_paf/plot_ragtag_paf.R index 4d62bfd5..ea134478 100644 --- a/tools/plot_ragtag_paf/plot_ragtag_paf.R +++ b/tools/plot_ragtag_paf/plot_ragtag_paf.R @@ -98,20 +98,35 @@ lookup_qstart <- function(x) { sort_columns <- c("tname", "tstart", "tend", "qname", "qstart", "qend") config_file <- args[1] -config <- yaml.load_file(config_file) -typed_config <- lapply(config, type.convert, as.is = TRUE) -list2env(typed_config, envir = .GlobalEnv) + +# fixed plotting paramaters +t_y <- 1 +q_y <- 2 ######## # MAIN # ######## +# process the config +message("Reading the plot config") +config <- yaml.load_file(config_file) +typed_config <- lapply(config, type.convert, as.is = TRUE) +invisible( + list2env( + typed_config, + envir = .GlobalEnv + ) +) + + # read the data +message("Reading the plot data") agp <- fread(agp_file, fill = TRUE, skip = 2)[!V5 %in% c("N", "U")] raw_paf <- read_paf(paf_file) paf_dt <- data.table(raw_paf) # calculate spacing +message("Calculating spacing between contigs") padding <- get_padding(paf_dt[tp == "P" & nmatch >= min_nmatch]) # order the reference contigs @@ -119,6 +134,7 @@ paf_dt[, tname := factor(tname, levels = gtools::mixedsort(unique(tname)))] setkeyv(paf_dt, cols = sort_columns) # generate continuous reference coordinates +message("Generating coordinates for contigs") tpaf <- unique(paf_dt, by = "tname") tpaf[, pad_tstart := shift(cumsum(tlen + padding[["t_padding"]]), 1, 0)] tpaf[, shift_tstart := pad_tstart + (padding[["t_padding"]] / 2)] @@ -140,6 +156,7 @@ qpaf[, shift_qstart := pad_qstart + (padding[["q_padding"]] / 2)] qpaf[, pad_qend := shift_qstart + qlen] # generate offsets for the alignment records +message("Generating coordinates for alignments") tstarts <- unique(tpaf[, .(tname, shift_tstart)]) qstarts <- unique(qpaf[, .(qname, shift_qstart)]) @@ -155,6 +172,7 @@ paf_dt[, ] # generate polygons. P is for primary alignments only +message("Generating polygons for alignments") polygon_y_bump <- 0.017 # account for contig thickness paf_polygons <- paf_dt[ tp == "P" & nmatch >= min_nmatch, @@ -176,8 +194,6 @@ total_height <- (q_y - t_y) * 1.618 y_axis_space <- (total_height - (q_y - t_y)) / 2 middle_x <- tpaf[1, shift_tstart] + tpaf[.N, pad_tend] / 2 - - all_contig_names <- c(tpaf[, unique(tname)]) all_colours <- viridis( length(all_contig_names) + palette_space + 1 @@ -189,6 +205,7 @@ names(all_colours) <- c( ) # Plot the ideogram with ribbons connecting the two sets of contigs +message("Plotting") gp <- ggplot() + theme_void(base_family = "Lato", base_size = 12) + scale_fill_manual( @@ -246,6 +263,7 @@ gp <- ggplot() + vjust = 0.5 ) +message("Writing the plot to file") ggsave(plot_file, gp, width = plot_width, @@ -255,6 +273,7 @@ ggsave(plot_file, ) # Print session info to stderr +message("\nsessionInfo():\n") sink(stderr()) sessionInfo() sink() diff --git a/tools/plot_ragtag_paf/plot_ragtag_paf.xml b/tools/plot_ragtag_paf/plot_ragtag_paf.xml index 75fdeab1..ab9a6ae9 100644 --- a/tools/plot_ragtag_paf/plot_ragtag_paf.xml +++ b/tools/plot_ragtag_paf/plot_ragtag_paf.xml @@ -14,9 +14,9 @@ /etc/R/Rprofile.site && - cat /etc/R/Rprofile.site.old >> /etc/R/Rprofile.site && + sed -i + '/options(bspm.version.check=FALSE)/i options(bspm.sudo = TRUE)' + /etc/R/Rprofile.site && ## Print the plot config to stderr sed -e 's/^[ \t]*//' -e '/^$/d' '${plot_config}' > config.yaml && @@ -40,8 +40,6 @@ palette_space: '${plot_params.palette_space}' plot_height: '${plot_params.plot_height}' plot_width: '${plot_params.plot_width}' - q_y: '${plot_params.q_y}' - t_y: '${plot_params.t_y}' @@ -54,8 +52,6 @@ - -