Skip to content

Commit 1fd9692

Browse files
committed
refactor: rename REGION field to CHROM
1 parent 29d75e5 commit 1fd9692

6 files changed

Lines changed: 17 additions & 19 deletions

File tree

workflow/rules/sites.smk

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ rule filter_mpileup_all_sites:
3131
output:
3232
sites_pass = temp(OUTDIR / "all_sites" / "{sample}.filtered_sites.tsv"),
3333
sites_fail = temp(OUTDIR / "all_sites" / "{sample}.fail_sites.tsv"),
34-
log:
35-
LOGDIR / "filter_mpileup_all_sites" / "{sample}.txt"
3634
run:
3735
import pandas as pd
3836
df = pd.read_csv(input[0], sep="\t")

workflow/scripts/fill_all_sites.R

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,25 @@ variants <- read_tsv(snakemake@input[["variants"]])
1717

1818
# Create a mapping of variant names to their genomic position
1919
variant_coords <- variants %>%
20-
select(VARIANT_NAME, REGION, POS) %>%
20+
select(VARIANT_NAME, CHROM, POS) %>%
2121
distinct()
2222

2323
log_info("Reading filtered sites")
2424
sites <- read_tsv(snakemake@input[["sites"]]) %>%
25-
select(SAMPLE, POS) %>% # TODO: consider region/chrom
26-
distinct() %>%
25+
distinct(SAMPLE, POS) %>% # TODO: consider region/chrom
2726
mutate(FILTER_PASS = TRUE)
2827

2928
log_info("Processing variants")
3029
all_variants <- variants %>%
3130
# Select minimal columns
32-
select(VARIANT_NAME, REGION, SAMPLE, ALT_FREQ) %>%
31+
distinct(VARIANT_NAME, CHROM, SAMPLE, ALT_FREQ) %>%
3332
# Handle duplicates
34-
group_by(SAMPLE, VARIANT_NAME, REGION) %>%
33+
group_by(SAMPLE, VARIANT_NAME, CHROM) %>%
3534
summarise(ALT_FREQ = sum(ALT_FREQ, na.rm = TRUE), .groups = "drop") %>%
3635
# Complete with NA
37-
complete(SAMPLE, VARIANT_NAME, REGION) %>%
36+
complete(SAMPLE, VARIANT_NAME, CHROM) %>%
3837
# Assign genomic positions for all combinations
39-
left_join(variant_coords, by = c("REGION", "VARIANT_NAME")) %>%
38+
left_join(variant_coords, by = c("CHROM", "VARIANT_NAME")) %>%
4039
# Merge filtered sites
4140
# TODO: consider region/chrom
4241
left_join(sites, by = c("SAMPLE", "POS")) %>%

workflow/scripts/merge_annotation.R

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ library(logger)
1111

1212
log_threshold(INFO)
1313

14-
log_info("Reading variants table, replacing REGION with the reference name")
14+
log_info("Reading variants table, replacing CHROM with the reference name")
1515
variants <- read_tsv(
1616
snakemake@input$tsv,
1717
col_types = list(
18-
REGION = col_character(),
18+
CHROM = col_character(),
1919
POS = col_integer(),
2020
REF = col_character(),
2121
ALT = col_character()
2222
)
2323
) %>%
2424
mutate(
25-
REGION = snakemake@params$ref_name,
25+
CHROM = snakemake@params$ref_name,
2626
is_insertion = startsWith(ALT, "+"),
2727
is_deletion = startsWith(ALT, "-"),
2828
REF_VCF = case_when(
@@ -35,7 +35,8 @@ variants <- read_tsv(
3535
TRUE ~ ALT
3636
)
3737
) %>%
38-
select(-is_insertion, -is_deletion)
38+
select(-is_insertion, -is_deletion) %>%
39+
rename(CHROM = REGION)
3940

4041
log_info("Reading annotation table")
4142
annotation <- read_tsv(
@@ -67,7 +68,7 @@ merged <- left_join(
6768
variants,
6869
annotation,
6970
by = c(
70-
"REGION" = "CHROM",
71+
"CHROM" = "CHROM",
7172
"POS" = "POS",
7273
"REF_VCF" = "REF",
7374
"ALT_VCF" = "ALT"

workflow/scripts/report/af_time_correlation_data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ variants <- read_delim(
1919
col_select = c(
2020
"VARIANT_NAME",
2121
"SAMPLE",
22-
"REGION",
22+
"CHROM",
2323
"ALT_FREQ",
2424
"POS"
2525
)
2626
) %>%
2727
# Fill positions without alt frequency with NA
2828
complete(
29-
nesting(REGION, VARIANT_NAME, POS),
29+
nesting(CHROM, VARIANT_NAME, POS),
3030
SAMPLE,
3131
fill = list(ALT_FREQ = NA)
3232
)

workflow/scripts/report/nv_panel_data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ variants <- read_delim(
1919
snakemake@input$variants,
2020
col_select = c(
2121
"SAMPLE",
22-
"REGION",
22+
"CHROM",
2323
"POS",
2424
"ALT",
2525
"VARIANT_NAME",
@@ -77,7 +77,7 @@ if (nrow(variants) == 0) {
7777
log_warning("No variants found, using an empty table")
7878
variants <- tibble(
7979
SAMPLE = date_order,
80-
REGION = as.character(NA),
80+
CHROM = as.character(NA),
8181
VARIANT_NAME = as.character(NA),
8282
ALT_FREQ = as.numeric(NA),
8383
EFFECT = as.character(NA),

workflow/scripts/report/polymorphic_sites_over_time_data.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ if (nrow(sites) == 0) {
4242
log_warn("There are none, using an empty table and no linear regression")
4343
sites <- tibble(
4444
SAMPLE = date_order,
45-
REGION = as.character(NA),
45+
CHROM = as.character(NA),
4646
VARIANT_NAME = as.character(NA),
4747
ALT_FREQ = as.numeric(NA),
4848
EFFECT = as.character(NA),

0 commit comments

Comments
 (0)