Skip to content

Commit 68b86e4

Browse files
authored
Merge pull request #156 from uclahs-cds/hwinata-expose-polygon-alpha
Polygon parameters
2 parents 6182709 + a8e52eb commit 68b86e4

23 files changed

+186
-78
lines changed

DESCRIPTION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: CancerEvolutionVisualization
22
Title: Publication Quality Phylogenetic Tree Plots
33
Version: 3.0.0
4-
Date: 2024-10-14
4+
Date: 2024-12-09
55
Authors@R: c(
66
person("Paul Boutros", role = "cre", email = "[email protected]"),
77
person("Adriana Salcedo", role = "aut"),

NAMESPACE

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,16 @@ importFrom("graphics", "par", "strheight", "strwidth")
77
importFrom("grDevices", "dev.list", "rainbow")
88
importFrom("utils", "read.table", "vi", "head")
99
importFrom("stats", "median", "setNames", "aggregate", "reshape")
10-
importFrom("grDevices", "col2rgb", "dev.off", "pdf", "png", "svg", "tiff")
10+
importFrom(
11+
"grDevices",
12+
"col2rgb",
13+
"dev.off",
14+
"pdf",
15+
"png",
16+
"svg",
17+
"tiff",
18+
"colorRampPalette"
19+
)
1120

1221
export(SRCGrob)
1322
export(create.phylogenetic.tree)

NEWS.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# CancerEvolutionVisualization 3.0.0 (2024-10-14)
1+
# CancerEvolutionVisualization 3.0.0 (2024-12-09)
22

33
## Added
44
* Dendrogram mode
@@ -8,7 +8,7 @@
88
* Option to disable node drawing with node-by-node control
99
* Node-by-node control of node size
1010
* Aesthetic changes for heatmap and clone-genome distribution plot
11-
* Add parameters to specify polygon shape and width.
11+
* Add parameters to specify polygon shape, width, color, and transparency (alpha).
1212
* Add option to use scale bars instead of y-axes.
1313
* Wrapper function for `SRCgrob` to automatically save plots to file
1414
* Add option to annotate the CCF summary heatmap with the cell values.

R/SRCGrob.R

+9-8
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ SRCGrob <- function(
1818
main.y = NULL,
1919
main.cex = 1.7,
2020
node.text.line.dist = 0.1,
21-
colour.scheme = 'grey',
21+
polygon.colour.scheme = 'grey',
22+
polygon.scale = 1,
2223
add.normal = FALSE,
2324
use.radians = FALSE,
2425
normal.cex = 1,
2526
label.nodes = TRUE,
2627
disable.polygons = FALSE,
27-
polygon.shape = 3,
28-
polygon.width = 1.2,
2928
length.from.node.edge = TRUE,
3029
size.units = 'npc',
3130
scale.bar = FALSE,
@@ -43,15 +42,18 @@ SRCGrob <- function(
4342
yat <- prep.yat(yat);
4443
yaxis.position <- get.y.axis.position(colnames(tree));
4544

46-
node.col <- 'white';
47-
if (length(colour.scheme) == 1) {
48-
colour.scheme <- c(NA, BoutrosLab.plotting.general::colour.gradient(colour.scheme, nrow(tree)));
45+
if (polygon.scale < 0) {
46+
stop('"polygon.scale" must be positive.');
4947
}
48+
polygon.width <- 1.2 * polygon.scale;
49+
50+
node.col <- 'white';
51+
colour.scheme <- gradient.color.scheme(polygon.colour.scheme, nrow(tree));
5052

5153
inputs <- prep.tree(
5254
tree,
5355
node.text,
54-
colour.scheme = colour.scheme,
56+
polygon.colour.scheme = colour.scheme,
5557
use.radians = use.radians,
5658
default.node.colour = node.col
5759
);
@@ -92,7 +94,6 @@ SRCGrob <- function(
9294
length.from.node.edge = length.from.node.edge,
9395
default.branch.width = 4,
9496
add.polygons = add.polygons,
95-
sig.shape = polygon.shape,
9697
spread = spread,
9798
fixed.angle = fixed.angle,
9899
add.node.text = add.node.text,

R/calculate.clone.polygons.R

+2-9
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ make.polygon <- function(
2424
y0,
2525
x1,
2626
x2,
27+
sig.shape,
2728
wid = 1,
2829
len = 1,
2930
col = 'gray',
30-
sig.shape = 4,
3131
beta.in = 3
3232
) {
3333

@@ -62,7 +62,6 @@ position.polygons <- function(
6262
x,
6363
y,
6464
len,
65-
sig.shape = 4,
6665
beta.in = 3,
6766
branching = TRUE,
6867
fixed.angle = NULL,
@@ -75,6 +74,7 @@ position.polygons <- function(
7574

7675
# get the row of v that corresponds to the clone
7776
vi <- v[i,];
77+
sig.shape <- vi[['polygon.shape']];
7878

7979
if (!is.na(vi$parent) && vi$parent == -1 && nrow(v[v$parent == -1, ]) == 1) {
8080
# If root the clone extends the full width of the plot
@@ -238,7 +238,6 @@ get.clones <- function(
238238
y = 0,
239239
wid = 1.2,
240240
len = len,
241-
sig.shape = 3,
242241
beta.in = 3,
243242
branching = FALSE,
244243
no.ccf = FALSE,
@@ -266,7 +265,6 @@ get.clones <- function(
266265
x = x,
267266
y = y,
268267
len = len,
269-
sig.shape = sig.shape,
270268
beta.in = beta.in,
271269
branching = branching,
272270
no.ccf = no.ccf,
@@ -290,7 +288,6 @@ get.clones <- function(
290288
x = x,
291289
y = y,
292290
len = len,
293-
sig.shape = sig.shape,
294291
beta.in = beta.in + beta.add,
295292
branching = branching,
296293
no.ccf = no.ccf,
@@ -319,7 +316,6 @@ compute.clones <- function(
319316
extra.len = 1,
320317
tree = NULL,
321318
fixed.angle = NULL,
322-
sig.shape = 3,
323319
beta.in = 3,
324320
branching = TRUE,
325321
no.ccf = FALSE,
@@ -361,7 +357,6 @@ compute.clones <- function(
361357
x = x,
362358
y = y,
363359
len = len,
364-
sig.shape = sig.shape,
365360
beta.in = beta.in,
366361
branching = branching,
367362
no.ccf = no.ccf,
@@ -379,7 +374,6 @@ compute.clones <- function(
379374
y = y,
380375
wid = wid,
381376
len = len,
382-
sig.shape = sig.shape,
383377
beta.in = beta.in,
384378
branching = branching,
385379
no.ccf = no.ccf,
@@ -394,7 +388,6 @@ compute.clones <- function(
394388
x = x,
395389
y = y,
396390
len = len,
397-
sig.shape = sig.shape,
398391
beta.in = beta.in,
399392
branching = branching,
400393
no.ccf = no.ccf,

R/create.ccf.summary.heatmap.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ create.ccf.summary.heatmap <- function(
44
median.col = 'median.ccf.per.sample',
55
clone.order = NULL,
66
sample.order = NULL,
7-
hm.col.scheme = c('white', 'blue'),
7+
colour.scheme = c('white', 'blue'),
88
clone.colours = NULL,
99
subplot.xlab.cex = 1.2,
1010
subplot.xaxis.cex = 1,
@@ -107,7 +107,7 @@ create.ccf.summary.heatmap <- function(
107107
yaxis.cex = subplot.yaxis.cex,
108108
yaxis.fontface = subplot.yaxis.fontface,
109109
print.colour.key = FALSE,
110-
colour.scheme = hm.col.scheme
110+
colour.scheme = colour.scheme
111111
);
112112

113113
if (add.median.text) {

R/make.clone.polygons.R

-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ make.clone.polygons <- function(
77
extra.len,
88
node.col,
99
spread = 1,
10-
sig.shape = 3,
1110
fixed.angle = NULL,
1211
beta.in = 3,
1312
add.polygons = TRUE,
@@ -34,7 +33,6 @@ make.clone.polygons <- function(
3433
x = 0,
3534
y = tree$length[tree$parent == -1],
3635
fixed.angle = fixed.angle,
37-
sig.shape = sig.shape,
3836
beta.in = beta.in,
3937
branching = branching,
4038
no.ccf = no.ccf,

R/make.clone.tree.grobs.R

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ make.clone.tree.grobs <- function(
1212
seg2.col,
1313
cluster.list,
1414
add.polygons,
15-
sig.shape,
1615
spread,
1716
fixed.angle,
1817
add.node.text,
@@ -106,7 +105,6 @@ make.clone.tree.grobs <- function(
106105
extra.len,
107106
node.col,
108107
spread = spread,
109-
sig.shape = sig.shape,
110108
fixed.angle = fixed.angle,
111109
add.polygons = add.polygons,
112110
no.ccf = no.ccf

R/polygon.color.R

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
gradient.color.scheme <- function(color.scheme, gradient.length) {
2+
if (length(color.scheme) == 1) {
3+
palette.ramp <- colorRampPalette(c('white', color.scheme, 'black'))
4+
gradient <- palette.ramp(gradient.length + 2)[2:(gradient.length + 1)];
5+
} else {
6+
palette.ramp <- colorRampPalette(color.scheme);
7+
gradient <- palette.ramp(gradient.length);
8+
}
9+
return(gradient);
10+
}

R/prep.tree.R

+31-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ prep.tree <- function(
22
tree.df,
33
text.df,
44
bells = TRUE,
5-
colour.scheme,
5+
polygon.colour.scheme,
66
use.radians = FALSE,
77
default.node.colour = 'white'
88
) {
@@ -172,6 +172,33 @@ prep.tree <- function(
172172
conversion.fun = as.character
173173
);
174174

175+
if (!('polygon.col' %in% colnames(tree.df))) {
176+
tree.df$polygon.col <- NA;
177+
}
178+
tree.df$polygon.col <- prep.column.values(
179+
tree.df$polygon.col,
180+
default.values = polygon.colour.scheme[1:nrow(tree.df)],
181+
conversion.fun = as.character
182+
);
183+
184+
if (!('polygon.alpha' %in% colnames(tree.df))) {
185+
tree.df$polygon.alpha <- NA;
186+
}
187+
tree.df$polygon.alpha <- prep.column.values(
188+
tree.df$polygon.alpha,
189+
default.values = 0.5,
190+
conversion.fun = as.numeric
191+
);
192+
193+
if (!('polygon.shape' %in% colnames(tree.df))) {
194+
tree.df$polygon.shape <- NA;
195+
}
196+
tree.df$polygon.shape <- prep.column.values(
197+
tree.df$polygon.shape,
198+
default.values = 3,
199+
conversion.fun = as.numeric
200+
);
201+
175202
tree.df <- reorder.nodes(tree.df);
176203

177204
# Include -1 value for root node.
@@ -208,7 +235,6 @@ prep.tree <- function(
208235
id = c(-1, tree.df$child),
209236
label.text = c('', tree.df$label),
210237
ccf = if (is.null(tree.df$CP)) NA else c(1, tree.df$CP),
211-
color = colour.scheme[1:(nrow(tree.df) + 1)],
212238
angle = c(NA, tree.df$angle),
213239
draw.node = c(NA, tree.df$draw.node),
214240
node.size = c(NA, tree.df$node.size),
@@ -229,7 +255,9 @@ prep.tree <- function(
229255
connector.type = c(NA, tree.df$connector.type),
230256
mode = c(NA, tree.df$mode),
231257
bell = c(FALSE, rep(bells, nrow(tree.df))),
232-
alpha = rep(0.5, (nrow(tree.df) + 1)),
258+
alpha = c(0, tree.df$polygon.alpha),
259+
polygon.shape = c(NA, tree.df$polygon.shape),
260+
color = c(NA, tree.df$polygon.col),
233261
stringsAsFactors = FALSE
234262
);
235263
if (length(branch.names) > 1) {

man/SRCGrob.Rd

+4-10
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,20 @@ SRCGrob(
2626
main.y = NULL,
2727
main.cex = 1.7,
2828
node.text.line.dist = 0.1,
29-
colour.scheme = 'grey',
29+
polygon.colour.scheme = 'grey',
30+
polygon.scale = 1,
3031
add.normal = FALSE,
3132
use.radians = FALSE,
3233
normal.cex = 1,
3334
label.nodes = TRUE,
3435
disable.polygons = FALSE,
35-
polygon.shape = 3,
36-
polygon.width = 1.2,
3736
length.from.node.edge = TRUE,
3837
size.units = 'npc',
3938
scale.bar = FALSE,
4039
scale.bar.coords = c(0.5, 1),
4140
scale.size.1 = NA,
4241
scale.size.2 = NA,
4342
scale.padding = 1
44-
4543
);
4644
}
4745
\arguments{
@@ -76,17 +74,13 @@ SRCGrob(
7674
\item{node.text.line.dist}{
7775
Distance between node text and tree branches (as a value between 0 and 1)
7876
}
79-
\item{colour.scheme}{Vector of colour values to be used for CCF polygons}
8077
\item{add.normal}{Adds a normal}
8178
\item{use.radians}{Unit to be used for 'angle' column (degrees or radians)}
8279
\item{normal.cex}{Font size within the normal 'box'}
8380
\item{label.nodes}{Enable/disable node labels}
8481
\item{disable.polygons}{Disables CCF polygon drawing (even when CCF values are provided)}
85-
\item{polygon.shape}{
86-
Changes the shape of the CCF shading.
87-
Lower values are smoother.
88-
}
89-
\item{polygon.width}{Width of the CCF shading}
82+
\item{polygon.colour.scheme}{Vector of colour values to be used for CCF polygons. Creates a gradient color scheme.}
83+
\item{polygon.scale}{Multiplier to scale CCF polygons (must be positive).}
9084
\item{length.from.node.edge}{
9185
Sets the branch length to be calculated from the edge of the node instead of the centre
9286
}

man/create.ccf.summary.heatmap.Rd

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ create.ccf.summary.heatmap(
1212
median.col = 'median.ccf.per.sample',
1313
clone.order = NULL,
1414
sample.order = NULL,
15-
hm.col.scheme = c('white', 'blue'),
15+
colour.scheme = c('white', 'blue'),
1616
clone.colours = NULL,
1717
subplot.xlab.cex = 1.2,
1818
subplot.xaxis.cex = 1,
@@ -38,7 +38,7 @@ create.ccf.summary.heatmap(
3838
\item{median.col}{Defaults to \dQuote{median.ccf.per.sample}}
3939
\item{clone.order}{Defaults to \code{NULL}}
4040
\item{sample.order}{Defaults to \code{NULL}}
41-
\item{hm.col.scheme}{Heatmap colour scheme. Defaults to \code{c('white', 'blue')}}
41+
\item{colour.scheme}{Heatmap colour scheme. Defaults to \code{c('white', 'blue')}}
4242
\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.}
4343
\item{subplot.xlab.cex}{Subplot parameter. Defaults to 1.2}
4444
\item{subplot.xaxis.cex}{Subplot parameter. Defaults to 1}

tests/testthat/data/fish.data.Rda

294 Bytes
Binary file not shown.

tests/testthat/data/fish.plots.Rda

14.3 KB
Binary file not shown.

tests/testthat/data/linear.data.Rda

21 Bytes
Binary file not shown.

tests/testthat/data/linear.plots.Rda

493 Bytes
Binary file not shown.

tests/testthat/test-fish.R

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
test_that(
2+
'Fishplot case', {
3+
load('data/fish.plots.Rda');
4+
load('data/fish.data.Rda')
5+
6+
expect_true(compare.trees(
7+
fish.example,
8+
SRCGrob(
9+
fish.test.data$tree,
10+
polygon.colour.scheme = fish.test.data$colour.scheme
11+
)
12+
));
13+
});

0 commit comments

Comments
 (0)