From 1fafdae1d11a6f2ac9badf2484997298e42dd4d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez=20Herrera?= Date: Thu, 19 Feb 2026 16:09:21 +0100 Subject: [PATCH 1/6] fix: write file as tab-separated file for coherence --- workflow/scripts/report/af_time_correlation_data.R | 2 +- workflow/scripts/report/af_trajectory_panel_plot.R | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/scripts/report/af_time_correlation_data.R b/workflow/scripts/report/af_time_correlation_data.R index 64ad974..2d65b58 100644 --- a/workflow/scripts/report/af_time_correlation_data.R +++ b/workflow/scripts/report/af_time_correlation_data.R @@ -53,7 +53,7 @@ variants <- left_join(variants, metadata, by = c("SAMPLE" = "ID")) %>% # Save processed input log_info("Writing dated and frequency-filled variants") -write_csv(variants, snakemake@output$fmt_variants) +write_tsv(variants, snakemake@output$fmt_variants) log_info("Calculating correlations") log_debug("Calculating unique SNPs") diff --git a/workflow/scripts/report/af_trajectory_panel_plot.R b/workflow/scripts/report/af_trajectory_panel_plot.R index 61e7190..26c247e 100644 --- a/workflow/scripts/report/af_trajectory_panel_plot.R +++ b/workflow/scripts/report/af_trajectory_panel_plot.R @@ -19,7 +19,7 @@ log_threshold(INFO) source(snakemake@params[["design"]]) log_info("Reading formatted variants table") -variants <- read_csv(snakemake@input$fmt_variants) +variants <- read_tsv(snakemake@input$fmt_variants) log_info("Reading subset of variants to represent") selected.variants <- read_lines(snakemake@input$subset) From ac145e40cb1bf8c46ce190433ca90c85290d7e62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez=20Herrera?= Date: Thu, 19 Feb 2026 16:09:33 +0100 Subject: [PATCH 2/6] refactor: add horizontal space in trees --- workflow/scripts/report/allele_freq_tree_plot.R | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/workflow/scripts/report/allele_freq_tree_plot.R b/workflow/scripts/report/allele_freq_tree_plot.R index 2a08851..1e41872 100644 --- a/workflow/scripts/report/allele_freq_tree_plot.R +++ b/workflow/scripts/report/allele_freq_tree_plot.R @@ -77,7 +77,8 @@ max.tip.length <- max( p <- ggtree(tree) %<+% tree_tiplab + geom_tiplab(aes(label = tip_label)) + geom_treescale(1.1 * max.tip.length) + - geom_rootedge(0.05 * max.tip.length) + geom_rootedge(0.05 * max.tip.length) + + hexpand(0.2) ggsave( filename = snakemake@output$plot, From 8bc79b061b43c10cd7b3db97afee537ac8661b01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez=20Herrera?= Date: Thu, 19 Feb 2026 17:07:07 +0100 Subject: [PATCH 3/6] fix: handle variants with fewer than necessary time points --- .../scripts/report/af_time_correlation_data.R | 25 ++++++++++++++----- 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/workflow/scripts/report/af_time_correlation_data.R b/workflow/scripts/report/af_time_correlation_data.R index 2d65b58..fa4e644 100644 --- a/workflow/scripts/report/af_time_correlation_data.R +++ b/workflow/scripts/report/af_time_correlation_data.R @@ -48,7 +48,11 @@ variants <- left_join(variants, metadata, by = c("SAMPLE" = "ID")) %>% CollectionDate ) %>% mutate( - interval = as.numeric(difftime(CollectionDate, min(CollectionDate), units = "days")) + interval = as.numeric(difftime( + CollectionDate, + min(CollectionDate), + units = "days" + )) ) # Save processed input @@ -81,12 +85,21 @@ correlations <- lapply( VARIANT_NAME == snp ) # Perform calculation - test <- cor.test( - df$ALT_FREQ, - df$interval, - method = snakemake@params$cor_method, - exact = snakemake@params$cor_exact + test <- tryCatch( + { + cor.test( + df$ALT_FREQ, + df$interval, + method = "spearman", + exact = TRUE + ) + }, + error = function(e) { + log_warn("Cannot run cor.test for {snp}: {e}") + list(p.value = NA, estimate = NA) + } ) + # Adjust p-value p.value.adj <- p.adjust( test$p.value, From ea031ed4dce27ea5325251180a7f623ea3f3c9c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez=20Herrera?= Date: Thu, 19 Feb 2026 23:34:28 +0100 Subject: [PATCH 4/6] fix: add back snakemake option reverts bug introduced in 8bc79b0 --- workflow/scripts/report/af_time_correlation_data.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/workflow/scripts/report/af_time_correlation_data.R b/workflow/scripts/report/af_time_correlation_data.R index fa4e644..87128ad 100644 --- a/workflow/scripts/report/af_time_correlation_data.R +++ b/workflow/scripts/report/af_time_correlation_data.R @@ -90,8 +90,8 @@ correlations <- lapply( cor.test( df$ALT_FREQ, df$interval, - method = "spearman", - exact = TRUE + method = snakemake@params$cor_method, + exact = snakemake@params$cor_exact ) }, error = function(e) { From bc8eaa50a79da7e087bf59ae076d2793aa92d45d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez=20Herrera?= Date: Fri, 20 Feb 2026 09:32:03 +0100 Subject: [PATCH 5/6] refactor: update af-time correlation data logging --- workflow/scripts/report/af_time_correlation_data.R | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/workflow/scripts/report/af_time_correlation_data.R b/workflow/scripts/report/af_time_correlation_data.R index 87128ad..7b8bf2c 100644 --- a/workflow/scripts/report/af_time_correlation_data.R +++ b/workflow/scripts/report/af_time_correlation_data.R @@ -65,6 +65,7 @@ log_debug("Calculating unique SNPs") unique.snps <- unique(variants$VARIANT_NAME) # Create an empty dataframe to be filled +log_debug("Initializing empty results") cor.df <- data.frame( variant = "", min_af = 0, @@ -75,10 +76,11 @@ cor.df <- data.frame( ) %>% filter(p.value != 0) -log_debug("Calculating correlation using method = {snakemake@params$cor_method} and exact p-value = {snakemake@params$cor_exact}") +log_info("Calculating correlation with method={snakemake@params$cor_method} and exact={snakemake@params$cor_exact}") correlations <- lapply( unique.snps, function(snp) { + log_debug("Processing {snp}") # Select SNP df <- filter( variants, @@ -99,7 +101,6 @@ correlations <- lapply( list(p.value = NA, estimate = NA) } ) - # Adjust p-value p.value.adj <- p.adjust( test$p.value, @@ -150,13 +151,11 @@ mult.alt.variants <- variants %>% ungroup() %>% pull(VARIANT_NAME) %>% unique() - -log_info("Mult all: {mult.alt.variants}") +log_debug("Mult all: {mult.alt.variants}") # Build selected subset to represent variant.selection <- unique(c(significant.variants, mult.alt.variants)) - -log_info("Selection: {variant.selection}") +log_debug("Selection: {variant.selection}") log_info("Writing selected variants subset") write_lines(variant.selection, snakemake@output$subset) From ff08879329df564c53f986d42f4b0f385210545d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81lvarez=20Herrera?= Date: Fri, 20 Feb 2026 09:44:52 +0100 Subject: [PATCH 6/6] refactor: update logging --- workflow/scripts/report/af_time_correlation_data.R | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/workflow/scripts/report/af_time_correlation_data.R b/workflow/scripts/report/af_time_correlation_data.R index 7b8bf2c..a9001d4 100644 --- a/workflow/scripts/report/af_time_correlation_data.R +++ b/workflow/scripts/report/af_time_correlation_data.R @@ -136,8 +136,7 @@ significant.variants <- correlations %>% ) %>% pull(variant) %>% unique() - -log_info("Significant: {significant.variants}") +log_debug("Significant: {significant.variants}") log_info("Selecting variants in positions with more than one alternative allele") mult.alt.variants <- variants %>%