annotate bismark_wrapper.py @ 38:b2d0e92f81c2 draft default tip

"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
author bgruening
date Thu, 22 Apr 2021 17:05:07 +0000
parents a81701137fa0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
1 #!/usr/bin/env python
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
2
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
3 import argparse
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
4 import fileinput
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
5 import logging
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
6 import math
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
7 import os
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
8 import shutil
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
9 import subprocess
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
10 import sys
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
11 import tempfile
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
12 from glob import glob
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
13
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
14
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
15 def stop_err(logger, msg):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
16 logger.critical(msg)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
17 sys.exit(1)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
18
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
19
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
20 def log_subprocess_output(logger, pipe):
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
21 for line in iter(pipe.readline, b""):
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
22 logger.debug(line.decode().rstrip())
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
23
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
24
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
25 def __main__():
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
26 # Parse Command Line
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
27 parser = argparse.ArgumentParser(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
28 description="Wrapper for the bismark bisulfite mapper."
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
29 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
30 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
31 "-p",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
32 "--num-threads",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
33 dest="num_threads",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
34 type=int,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
35 default=4,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
36 help="Use this many threads to align reads. The default is 4.",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
37 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
38
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
39 # input options
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
40 parser.add_argument("--own-file", dest="own_file", help="")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
41 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
42 "-D",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
43 "--indexes-path",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
44 dest="index_path",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
45 help="Indexes directory; location of .ebwt and .fa files.",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
46 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
47 parser.add_argument("-O", "--output", dest="output")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
48
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
49 parser.add_argument("--output-report-file", dest="output_report_file")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
50 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
51 "--suppress-header", dest="suppress_header", action="store_true"
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
52 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
53
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
54 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
55 "--mate-paired",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
56 dest="mate_paired",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
57 action="store_true",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
58 help="Reads are mate-paired",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
59 default=False,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
60 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
61
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
62 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
63 "-1",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
64 "--mate1",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
65 dest="mate1",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
66 help="The forward reads file in Sanger FASTQ or FASTA format.",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
67 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
68 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
69 "-2",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
70 "--mate2",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
71 dest="mate2",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
72 help="The reverse reads file in Sanger FASTQ or FASTA format.",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
73 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
74 parser.add_argument("--sort-bam", dest="sort_bam", action="store_true")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
75
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
76 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
77 "--output-unmapped-reads",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
78 dest="output_unmapped_reads",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
79 help="Additional output file with unmapped reads (single-end).",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
80 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
81 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
82 "--output-unmapped-reads-l",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
83 dest="output_unmapped_reads_l",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
84 help="File name for unmapped reads (left, paired-end).",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
85 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
86 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
87 "--output-unmapped-reads-r",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
88 dest="output_unmapped_reads_r",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
89 help="File name for unmapped reads (right, paired-end).",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
90 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
91
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
92 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
93 "--output-suppressed-reads",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
94 dest="output_suppressed_reads",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
95 help="Additional output file with suppressed reads (single-end).",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
96 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
97 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
98 "--output-suppressed-reads-l",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
99 dest="output_suppressed_reads_l",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
100 help="File name for suppressed reads (left, paired-end).",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
101 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
102 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
103 "--output-suppressed-reads-r",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
104 dest="output_suppressed_reads_r",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
105 help="File name for suppressed reads (right, paired-end).",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
106 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
107 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
108 "--stdout",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
109 dest="output_stdout",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
110 help="File name for the standard output of bismark.",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
111 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
112
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
113 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
114 "--single-paired",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
115 dest="single_paired",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
116 help="The single-end reads file in Sanger FASTQ or FASTA format.",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
117 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
118
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
119 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
120 "--fastq", action="store_true", help="Query filetype is in FASTQ format"
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
121 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
122 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
123 "--fasta", action="store_true", help="Query filetype is in FASTA format"
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
124 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
125 parser.add_argument("--phred64-quals", dest="phred64", action="store_true")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
126 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
127 "--non_directional", dest="non_directional", action="store_true"
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
128 )
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
129 parser.add_argument("--pbat", dest="pbat", action="store_true")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
130
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
131 parser.add_argument("--skip-reads", dest="skip_reads", type=int)
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
132 parser.add_argument("--score-min", dest="score_min", type=str)
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
133 parser.add_argument("--qupto", type=int)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
134
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
135 # paired end options
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
136 parser.add_argument("-I", "--minins", dest="min_insert")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
137 parser.add_argument("-X", "--maxins", dest="max_insert")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
138 parser.add_argument("--no-mixed", dest="no_mixed", action="store_true")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
139 parser.add_argument("--no-discordant", dest="no_discordant", action="store_true")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
140
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
141 # parse general options
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
142 # default 20
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
143 parser.add_argument("--seed-len", dest="seed_len", type=int)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
144 # default 15
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
145 parser.add_argument(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
146 "--seed-extention-attempts", dest="seed_extention_attempts", type=int
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
147 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
148 # default 0
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
149 parser.add_argument("--seed-mismatches", dest="seed_mismatches", type=int)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
150 # default 2
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
151 parser.add_argument("--max-reseed", dest="max_reseed", type=int)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
152
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
153 """
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
154 The number of megabytes of memory a given thread is given to store path
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
155 descriptors in --best mode. Best-first search must keep track of many paths
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
156 at once to ensure it is always extending the path with the lowest cumulative
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
157 cost. Bowtie tries to minimize the memory impact of the descriptors, but
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
158 they can still grow very large in some cases. If you receive an error message
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
159 saying that chunk memory has been exhausted in --best mode, try adjusting
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
160 this parameter up to dedicate more memory to the descriptors. Default: 512.
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
161 """
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
162 parser.add_argument("--chunkmbs", type=int, default=512)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
163
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
164 args = parser.parse_args()
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
165
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
166 logger = logging.getLogger("bismark_wrapper")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
167 logger.setLevel(logging.DEBUG)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
168 ch = logging.StreamHandler(sys.stdout)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
169 if args.output_stdout:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
170 ch.setLevel(logging.WARNING)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
171 handler = logging.FileHandler(args.output_stdout)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
172 handler.setLevel(logging.DEBUG)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
173 logger.addHandler(handler)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
174 else:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
175 ch.setLevel(logging.DEBUG)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
176 logger.addHandler(ch)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
177
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
178 # Create bismark index if necessary.
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
179 index_dir = ""
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
180 tmp_index_dir = None
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
181 if args.own_file:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
182 logger.info(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
183 "Create a temporary index with the offered files from the user. "
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
184 "Utilizing the script: bismark_genome_preparation"
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
185 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
186 tmp_index_dir = tempfile.mkdtemp()
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
187 index_path = os.path.join(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
188 tmp_index_dir, ".".join(os.path.split(args.own_file)[1].split(".")[:-1])
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
189 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
190 try:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
191 # Create a hard link pointing to args.own_file named 'index_path'.fa.
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
192 os.symlink(args.own_file, index_path + ".fa")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
193 except Exception as e:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
194 if os.path.exists(tmp_index_dir):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
195 shutil.rmtree(tmp_index_dir)
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
196 stop_err(logger, "Error in linking the reference database!\n%s" % e)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
197 # bismark_genome_preparation needs the complete path to the folder in which the database is stored
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
198 cmd_index = ["bismark_genome_preparation", "--bowtie2", tmp_index_dir]
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
199 try:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
200 logger.info("Generating index with: '%s'", " ".join(cmd_index))
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
201 process = subprocess.Popen(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
202 cmd_index, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
203 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
204 with process.stdout:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
205 log_subprocess_output(logger, process.stdout)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
206 exitcode = process.wait()
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
207 if exitcode != 0:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
208 raise Exception(process.stderr)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
209 except Exception as e:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
210 if os.path.exists(tmp_index_dir):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
211 shutil.rmtree(tmp_index_dir)
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
212 stop_err(logger, "Error indexing reference sequence!\n%s" % e)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
213 index_dir = tmp_index_dir
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
214 else:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
215 # bowtie path is the path to the index directory and the first path of the index file name
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
216 index_dir = os.path.dirname(args.index_path)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
217
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
218 # Build bismark command
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
219 tmp_bismark_dir = tempfile.mkdtemp()
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
220 output_dir = os.path.join(tmp_bismark_dir, "results")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
221 cmd = [
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
222 "bismark",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
223 "--bam",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
224 "--temp_dir",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
225 tmp_bismark_dir,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
226 "-o",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
227 output_dir,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
228 "--quiet",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
229 ]
34
e5105f7e7b0d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit d85012b50faac3234496bb51e2a29c2d8c113bde"
bgruening
parents: 33
diff changeset
230 if not args.pbat:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
231 cmd.append("--gzip")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
232
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
233 if args.fasta:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
234 # the query input files (specified as mate1,mate2 or singles) are FastA
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
235 cmd.append("--fasta")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
236 elif args.fastq:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
237 cmd.append("--fastq")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
238
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
239 # alignment options
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
240 if args.num_threads > 2:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
241 # divide num_threads by 2 here since bismark will spawn 2 jobs with -p threads each
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
242 cmd.extend(["-p", str(int(math.floor(args.num_threads / 2)))])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
243 if args.seed_mismatches:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
244 cmd.extend(["-N", str(args.seed_mismatches)])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
245 if args.seed_len:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
246 cmd.extend(["-L", str(args.seed_len)])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
247 if args.seed_extention_attempts:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
248 cmd.extend(["-D", str(args.seed_extention_attempts)])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
249 if args.max_reseed:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
250 cmd.extend(["-R", str(args.max_reseed)])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
251 if args.no_discordant:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
252 cmd.append("--no-discordant")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
253 if args.no_mixed:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
254 cmd.append("--no-mixed")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
255 if args.skip_reads:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
256 cmd.extend(["--skip", str(args.skip_reads)])
33
f06523fe7828 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit ce4520063ab4d016dd5c5680c0f03eae849b150c"
bgruening
parents: 27
diff changeset
257 if args.score_min:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
258 cmd.extend(["--score_min", str(args.score_min)])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
259 if args.qupto:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
260 cmd.extend(["--upto", "args.qupto"])
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
261 if args.phred64:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
262 cmd.append("--phred64-quals")
27
b26a0df246fd planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 23685f742f0b5cd5de871c285d247d560485b11b
bgruening
parents: 25
diff changeset
263 if args.non_directional:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
264 cmd.append("--non_directional")
34
e5105f7e7b0d "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit d85012b50faac3234496bb51e2a29c2d8c113bde"
bgruening
parents: 33
diff changeset
265 if args.pbat:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
266 cmd.append("--pbat")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
267 if args.suppress_header:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
268 cmd.append("--sam-no-hd")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
269 if args.output_unmapped_reads or (
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
270 args.output_unmapped_reads_l and args.output_unmapped_reads_r
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
271 ):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
272 cmd.append("--un")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
273 if args.output_suppressed_reads or (
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
274 args.output_suppressed_reads_l and args.output_suppressed_reads_r
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
275 ):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
276 cmd.append("--ambiguous")
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
277
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
278 cmd.append(index_dir)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
279 # Set up the reads
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
280 if args.mate_paired:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
281 # paired-end reads library
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
282 cmd.extend(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
283 [
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
284 "-1",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
285 args.mate1,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
286 "-2",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
287 args.mate2,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
288 "-I",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
289 str(args.min_insert),
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
290 "-X",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
291 str(args.max_insert),
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
292 ]
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
293 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
294 else:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
295 # single paired reads library
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
296 cmd.append(args.single_paired)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
297
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
298 # Run
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
299 try:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
300 logger.info("Running bismark with: '%s'", " ".join(cmd))
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
301 process = subprocess.Popen(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
302 args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
303 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
304 with process.stdout:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
305 log_subprocess_output(logger, process.stdout)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
306 exitcode = process.wait()
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
307 if exitcode != 0:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
308 raise Exception(process.stderr)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
309 except Exception as e:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
310 stop_err(logger, "Error in running bismark!\n%s" % e)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
311
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
312 # collect and copy output files
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
313 if args.output_report_file:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
314 output_report_file = open(args.output_report_file, "w+")
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
315 for line in fileinput.input(glob(os.path.join(output_dir, "*report.txt"))):
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
316 output_report_file.write(line)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
317 output_report_file.close()
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
318
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
319 if args.output_suppressed_reads:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
320 if glob(os.path.join(output_dir, "*ambiguous_reads.*")):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
321 shutil.move(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
322 glob(os.path.join(output_dir, "*ambiguous_reads.*"))[0],
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
323 args.output_suppressed_reads,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
324 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
325 if args.output_suppressed_reads_l:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
326 if glob(os.path.join(output_dir, "*ambiguous_reads_1.*")):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
327 shutil.move(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
328 glob(os.path.join(output_dir, "*ambiguous_reads_1.*"))[0],
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
329 args.output_suppressed_reads_l,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
330 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
331 if args.output_suppressed_reads_r:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
332 if glob(os.path.join(output_dir, "*ambiguous_reads_2.*")):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
333 shutil.move(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
334 glob(os.path.join(output_dir, "*ambiguous_reads_2.*"))[0],
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
335 args.output_suppressed_reads_r,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
336 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
337
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
338 if args.output_unmapped_reads:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
339 if glob(os.path.join(output_dir, "*unmapped_reads.*")):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
340 shutil.move(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
341 glob(os.path.join(output_dir, "*unmapped_reads.*"))[0],
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
342 args.output_unmapped_reads,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
343 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
344 if args.output_unmapped_reads_l:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
345 if glob(os.path.join(output_dir, "*unmapped_reads_1.*")):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
346 shutil.move(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
347 glob(os.path.join(output_dir, "*unmapped_reads_1.*"))[0],
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
348 args.output_unmapped_reads_l,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
349 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
350 if args.output_unmapped_reads_r:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
351 if glob(os.path.join(output_dir, "*unmapped_reads_2.*")):
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
352 shutil.move(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
353 glob(os.path.join(output_dir, "*unmapped_reads_2.*"))[0],
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
354 args.output_unmapped_reads_r,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
355 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
356
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
357 try:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
358 # merge all bam files
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
359 tmp_res = tempfile.NamedTemporaryFile(dir=output_dir).name
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
360
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
361 bam_files = glob(os.path.join(output_dir, "*.bam"))
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
362 if len(bam_files) > 1:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
363 cmd = [
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
364 "samtools",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
365 "merge",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
366 "-@",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
367 str(args.num_threads),
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
368 "-f",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
369 tmp_res
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
370 ]
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
371 [cmd.append(x) for x in bam_files]
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
372 logger.info("Merging bams with: '%s'", cmd)
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
373 process = subprocess.Popen(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
374 args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
375 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
376 with process.stdout:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
377 log_subprocess_output(logger, process.stdout)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
378 exitcode = process.wait()
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
379 if exitcode != 0:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
380 raise Exception(process.stderr)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
381 else:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
382 tmp_res = bam_files[0]
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
383
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
384 bam_path = "%s" % tmp_res
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
385
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
386 if os.path.exists(bam_path):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
387 if args.sort_bam:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
388 cmd = [
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
389 "samtools",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
390 "sort",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
391 "-@",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
392 str(args.num_threads),
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
393 bam_path,
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
394 "sorted_bam",
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
395 ]
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
396 logger.info("Sorting bam with: '%s'", cmd)
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
397 process = subprocess.Popen(
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
398 args=cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
399 )
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
400 with process.stdout:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
401 log_subprocess_output(logger, process.stdout)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
402 exitcode = process.wait()
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
403 if exitcode != 0:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
404 raise Exception(process.stderr)
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
405 shutil.move("sorted_bam.bam", args.output)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
406 else:
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
407 shutil.move(bam_path, args.output)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
408 else:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
409 stop_err(logger, "BAM file no found:\n%s" % bam_path)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
410
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
411 except Exception as e:
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
412 stop_err(logger, "Error in merging bam files!\n%s" % e)
25
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
413
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
414 # Clean up temp dirs
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
415 if tmp_index_dir and os.path.exists(tmp_index_dir):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
416 shutil.rmtree(tmp_index_dir)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
417 if os.path.exists(tmp_bismark_dir):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
418 shutil.rmtree(tmp_bismark_dir)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
419 if os.path.exists(output_dir):
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
420 shutil.rmtree(output_dir)
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
421
a5faad9e4138 planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff changeset
422
38
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
423 if __name__ == "__main__":
b2d0e92f81c2 "planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 8fdc76a99a9dcf34549898a208317607afd18798"
bgruening
parents: 35
diff changeset
424 __main__()