Skip to content

Commit b455614

Browse files
committed
temp: consider filtered sites before imputing zero alt frequency
1 parent bd911f1 commit b455614

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

workflow/rules/report.smk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ rule af_time_correlation_data:
347347
input:
348348
variants = OUTDIR/f"{OUTPUT_NAME}.variants.tsv",
349349
metadata = config["METADATA"],
350+
sites = OUTDIR / f"{OUTPUT_NAME}.filtered_sites.tsv",
350351
output:
351352
fmt_variants = temp(REPORT_DIR_TABLES/"variants.filled.dated.tsv"),
352353
correlations = report(REPORT_DIR_TABLES/"af_time_correlation.csv"),

workflow/scripts/report/af_time_correlation_data.R

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ library(logger)
1313
log_threshold(INFO)
1414

1515
# Read data
16+
log_info("Reading filtered sites")
17+
sites <- read_tsv(
18+
snakemake@input[["sites"]],
19+
col_select = c("SAMPLE", "POS")
20+
) %>%
21+
mutate(SELECTED_SITE = TRUE)
22+
1623
log_info("Reading variants table")
1724
variants <- read_delim(
1825
snakemake@input[["variants"]],
@@ -24,11 +31,20 @@ variants <- read_delim(
2431
"POS"
2532
)
2633
) %>%
34+
# Annotate sites selected after filter
35+
left_join(sites, by = c("SAMPLE", "POS")) %>%
36+
replace_na(list(SELECTED_SITE = FALSE)) %>%
2737
# Fill positions without alt frequency with 0
38+
# TODO: add a flag to choose behavior
2839
complete(
2940
nesting(REGION, VARIANT_NAME, POS),
3041
SAMPLE,
31-
fill = list(ALT_FREQ = 0)
42+
fill = list(ALT_FREQ = NA)
43+
) %>%
44+
mutate(
45+
ALT_FREQ = case_when(
46+
is.na(ALT_FREQ) & SELECTED_POS ~ 0
47+
)
3248
)
3349

3450
log_info("Reading metadata")

0 commit comments

Comments
 (0)