From d1f9706fff44e1a97ed95ece0fcc96c0c29dea3e Mon Sep 17 00:00:00 2001 From: whelena Date: Fri, 6 Jun 2025 13:06:15 -0700 Subject: [PATCH 1/7] add function to automatically spread labels in single-sample densityplot --- R/create.ccf.densityplot.R | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/R/create.ccf.densityplot.R b/R/create.ccf.densityplot.R index c804fc1..70f2bc6 100644 --- a/R/create.ccf.densityplot.R +++ b/R/create.ccf.densityplot.R @@ -2,7 +2,6 @@ create.ccf.densityplot <- function( x, filename = NULL, clone.colours = NULL, - breaks = 100, xlab.label = 'CCF', ylab.label = 'SNV Density', xlimits = c(0, 1.5), @@ -93,7 +92,7 @@ create.ccf.densityplot <- function( abline.col = 'gray50', add.text = TRUE, text.labels = lapply(mean.ccf$CCF, round, 2), - text.x = mean.ccf$CCF, + text.x = spread.values(mean.ccf$CCF, min.dist = legend.title.cex / 10), text.y = ymax, text.fontface = 'bold', text.cex = legend.title.cex @@ -109,3 +108,26 @@ create.ccf.densityplot <- function( resolution = resolution )); } + + +spread.values <- function(x, min.dist = 0.1, max.iter = 10) { + x.out <- x; + for (iter in seq_len(max.iter)) { + changed <- FALSE; + ord <- order(x.out); + x.sorted <- x.out[ord]; + + for (i in 2:length(x.sorted)) { + gap <- x.sorted[i] - x.sorted[i - 1]; + if (gap < min.dist) { + shift <- (min.dist - gap) / 2; + x.sorted[i - 1] <- x.sorted[i - 1] - shift; + x.sorted[i] <- x.sorted[i] + shift; + changed <- TRUE; + } + } + x.out[ord] <- x.sorted; + if (!changed) break; + }; + return(x.out); +} From 40e321990ce2eb91a40509c541d79f3d26c2da6e Mon Sep 17 00:00:00 2001 From: whelena Date: Fri, 6 Jun 2025 13:10:42 -0700 Subject: [PATCH 2/7] make tree work with CCF and CP --- R/SRCGrob.R | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/R/SRCGrob.R b/R/SRCGrob.R index ad4f389..820a5d4 100644 --- a/R/SRCGrob.R +++ b/R/SRCGrob.R @@ -41,6 +41,10 @@ SRCGrob <- function( )); } + if ('CCF' %in% colnames(tree) && !('CP' %in% colnames(tree))) { + tree$CP <- tree$CCF; + } + add.node.text <- !is.null(node.text); add.polygons <- !is.null(tree$CP) && !disable.polygons; text.on.nodes <- FALSE; From 0f5551ed083ac8cb49aa5f585cdf53dab8d9322b Mon Sep 17 00:00:00 2001 From: whelena Date: Tue, 10 Jun 2025 17:54:06 -0700 Subject: [PATCH 3/7] update .Rd file --- man/create.ccf.densityplot.Rd | 2 -- 1 file changed, 2 deletions(-) diff --git a/man/create.ccf.densityplot.Rd b/man/create.ccf.densityplot.Rd index 30ff75d..9f7593d 100644 --- a/man/create.ccf.densityplot.Rd +++ b/man/create.ccf.densityplot.Rd @@ -9,7 +9,6 @@ create.ccf.densityplot( x, filename = NULL, clone.colours = NULL, - breaks = 100, xlab.label = 'CCF', ylab.label = 'SNV Density', xlimits = c(0, 1.5), @@ -30,7 +29,6 @@ create.ccf.densityplot( \item{x}{A data-frame with the following column names: 'SNV.id', 'clone.id', 'CCF'.} \item{filename}{Filename for tiff output, or if NULL returns the trellis object itself. Defaults to \code{NULL}.} \item{clone.colours}{Named list to provide a colour scheme for the clone ID covariate bar. If NULL, colours will be randomly generated. Defaults to \code{NULL}.} - \item{breaks}{Number of breaks for the histogram. Defaults to 100.} \item{xlab.label}{Defaults to \dQuote{CCF}.} \item{ylab.label}{Defaults to \dQuote{SNV Density}.} \item{xlimits}{Limits for the x-axis. Defaults to \code{c(0, 1.5)}.} From 13d70f93263b985eeface831dd86ac52c9ffa13a Mon Sep 17 00:00:00 2001 From: whelena Date: Thu, 12 Jun 2025 13:55:30 -0700 Subject: [PATCH 4/7] automate x axis spacing in fishplot --- R/set.up.plot.area.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/R/set.up.plot.area.R b/R/set.up.plot.area.R index 07a48cb..c6f3471 100644 --- a/R/set.up.plot.area.R +++ b/R/set.up.plot.area.R @@ -295,14 +295,14 @@ add.xaxis <- function( name = 'axis.content', at = xat, label = xlabels, - gp = gpar(cex = axis.label.cex), + gp = gpar(cex = axis.label.cex, vjust = 2), main = TRUE ); # Move the labels up slightly xaxis.labels <- editGrob( getGrob(xaxis, 'labels'), - y = unit(-0.09, 'npc'), + y = unit(-0.05 * axis.label.cex, 'npc'), vjust = 1 ); From 63d9589a827785308c0ee9f8d9d99f171603d6f4 Mon Sep 17 00:00:00 2001 From: whelena Date: Thu, 12 Jun 2025 15:35:47 -0700 Subject: [PATCH 5/7] use axis.cex instead of axis.label.cex when adding x axis --- R/set.up.plot.area.R | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/R/set.up.plot.area.R b/R/set.up.plot.area.R index c6f3471..6773a00 100644 --- a/R/set.up.plot.area.R +++ b/R/set.up.plot.area.R @@ -86,12 +86,13 @@ extend.axis <- function(axisGrob, limits, type) { } add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, vp) { + axis.cex <- axisGrob$gp$cex; if (axis.position == 'bottom') { d <- 'y'; just <- c('centre', 'top'); rot <- 0; x <- unit(0.5, 'npc'); - y <- (getGrob(axisGrob, 'labels')$y + getGrob(axisGrob, 'ticks')$y1) * 1.75; + y <- getGrob(axisGrob, 'labels')$y * max(1, (axis.label.cex + axis.cex)); } else { pushViewport(vp); @@ -114,9 +115,9 @@ add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, rot <- 90; x <- unit( - convertX(grobWidth(getGrob(axisGrob, 'labels')), 'mm', valueOnly = TRUE) * -(axisGrob$gp$cex) - - convertX(unit(1, 'lines') * axisGrob$gp$cex, 'mm', valueOnly = TRUE) + - convertX(getGrob(axisGrob, 'labels')$x * axisGrob$gp$cex, 'mm', valueOnly = TRUE), + convertX(grobWidth(getGrob(axisGrob, 'labels')), 'mm', valueOnly = TRUE) * -(axis.cex) - + convertX(unit(1, 'lines') * axis.cex, 'mm', valueOnly = TRUE) + + convertX(getGrob(axisGrob, 'labels')$x * axis.cex, 'mm', valueOnly = TRUE), 'mm' ); } else if (axis.position == 'right') { @@ -295,14 +296,14 @@ add.xaxis <- function( name = 'axis.content', at = xat, label = xlabels, - gp = gpar(cex = axis.label.cex, vjust = 2), + gp = gpar(cex = axis.cex, vjust = 2), main = TRUE ); # Move the labels up slightly xaxis.labels <- editGrob( getGrob(xaxis, 'labels'), - y = unit(-0.05 * axis.label.cex, 'npc'), + y = getGrob(xaxis, 'ticks')$y1 * 1.5, vjust = 1 ); From dc372f1aa3066b026ecd606699d3f17b280f2ed2 Mon Sep 17 00:00:00 2001 From: whelena Date: Thu, 12 Jun 2025 16:10:09 -0700 Subject: [PATCH 6/7] handle left and right y-axis label spacing using the same calculationg --- R/set.up.plot.area.R | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/R/set.up.plot.area.R b/R/set.up.plot.area.R index 6773a00..303211e 100644 --- a/R/set.up.plot.area.R +++ b/R/set.up.plot.area.R @@ -113,21 +113,21 @@ add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, d <- 'x'; just <- c('centre', 'centre'); rot <- 90; - - x <- unit( - convertX(grobWidth(getGrob(axisGrob, 'labels')), 'mm', valueOnly = TRUE) * -(axis.cex) - - convertX(unit(1, 'lines') * axis.cex, 'mm', valueOnly = TRUE) + - convertX(getGrob(axisGrob, 'labels')$x * axis.cex, 'mm', valueOnly = TRUE), - 'mm' - ); + sign <- -1; } else if (axis.position == 'right') { d <- 'x'; just <- c('left', 'centre'); x <- (getGrob(axisGrob, 'labels')$x + tick.length) * 1.5; rot <- 270; + sign <- 1; } - popViewport() + x <- unit( + sign * ( + convertX(grobWidth(getGrob(axisGrob, 'labels')), 'mm', valueOnly = TRUE) * axis.cex + + convertX(unit(1, 'lines') * axis.cex, 'mm', valueOnly = TRUE) + ) + + convertX(getGrob(axisGrob, 'labels')$x, 'mm', valueOnly = TRUE), 'mm'); } axis.lab <- textGrob( From e4917a302ec0c990d3ad581973dffcf532624f3e Mon Sep 17 00:00:00 2001 From: whelena Date: Thu, 12 Jun 2025 16:39:00 -0700 Subject: [PATCH 7/7] fix x label spacing --- R/set.up.plot.area.R | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/R/set.up.plot.area.R b/R/set.up.plot.area.R index 303211e..fe89edc 100644 --- a/R/set.up.plot.area.R +++ b/R/set.up.plot.area.R @@ -92,7 +92,12 @@ add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, just <- c('centre', 'top'); rot <- 0; x <- unit(0.5, 'npc'); - y <- getGrob(axisGrob, 'labels')$y * max(1, (axis.label.cex + axis.cex)); + + y <- unit( + convertY(getGrob(axisGrob, 'labels')$y, 'mm', valueOnly = TRUE) - + convertY(unit(1.2, 'lines') * axis.cex, 'mm', valueOnly = TRUE), + 'mm' + ); } else { pushViewport(vp); @@ -134,7 +139,7 @@ add.axis.label <- function(axisGrob, axis.label, axis.position, axis.label.cex, name = 'axis.label', axis.label, gp = gpar(cex = axis.label.cex), - vjust = 0, + vjust = 1, x = x, rot = rot, y = y