BOWTIE2

Map reads with bowtie2.

URL: http://bowtie-bio.sourceforge.net/bowtie2/manual.shtml

Example

This wrapper can be used in the following way:

rule bowtie2:
    input:
        sample=["reads/{sample}.1.fastq", "reads/{sample}.2.fastq"],
        idx=multiext(
            "index/genome",
            ".1.bt2",
            ".2.bt2",
            ".3.bt2",
            ".4.bt2",
            ".rev.1.bt2",
            ".rev.2.bt2",
        ),
    output:
        "mapped/{sample}.bam",
    log:
        "logs/bowtie2/{sample}.log",
    params:
        extra="",  # optional parameters
    threads: 8  # Use at least two threads
    wrapper:
        "v1.9.0/bio/bowtie2/align"

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 extra param allows for additional program arguments.
  • This wrapper uses an inner pipe. Make sure to use at least two threads in your Snakefile.

Software dependencies

  • bowtie2=2.4
  • samtools=1.14
  • snakemake-wrapper-utils=0.3

Input/Output

Input:

  • FASTQ file(s)
  • Bowtie2 indexed reference index

Output:

  • SAM/BAM/CRAM file

Authors

  • Johannes Köster
  • Filipe G. Vieira

Code

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


import os
from snakemake.shell import shell
from snakemake_wrapper_utils.samtools import get_samtools_opts


samtools_opts = get_samtools_opts(snakemake)
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)


n = len(snakemake.input.sample)
assert (
    n == 1 or n == 2
), "input->sample must have 1 (single-end) or 2 (paired-end) elements."

if n == 1:
    reads = "-U {}".format(*snakemake.input.sample)
else:
    reads = "-1 {} -2 {}".format(*snakemake.input.sample)


index = os.path.commonprefix(snakemake.input.idx).rstrip(".")


shell(
    "(bowtie2"
    " --threads {snakemake.threads}"
    " {reads} "
    " -x {index}"
    " {extra}"
    "| samtools view"
    " {samtools_opts}"
    " -"
    ") {log}"
)