BCFTOOLS MPILEUP¶
Generate VCF or BCF containing genotype likelihoods for one or multiple alignment (BAM or CRAM) files with bcftools mpileup.
Example¶
This wrapper can be used in the following way:
rule bcftools_mpileup:
input:
index="genome.fasta.fai",
ref="genome.fasta", # this can be left out if --no-reference is in options
alignments="mapped/{sample}.bam",
output:
pileup="pileups/{sample}.pileup.bcf",
params:
options="--max-depth 100 --min-BQ 15",
log:
"logs/bcftools_mpileup/{sample}.log",
wrapper:
"v1.6.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.
Software dependencies¶
bcftools=1.11
Authors¶
- Michael Hall
Code¶
__author__ = "Michael Hall"
__copyright__ = "Copyright 2020, Michael Hall"
__email__ = "michael@mbh.sh"
__license__ = "MIT"
from snakemake.shell import shell
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
class MissingReferenceError(Exception):
pass
options = snakemake.params.get("options", "")
# determine if a fasta reference is provided or not and add to options
if "--no-reference" not in options:
ref = snakemake.input.get("ref", "")
if not ref:
raise MissingReferenceError(
"The --no-reference option was not given, but no fasta reference was "
"provided."
)
options += " --fasta-ref {}".format(ref)
shell(
"bcftools mpileup {options} --threads {snakemake.threads} "
"--output {snakemake.output.pileup} "
"{snakemake.input.alignments} "
"{log}"
)