BBDUK

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

Run BBDuk.

URL: https://jgi.doe.gov/data-and-tools/bbtools/bb-tools-user-guide/bbduk-guide/

Example

This wrapper can be used in the following way:

rule bbduk_se:
    input:
        sample=["reads/se/{sample}.fastq"],
        adapters="reads/adapt.fas",
    output:
        trimmed="trimmed/se/{sample}.fastq.gz",
        singleton="trimmed/se/{sample}.single.fastq.gz",
        discarded="trimmed/se/{sample}.discarded.fastq.gz",
        stats="trimmed/se/{sample}.stats.txt",
    log:
        "logs/bbduk/se/{sample}.log"
    params:
        extra = lambda w, input: "ref={},adapters,artifacts ktrim=r k=23 mink=11 hdist=1 tpe tbo trimpolygright=10 minlen=25 maxns=30 entropy=0.5 entropywindow=50 entropyk=5".format(input.adapters),
    threads: 7
    wrapper:
        "v1.21.4-1-g701abe08/bio/bbtools/bbduk"


rule bbduk_pe:
    input:
        sample=["reads/pe/{sample}.1.fastq", "reads/pe/{sample}.2.fastq"],
        adapters="reads/adapt.fas",
    output:
        trimmed=["trimmed/pe/{sample}.1.fastq", "trimmed/pe/{sample}.2.fastq"],
        singleton="trimmed/pe/{sample}.single.fastq",
        discarded="trimmed/pe/{sample}.discarded.fastq",
        stats="trimmed/pe/{sample}.stats.txt",
    log:
        "logs/fastp/pe/{sample}.log"
    params:
        extra = lambda w, input: "ref={},adapters,artifacts ktrim=r k=23 mink=11 hdist=1 tpe tbo trimpolygright=10 minlen=25 maxns=30 entropy=0.5 entropywindow=50 entropyk=5".format(input.adapters),
    threads: 7
    wrapper:
        "v1.21.4-1-g701abe08/bio/bbtools/bbduk"

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 java_opts param allows for additional arguments to be passed to the java compiler, e.g. “-XX:ParallelGCThreads=10” (not for -XmX or -Djava.io.tmpdir, since they are handled automatically).
  • The extra param allows for additional program arguments.

Software dependencies

  • bbmap=39.01
  • snakemake-wrapper-utils=0.5.0

Input/Output

Input:

  • sample: list of paths. Raw fastq file with R1 reads, raw fastq file with R2 reads (PE only, optional)

Output:

  • trimmed: trimmed fastq file with R1 reads, trimmed fastq file with R2 reads (PE only, optional)
  • singleton: fastq file with singleton reads (optional)
  • discarded: fastq file with discarded reads (optional)
  • stats: stats file (optonal)

Params

  • extra: Optional parameters
  • adapters: Literal adapters sequences

Authors

  • Filipe G. Vieira

Code

__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2021, Filipe G. Vieira"
__license__ = "MIT"

from snakemake.shell import shell
from snakemake_wrapper_utils.java import get_java_opts

java_opts = get_java_opts(snakemake)
extra = snakemake.params.get("extra", "")
adapters = snakemake.params.get("adapters", "")
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 = "in={}".format(snakemake.input.sample)
    trimmed = "out={}".format(snakemake.output.trimmed)
else:
    reads = "in={} in2={}".format(*snakemake.input.sample)
    trimmed = "out={} out2={}".format(*snakemake.output.trimmed)


singleton = snakemake.output.get("singleton", "")
if singleton:
    singleton = f"outs={singleton}"


discarded = snakemake.output.get("discarded", "")
if discarded:
    discarded = f"outm={discarded}"


stats = snakemake.output.get("stats", "")
if stats:
    stats = f"stats={stats}"


shell(
    "bbduk.sh {java_opts} t={snakemake.threads} "
    "{reads} "
    "{adapters} "
    "{extra} "
    "{trimmed} {singleton} {discarded} "
    "{stats} "
    "{log}"
)