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

Make mutation and cluster plotting single sample compatible #166

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
46 changes: 43 additions & 3 deletions R/create.ccf.summary.heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,18 @@ create.ccf.summary.heatmap <- function(
xat = sample.xaxis$at
);

same.as.matrix <- !is.matrix(arr)
if (same.as.matrix) {
arr <- as.data.frame(arr)
colnames(arr) <- as.character(unique(DF$ID))
arr <- as.matrix(arr)
hm.args.x <- as.data.frame(arr)
} else {
hm.args.x <- arr
}

hm.args <- list(
x = arr,
x = hm.args.x,
cluster.dimensions = 'none',
xlab.label = 'Clone',
xlab.cex = ifelse(is.null(clone.colours), subplot.xlab.cex, 0),
Expand All @@ -107,7 +117,8 @@ create.ccf.summary.heatmap <- function(
yaxis.cex = subplot.yaxis.cex,
yaxis.fontface = subplot.yaxis.fontface,
print.colour.key = FALSE,
colour.scheme = hm.col.scheme
colour.scheme = hm.col.scheme,
same.as.matrix = same.as.matrix
);

if (add.median.text) {
Expand All @@ -118,14 +129,32 @@ create.ccf.summary.heatmap <- function(
hm.args$text.col <- ifelse(arr > contrast.thres, 'white', 'black');
}

if (same.as.matrix) {
hm.args$yat <- 1.5
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For parameters added here (line 132 - 148), is everything necessary? Generally, we want to avoid hard coding project/user specific params

hm.args$row.pos <- 1.5
}

if (nrow(hm.args.x) == 1 & ncol(hm.args.x) == 1) {
legend.colour.change <- hm.col.scheme[length(hm.col.scheme)]
hm.args$x <- as.data.frame(hm.col.scheme[length(hm.col.scheme)])
hm.args$input.colours <- TRUE
hm.args$clustering.method <- 'none'
hm.args$yat <- 1
hm.args$col.pos <- 1.5
hm.args$row.pos <- 1
legend.col <- hm.col.scheme[length(hm.col.scheme)]
} else {
legend.col <- hm.col.scheme
}

hm <- do.call(BoutrosLab.plotting.general::create.heatmap, hm.args);

legend.ccf <- BoutrosLab.plotting.general::legend.grob(
list(
legend = list(
title = 'CCF',
labels = c(signif(min(arr), 2), rep('', legend.size), signif(max(arr), 2)),
colours = c('white', 'blue'),
colours = legend.col,
border = 'black',
continuous = TRUE,
cex = legend.label.cex
Expand All @@ -137,6 +166,16 @@ create.ccf.summary.heatmap <- function(
);

if (!is.null(clone.colours)) {
if (length(clone.colours) == 1) {
clone.cov <- BoutrosLab.plotting.general::create.heatmap(
x = as.data.frame(clone.colours),
xlab.label = 'Clone',
input.colours = TRUE,
clustering.method = 'none',
print.colour.key = FALSE,
yaxis.tck = 0
);
} else {
clone.cov <- BoutrosLab.plotting.general::create.heatmap(
x = t(clone.colours[rownames(arr)]),
xlab.label = 'Clone',
Expand All @@ -151,6 +190,7 @@ create.ccf.summary.heatmap <- function(
print.colour.key = FALSE,
yaxis.tck = 0
);
}
plot.list <- list(clone.bar, hm, sample.bar, clone.cov);
layout.skip <- c(FALSE, TRUE, FALSE, FALSE, FALSE, TRUE);
layout.height <- 3;
Expand Down
32 changes: 24 additions & 8 deletions R/create.cluster.heatmap.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,30 @@ create.cluster.heatmap <- function(
arr[arr > ccf.limits[2]] <- ccf.limits[2];
}

hm <- create.ccf.heatmap(
x = arr,
cluster.dimensions = 'none',
xlab.label = '',
xaxis.lab = xaxis.label,
colour.scheme = colour.scheme,
...
);
if (!is.matrix(arr)) {
arr <- as.data.frame(arr)
colnames(arr) <- as.character(unique(DF$ID))

hm <- create.ccf.heatmap(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is somewhat redundant I think, especially since users can pass through the same.as.matrix and yat arguments to BPGs create.heatmap.

x = arr,
cluster.dimensions = 'none',
xlab.label = '',
xaxis.lab = xaxis.label,
colour.scheme = colour.scheme,
same.as.matrix = TRUE,
yat = 1.5,
...
);
} else {
hm <- create.ccf.heatmap(
x = arr,
cluster.dimensions = 'none',
xlab.label = '',
xaxis.lab = xaxis.label,
colour.scheme = colour.scheme,
...
);
}

cov <- BoutrosLab.plotting.general::create.heatmap(
x = t(clone.colours[snv.order$clone.id]),
Expand Down
Loading