-
Notifications
You must be signed in to change notification settings - Fork 175
/
wrapper.py
64 lines (53 loc) · 1.53 KB
/
wrapper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
__author__ = "Filipe G. Vieira"
__copyright__ = "Copyright 2023, Filipe G. Vieira"
__license__ = "MIT"
from os import path
import tempfile
from snakemake.shell import shell
log = snakemake.log_fmt_shell(stdout=True, stderr=True)
extra = snakemake.params.get("extra", "")
uncomp = ""
in_name, in_ext = path.splitext(snakemake.input[0])
if in_ext in [".gz", ".bz2"]:
uncomp = "zcat" if in_ext == ".gz" else "bzcat"
in_name, in_ext = path.splitext(in_name)
# Infer output format
if in_ext in [".fa", ".fas", ".fasta"]:
in_format = "fasta"
elif in_ext in [".fq", ".fastq"]:
in_format = "fastq"
else:
raise ValueError("invalid input format")
# Redundancy summary
redund_sum = snakemake.output.get("redund_sum", "")
if redund_sum:
redund_sum = f"-o {redund_sum}"
# Redundancy values
redund_val = snakemake.output.get("redund_val", "")
if redund_val:
redund_val = f"-a {redund_val}"
# Mate distribution
mate_distr = snakemake.output.get("mate_distr", "")
if mate_distr:
mate_distr = f"-C {mate_distr}"
# Log
out_log = snakemake.output.get("log", "")
if out_log:
out_log = f"-l {out_log}"
with tempfile.NamedTemporaryFile() as tmp:
in_uncomp = snakemake.input[0]
if uncomp:
in_uncomp = tmp.name
shell("{uncomp} {snakemake.input[0]} > {in_uncomp}")
shell(
"nonpareil"
" -T {snakemake.params.alg}"
" -s {in_uncomp}"
" -f {in_format}"
" {extra}"
" {redund_sum}"
" {redund_val}"
" {mate_distr}"
" {out_log}"
" {log}"
)