BCFTOOLS MPILEUP

Generate VCF or BCF containing genotype likelihoods for one or multiple alignment (BAM or CRAM) files.

URL: http://www.htslib.org/doc/bcftools.html#mpileup

Example

This wrapper can be used in the following way:

rule bcftools_mpileup:
    input:
        alignments="mapped/{sample}.bam",
        ref="genome.fasta",  # this can be left out if --no-reference is in options
        index="genome.fasta.fai",
    output:
        pileup="pileups/{sample}.pileup.bcf",
    params:
        uncompressed_bcf=False,
        extra="--max-depth 100 --min-BQ 15",
    log:
        "logs/bcftools_mpileup/{sample}.log",
    wrapper:
        "v1.9.0/bio/bcftools/mpileup"

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.

Notes

  • The uncompressed_bcf param allows to specify that a BCF output should be uncompressed (ignored otherwise).
  • The extra param allows for additional program arguments (not –threads, -f/–fasta-ref, -o/–output, or -O/–output-type).

Software dependencies

  • bcftools=1.14
  • snakemake-wrapper-utils=0.4

Authors

  • Michael Hall
  • Filipe G. Vieira

Code

__author__ = "Michael Hall"
__copyright__ = "Copyright 2020, Michael Hall"
__email__ = "michael@mbh.sh"
__license__ = "MIT"


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


extra = snakemake.params.get("extra", "")
bcftools_opts = get_bcftools_opts(
    snakemake, parse_ref=("--no-reference" not in extra), parse_memory=False
)
log = snakemake.log_fmt_shell(stdout=True, stderr=True)


class MissingReferenceError(Exception):
    pass


shell("bcftools mpileup {bcftools_opts} {extra} {snakemake.input[0]} {log}")