SAMTOOLS FASTX
Converts a SAM, BAM or CRAM into FASTQ or FASTA format.
URL: http://www.htslib.org/doc/samtools-fasta.html
Example
This wrapper can be used in the following way:
rule samtools_fastq:
input:
"{prefix}.sam",
output:
read1="{prefix}.1.fasta",
read2="{prefix}.2.fasta",
read0="{prefix}.0.fasta",
log:
"{prefix}.log",
# Samtools takes additional threads through its option -@
threads: 2 # This value - 1 will be sent to -@
params:
outputtype="fasta",
extra="",
message:
""
wrapper:
"v9.15.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.24snakemake-wrapper-utils=0.9.0
Input/Output
Input:
bam or sam file (.bam, .sam)
Output:
read1: FASTA or FASTQ file for read 1read2: FASTA or FASTQ file for read 2reado: FASTA or FASTQ file for both reads 1 and 2reads: FASTA or FASTQ file for singleton reads (both reads 1 and 2, where the pair is not present)read0: FASTA or FASTQ file for other reads (marked as both/none read 1 and 2)
Params
extra: additional program arguments (not -@/–threads, -o, -1, -2, -s, or -0).
Code
__author__ = "William Rowell"
__copyright__ = "Copyright 2020, William Rowell"
__email__ = "wrowell@pacb.com"
__license__ = "MIT"
from snakemake.shell import shell
from snakemake_wrapper_utils.samtools import get_samtools_opts
samtools_opts = get_samtools_opts(
snakemake, parse_write_index=False, parse_output=False, parse_output_format=False
)
extra = snakemake.params.get("extra", "")
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
# Parse outputs
fq_out = ""
for label, out_file in snakemake.output.items():
if label.startswith("read"):
fq_out += f" -{label.removeprefix('read')} {out_file}"
shell(
"samtools {snakemake.params.outputtype} {samtools_opts} {fq_out} {extra} {snakemake.input} {log}"
)