bwa bwa samse

bwa samse

Version:
0.7.x
Identifier: TL_a6be17_12.8e
Tool
1"""Snakemake wrapper for bwa sampe."""
2# Snakemake wrappers are provided by Truwl to teach the internal mechanics of Snakemake recipes. View https://github.com/snakemake/snakemake-wrappers to learn how to use wrappers.
3
4__author__ = "Julian de Ruiter"
5__copyright__ = "Copyright 2017, Julian de Ruiter"
6__email__ = "julianderuiter@gmail.com"
7__license__ = "MIT"
8
9
10from os import path
11
12from snakemake.shell import shell
13
14
15# Extract arguments.
16extra = snakemake.params.get("extra", "")
17
18sort = snakemake.params.get("sort", "none")
19sort_order = snakemake.params.get("sort_order", "coordinate")
20sort_extra = snakemake.params.get("sort_extra", "")
21
22log = snakemake.log_fmt_shell(stdout=False, stderr=True)
23
24# Determine which pipe command to use for converting to bam or sorting.
25if sort == "none":
26
27    # Simply convert to bam using samtools view.
28    pipe_cmd = "samtools view -Sbh -o {snakemake.output[0]} -"
29
30elif sort == "samtools":
31
32    # Sort alignments using samtools sort.
33    pipe_cmd = "samtools sort {sort_extra} -o {snakemake.output[0]} -"
34
35    # Add name flag if needed.
36    if sort_order == "queryname":
37        sort_extra += " -n"
38
39    # Use prefix for temp.
40    prefix = path.splitext(snakemake.output[0])[0]
41    sort_extra += " -T " + prefix + ".tmp"
42
43elif sort == "picard":
44
45    # Sort alignments using picard SortSam.
46    pipe_cmd = (
47        "picard SortSam {sort_extra} INPUT=/dev/stdin"
48        " OUTPUT={snakemake.output[0]} SORT_ORDER={sort_order}"
49    )
50
51else:
52    raise ValueError("Unexpected value for params.sort ({})".format(sort))
53
54# Run command.
55shell(
56    "(bwa samse"
57    " {extra}"
58    " {snakemake.params.index}"
59    " {snakemake.input.sai}"
60    " {snakemake.input.fastq}"
61    " | " + pipe_cmd + ") {log}"
62)
63