pear pear __main__

pear __main__

Version:
0.9.6
Identifier: TL_8893dc_54.3b
Tool
1__author__ = "N. Tessa Pierce"
2__copyright__ = "Copyright 2019, N. Tessa Pierce"
3__email__ = "ntpierce@gmail.com"
4__license__ = "MIT"
5
6from os import path
7from snakemake.shell import shell
8
9extra = snakemake.params.get("extra", "")
10log = snakemake.log_fmt_shell(stdout=True, stderr=True)
11
12r1 = snakemake.input.get("read1")
13r2 = snakemake.input.get("read2")
14assert r1 is not None and r2 is not None, "r1 and r2 files are required as input"
15
16assembled = snakemake.output.get("assembled")
17assert assembled is not None, "require 'assembled' outfile"
18gzip = True if assembled.endswith(".gz") else False
19
20out_base, out_end = assembled.rsplit(".f")
21out_end = ".f" + out_end
22
23df_assembled = out_base + ".assembled.fastq"
24df_discarded = out_base + ".discarded.fastq"
25df_unassembled_r1 = out_base + ".unassembled.forward.fastq"
26df_unassembled_r2 = out_base + ".unassembled.reverse.fastq"
27
28df_outputs = [df_assembled, df_discarded, df_unassembled_r1, df_unassembled_r2]
29
30discarded = snakemake.output.get("discarded", out_base + ".discarded" + out_end)
31unassembled_r1 = snakemake.output.get(
32    "unassembled_read1", out_base + ".unassembled_r1" + out_end
33)
34unassembled_r2 = snakemake.output.get(
35    "unassembled_read2", out_base + ".unassembled_r2" + out_end
36)
37
38final_outputs = [assembled, discarded, unassembled_r1, unassembled_r2]
39
40
41def move_files(in_list, out_list, gzip):
42    for f, o in zip(in_list, out_list):
43        if f != o:
44            if gzip:
45                shell("gzip -9 -c {f} > {o}")
46                shell("rm -f {f}")
47            else:
48                shell("cp {f} {o}")
49                shell("rm -f {f}")
50        elif gzip:
51            shell("gzip -9 {f}")
52
53
54pval = float(snakemake.params.get("pval", ".01"))
55max_mem = snakemake.resources.get("mem_mb", "4000")
56extra = snakemake.params.get("extra", "")
57
58shell(
59    "pear -f {r1} -r {r2} -p {pval} -j {snakemake.threads} -y {max_mem} {extra} -o {out_base} {log}"
60)
61
62move_files(df_outputs, final_outputs, gzip)
63