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

Extend edge style functionality #82

Merged
merged 37 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
b38337a
Use edge.col column internally
dan-knight Aug 2, 2023
a94470a
Remove seg1.col and seg2.col parameters
dan-knight Aug 2, 2023
cd7b47b
Fix bug in edge colour prep
dan-knight Aug 2, 2023
6093553
Update linear test plot
dan-knight Aug 2, 2023
f69f3ae
Edge line type columns
dan-knight Aug 2, 2023
e0fe4e7
Edge width columns
dan-knight Aug 2, 2023
3706a06
Update changelog
dan-knight Aug 2, 2023
5ee9ce3
Basic edge prep unit tests
dan-knight Aug 17, 2023
428b4cd
Refactor edge colour prep
dan-knight Aug 17, 2023
2029016
Fix default edge linewidth
dan-knight Aug 17, 2023
a8024d2
Fix test helper
dan-knight Aug 17, 2023
1c4051c
Update test example plot
dan-knight Aug 17, 2023
691c2ab
Fix code style
dan-knight Aug 17, 2023
8fd981c
Merge branch 'main' of github.com:uclahs-cds/public-R-CancerEvolution…
dan-knight Aug 17, 2023
e3c072e
Fix test plot name
dan-knight Aug 24, 2023
179ad57
Update SRCGrob docs
dan-knight Aug 24, 2023
d3b30f8
Remove line.lwd parameter
dan-knight Aug 24, 2023
7588fba
Update test helper
dan-knight Aug 24, 2023
0bc5115
Update User Guide vignette with node style
dan-knight Sep 1, 2023
5bfb2a8
Add node style columns to vignette data
dan-knight Sep 1, 2023
6f1d5fc
Add line type options to User Guide vignette
dan-knight Sep 1, 2023
df97205
Update User Guide vignette
dan-knight Sep 1, 2023
857b4c1
Update changelog
dan-knight Sep 1, 2023
634dd88
Create multiple default branch length columns
dan-knight Sep 1, 2023
b5318f5
Update changelog
dan-knight Oct 21, 2023
ddbef15
Merge branch 'main' of github.com:uclahs-cds/package-CancerEvolutionV…
dan-knight Oct 23, 2023
67e6e75
Fix code style
dan-knight Oct 24, 2023
53fb96e
Update test plot output
dan-knight Oct 24, 2023
6a79d85
Update User Guide vignette styling section
dan-knight Oct 30, 2023
05c4240
Update changelog
dan-knight Oct 30, 2023
294e9b3
Merge branch 'main' of github.com:uclahs-cds/package-CancerEvolutionV…
dan-knight Nov 10, 2023
975d7e0
Fix code style
dan-knight Nov 13, 2023
7f47d10
Fix branch length bug
dan-knight Nov 14, 2023
7ad8b23
Fix default edge width
dan-knight Nov 15, 2023
5fee7c8
Update test plots
dan-knight Nov 15, 2023
6e68003
Update linear test data
dan-knight Nov 15, 2023
f51b0fe
Update branching test plots
dan-knight Nov 15, 2023
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
13 changes: 10 additions & 3 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CancerEvolutionVisualization 2.0.0 2023-11-09
CancerEvolutionVisualization 2.0.0 2023-11-09 (Helena Winata, Dan Knight)

ADDED
* Option to specify edge colour with "edge.col.1" and "edge.col.2"
columns in tree input dataframe
* Option to specify edge width using "edge.width.1" and "edge.width.2"
columns in tree input dataframe
* Option to specify edge linetype with "edge.type.1" and "edge.type.2"
columns in tree input dataframe
* Support for specifying tree angles in either radians or degrees using
an optional "angle" column
* Generic functions to generate accompanying heatmaps
Expand All @@ -14,8 +20,9 @@ UPDATE
* Fixed lopsided radial tree bug

REMOVED
* "node.col" parameter to SRCGrob. (Node colour only customizable through
tree input data.frame.)
* "seg1.col" and "seg2.col" parameters (replaced by tree input columns).
* "node.col" parameter to SRCGrob. (Node colour only customizable through tree input data.frame.)


--------------------------------------------------------------------------
CancerEvolutionVisualization 1.0.1 2022-10-03 (Dan Knight)
Expand Down
5 changes: 1 addition & 4 deletions R/SRCGrob.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ SRCGrob <- function(
main.y = NULL,
main.cex = 1.7,
node.radius = 0.1,
seg1.col = 'black',
seg2.col = 'green',
line.lwd = 3,
node.text.line.dist = 0.1,
colour.scheme = CancerEvolutionVisualization::colours,
draw.nodes = TRUE,
Expand Down Expand Up @@ -85,10 +82,10 @@ SRCGrob <- function(
scale2 = scale2,
yat = yat,
wid = wid,
line.lwd = line.lwd,
length.from.node.edge = length.from.node.edge,
seg1.col = seg1.col,
seg2.col = seg2.col,
default.branch.width = 4,
add.polygons = add.polygons,
sig.shape = sig.shape,
spread = spread,
Expand Down
10 changes: 6 additions & 4 deletions R/add.segs.R
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,9 @@ add.tree.segs <- function(
y1 = tree.segs1$tipy,
default.units = 'native',
gp = gpar(
col = seg1.col,
lwd = line.lwd
col = clone.out$v$edge.colour.1,
lwd = clone.out$v$edge.width.1,
lty = clone.out$v$edge.type.1
)
);

Expand All @@ -236,8 +237,9 @@ add.tree.segs <- function(
y1 = tree.segs2$tipy,
default.units = 'native',
gp = gpar(
col = seg2.col,
lwd = line.lwd
col = clone.out$v$edge.colour.2,
lwd = clone.out$v$edge.width.2,
lty = clone.out$v$edge.type.2
)
);
}
Expand Down
4 changes: 2 additions & 2 deletions R/make.clone.tree.grobs.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ make.clone.tree.grobs <- function(
scale2,
wid,
yat,
line.lwd,
default.branch.width,
length.from.node.edge,
seg1.col,
seg2.col,
Expand Down Expand Up @@ -121,7 +121,7 @@ make.clone.tree.grobs <- function(
get.CP.polygons(clone.out);
}

add.tree.segs(clone.out, node.radius, line.lwd, scale1, seg1.col, seg2.col);
add.tree.segs(clone.out, node.radius, default.branch.width, scale1, seg1.col, seg2.col);

if (!is.null(cluster.list)) {
message(paste(
Expand Down
12 changes: 8 additions & 4 deletions R/prep.branch.lengths.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ get.default.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.default.branch.length.colnames(1);
get.default.branch.lengths <- function(num.rows, num.cols) {
lengths <- data.frame(a = rep(num.cols, times = num.rows));
colnames(lengths) <- get.default.branch.length.colnames(num.cols);

return(lengths);
}
Expand Down Expand Up @@ -78,12 +78,16 @@ prep.branch.lengths <- function(tree.df) {
)
);

# TODO: Automatically create length2 if an edge.style.2 column is present.
if (length(length.cols) > 0) {
lengths.df <- data.frame(tree.df[, length.cols]);
colnames(lengths.df) <- get.default.branch.length.colnames(length(length.cols));

return(lengths.df);
} else {
return(get.default.branch.lengths(nrow(tree.df)));
return(get.default.branch.lengths(
num.rows = nrow(tree.df),
num.cols = 1
));
}
}
67 changes: 67 additions & 0 deletions R/prep.tree.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ prep.tree <- function(
}
}

tree.df <- prep.edge.colours(tree.df);

default.edge.type <- 'solid';
if ('edge.type.1' %in% colnames(tree.df)) {
tree.df$edge.type.1[is.na(tree.df$edge.type.1)] <- default.edge.type;
} else {
tree.df$edge.type.1 <- default.edge.type;
}

if ('edge.type.2' %in% colnames(tree.df)) {
tree.df$edge.type.2[is.na(tree.df$edge.type.2)] <- default.edge.type;
} else {
tree.df$edge.type.2 <- default.edge.type;
}

default.edge.width <- 3;
if ('edge.width.1' %in% colnames(tree.df)) {
tree.df$edge.width.1[is.na(tree.df$edge.width.1)] <- default.edge.width;
} else {
tree.df$edge.width.1 <- default.edge.width;
}

if ('edge.width.2' %in% colnames(tree.df)) {
tree.df$edge.width.2[is.na(tree.df$edge.width.2)] <- default.edge.width;
} else {
tree.df$edge.width.2 <- default.edge.width;
}

tree.df <- reorder.nodes(tree.df);

# Include -1 value for root node.
Expand Down Expand Up @@ -133,6 +161,12 @@ prep.tree <- function(
border.width = c(NA, tree.df$border.width),
parent = as.numeric(c(NA,tree.df$parent)),
excluded = c(TRUE, rep(FALSE, nrow(tree.df))),
edge.colour.1 = c(NA, tree.df$edge.col.1),
edge.colour.2 = c(NA, tree.df$edge.col.2),
edge.type.1 = c(NA, tree.df$edge.type.1),
edge.type.2 = c(NA, tree.df$edge.type.2),
edge.width.1 = c(NA, tree.df$edge.width.1),
edge.width.2 = c(NA, tree.df$edge.width.2),
bell = c(FALSE, rep(bells, nrow(tree.df))),
alpha = rep(0.5, (nrow(tree.df) + 1)),
stringsAsFactors = FALSE
Expand Down Expand Up @@ -257,6 +291,39 @@ get.y.axis.position <- function(tree.colnames) {
return(y.axis.position);
}

prep.edge.colours <- function(tree.df) {
edge.colours <- list();

default.edge.colours <- c('black', 'green');
edge.colour.column.names <- sapply(
1:2,
function(i) paste('edge', 'col', i, sep = '.')
);

for (i in 1:length(edge.colour.column.names)) {
column.name <- edge.colour.column.names[i];
default.colour <- default.edge.colours[i];

if (column.name %in% colnames(tree.df)) {
tree.df[is.na(tree.df[, column.name]), column.name] <- default.colour;
} else {
tree.df[, column.name] <- default.colour;
}
}

return(tree.df);
}

prep.edge.colour.column <- function(tree.df, column.name, default.value) {
if (column.name %in% colnames(tree.df)) {
values <- tree.df[, column.name];
values[is.na(values)] <- default.value;
return(values);
} else {
return(rep(default.value, nrow(tree.df)));
}
}

prep.node.label.colours <- function(tree.df) {
node.col.error.message <- 'Cannot prepare node label colour without node colour values.';

Expand Down
6 changes: 0 additions & 6 deletions man/SRCGrob.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ SRCGrob(
main.y = NULL,
main.cex = 1.7,
node.radius = 0.1,
seg1.col = "black",
seg2.col = "green",
line.lwd = 3,
node.text.line.dist = 0.1,
colour.scheme = CancerEvolutionVisualization::colours,
draw.nodes = TRUE,
Expand Down Expand Up @@ -72,9 +69,6 @@ SRCGrob(
\item{main.y}{Move the main plot title position up or down}
\item{main.cex}{Font size for the main plot title}
\item{node.radius}{Node size}
\item{seg1.col}{Colour of the first set of tree branch segments}
\item{seg2.col}{Colour of the second set of tree branch segments}
\item{line.lwd}{Branch segment thickness}
\item{node.text.line.dist}{
Distance between node text and tree branches (as a value between 0 and 1)
}
Expand Down
Binary file modified tests/testthat/data/branching.fixed.data.Rda
Binary file not shown.
Binary file modified tests/testthat/data/branching.fixed.plots.Rda
Binary file not shown.
Binary file modified tests/testthat/data/branching.radial.data.Rda
Binary file not shown.
Binary file modified tests/testthat/data/branching.radial.plots.Rda
Binary file not shown.
Binary file modified tests/testthat/data/linear.data.Rda
Binary file not shown.
Binary file modified tests/testthat/data/linear.plots.Rda
Binary file not shown.
3 changes: 0 additions & 3 deletions tests/testthat/helper-multitest.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ create.test.tree <- function(tree, node.text, sample, ...) {
node.radius = 0.1,
node.text.cex = 0.85,
scale1 = 0.9,
seg1.col = 'navy',
seg2.col = 'gold',
line.lwd = 4,
yaxis1.label = 'PGA',
yaxis2.label = 'SNV',
xaxis.label = 'CP',
Expand Down
7 changes: 5 additions & 2 deletions tests/testthat/test-prep.branch.lengths.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ test_that(
expected.length <- 10;

expect_equal(
nrow(get.default.branch.lengths(expected.length)),
nrow(get.default.branch.lengths(
num.rows = expected.length,
num.cols = 1
)),
expected.length
);
});
Expand All @@ -80,7 +83,7 @@ test_that(

expect_true(all(
apply(
get.default.branch.lengths(3),
get.default.branch.lengths(num.rows = 3, num.cols = 1),
MARGIN = 1,
FUN = function(x) {
x == expected.value;
Expand Down
Loading
Loading