Skip to content

Commit

Permalink
feat: make it possible to set output type, vcf or gvcf. (#476)
Browse files Browse the repository at this point in the history
* feat: make it possible to set output type, vcf or gvcf.

* fix: lock mamba version.

* Update wrapper.py

* Update main.yml

* Update main.yml

* Update qc.yml

* Update qc.yml
  • Loading branch information
Smeds committed May 5, 2022
1 parent bd3cdbc commit e62744d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
20 changes: 20 additions & 0 deletions bio/gatk/haplotypecaller/test/Snakefile
@@ -1,4 +1,24 @@
rule haplotype_caller:
input:
# single or list of bam files
bam="mapped/{sample}.bam",
ref="genome.fasta",
# known="dbsnp.vcf" # optional
output:
vcf="calls/{sample}.vcf",
# bam="{sample}.assemb_haplo.bam",
log:
"logs/gatk/haplotypecaller/{sample}.log",
params:
extra="", # optional
java_opts="", # optional
threads: 4
resources:
mem_mb=1024,
wrapper:
"master/bio/gatk/haplotypecaller"

rule haplotype_caller_gvcf:
input:
# single or list of bam files
bam="mapped/{sample}.bam",
Expand Down
22 changes: 19 additions & 3 deletions bio/gatk/haplotypecaller/wrapper.py
Expand Up @@ -27,9 +27,25 @@
if known:
known = "--dbsnp " + str(known)

vcf_output = snakemake.output.get("vcf", "")
if vcf_output:
output = " --output " + str(vcf_output)

gvcf_output = snakemake.output.get("gvcf", "")
if gvcf_output:
output = " --emit-ref-confidence GVCF " + " --output " + str(gvcf_output)

if (vcf_output and gvcf_output) or (not gvcf_output and not vcf_output):
if vcf_output and gvcf_output:
raise ValueError(
"please set vcf or gvcf as output, not both! It's not supported by gatk"
)
else:
raise ValueError("please set one of vcf or gvcf as output (not both)!")

bam_output = snakemake.output.get("bam", "")
if bam_output:
bam_output = "--bam-output " + str(bam_output)
bam_output = " --bam-output " + str(bam_output)

log = snakemake.log_fmt_shell(stdout=True, stderr=True)

Expand All @@ -43,7 +59,7 @@
" {known}"
" {extra}"
" --tmp-dir {tmpdir}"
" --emit-ref-confidence GVCF {bam_output}"
" --output {snakemake.output.gvcf}"
" {output}"
" {bam_output}"
" {log}"
)
9 changes: 8 additions & 1 deletion test.py
Expand Up @@ -3160,7 +3160,14 @@ def test_gatk_applybqsrspark():


@skip_if_not_modified
def test_gatk_haplotypecaller():
def test_gatk_haplotypecaller_vcf():
run(
"bio/gatk/haplotypecaller",
["snakemake", "--cores", "1", "calls/a.vcf", "--use-conda", "-F"],
)

@skip_if_not_modified
def test_gatk_haplotypecaller_gvcf():
run(
"bio/gatk/haplotypecaller",
["snakemake", "--cores", "1", "calls/a.g.vcf", "--use-conda", "-F"],
Expand Down

0 comments on commit e62744d

Please sign in to comment.