comparison bismark2report_wrapper.py @ 8:9bfe38410155 draft

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