From 1273a5f8d1f7eea53783936f8dcff71bf89dbc5a Mon Sep 17 00:00:00 2001 From: whelena Date: Mon, 13 May 2024 13:32:15 -0700 Subject: [PATCH 1/4] set defaults for summary heatmap --- R/create.ccf.heatmap.R | 26 ++++---- R/create.ccf.summary.heatmap.R | 107 +++++++++++++++------------------ 2 files changed, 62 insertions(+), 71 deletions(-) diff --git a/R/create.ccf.heatmap.R b/R/create.ccf.heatmap.R index 5634759..3e3aeeb 100644 --- a/R/create.ccf.heatmap.R +++ b/R/create.ccf.heatmap.R @@ -25,21 +25,21 @@ create.ccf.heatmap <- function( cols.distance.method = dist.method, xaxis.lab = xaxis.lab, xlab.label = xlab.label, - xlab.cex = 1, - xaxis.cex = 0.6, - xaxis.fontface = 1, - xaxis.rot = 90, + # xlab.cex = 1, + # xaxis.cex = 0.6, + # xaxis.fontface = 1, + # xaxis.rot = 90, yaxis.lab = colnames(hm.array), - ylab.cex = 1, - yaxis.cex = 0.6, - yaxis.fontface = 1, - colourkey.cex = 0.6, + # ylab.cex = 1, + # yaxis.cex = 0.6, + # yaxis.fontface = 1, + # colourkey.cex = 0.6, colour.scheme = hm.cols, - left.padding = 1, - right.padding = 1, - resolution = 3000, - width = 9, - height = 5, + # left.padding = 1, + # right.padding = 1, + # resolution = 3000, + # width = 9, + # height = 5, colourkey.labels.at = col.labels, ... ); diff --git a/R/create.ccf.summary.heatmap.R b/R/create.ccf.summary.heatmap.R index 66a6c95..394815d 100644 --- a/R/create.ccf.summary.heatmap.R +++ b/R/create.ccf.summary.heatmap.R @@ -1,20 +1,34 @@ create.ccf.summary.heatmap <- function( DF, ccf.thres = 0, + median.col = 'median.ccf.per.sample', clone.order = NULL, - sample.order = NULL + sample.order = NULL, + hm.col.scheme = c('white', 'blue'), + subplot.xlab.cex = 1.2, + subplot.xaxis.cex = 1, + subplot.xaxis.fontface = 'bold', + subplot.xaxis.rot = 90, + subplot.ylab.cex = 1.2, + subplot.yaxis.cex = 1, + subplot.yaxis.fontface = 'bold', + hm.xaxis.rot = 90, + legend.size = 3, + legend.title.cex = 1.2, + legend.label.cex = 1, + ... ) { arr <- data.frame.to.array( DF = DF, - value = 'median.ccf.per.sample', + value = median.col, x.axis = 'clone.id' ); arr[arr <= ccf.thres] <- 0; - clone.df <- unique(DF[, c('clone.id', 'total.snv')]); + clone.df <- aggregate(CCF ~ clone.id, data = DF[DF$CCF > 0, ], FUN = length); sample.df <- aggregate(CCF ~ ID, data = DF[DF$CCF > 0, ], FUN = length); - names(sample.df)[2] <- 'nsnv'; + names(sample.df)[2] <- names(clone.df)[2] <- 'nsnv'; if (!is.null(clone.order) & !is.null(sample.order)) { arr <- arr[clone.order, sample.order]; @@ -23,47 +37,46 @@ create.ccf.summary.heatmap <- function( } clone.bar <- BoutrosLab.plotting.general::create.barplot( - formula = total.snv ~ clone.id, + formula = nsnv ~ clone.id, data = clone.df, - yaxis.cex = 0, - xaxis.lab = rep('', nrow(arr)), xaxis.cex = 0, - ylimits = c( - max(clone.df$total.snv) * 0.05, max(clone.df$total.snv) * 1.05), - resolution = 50 + xlab.label = NULL, + ylab.label = 'SNV per clone', + ylab.cex = subplot.ylab.cex, + yaxis.cex = subplot.yaxis.cex, + yaxis.fontface = subplot.yaxis.fontface, + ylimits = c( - max(clone.df$nsnv) * 0.05, max(clone.df$nsnv) * 1.05) ); sample.bar <- BoutrosLab.plotting.general::create.barplot( formula = ID ~ nsnv, data = sample.df, xlab.label = 'SNV per sample', + xlab.cex = subplot.xlab.cex, + xaxis.cex = subplot.xaxis.cex, + xaxis.fontface = subplot.xaxis.fontface, xlimits = c( - max(sample.df$nsnv) * 0.05, max(sample.df$nsnv) * 1.05), - ylab.label = NULL, - yaxis.lab = rep('', length(arr)), yaxis.cex = 0, - resolution = 50, + ylab.label = NULL, plot.horizontal = TRUE ); hm <- BoutrosLab.plotting.general::create.heatmap( x = arr, cluster.dimensions = 'none', - xlab.cex = 1, xlab.label = 'Clone ID', + xlab.cex = subplot.xlab.cex, xaxis.lab = rownames(arr), - xaxis.cex = 0.6, - xaxis.fontface = 1, - xaxis.rot = 90, - ylab.cex = 1, + xaxis.cex = subplot.xaxis.cex, + xaxis.fontface = subplot.xaxis.fontface, + xaxis.rot = hm.xaxis.rot, ylab.label = 'Sample ID', + ylab.cex = subplot.ylab.cex, yaxis.lab = colnames(arr), - yaxis.cex = 0.6, - yaxis.fontface = 1, + yaxis.cex = subplot.yaxis.cex, + yaxis.fontface = subplot.yaxis.fontface, print.colour.key = FALSE, - colour.scheme = c('white', 'blue'), - left.padding = 1, - right.padding = 1, - width = 9, - height = 5 + colour.scheme = hm.col.scheme ); legend.ccf <- BoutrosLab.plotting.general::legend.grob( @@ -73,46 +86,24 @@ create.ccf.summary.heatmap <- function( labels = c(min(arr), max(arr)), colours = c('white', 'blue'), border = 'black', - continuous = TRUE, - size = 0.6 + continuous = TRUE ) ), - size = 1, - title.cex = 0.75, - label.cex = 0.6 + size = legend.size, + title.cex = legend.title.cex, + label.cex = legend.label.cex ); - return(BoutrosLab.plotting.general::create.multiplot( - filename = NULL, - plot.objects = list(hm, sample.bar, clone.bar), - plot.layout = c(2, 2), - layout.skip = c(FALSE, FALSE, FALSE, TRUE), - panel.heights = c(0.3, 1), - panel.widths = c(1, 0.2), - plot.labels.to.retrieve = 1:3, - xlab.label = c('\t', 'Clone ID', '\t', '\t', 'SNV per sample'), - xlab.cex = 0.7, - xaxis.cex = 0.6, - xaxis.tck = 0.4, - xaxis.rot = 90, - xaxis.fontface = 1, - xlab.to.xaxis.padding = - 0.5, - ylab.label = c( 'SNV per clone', '\t', '\t', 'Sample ID', '\t'), - ylab.padding = 13, - ylab.cex = 0.7, - yaxis.cex = 0.6, - yaxis.tck = 0.4, - yaxis.fontface = 1, - x.spacing = c(- 3), - y.spacing = c(- 1.5), - left.padding = 10, - bottom.padding = 3, - # merge.legends = FALSE, - print.new.legend = TRUE, + return(BoutrosLab.plotting.general::create.multipanelplot( + plot.objects = list(clone.bar, hm, sample.bar), + layout.width = 2, + layout.height = 2, + plot.objects.heights = c(0.3, 1), + plot.objects.widths = c(1, 0.2), + layout.skip = c(FALSE, TRUE, FALSE, FALSE), legend = list(right = list( fun = legend.ccf )), - height = 6, - width = 11 + ... )); } From 97db1585cb3724d67d293da794152abc9ea9978a Mon Sep 17 00:00:00 2001 From: whelena Date: Tue, 14 May 2024 18:08:56 -0700 Subject: [PATCH 2/4] set defaults for create.cluster.heatmap --- R/create.cluster.heatmap.R | 74 ++++++++++++++++++++------------------ R/utility.R | 2 +- 2 files changed, 40 insertions(+), 36 deletions(-) diff --git a/R/create.cluster.heatmap.R b/R/create.cluster.heatmap.R index c4ef5d1..edf0c83 100644 --- a/R/create.cluster.heatmap.R +++ b/R/create.cluster.heatmap.R @@ -1,81 +1,85 @@ create.cluster.heatmap <- function( DF, + clone.colours = NULL, plt.height = 6, plt.width = 11, - hm.cols = NULL, xaxis.col = NULL, + legend.size = 3, + legend.title.cex = 1.2, + legend.label.cex = 1, + filename = NULL, + xlab.cex = 1.2, + xaxis.cex = 1, + xaxis.fontface = 'bold', ... ) { if (is.null(levels(DF$ID))) { DF$ID <- factor(DF$ID, levels = sort(unique(DF$ID))); } + + if (is.null(clone.colours)) { + clone.colours <- get.colours(DF$clone.id, return.names = TRUE); + } DF <- droplevels(DF)[order(DF$clone.id, -abs(DF$CCF)), ]; + snv.order <- unique(DF[, c('SNV.id', 'clone.id')]); arr <- data.frame.to.array(DF); - snv.order <- unique(DF[, c('snv.id', 'clone.id')]); - cls.colours <- get.colours(DF$clone.id, return.names = TRUE); - arr <- arr[snv.order$snv.id, levels(DF$ID)]; + arr <- arr[snv.order$SNV.id, levels(DF$ID)]; if (!is.null(xaxis.col)) { - xaxis.label <- unique(DF[DF$snv.id %in% rownames(arr), xaxis.col]); + xaxis.label <- unique(DF[DF$SNV.id %in% rownames(arr), xaxis.col]); + } else { + xaxis.label <- NULL; } hm <- create.ccf.heatmap( hm.array = arr, - fname = NULL, - cls.dim = 'none', - hm.cols = hm.cols, + cluster.dimensions = 'none', + xlab.label = '', + xaxis.lab = xaxis.label, ... ); cov <- BoutrosLab.plotting.general::create.heatmap( - x = t(cls.colours[snv.order$clone.id]), + x = t(clone.colours[snv.order$clone.id]), + xlab.label = 'Mutations', + xlab.cex = xlab.cex, + xaxis.cex = xaxis.cex, + xaxis.fontface = xaxis.fontface, input.colours = TRUE, clustering.method = 'none', grid.col = FALSE, print.colour.key = FALSE, - resolution = 5000 + yaxis.tck = 0 ); legend.clone <- BoutrosLab.plotting.general::legend.grob( list( legend = list( title = 'Clones', - labels = names(cls.colours), - colours = cls.colours, + labels = names(clone.colours), + colours = clone.colours, border = 'black' ), legend = list( title = 'CCF', labels = c(min(arr), max(arr)), - colours = if (is.null(hm.cols)) c('white', 'blue') else hm.cols, + colours = if (is.null(colour.scheme)) c('white', 'blue') else colour.scheme, border = 'black', - continuous = TRUE, - size = 0.6 + continuous = TRUE ) ), - size = 1, - title.cex = 0.75, - label.cex = 0.6 + size = legend.size, + title.cex = legend.title.cex, + label.cex = legend.label.cex ); - return(BoutrosLab.plotting.general::create.multiplot( - filename = NULL, - plot.objects = list(cov, hm), - plot.layout = c(1, 2), - panel.heights = c(1, 0.05), - xaxis.lab = if (!is.null(xaxis.col)) xaxis.label else NULL, - xaxis.cex = 0.6, - xaxis.rot = 90, - xaxis.fontface = 1, - xaxis.tck = 0, - yaxis.lab = list(NULL, colnames(arr)), - yaxis.cex = 0.6, - yaxis.tck = 0, - yaxis.fontface = 1, - y.spacing = 0.5, - left.padding = 17, - print.new.legend = TRUE, + return(BoutrosLab.plotting.general::create.multipanelplot( + filename = filename, + plot.objects = list(hm, cov), + layout.width = 1, + layout.height = 2, + plot.objects.heights = c(1, 0.2), legend = list(right = list( fun = legend.clone )), diff --git a/R/utility.R b/R/utility.R index ec2b060..e4cadd5 100644 --- a/R/utility.R +++ b/R/utility.R @@ -22,7 +22,7 @@ reindex.column <- function(column.values, new.value.index) { data.frame.to.array <- function( DF, value = 'CCF', - x.axis = 'snv.id', + x.axis = 'SNV.id', y.axis = 'ID' ) { From 2f46f9619cc18a1a2c6817e885e500acd85a349a Mon Sep 17 00:00:00 2001 From: whelena Date: Tue, 14 May 2024 18:09:49 -0700 Subject: [PATCH 3/4] set defaults for create.ccf.heatmap --- R/create.ccf.heatmap.R | 44 +++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 28 deletions(-) diff --git a/R/create.ccf.heatmap.R b/R/create.ccf.heatmap.R index 3e3aeeb..97d5179 100644 --- a/R/create.ccf.heatmap.R +++ b/R/create.ccf.heatmap.R @@ -1,47 +1,35 @@ create.ccf.heatmap <- function( hm.array, ccf.thres = NULL, - cls.dim = 'both', - cls.method = 'complete', - dist.method = 'euclidean', - hm.cols = c('white', 'blue'), - xaxis.lab = NULL, + cluster.dimensions = 'both', + clustering.method = 'complete', + distance.method = 'euclidean', + xaxis.lab = '', xlab.label = 'Mutations', + print.colour.key = FALSE, + colour.scheme = c('white', 'blue'), ... ) { if (!is.null(ccf.thres)) { hm.array[hm.array <= ccf.thres] <- 0; } - col.labels <- seq(0, 1, .2); - hm <- BoutrosLab.plotting.general::create.heatmap( - filename = NULL, + col.labels <- seq(min(hm.array), max(hm.array), length.out = 5); + + return(BoutrosLab.plotting.general::create.heatmap( x = hm.array, force.clustering = TRUE, - cluster.dimensions = cls.dim, - clustering.method = cls.method, - rows.distance.method = dist.method, - cols.distance.method = dist.method, + cluster.dimensions = cluster.dimensions, + clustering.method = clustering.method, + rows.distance.method = distance.method, + cols.distance.method = distance.method, xaxis.lab = xaxis.lab, xlab.label = xlab.label, - # xlab.cex = 1, - # xaxis.cex = 0.6, - # xaxis.fontface = 1, - # xaxis.rot = 90, yaxis.lab = colnames(hm.array), - # ylab.cex = 1, - # yaxis.cex = 0.6, - # yaxis.fontface = 1, - # colourkey.cex = 0.6, - colour.scheme = hm.cols, - # left.padding = 1, - # right.padding = 1, - # resolution = 3000, - # width = 9, - # height = 5, + print.colour.key = print.colour.key, colourkey.labels.at = col.labels, + colour.scheme = colour.scheme, ... - ); - return(hm); + )); } From f7c403113379f7df147dc8b1eca79bc40c15f5fb Mon Sep 17 00:00:00 2001 From: whelena Date: Wed, 15 May 2024 09:59:04 -0700 Subject: [PATCH 4/4] rename hm.array to x and update NEWS file --- NEWS | 4 ++-- R/create.ccf.heatmap.R | 10 +++++----- R/create.cluster.heatmap.R | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 4090c2e..36ef08b 100644 --- a/NEWS +++ b/NEWS @@ -1,8 +1,8 @@ -CancerEvolutionVisualization 2.0.2 2023-12-15 (Dan Knight) +CancerEvolutionVisualization 2.0.2 2023-12-15 (Helena Winata, Dan Knight) UPDATE * Updated package metadata and README - +* Set default parameters for heatmaps, defaulting too BPG defaults unless necessary -------------------------------------------------------------------------- CancerEvolutionVisualization 2.0.1 2023-11-17 (Helena Winata, Dan Knight) diff --git a/R/create.ccf.heatmap.R b/R/create.ccf.heatmap.R index 97d5179..bee13c8 100644 --- a/R/create.ccf.heatmap.R +++ b/R/create.ccf.heatmap.R @@ -1,5 +1,5 @@ create.ccf.heatmap <- function( - hm.array, + x, ccf.thres = NULL, cluster.dimensions = 'both', clustering.method = 'complete', @@ -12,13 +12,13 @@ create.ccf.heatmap <- function( ) { if (!is.null(ccf.thres)) { - hm.array[hm.array <= ccf.thres] <- 0; + x[x <= ccf.thres] <- 0; } - col.labels <- seq(min(hm.array), max(hm.array), length.out = 5); + col.labels <- seq(min(x), max(x), length.out = 5); return(BoutrosLab.plotting.general::create.heatmap( - x = hm.array, + x = x, force.clustering = TRUE, cluster.dimensions = cluster.dimensions, clustering.method = clustering.method, @@ -26,7 +26,7 @@ create.ccf.heatmap <- function( cols.distance.method = distance.method, xaxis.lab = xaxis.lab, xlab.label = xlab.label, - yaxis.lab = colnames(hm.array), + yaxis.lab = colnames(x), print.colour.key = print.colour.key, colourkey.labels.at = col.labels, colour.scheme = colour.scheme, diff --git a/R/create.cluster.heatmap.R b/R/create.cluster.heatmap.R index edf0c83..32842ef 100644 --- a/R/create.cluster.heatmap.R +++ b/R/create.cluster.heatmap.R @@ -33,7 +33,7 @@ create.cluster.heatmap <- function( } hm <- create.ccf.heatmap( - hm.array = arr, + x = arr, cluster.dimensions = 'none', xlab.label = '', xaxis.lab = xaxis.label,