.. _`bio/bcftools/reheader`: BCFTOOLS REHEADER ================= .. image:: https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/bcftools/reheader?label=version%20update%20pull%20requests :target: https://github.com/snakemake/snakemake-wrappers/pulls?q=is%3Apr+is%3Aopen+label%3Abio/bcftools/reheader Change header or sample names of vcf/bcf file. **URL**: http://www.htslib.org/doc/bcftools.html#reheader Example ------- This wrapper can be used in the following way: .. code-block:: python rule bcftools_reheader: input: vcf="a.bcf", ## new header, can be omitted if "samples" is set header="header.txt", ## file containing new sample names, can be omitted if "header" is set samples="samples.tsv", output: "a.reheader.bcf", log: "a.reheader.log", params: uncompressed_bcf=False, extra="", # optional parameters for bcftools reheader view_extra="", # optional parameters for bcftools view threads: 2 wrapper: "v3.0.1//bio/bcftools/reheader" use rule bcftools_reheader as bcftools_reheader_map with: input: vcf="a.bcf", header="header.txt", samples="samples_map.tsv", output: "a.reheader_map.bcf", log: "a.reheader_map.log", Note that input, output and log file paths can be chosen freely. When running with .. code-block:: bash snakemake --use-conda the software dependencies will be automatically deployed into an isolated environment before execution. Software dependencies --------------------- * ``bcftools=1.18`` * ``snakemake-wrapper-utils=0.6.2`` Input/Output ------------ **Input:** * VCF/BCF file * ``header``: new header (optional if "samples" is set) * ``samples``: new sample names (optional if "header" is set) **Output:** * VCF/BCF file with new header Params ------ * ``uncompressed_bcf``: specify that a BCF output should be uncompressed (ignored otherwise). * ``extra``: additional program arguments (not `--threads`, `-o/--output`, `-O/--output-type`, or `-T/--temp-prefix`) Authors ------- * Jan Forster * Filipe G. Vieira Code ---- .. code-block:: python __author__ = "Jan Forster" __copyright__ = "Copyright 2020, Jan Forster" __email__ = "j.forster@dkfz.de" __license__ = "MIT" import tempfile from pathlib import Path from snakemake.shell import shell from snakemake_wrapper_utils.bcftools import get_bcftools_opts bcftools_opts = get_bcftools_opts( snakemake, parse_ref=False, parse_samples=False, parse_memory=False ) extra = snakemake.params.get("extra", "") view_extra = snakemake.params.get("view_extra", "") log = snakemake.log_fmt_shell(stdout=False, stderr=True) ## Extract arguments header = snakemake.input.get("header", "") if header: header = f"--header {header}" samples = snakemake.input.get("samples", "") if samples: samples = f"--samples {samples}" with tempfile.TemporaryDirectory() as tmpdir: tmp_prefix = Path(tmpdir) / "bcftools_reheader." shell( "(bcftools reheader" " --threads {snakemake.threads}" " {header}" " {samples}" " {extra}" " --temp-prefix {tmp_prefix}" " {snakemake.input[0]}" "| bcftools view" " {bcftools_opts}" " {view_extra}" ") {log}" ) .. |nl| raw:: html