Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Split intersection with target region and normalize calls in separate rules. #90

Merged
merged 4 commits into from
Jun 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion workflow/rules/common.smk
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_plot_cov_labels(): # TODO check if ever used anywhere
def label(name):
lower, upper = get_cov_interval(name)
if upper:
return f"{lower}-{upper - 1}"
return f"{lower}-{upper-1}"
return f"≥{lower}"

return {name: label(name) for name in low_coverages}
Expand Down Expand Up @@ -260,6 +260,13 @@ def get_target_regions(wildcards):
return []


def intersect_calls(wildcards):
if get_target_regions(wildcards) == []:
return False
else:
return True


def get_target_regions_intersect_statement(wildcards, input):
if input.target:
return f"bedtools intersect -a /dev/stdin -b {input.target} |"
Expand Down
26 changes: 21 additions & 5 deletions workflow/rules/eval.smk
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,30 @@ rule remove_non_pass:
"v3.3.6/bio/bcftools/view"


rule normalize_calls:
rule intersect_calls_with_target_regions:
input:
bcf="results/filtered-variants/{callset}.bcf",
regions=get_target_regions,
output:
pipe("results/normalized-variants/{callset}_intersected.vcf"),
log:
"logs/intersect-calls/{callset}.log",
conda:
"../envs/tools.yaml"
shell:
"(bedtools intersect -b {input.regions} -a "
"<(bcftools view {input.bcf}) -wa -f 1.0 -header > {output}) 2> {log}"


rule normalize_calls:
input:
calls=branch(
intersect_calls,
then="results/normalized-variants/{callset}_intersected.vcf",
otherwise="results/filtered-variants/{callset}.bcf",
),
ref="resources/reference/genome.fasta",
ref_index="resources/reference/genome.fasta.fai",
regions=get_target_regions,
output:
"results/normalized-variants/{callset}.vcf.gz",
params:
Expand All @@ -106,9 +124,7 @@ rule normalize_calls:
conda:
"../envs/tools.yaml"
shell:
"(bedtools intersect -b {input.regions} -a "
"<(bcftools view {input.bcf}) -wa -f 1.0 -header | "
"bcftools norm {params.extra} --fasta-ref {input.ref} | "
"(bcftools norm {params.extra} --fasta-ref {input.ref} {input.calls} | "
"bcftools view -Oz > {output}) 2> {log}"


Expand Down
Loading