Skip to content

Commit b697a7c

Browse files
committed
fix: fill missing dN and dS count categories with zero
1 parent 8ef5c15 commit b697a7c

1 file changed

Lines changed: 8 additions & 11 deletions

File tree

workflow/scripts/calculate_dnds.R

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,17 @@ variants <- left_join(variants, metadata)
5959
log_info("Reading N/S sites")
6060
n_s_position <- read_delim(snakemake@input[["n_s_sites"]])
6161

62-
log_info("Computing dN/dS over time (NG86)")
62+
log_info("Computing dN/dS analog over time")
63+
total_n <- sum(n_s_position$N)
64+
total_s <- sum(n_s_position$S)
6365
dn.ds <- variants %>%
6466
group_by(SAMPLE, SYNONYMOUS) %>%
65-
summarise(
66-
Freq = sum(ALT_FREQ, na.rm = TRUE)
67-
) %>%
68-
pivot_wider(
69-
names_from = SYNONYMOUS,
70-
values_from = Freq,
71-
values_fill = 0
72-
) %>%
67+
summarise(Freq = sum(ALT_FREQ, na.rm = TRUE), .groups = "drop") %>%
68+
complete(SAMPLE, SYNONYMOUS = c("No", "Yes"), fill = list(Freq = 0)) %>%
69+
pivot_wider(names_from = SYNONYMOUS, values_from = Freq) %>%
7370
transmute(
74-
dn = No / sum(n_s_position$N),
75-
ds = Yes / sum(n_s_position$S)
71+
dn = No / total_n,
72+
ds = Yes / total_s
7673
) %>%
7774
ungroup() %>%
7875
left_join(unique(select(variants, SAMPLE, interval))) %>%

0 commit comments

Comments
 (0)