BCFTOOLS VIEW

View vcf/bcf file in a different format.

URL:

Example

This wrapper can be used in the following way:

rule bcf_view_sample_file:
    input:
        "{prefix}.bcf",  # input bcf/vcf needs to be first input
        index="{prefix}.bcf.csi",  # other inputs are optional
        samples="samples.txt",
    output:
        "{prefix}.view_sample.vcf",
    log:
        "log/{prefix}.view_sample.vcf.log",
    params:
        # optional extra parameters
        extra=lambda w, input: f"-S {input.samples}",
    wrapper:
        "v1.2.0/bio/bcftools/view"


rule bcf_view_o_vcf:
    input:
        "{prefix}.bcf",
    output:
        "{prefix}.view.vcf",
    log:
        "log/{prefix}.view.vcf.log",
    params:
        extra="",
    wrapper:
        "v1.2.0/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:
        "v1.2.0/bio/bcftools/view"


rule bcf_view_o_bcf:
    input:
        "{prefix}.bcf",
    output:
        "{prefix}.view.bcf",
    log:
        "log/{prefix}.view.bcf.log",
    params:
        extra="",
    wrapper:
        "v1.2.0/bio/bcftools/view"


rule bcf_view_o_uncompressed_bcf:
    input:
        "{prefix}.bcf",
    output:
        "{prefix}.view.uncompressed.bcf",
    log:
        "log/{prefix}.view.uncompressed.bcf.log",
    params:
        uncompressed_bcf=True,
        extra="",
    wrapper:
        "v1.2.0/bio/bcftools/view"

Note that input, output and log file paths can be chosen freely.

When running with

snakemake --use-conda

the software dependencies will be automatically deployed into an isolated environment before execution.

Software dependencies

  • bcftools==1.12
  • snakemake-wrapper-utils==0.2

Input/Output

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

Authors

  • Johannes Köster
  • Nikos Tsardakas Renhuldt

Code

__author__ = "Johannes Köster"
__copyright__ = "Copyright 2016, Johannes Köster"
__email__ = "koester@jimmy.harvard.edu"
__license__ = "MIT"


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 {bcftools_opts} "
    "{extra} "
    "{snakemake.input[0]} "
    "-o {snakemake.output} "
    "{log}"
)