Skip to content

Commit 245ba23

Browse files
committed
Harmonize plot colors and shapes
1 parent 8352ce3 commit 245ba23

5 files changed

Lines changed: 58 additions & 50 deletions

File tree

workflow/scripts/report/af_time_correlation_plot.R

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,18 @@ p <- correlations %>%
2727
x = coefficient,
2828
y = trans.p
2929
) +
30-
geom_point() +
31-
geom_text_repel(aes(label = label), max.overlaps = 1000, direction = "x") +
30+
geom_text_repel(aes(label = label), max.overlaps = 10000, direction = "x") +
31+
geom_point(
32+
data = function(x) subset(x, !is.na(label)),
33+
color = "orange",
34+
size = 2
35+
) +
36+
geom_point(size = 2, shape = 1) +
3237
xlim(c(-1, 1)) +
3338
geom_hline(
3439
aes(yintercept = -log10(0.05)),
3540
linetype = 2,
36-
color = "red"
41+
color = "orange"
3742
) +
3843
labs(
3944
x = "Correlation coefficient",

workflow/scripts/report/context_phylogeny_data.R

Lines changed: 46 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ sink(log, type = "output")
88
library(tidyverse)
99
library(jsonlite)
1010
library(ape)
11-
library(ggtree)
1211
library(logger)
1312

1413
log_threshold(INFO)
@@ -23,40 +22,44 @@ TREE_LEGEND_NAMES["boot_alrt_pass"] <- sprintf(
2322
snakemake@params[["alrt_th"]], "%"
2423
)
2524

25+
log_info("Reading tree")
2626
tree_ml <- read.tree(snakemake@input[["tree"]]) %>%
27-
root(
28-
snakemake@params[["ref_name"]],
29-
resolve.root = TRUE
30-
)
27+
root(
28+
snakemake@params[["ref_name"]],
29+
resolve.root = TRUE
30+
)
31+
log_debug("Read tree with {length(tree_ml$node.label)} labels")
3132

33+
log_info("Reading target names from FASTA")
3234
target_names <- read.dna(
33-
snakemake@input[["target_fasta"]],
34-
format = "fasta",
35-
as.matrix = FALSE,
35+
snakemake@input[["target_fasta"]],
36+
format = "fasta",
37+
as.matrix = FALSE,
3638
)
39+
log_debug("Read {length(target_names)} records")
3740

41+
log_info("Processing target names")
3842
target_names <- target_names[
39-
!startsWith(names(target_names), snakemake@config[["ALIGNMENT_REFERENCE"]])
43+
!startsWith(names(target_names), snakemake@config[["ALIGNMENT_REFERENCE"]])
4044
]
4145
target_names <- names(target_names)
46+
log_debug("{length(target_names)} records remaining after processing")
4247

4348
# ML tree with context data
4449
# Internal nodes color
4550
# Node labels contain SH-aLRT/UFboot values
51+
log_info("Reading support values from labels")
52+
labels <- strsplit(tree_ml$node.label, "/")
4653
aLRT.values <- sapply(
47-
strsplit(tree_ml$node.label, "/"),
48-
function(x) {
49-
as.numeric(x[1])
50-
}
54+
labels,
55+
function(x) as.numeric(x[1])
5156
)
52-
5357
bootstrap.values <- sapply(
54-
strsplit(tree_ml$node.label, "/"),
55-
function(x) {
56-
as.numeric(x[2])
57-
}
58+
labels,
59+
function(x) as.numeric(x[2])
5860
)
5961

62+
log_info("Calculating support mask for the given thresholds")
6063
aLRT.mask <- aLRT.values >= snakemake@params[["alrt_th"]]
6164
boot.mask <- bootstrap.values >= snakemake@params[["boot_th"]]
6265

@@ -73,15 +76,15 @@ tree_ml.labels <- tree_ml$tip.label[1:tree_ml.nodes]
7376
tree_ml.node.pass <- c(rep(FALSE, tree_ml.ntips), aLRT.mask & boot.mask)
7477

7578
ml.tree.annot <- tibble(
76-
node = 1:tree_ml.nodes,
79+
node = 1:tree_ml.nodes,
7780
) %>%
78-
mutate(
79-
Class = case_when(
80-
tree_ml.labels %in% target_names ~ TREE_LEGEND_NAMES["tip_label"],
81-
tree_ml.node.pass ~ TREE_LEGEND_NAMES["boot_alrt_pass"],
82-
TRUE ~ NA
83-
)
81+
mutate(
82+
Class = case_when(
83+
tree_ml.labels %in% target_names ~ TREE_LEGEND_NAMES["tip_label"],
84+
tree_ml.node.pass ~ TREE_LEGEND_NAMES["boot_alrt_pass"],
85+
TRUE ~ NA
8486
)
87+
)
8588

8689
# Write output files
8790
log_info("Writing tree annotation")
@@ -90,22 +93,22 @@ write_csv(ml.tree.annot, snakemake@output$annotation)
9093
log_info("Writing JSON data")
9194
target.node <- tree_ml$node.label[target.mrca - length(tree_ml$tip.label)]
9295
list(
93-
"boot" = strsplit(target.node, "/")[[1]][2] %>% as.numeric(),
94-
"alrt" = strsplit(target.node, "/")[[1]][1] %>% as.numeric(),
95-
"monophyly" = ifelse(
96-
is.monophyletic(tree_ml, target_names),
97-
"are",
98-
"are not"
99-
),
100-
"target_mrca" = target.mrca,
101-
"clade_tips" = target.mrca.clade.ntips,
102-
"max_tip_length" = max(node.depth.edgelength(tree_ml)[
103-
1:length(tree_ml$tip.label)
104-
]),
105-
"root" = snakemake@params[["ref_name"]]
96+
"boot" = strsplit(target.node, "/")[[1]][2] %>% as.numeric(),
97+
"alrt" = strsplit(target.node, "/")[[1]][1] %>% as.numeric(),
98+
"monophyly" = ifelse(
99+
is.monophyletic(tree_ml, target_names),
100+
"are",
101+
"are not"
102+
),
103+
"target_mrca" = target.mrca,
104+
"clade_tips" = target.mrca.clade.ntips,
105+
"max_tip_length" = max(node.depth.edgelength(tree_ml)[
106+
1:length(tree_ml$tip.label)
107+
]),
108+
"root" = snakemake@params[["ref_name"]]
106109
) %>%
107-
write_json(
108-
snakemake@output$json,
109-
auto_unbox = TRUE,
110-
digits = NA
111-
)
110+
write_json(
111+
snakemake@output$json,
112+
auto_unbox = TRUE,
113+
digits = NA
114+
)

workflow/scripts/report/context_phylogeny_plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ annotation <- read_csv(snakemake@input$annotation)
3939
log_info("Plotting M-L tree with context samples")
4040
p <- ggtree(tree_ml, layout = "circular") %<+%
4141
annotation +
42-
geom_highlight(node = json$target_mrca, colour = "red", alpha = 0) +
42+
geom_highlight(node = json$target_mrca, colour = "orange", alpha = 0) +
4343
geom_point(aes(color = Class, size = Class)) +
4444
geom_treescale(1.05 * json$max_tip_length) +
4545
geom_rootedge(0.05 * json$max_tip_length) +

workflow/scripts/report/polymorphic_sites_over_time_plot.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ p <- df %>%
2525
alpha = 0.6,
2626
colour = "orange"
2727
) +
28-
geom_point(size = 1, shape = 1) +
28+
geom_point(size = 2, shape = 1) +
2929
labs(
3030
x = "Days since the initial sampling",
3131
y = "No. of polimorphic sites"

workflow/scripts/report/time_signal_plot.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ p <- time.signal %>%
2929
method = "lm",
3030
fill = "gray95",
3131
alpha = 0.6,
32-
color = "red"
32+
color = "orange"
3333
) +
34-
geom_point() +
34+
geom_point(size = 2, shape = 1) +
3535
labs(
3636
y = "Root-to-tip distance",
3737
x = "Days since the initial sampling"

0 commit comments

Comments
 (0)