Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting default values for heatmaps #128

Merged
merged 5 commits into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
52 changes: 20 additions & 32 deletions R/create.ccf.heatmap.R
Original file line number Diff line number Diff line change
@@ -1,47 +1,35 @@
create.ccf.heatmap <- function(
hm.array,
x,
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;
x[x <= ccf.thres] <- 0;
}
col.labels <- seq(0, 1, .2);

hm <- BoutrosLab.plotting.general::create.heatmap(
filename = NULL,
x = hm.array,
col.labels <- seq(min(x), max(x), length.out = 5);

return(BoutrosLab.plotting.general::create.heatmap(
x = x,
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,
yaxis.lab = colnames(x),
print.colour.key = print.colour.key,
colourkey.labels.at = col.labels,
colour.scheme = colour.scheme,
...
);
return(hm);
));
}
107 changes: 49 additions & 58 deletions R/create.ccf.summary.heatmap.R
Original file line number Diff line number Diff line change
@@ -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];
Expand All @@ -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(
Expand All @@ -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
...
));
}
76 changes: 40 additions & 36 deletions R/create.cluster.heatmap.R
Original file line number Diff line number Diff line change
@@ -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,
x = arr,
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
)),
Expand Down
2 changes: 1 addition & 1 deletion R/utility.R
Original file line number Diff line number Diff line change
Expand Up @@ -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'
) {

Expand Down