generated from snakemake-workflows/snakemake-workflow-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add further plots to compare across models and missingness
- Loading branch information
1 parent
70cd27d
commit e8cebab
Showing
5 changed files
with
240 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
workflow/scripts/plot_bootstrap_support_values_across_missingness.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
log <- file(snakemake@log[[1]], open="wt") | ||
sink(log) | ||
sink(log, type="message") | ||
|
||
|
||
library("treeio") | ||
library("tidyverse") | ||
|
||
best_trees_support_values <- snakemake@input[["support_trees"]] |> | ||
map( | ||
\(filename) | ||
read.newick( | ||
filename, | ||
node.label = "support" | ||
) |> | ||
as_tibble() |> | ||
drop_na(support) |> | ||
add_column( | ||
max_missing = str_extract( | ||
filename, | ||
"max_(\\d+)_missing\\.support", | ||
group = 1 | ||
), | ||
model = str_extract( | ||
filename, | ||
"results/([^/]+)/max_", | ||
group = 1 | ||
) | ||
) |> | ||
mutate(max_missing = as.integer(max_missing)) |> | ||
select(support, max_missing, model)) |> | ||
list_rbind() | ||
|
||
support_across_missingness <- ggplot( | ||
best_trees_support_values, | ||
aes(x=factor(max_missing), y=support) | ||
) + | ||
geom_violin() + | ||
geom_jitter(width=0.25) + | ||
stat_summary(color="red") + | ||
facet_grid( | ||
cols = vars(model) | ||
) | ||
|
||
number_of_models <- best_trees_support_values |> distinct(model) |> count() |> pull(n) | ||
plot_width = 2 + number_of_models * 5 | ||
|
||
ggsave( | ||
filename = snakemake@output[["support_plot"]], | ||
plot = support_across_missingness, | ||
width = plot_width | ||
) |
148 changes: 148 additions & 0 deletions
148
workflow/scripts/plot_bootstrap_support_values_vs_branch_lengths.R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
log <- file(snakemake@log[[1]], open="wt") | ||
sink(log) | ||
sink(log, type="message") | ||
|
||
|
||
library("treeio") | ||
library("tidyverse") | ||
library("hexbin") | ||
|
||
best_trees_support_vs_branch_length <- snakemake@input[["support_trees"]] |> | ||
map( | ||
\(filename) | ||
read.newick( | ||
filename, | ||
node.label = "support" | ||
) |> | ||
as_tibble() |> | ||
drop_na( | ||
branch.length, | ||
support | ||
) |> | ||
add_column( | ||
max_missing = str_extract( | ||
filename, | ||
"max_(\\d+)_missing\\.support", | ||
group = 1 | ||
), | ||
model = str_extract( | ||
filename, | ||
"results/([^/]+)/max_", | ||
group = 1 | ||
) | ||
) |> | ||
mutate(max_missing = as.integer(max_missing)) |> | ||
select( | ||
branch.length, | ||
support, | ||
max_missing, | ||
model | ||
) | ||
) |> | ||
list_rbind() | ||
|
||
number_of_models <- best_trees_support_vs_branch_length |> distinct(model) |> count() |> pull(n) | ||
plot_height = number_of_models * 3 | ||
plot_width = 2 + plot_height | ||
|
||
data_plot <- ggplot( | ||
data = best_trees_support_vs_branch_length, | ||
mapping = aes( | ||
x=branch.length, | ||
y=support | ||
) | ||
) + | ||
geom_hex( | ||
bins = 10 | ||
) + | ||
scale_fill_viridis_c() + | ||
geom_point( | ||
color = "orange", | ||
alpha = .6 | ||
) + | ||
facet_grid( | ||
cols=vars(model), | ||
rows=vars(max_missing) | ||
) + | ||
theme_bw() + | ||
theme( | ||
text = element_text(size=rel(5.5)), | ||
# x-axis facet labels do not seem to inherit from text above | ||
strip.text.x = element_text(size=rel(5.5)), | ||
axis.text.x = element_text( | ||
angle=45, | ||
vjust=0.9, | ||
hjust=0.9 | ||
) | ||
) | ||
|
||
|
||
ggsave( | ||
filename = snakemake@output[["data_plot"]], | ||
plot = data_plot, | ||
width = plot_width, | ||
height = plot_height | ||
) | ||
|
||
|
||
best_trees_2d_summary <- best_trees_support_vs_branch_length |> | ||
group_by(model, max_missing) |> | ||
summarise( | ||
branch_length_summary = mean_se(branch.length), | ||
support_summary = mean_se(support), | ||
.groups = "drop" | ||
) |> | ||
unnest( | ||
cols = c( | ||
branch_length_summary, | ||
support_summary | ||
), | ||
names_sep="_" | ||
) | ||
|
||
summary_plot <- ggplot( | ||
data = best_trees_2d_summary, | ||
mapping = aes( | ||
x=branch_length_summary_y, | ||
y=support_summary_y | ||
) | ||
) + | ||
geom_point( | ||
color="red" | ||
) + | ||
geom_errorbarh( | ||
mapping = aes( | ||
xmin=branch_length_summary_ymin, | ||
xmax=branch_length_summary_ymax | ||
), | ||
color="red" | ||
) + | ||
geom_errorbar( | ||
mapping = aes( | ||
ymin=support_summary_ymin, | ||
ymax=support_summary_ymax | ||
), | ||
color="red" | ||
) + | ||
facet_grid( | ||
cols=vars(model), | ||
rows=vars(max_missing) | ||
) + | ||
theme_bw() + | ||
theme( | ||
text = element_text(size=rel(5.5)), | ||
# x-axis facet labels do not seem to inherit from text above | ||
strip.text.x = element_text(size=rel(5.5)), | ||
axis.text.x = element_text( | ||
angle=45, | ||
vjust=0.9, | ||
hjust=0.9 | ||
) | ||
) | ||
|
||
ggsave( | ||
filename = snakemake@output[["summary_plot"]], | ||
plot = summary_plot, | ||
width = plot_width, | ||
height = plot_height | ||
) |