SAMTOOLS FASTX

Converts a SAM, BAM or CRAM into FASTQ or FASTA format.

URL:

Example

This wrapper can be used in the following way:

rule samtools_fastq:
    input:
        "{prefix}.sam",
    output:
        "{prefix}.fasta",
    log:
        "{prefix}.log",
    message:
        ""
    threads:  # Samtools takes additional threads through its option -@
        2     # This value - 1 will be sent to -@
    params:
        outputtype = "fasta",
        extra = ""
    wrapper:
        "v1.1.0/bio/samtools/fastx/"

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

  • samtools==1.12

Input/Output

Input:

  • bam or sam file (.bam, .sam)

Output:

  • fastq file (.fastq) or fasta file (.fasta)

Authors

  • William Rowell

Code

__author__ = "William Rowell"
__copyright__ = "Copyright 2020, William Rowell"
__email__ = "wrowell@pacb.com"
__license__ = "MIT"


from snakemake.shell import shell

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

extra = snakemake.params.get("extra", "")
# Samtools takes additional threads through its option -@
# One thread for samtools merge
# Other threads are *additional* threads passed to the '-@' argument
threads = "" if snakemake.threads <= 1 else " -@ {} ".format(snakemake.threads - 1)

shell(
    """
    (samtools {snakemake.params.outputtype} \
        {threads} {extra} \
        {snakemake.input} > {snakemake.output}) {log}
    """
)