-
Notifications
You must be signed in to change notification settings - Fork 0
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
Refactor heatmaps #73
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ca17d57
Heatmap default colours
dan-knight e683765
Move heatmap functions
dan-knight 9e6171b
Refactor summary heatmap
dan-knight 0d30107
Tests and test data for heatmap functions
dan-knight e57e6aa
Suppress three-colour warning in create.heatmap
dan-knight 33528a4
Fix linting errors
dan-knight c519eab
Update function imports
dan-knight 32ac364
Update changelog
dan-knight 78ded72
Update heatmap argument names
dan-knight 48cad6b
Merge branch 'main' of github.com:uclahs-cds/package-CancerEvolutionV…
dan-knight File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
Package: CancerEvolutionVisualization | ||
Title: Publication Quality Phylogenetic Tree Plots | ||
Version: 2.0.0 | ||
Date: 2023-11-16 | ||
Date: 2023-11-17 | ||
Authors@R: c( | ||
person("Paul Boutros", role = "cre", email = "[email protected]"), | ||
person("Adriana Salcedo", role = "aut"), | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,291 @@ | ||
plot.ccf.hm <- function( | ||
CCF.df, | ||
CCF.threshold = NULL, | ||
cluster.dim = 'both', | ||
cluster.method = 'complete', | ||
dist.method = 'euclidean', | ||
colour.scheme = NULL, | ||
xaxis.lab = NULL, | ||
xlab.label = 'Mutations', | ||
... | ||
) { | ||
|
||
if (!is.null(CCF.threshold)) { | ||
CCF.df[CCF.df <= CCF.threshold] <- 0; | ||
} | ||
col.labels <- seq(0, 1, .2); | ||
sample.names <- colnames(CCF.df); | ||
|
||
heatmap.colours <- if (!is.null(colour.scheme)) { | ||
colour.scheme; | ||
} else { | ||
default.heatmap.colours(); | ||
} | ||
|
||
hm <- BoutrosLab.plotting.general::create.heatmap( | ||
filename = NULL, | ||
x = CCF.df, | ||
force.clustering = TRUE, | ||
cluster.dimensions = cluster.dim, | ||
clustering.method = cluster.method, | ||
rows.distance.method = dist.method, | ||
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, | ||
yaxis.lab = sample.names, | ||
ylab.cex = 1, | ||
yaxis.cex = 0.6, | ||
yaxis.fontface = 1, | ||
colourkey.cex = 0.6, | ||
colour.scheme = heatmap.colours, | ||
left.padding = 1, | ||
right.padding = 1, | ||
resolution = 3000, | ||
width = 9, | ||
height = 5, | ||
colourkey.labels.at = col.labels, | ||
... | ||
); | ||
|
||
return(hm); | ||
} | ||
|
||
plot.cluster.hm <- function( | ||
cluster.df, | ||
plt.height = 6, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll stick to BPG params to simplify things |
||
plt.width = 11, | ||
colour.scheme = NULL, | ||
xaxis.col = NULL, | ||
... | ||
) { | ||
|
||
if (is.null(levels(cluster.df$ID))) { | ||
cluster.df$ID <- factor( | ||
cluster.df$ID, | ||
levels = sort(unique(cluster.df$ID)) | ||
); | ||
} | ||
|
||
cluster.df <- droplevels(cluster.df)[order(cluster.df$clone.id, -abs(cluster.df$CCF)), ]; | ||
arr <- data.frame.to.array(cluster.df); | ||
snv.order <- unique(cluster.df[, c('snv.id', 'clone.id')]); | ||
cluster.colours <- get.colours(cluster.df$clone.id, return.names = TRUE); | ||
arr <- arr[snv.order$snv.id, levels(cluster.df$ID)]; | ||
|
||
heatmap.colours <- if (!is.null(colour.scheme)) { | ||
colour.scheme; | ||
} else { | ||
default.heatmap.colours(); | ||
} | ||
|
||
if (!is.null(xaxis.col)) { | ||
xaxis.label <- unique(cluster.df[cluster.df$snv.id %in% rownames(arr), xaxis.col]); | ||
} | ||
|
||
hm <- plot.ccf.hm( | ||
CCF.df = arr, | ||
cluster.dim = 'none', | ||
colour.scheme = heatmap.colours, | ||
... | ||
); | ||
|
||
# Suppress "three-colour scheme" warning with 3 clones. | ||
cov <- suppressWarnings(BoutrosLab.plotting.general::create.heatmap( | ||
x = t(cluster.colours[snv.order$clone.id]), | ||
input.colours = TRUE, | ||
clustering.method = 'none', | ||
grid.col = FALSE, | ||
print.colour.key = FALSE, | ||
resolution = 5000 | ||
)); | ||
|
||
legend.clone <- BoutrosLab.plotting.general::legend.grob( | ||
list( | ||
legend = list( | ||
title = 'Clones', | ||
labels = names(cluster.colours), | ||
colours = cluster.colours, | ||
border = 'black' | ||
), | ||
legend = list( | ||
title = 'CCF', | ||
labels = c(min(arr), max(arr)), | ||
colours = heatmap.colours, | ||
border = 'black', | ||
continuous = TRUE, | ||
size = 0.6 | ||
) | ||
), | ||
size = 1, | ||
title.cex = 0.75, | ||
label.cex = 0.6 | ||
); | ||
|
||
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, | ||
legend = list(right = list( | ||
fun = legend.clone | ||
)), | ||
height = plt.height, | ||
width = plt.width | ||
)); | ||
} | ||
|
||
plot.summary.ccf.hm <- function( | ||
mutation.df, | ||
CCF.threshold = 0 | ||
) { | ||
|
||
median.ccf <- aggregate( | ||
mutation.df$CCF, | ||
by = list(mutation.df$ID, mutation.df$clone.id), | ||
FUN = median | ||
); | ||
|
||
colnames(median.ccf) <- c('ID', 'clone.id', 'median.CCF'); | ||
|
||
arr <- data.frame.to.array( | ||
median.ccf, | ||
value = 'median.CCF', | ||
x.axis = 'clone.id', | ||
y.axis = 'ID' | ||
); | ||
arr[arr <= CCF.threshold] <- 0; | ||
|
||
filtered.CCFs <- mutation.df$CCF > 0; | ||
SNV.per.clone <- aggregate(snv.id ~ clone.id, mutation.df[filtered.CCFs, ], FUN = length); | ||
colnames(SNV.per.clone) <- c('clone.id', 'num.SNV'); | ||
|
||
SNV.per.sample <- aggregate(snv.id ~ ID, mutation.df[filtered.CCFs, ], FUN = length); | ||
colnames(SNV.per.sample) <- c('ID', 'num.SNV'); | ||
|
||
heatmap.colours <- default.heatmap.colours(); | ||
barplot.padding.percentage <- 0.05; | ||
|
||
max.clone.SNV <- max(SNV.per.clone$num.SNV); | ||
|
||
clone.bar <- BoutrosLab.plotting.general::create.barplot( | ||
formula = num.SNV ~ clone.id, | ||
data = SNV.per.clone, | ||
yaxis.cex = 0, | ||
xaxis.lab = rep('', nrow(arr)), | ||
xaxis.cex = 0, | ||
ylimits = c( | ||
-(max.clone.SNV * barplot.padding.percentage), | ||
max.clone.SNV * (1 + barplot.padding.percentage) | ||
), | ||
resolution = 50 | ||
); | ||
|
||
max.sample.SNV <- max(SNV.per.sample$num.SNV); | ||
|
||
sample.bar <- BoutrosLab.plotting.general::create.barplot( | ||
formula = ID ~ num.SNV, | ||
data = SNV.per.sample, | ||
xlab.label = 'SNV per sample', | ||
xlimits = c( | ||
-(max.sample.SNV * barplot.padding.percentage), | ||
max.sample.SNV * (1 + barplot.padding.percentage) | ||
), | ||
ylab.label = NULL, | ||
yaxis.lab = rep('', length(arr)), | ||
yaxis.cex = 0, | ||
resolution = 50, | ||
plot.horizontal = TRUE | ||
); | ||
|
||
hm <- BoutrosLab.plotting.general::create.heatmap( | ||
x = arr, | ||
cluster.dimensions = 'none', | ||
xlab.cex = 1, | ||
xlab.label = 'Clone ID', | ||
xaxis.lab = rownames(arr), | ||
xaxis.cex = 0.6, | ||
xaxis.fontface = 1, | ||
xaxis.rot = 90, | ||
ylab.cex = 1, | ||
ylab.label = 'Sample ID', | ||
yaxis.lab = colnames(arr), | ||
yaxis.cex = 0.6, | ||
yaxis.fontface = 1, | ||
print.colour.key = FALSE, | ||
colour.scheme = heatmap.colours, | ||
left.padding = 1, | ||
right.padding = 1, | ||
width = 9, | ||
height = 5 | ||
); | ||
|
||
legend.ccf <- BoutrosLab.plotting.general::legend.grob( | ||
list( | ||
legend = list( | ||
title = 'CCF', | ||
labels = c(min(arr), max(arr)), | ||
colours = heatmap.colours, | ||
border = 'black', | ||
continuous = TRUE, | ||
size = 0.6 | ||
) | ||
), | ||
size = 1, | ||
title.cex = 0.75, | ||
label.cex = 0.6 | ||
); | ||
|
||
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 = 8, | ||
ylab.cex = 0.7, | ||
yaxis.cex = 0.6, | ||
yaxis.tck = 0.4, | ||
yaxis.fontface = 1, | ||
x.spacing = c(0), | ||
y.spacing = c(-0.5), | ||
left.padding = 10, | ||
bottom.padding = 3, | ||
merge.legends = FALSE, | ||
print.new.legend = TRUE, | ||
legend = list(right = list( | ||
fun = legend.ccf | ||
)), | ||
height = 6, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
width = 11 | ||
)); | ||
} | ||
|
||
default.heatmap.colours <- function() { | ||
return(c('white', 'blue')) | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to make the
height
andwidth
customizable since the H:W ratio depends on the number of samples and mutations