Mercurial > repos > bgruening > bismark
annotate bismark2report_wrapper.py @ 19:359f8b60d316 draft
"planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 36810f2b29fdaffc73c3f85c6ed2f91887b49e93"
author | bgruening |
---|---|
date | Fri, 04 Oct 2019 07:54:51 -0400 |
parents | 9bfe38410155 |
children | 120b7b35e442 |
rev | line source |
---|---|
8
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
1 #!/usr/bin/python |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
2 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
3 import argparse |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
4 import logging |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
5 import subprocess |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
6 import sys |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
7 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
8 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
9 def stop_err(logger, msg): |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
10 logger.critical(msg) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
11 sys.exit() |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
12 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
13 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
14 def log_subprocess_output(logger, pipe): |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
15 for line in iter(pipe.readline, b''): |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
16 logger.debug(line.decode().rstrip()) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
17 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
18 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
19 def get_arg(): |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
20 parser = argparse.ArgumentParser() |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
21 parser.add_argument('--alignment_report', dest='alignment_report', action='store', metavar='alignment_report', |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
22 type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
23 parser.add_argument('--dedup_report', dest='dedup_report', action='store', metavar='dedup_report', type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
24 parser.add_argument('--splitting_report', dest='splitting_report', action='store', metavar='splitting_report', |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
25 type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
26 parser.add_argument('--mbias_report', dest='mbias_report', action='store', metavar='mbias_report', type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
27 parser.add_argument('--nucleotide_report', dest='nucleotide_report', action='store', metavar='nucleotide_report', |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
28 type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
29 parser.add_argument('--output_html_report', dest='output_html_report', action='store', metavar='output_html_report', |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
30 type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
31 parser.add_argument('--log_report', dest='log_report', action='store', metavar='log_report', type=str) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
32 args = parser.parse_args() |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
33 return args |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
34 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
35 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
36 def __main__(): |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
37 args = get_arg() |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
38 logger = logging.getLogger('bismark_deduplicate_wrapper') |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
39 logger.setLevel(logging.DEBUG) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
40 ch = logging.StreamHandler(sys.stdout) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
41 if args.log_report: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
42 ch.setLevel(logging.WARNING) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
43 handler = logging.FileHandler(args.log_report) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
44 handler.setLevel(logging.DEBUG) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
45 logger.addHandler(handler) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
46 else: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
47 ch.setLevel(logging.DEBUG) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
48 logger.addHandler(ch) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
49 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
50 cmd = ['bismark2report', '--verbose', '--alignment_report', args.alignment_report, |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
51 '--output', args.output_html_report] |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
52 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
53 if args.dedup_report: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
54 cmd.extend(['--dedup_report', args.dedup_report]) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
55 if args.splitting_report: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
56 cmd.extend(['--splitting_report', args.splitting_report]) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
57 if args.mbias_report: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
58 cmd.extend(['--mbias_report', args.mbias_report]) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
59 if args.nucleotide_report: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
60 cmd.extend(['--nucleotide_report', args.nucleotide_report]) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
61 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
62 logger.info("Generating report with: '%s'", " ".join(cmd)) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
63 process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
64 with process.stdout: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
65 log_subprocess_output(logger, process.stdout) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
66 exitcode = process.wait() |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
67 if exitcode != 0: |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
68 stop_err(logger, "Bismark pretty report error (also check the log file if any)!\n%s" % process.stderr) |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
69 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
70 |
9bfe38410155
planemo upload for repository https://github.com/bgruening/galaxytools/tree/master/tools/bismark commit 51299fa62f0566a4a897b1c149db564631282fff
bgruening
parents:
diff
changeset
|
71 if __name__ == "__main__": __main__() |