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
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: CancerEvolutionVisualization
Title: Function to Generate Publication Quality Phylogenetic Tree Plots
Version: 1.0.0
Date: 2022-08-03
Date: 2022-09-01
Authors@R: c(
person("Paul Boutros", role = "cre", email = "PBoutros@mednet.ucla.edu"),
person("Adriana Salcedo", role = "aut"),
Expand Down
3 changes: 2 additions & 1 deletion NEWS
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
CancerEvolutionVisualization 1.0.0 2022-08-03 (Dan Knight)
CancerEvolutionVisualization 1.0.0 2022-09-01 (Dan Knight)

ADDED
* Documentation for default colour scheme

UPDATE
* Fixed discrepancies between documentation and code
* Fixed bug related to referencing an uninitialized variable
* Fixed y-axis positioning bug
* Updated packaging/development dependencies


Expand Down
6 changes: 1 addition & 5 deletions R/SRCGrob.R
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,11 @@ SRCGrob <- function(
gene.line.dist <- prep.gene.line.dist(gene.line.dist);

yat <- prep.yat(yat);

yaxis.position <- if (is.null(yaxis2.label)) 'left' else {
if (!is.null(yaxis1.label)) 'both' else 'right';
};
yaxis.position <- get.y.axis.position(colnames(tree));

inputs <- prep.tree(
tree,
genes,
yaxis.position,
colour.scheme = colour.scheme
);

Expand Down
10 changes: 7 additions & 3 deletions R/prep.branch.lengths.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
get.branch.length.colnames <- function(num.columns) {
get.default.branch.length.colnames <- function(num.columns) {
if (num.columns > 0) {
sapply(
1:num.columns,
Expand All @@ -13,7 +13,7 @@ get.branch.length.colnames <- function(num.columns) {

get.default.branch.lengths <- function(num.rows) {
lengths <- data.frame(a = rep(1, times = num.rows));
colnames(lengths) <- get.branch.length.colnames(1);
colnames(lengths) <- get.default.branch.length.colnames(1);

return(lengths);
}
Expand All @@ -22,6 +22,10 @@ validate.branch.colname <- function(column.name) {
grepl('length', column.name);
}

get.branch.length.colnames <- function(col.names) {
Filter(validate.branch.colname, col.names);
}

validate.branch.length.values <- function(length.column) {
return(tryCatch({
numeric.values <- as.numeric(length.column);
Expand Down Expand Up @@ -76,7 +80,7 @@ prep.branch.lengths <- function(tree.df) {

if (length(length.cols) > 0) {
lengths.df <- data.frame(tree.df[, length.cols]);
colnames(lengths.df) <- get.branch.length.colnames(length(length.cols));
colnames(lengths.df) <- get.default.branch.length.colnames(length(length.cols));

return(lengths.df);
} else {
Expand Down
11 changes: 10 additions & 1 deletion R/prep.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ prep.tree <- function(
tree.df,
genes.df,
bells = TRUE,
axis.type = 'left',
colour.scheme
) {

Expand Down Expand Up @@ -143,3 +142,13 @@ check.parent.values <- function(node.names, parent.col) {
}
));
}

get.y.axis.position <- function(tree.colnames) {
num.branch.length.cols <- length(get.branch.length.colnames(tree.colnames));

y.axis.position <- if (num.branch.length.cols == 1) 'left' else {
if (num.branch.length.cols > 1) 'both' else 'none';
};

return(y.axis.position);
}
8 changes: 4 additions & 4 deletions tests/testthat/test-prep.branch.lengths.R
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,21 @@ test_that(
});

test_that(
'get.branch.length.colnames returns the correct length', {
'get.default.branch.length.colnames returns the correct length', {
expected.length <- 5;

expect_length(
get.branch.length.colnames(expected.length),
get.default.branch.length.colnames(expected.length),
expected.length
);
});

test_that(
'get.branch.length.colnames handles length 0', {
'get.default.branch.length.colnames handles length 0', {
expected.length <- 0;

expect_length(
get.branch.length.colnames(expected.length),
get.default.branch.length.colnames(expected.length),
expected.length
);
});
Expand Down
41 changes: 41 additions & 0 deletions tests/testthat/test-prep.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,44 @@ test_that(

expect_true(check.parent.values(node.names, parents));
});

test_that(
'get.y.axis.position handles a single branch length column', {
valid.colname <- 'length1';
cols <- c(valid.colname, 'invalid');

yaxis.position <- get.y.axis.position(cols);
expected.position <- 'left';

expect_equal(yaxis.position, expected.position);
});

test_that(
'get.y.axis.position handles multiple valid branch length columns', {
valid.colnames <- sapply(
1:3,
FUN = function(x) {
paste0('length', x);
}
);

cols <- c(
valid.colnames,
'invalid.col'
);

yaxis.position <- get.y.axis.position(cols);
expected.position <- 'both';

expect_equal(yaxis.position, expected.position);
});

test_that(
'get.y.axis.position handles no valid branch length columns', {
cols <- c('parent');

yaxis.position <- get.y.axis.position(cols);
expected.position <- 'none';

expect_equal(yaxis.position, expected.position);
});