Skip to content

Commit

Permalink
using SED to modify Rprofile allow running on conda
Browse files Browse the repository at this point in the history
  • Loading branch information
TomHarrop committed Oct 1, 2024
1 parent 0e45c1a commit b956671
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 12 deletions.
29 changes: 24 additions & 5 deletions tools/plot_ragtag_paf/plot_ragtag_paf.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,27 +98,43 @@ 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
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)]
Expand All @@ -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)])

Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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(
Expand Down Expand Up @@ -246,6 +263,7 @@ gp <- ggplot() +
vjust = 0.5
)

message("Writing the plot to file")
ggsave(plot_file,
gp,
width = plot_width,
Expand All @@ -255,6 +273,7 @@ ggsave(plot_file,
)

# Print session info to stderr
message("\nsessionInfo():\n")
sink(stderr())
sessionInfo()
sink()
10 changes: 3 additions & 7 deletions tools/plot_ragtag_paf/plot_ragtag_paf.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
<command detect_errors="exit_code"><![CDATA[
## Suppress R warnings about container
mv /etc/R/Rprofile.site /etc/R/Rprofile.site.old &&
echo "options(bspm.sudo = TRUE)" > /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 &&
Expand All @@ -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}'
</configfile>
</configfiles>
<inputs>
Expand All @@ -54,8 +52,6 @@
<param type="integer" name="fontsize" label="Fontsize (pt)" value="12"/>
<param type="integer" name="palette_space" label="Number of unused colours in the colour palette between the query contig colour and the colour of the first reference contig." help="Try a higher value if the query contigs look too similar to the reference contigs." value="4"/>
<param type="float" min="0" max="1" name="gap_size" label="Total length of gaps between contigs relative to the total assembly length." help="Try a higher value if the contigs look too close together." value="0.1"/>
<param type="integer" name="t_y" label="Position of reference contigs on the y-axis" value="1"/>
<param type="integer" name="q_y" label="Position of query contigs on the y-axis" value="2"/>
</section>
</inputs>
<outputs>
Expand Down

0 comments on commit b956671

Please sign in to comment.