Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,4 @@ export(create.clone.genome.distribution.plot)

export(data.frame.to.array)
export(update.descendant.property)
export(get.colours.in.order)
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
* Wrapper function for `SRCgrob` to automatically save plots to file
* Add option to annotate the CCF summary heatmap with the cell values.
* Add support for 1xn and 1x1 heatmaps.
* Add `get.colours.in.order` function to get a list of colours and corresponding clone ID order.
* Add `sample.order` and `clone.order` as input parameters to `create.cluster.heatmap`

## Update
* Fixed angle calculation bug where child angles do not follow
Expand Down
14 changes: 12 additions & 2 deletions R/create.cluster.heatmap.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
create.cluster.heatmap <- function(
DF,
ccf.limits = NULL,
sample.order = NULL,
clone.order = NULL,
clone.colours = NULL,
height = 6,
width = 11,
Expand All @@ -18,9 +20,17 @@ create.cluster.heatmap <- function(
...
) {

if (is.null(levels(DF$ID))) {
DF$ID <- factor(DF$ID, levels = sort(unique(DF$ID)));
# Define the order of the samples
if (is.null(sample.order)) {
sample.order <- sort(unique(DF$ID));
}
DF$ID <- factor(DF$ID, levels = sample.order);

# Define the order of the clones
if (is.null(clone.order)) {
clone.order <- sort(unique(DF$clone.id));
}
DF$clone.id <- factor(DF$clone.id, levels = clone.order);

if (is.null(clone.colours)) {
clone.colours <- get.colours(DF$clone.id, return.names = TRUE);
Expand Down
21 changes: 8 additions & 13 deletions R/get.colours.R
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
get.colours <- function(
value.list,
return.names = FALSE,
predetermined.colours = NULL
return.names = FALSE
) {
colours <- grDevices::colors()[grep('(white|gr(a|e)y)', grDevices::colors(), invert = T)];
unique.values <- unique(value.list);
n <- length(unique.values);

col.list <- sample(colours, n);

if (!is.null(predetermined.colours) && !is.null(value.list)) {
col.list[seq_along(predetermined.colours)] <- predetermined.colours;
if (is.null(value.list)) {
return(setNames(character(0), character(0)));
}

if (is.null(levels(value.list))) {
value.list <- factor(value.list, levels = unique.values);
}
colours <- grDevices::colors()[grep('(white|gr(a|e)y)', grDevices::colors(), invert = TRUE)];
unique.values <- sort(unique(value.list));
n <- length(unique.values);

names(col.list) <- levels(value.list);
col.list <- sample(colours, n);
names(col.list) <- unique.values;

if (return.names) {
return(col.list);
Expand Down
4 changes: 2 additions & 2 deletions man/create.ccf.summary.heatmap.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ create.ccf.summary.heatmap(
\item{DF}{A data-frame with the following column names: 'ID', 'SNV.id', 'clone.id', 'CCF'.}
\item{ccf.limits}{CCF limits to be applied to the heatmap. Must be a vector of length 2 for min and max thresholds. Defaults to \code{NULL}}
\item{median.col}{Defaults to \dQuote{median.ccf.per.sample}}
\item{clone.order}{Defaults to \code{NULL}}
\item{sample.order}{Defaults to \code{NULL}}
\item{clone.order}{Define clone ID order. Defaults to \code{NULL}}
\item{sample.order}{Define sample ID order. Defaults to \code{NULL}}
\item{colour.scheme}{Heatmap colour scheme. Defaults to \code{c('white', 'blue')}}
\item{clone.colours}{A named vector specifying the color to use for each clone to generate a covariate heatmap. If \code{NULL}, no covariates will be added.}
\item{subplot.xlab.cex}{Subplot parameter. Defaults to 1.2}
Expand Down
4 changes: 4 additions & 0 deletions man/create.cluster.heatmap.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Creates a heatmap of cancer cell fraction (CCF) distribution across tumour sampl
create.cluster.heatmap(
DF,
ccf.limits = NULL,
sample.order = NULL,
clone.order = NULL,
clone.colours = NULL,
height = 6,
width = 11,
Expand All @@ -28,6 +30,8 @@ create.cluster.heatmap(
\arguments{
\item{DF}{A data-frame with the following column names: 'ID', 'SNV.id', 'clone.id', 'CCF'.}
\item{ccf.limits}{CCF limits to be applied to the heatmap. Must be a vector of length 2 for min and max thresholds. Defaults to \code{NULL}}
\item{clone.order}{Define clone ID order. Defaults to \code{NULL}}
\item{sample.order}{Define sample ID order. 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{height}{Defaults to 6}
\item{width}{Defaults to 11}
Expand Down
32 changes: 32 additions & 0 deletions man/get.colours.in.order.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 5 additions & 53 deletions tests/testthat/test-get.colours.R
Original file line number Diff line number Diff line change
Expand Up @@ -63,64 +63,16 @@ test_that('get.colours returns an empty color vector when value.list is empty an

test_that(
'get.colours returns expected vectors', {
result <- get.colours(NULL, predetermined.colours = NULL);
result <- get.colours(NULL);
expect_equal(length(result), 0);
expect.character.vector(result);
result <- get.colours(c('ABC', 'DEF'), predetermined.colours = NULL);
result <- get.colours(c('ABC', 'DEF'));
expect_equal(names(result), c('ABC', 'DEF'));
expect_true(!is.na(result['ABC']) && nzchar(result['ABC']));
expect_true(!is.na(result['DEF']) && nzchar(result['DEF']));
result <- get.colours(NULL, predetermined.colours = c('red','green'));
result <- get.colours(c());
expect_equal(length(result), 0);
expect.character.vector(result);
result <- get.colours(c(), predetermined.colours = c());
expect.character.vector(result);
result <- get.colours(NULL, predetermined.colours = c());
expect.character.vector(result);
result <- get.colours(c(), predetermined.colours = NULL);
expect.character.vector(result);
result <- get.colours(c('ABC', 'DEF'), predetermined.colours = c())
expect_equal(names(result), c('ABC', 'DEF'));
expect_true(!is.na(result['ABC']) && nzchar(result['ABC']));
expect_true(!is.na(result['DEF']) && nzchar(result['DEF']));
result <- get.colours(c(), predetermined.colours = c('red', 'green'));
expect.character.vector(result);
result <- get.colours(c('ABC','DEF'), predetermined.colours = c('red','green'));
expect_equal(result, c(ABC = 'red', DEF = 'green'));
result <- get.colours(c('ABC','DEF'), predetermined.colours = c('red'));
expect_equal(names(result), c('ABC', 'DEF'));
expect_true(result['ABC'] == 'red');
expect_true(!is.na(result['DEF']) && nzchar(result['DEF']));
result <- get.colours(c('ABC','DEF'), predetermined.colours = c(NULL,'red'));
expect_equal(names(result), c('ABC', 'DEF'));
expect_true(result['ABC'] == 'red');
expect_true(!is.na(result['DEF']) && nzchar(result['DEF']));
result <- get.colours(c('ABC','DEF'), predetermined.colours = c('red',NULL));
expect_equal(names(result), c('ABC', 'DEF'));
expect_true(result['ABC'] == 'red');
expect_true(!is.na(result['DEF']) && nzchar(result['DEF']));
result <- get.colours(c('ABC'), predetermined.colours = c('red','green'));
expect_equal(result, c(ABC = 'red'));
result <- get.colours(c(NULL,'ABC'), predetermined.colours = c('red','green'));
expect_equal(result, c(ABC = 'red'));
result <- get.colours(c('ABC',NULL), predetermined.colours = c('red','green'));
expect_equal(result, c(ABC = 'red'));
});

test_that(
'get.colours returns expected vectors with minimum colours specified', {
result <- get.colours(NULL, predetermined.colours = NULL)
expect.character.vector(result);
result <- get.colours(NULL, predetermined.colours = c('red', 'green'))
expect.character.vector(result);
result <- get.colours(NULL, predetermined.colours = c('red'))
expect.character.vector(result);
result <- get.colours(c('ABC','DEF'), predetermined.colours = c('red', 'green'))
expect_equal(result, c(ABC = 'red', DEF = 'green'));
result <- get.colours(c('ABC','DEF'), predetermined.colours = c('red'))
expect_equal(names(result), c('ABC', 'DEF'));
expect_true(result['ABC'] == 'red');
expect_true(!is.na(result['DEF']) && nzchar(result['DEF']));
result <- get.colours(c('ABC'), predetermined.colours = c('red', 'green'))
expect_equal(result, c(ABC = 'red'));
});

test_that(
Expand Down