Skip to content

Commit

Permalink
Bcftools view (#383)
Browse files Browse the repository at this point in the history
* use snakemake-wrapper-utils, allow more inputs

* update bcftools version

* update description

* add wrapper-utils to environment

* update test

* snakefmt test

* update tests

* add parsing of extra params

* add files necessary for subsetting test

* make environment compliant

* remove conda-forge dependency

* add comments to Snakefile

* readd conda-forge
  • Loading branch information
nikostr authored Jun 24, 2021
1 parent 0997adf commit 48be356
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 11 deletions.
3 changes: 2 additions & 1 deletion bio/bcftools/view/environment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ channels:
- bioconda
- conda-forge
dependencies:
- bcftools ==1.11
- bcftools ==1.12
- snakemake-wrapper-utils ==0.2
12 changes: 11 additions & 1 deletion bio/bcftools/view/meta.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,14 @@
name: bcftools view
description: View vcf/bcf file in a different format. For more information see `BCFtools documentation <https://www.htslib.org/doc/bcftools.html#view>`_.
description: View vcf/bcf file in a different format.
authors:
- Johannes Köster
- Nikos Tsardakas Renhuldt
input:
- VCF/BCF file
output:
- Filtered VCF/BCF file
notes: |
* The `uncompressed_bcf` param allows to specify that a BCF output should be uncompressed (ignored otherwise).
* The `bcftools_use_mem` param controls whether to pass the resources.mem_mb to bcftools
* The `extra` param allows for additional program arguments (not `--threads, `-O/--output-type`, `-m/--max-mem`, or `-T/--temp-dir`).
* For more information see, https://samtools.github.io/bcftools/bcftools.html
66 changes: 61 additions & 5 deletions bio/bcftools/view/test/Snakefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,67 @@
rule bcf_to_vcf:
rule bcf_view_sample_file:
input:
bcf="{prefix}.bcf"
"{prefix}.bcf", # input bcf/vcf needs to be first input
index="{prefix}.bcf.csi", # other inputs are optional
samples="samples.txt",
output:
vcf="{prefix}.vcf"
"{prefix}.view_sample.vcf",
log:
"log/{prefix}.view_sample.vcf.log",
params:
# optional extra parameters
extra=lambda w, input: f"-S {input.samples}",
wrapper:
"master/bio/bcftools/view"


rule bcf_view_o_vcf:
input:
"{prefix}.bcf",
output:
"{prefix}.view.vcf",
log:
"log/{prefix}.view.vcf.log",
params:
extra="",
wrapper:
"master/bio/bcftools/view"


rule bcf_view_o_vcf_gz:
input:
"{prefix}.bcf",
output:
"{prefix}.view.vcf.gz",
log:
"log/{prefix}.view.vcf.gz.log",
params:
extra="",
wrapper:
"master/bio/bcftools/view"


rule bcf_view_o_bcf:
input:
"{prefix}.bcf",
output:
"{prefix}.view.bcf",
log:
"log/{prefix}.view.bcf.log",
params:
"" # optional parameters for bcftools view (except -o)
extra="",
wrapper:
"master/bio/bcftools/view"


rule bcf_view_o_uncompressed_bcf:
input:
"{prefix}.bcf",
output:
"{prefix}.view.uncompressed.bcf",
log:
"logs/{prefix}.log"
"log/{prefix}.view.uncompressed.bcf.log",
params:
uncompressed_bcf=True,
extra="",
wrapper:
"master/bio/bcftools/view"
Binary file added bio/bcftools/view/test/a.bcf.csi
Binary file not shown.
1 change: 1 addition & 0 deletions bio/bcftools/view/test/samples.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A
9 changes: 7 additions & 2 deletions bio/bcftools/view/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@


from snakemake.shell import shell
from snakemake_wrapper_utils.bcftools import get_bcftools_opts

bcftools_opts = get_bcftools_opts(snakemake)
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)

shell(
"bcftools view {extra} --threads {snakemake.threads} {snakemake.input} "
"-o {snakemake.output} {log}"
"bcftools view {bcftools_opts} "
"{extra} "
"{snakemake.input[0]} "
"-o {snakemake.output} "
"{log}"
)
36 changes: 34 additions & 2 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -718,10 +718,42 @@ def test_bcftools_reheader():


@skip_if_not_modified
def test_bcftools_view():
def test_bcftools_view_sample_vcf():
run(
"bio/bcftools/view",
["snakemake", "--cores", "1", "--use-conda", "-F", "a.vcf"],
["snakemake", "--cores", "1", "a.view_sample.vcf", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_bcftools_view_vcf():
run(
"bio/bcftools/view",
["snakemake", "--cores", "1", "a.view.vcf", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_bcftools_view_vcf_gz():
run(
"bio/bcftools/view",
["snakemake", "--cores", "1", "a.view.vcf.gz", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_bcftools_view_bcf():
run(
"bio/bcftools/view",
["snakemake", "--cores", "1", "a.view.bcf", "--use-conda", "-F"],
)


@skip_if_not_modified
def test_bcftools_view_uncompressed_bcf():
run(
"bio/bcftools/view",
["snakemake", "--cores", "1", "a.view.uncompressed.bcf", "--use-conda", "-F"],
)


Expand Down

0 comments on commit 48be356

Please sign in to comment.