Skip to content

Commit fa8617d

Browse files
Merge pull request #5 from fgvieira/samtools
Added samtools utils to parse threads, and output format
2 parents 5df1b60 + 07e46c5 commit fa8617d

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

snakemake_wrapper_utils/samtools.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
from os import path
3+
4+
5+
def get_samtools_opts(snakemake, parse_threads=True, parse_output_format=True):
6+
"""Obtain samtools_opts from output, params, and handle resource definitions in resources."""
7+
samtools_opts = ""
8+
extra = snakemake.params.get("extra", "")
9+
10+
###############
11+
### Threads ###
12+
###############
13+
if parse_threads:
14+
if "-@" in extra or "--threads" in extra:
15+
sys.exit(
16+
"You have specified number of threads (`-@/--threads`) in params.extra; please use only `threads`."
17+
)
18+
samtools_opts += (
19+
""
20+
if snakemake.threads <= 1
21+
else "--threads {}".format(snakemake.threads - 1)
22+
)
23+
24+
#####################
25+
### Output format ###
26+
#####################
27+
if parse_output_format:
28+
if "-O" in extra or "--output-fmt" in extra:
29+
sys.exit(
30+
"You have specified output format (`-O/--output-fmt`) in params.extra; this is automatically infered from output file extension."
31+
)
32+
33+
out_name, out_ext = path.splitext(snakemake.output[0])
34+
out_ext = out_ext[1:].upper()
35+
samtools_opts += f" --output-fmt {out_ext}"
36+
37+
return samtools_opts

0 commit comments

Comments
 (0)