BWA-METH INDEX

https://img.shields.io/github/issues-pr/snakemake/snakemake-wrappers/bio/bwameth/index?label=version%20update%20pull%20requests

Index a reference sequence for future BS-Seq mapping.

URL: https://github.com/brentp/bwa-meth

Example

This wrapper can be used in the following way:

rule test_bwameth_index_mem:
    input:
        "genome.fasta",
    output:
        multiext(
            "genome.fasta.bwameth",
            ".c2t",
            ".c2t.amb",
            ".c2t.ann",
            ".c2t.bwt",
            ".c2t.pac",
            ".c2t.sa",
        ),
    cache: True  # save space and time with between workflow caching (see docs)
    threads: 1
    log:
        "bwameth_index.log",
    wrapper:
        "v5.0.1/bio/bwameth/index"


rule test_bwameth_index_mem2:
    input:
        "genome.fasta",
    output:
        multiext(
            "genome.fasta.bwameth",
            ".c2t",
            ".c2t.amb",
            ".c2t.ann",
            ".c2t.bwt.2bit.64",
            ".c2t.pac",
            ".c2t.0123",
        ),
    cache: True  # save space and time with between workflow caching (see docs)
    threads: 1
    log:
        "bwameth_index.log",
    wrapper:
        "v5.0.1/bio/bwameth/index"

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

While bwa-meth explicitely writes the index alongside the reference file, this wrapper lets user freely chose the output directory.

Software dependencies

  • bwameth=0.2.7

  • bwa-mem2=2.2.1

Input/Output

Input:

  • Path to reference fasta file.

Output:

  • List of paths to index files.

Params

  • N:

  • o:

  • `` ``:

  • o:

  • p:

  • t:

  • i:

  • o:

  • n:

  • a:

  • l:

  • `` ``:

  • a:

  • r:

  • g:

  • u:

  • m:

  • e:

  • n:

  • t:

  • `` ``:

  • u:

  • s:

  • e:

  • d:

  • ,:

  • `` ``:

  • e:

  • v:

  • e:

  • r:

  • y:

  • t:

  • h:

  • i:

  • n:

  • g:

  • `` ``:

  • i:

  • s:

  • `` ``:

  • h:

  • a:

  • n:

  • d:

  • l:

  • e:

  • d:

  • `` ``:

  • b:

  • y:

  • `` ``:

  • t:

  • h:

  • e:

  • `` ``:

  • w:

  • r:

  • a:

  • p:

  • p:

  • e:

  • r:

  • .:

Authors

  • Thibault Dayris

Code

# coding: utf-8

"""Snakemake wrapper for BWA-Meth index"""

__author__ = "Thibault Dayris"
__mail__ = "thibault.dayris@gustaveroussy.fr"
__copyright__ = "Copyright 2024, Thibault Dayris"
__license__ = "MIT"

import os
import os.path

from tempfile import TemporaryDirectory
from snakemake import shell

log = snakemake.log_fmt_shell(stdout=True, stderr=True, append=True)

# Automatic detection of aligner based on one output file
subcommand = "index"
if any(str(outfile).endswith(".0123") for outfile in snakemake.output):
    subcommand = "index-mem2"

with TemporaryDirectory() as tempdir:
    # Create symlink to avoid bwa-meth index to be written next to the input reference file
    ref_basename = os.path.basename(snakemake.input[0])
    used_reference = os.path.join(tempdir, ref_basename)
    os.symlink(os.path.abspath(snakemake.input[0]), os.path.join(tempdir, ref_basename))

    # Find user-defined reference directory
    prefix = os.path.commonprefix(snakemake.output)
    out_dir = os.path.dirname(prefix) or "./"

    # Run bwameth index command
    shell("bwameth.py {subcommand} {used_reference} {log}")

    # Return index file to user where they expect them
    os.unlink(used_reference)
    shell("mv -v {used_reference}.bwameth.c2t* {out_dir} {log}")