diff 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
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bismark2report_wrapper.py	Wed Aug 22 08:09:42 2018 -0400
@@ -0,0 +1,71 @@
+#!/usr/bin/python
+
+import argparse
+import logging
+import subprocess
+import sys
+
+
+def stop_err(logger, msg):
+    logger.critical(msg)
+    sys.exit()
+
+
+def log_subprocess_output(logger, pipe):
+    for line in iter(pipe.readline, b''):
+        logger.debug(line.decode().rstrip())
+
+
+def get_arg():
+    parser = argparse.ArgumentParser()
+    parser.add_argument('--alignment_report', dest='alignment_report', action='store', metavar='alignment_report',
+                        type=str)
+    parser.add_argument('--dedup_report', dest='dedup_report', action='store', metavar='dedup_report', type=str)
+    parser.add_argument('--splitting_report', dest='splitting_report', action='store', metavar='splitting_report',
+                        type=str)
+    parser.add_argument('--mbias_report', dest='mbias_report', action='store', metavar='mbias_report', type=str)
+    parser.add_argument('--nucleotide_report', dest='nucleotide_report', action='store', metavar='nucleotide_report',
+                        type=str)
+    parser.add_argument('--output_html_report', dest='output_html_report', action='store', metavar='output_html_report',
+                        type=str)
+    parser.add_argument('--log_report', dest='log_report', action='store', metavar='log_report', type=str)
+    args = parser.parse_args()
+    return args
+
+
+def __main__():
+    args = get_arg()
+    logger = logging.getLogger('bismark_deduplicate_wrapper')
+    logger.setLevel(logging.DEBUG)
+    ch = logging.StreamHandler(sys.stdout)
+    if args.log_report:
+        ch.setLevel(logging.WARNING)
+        handler = logging.FileHandler(args.log_report)
+        handler.setLevel(logging.DEBUG)
+        logger.addHandler(handler)
+    else:
+        ch.setLevel(logging.DEBUG)
+    logger.addHandler(ch)
+
+    cmd = ['bismark2report', '--verbose', '--alignment_report', args.alignment_report,
+           '--output', args.output_html_report]
+
+    if args.dedup_report:
+        cmd.extend(['--dedup_report', args.dedup_report])
+    if args.splitting_report:
+        cmd.extend(['--splitting_report', args.splitting_report])
+    if args.mbias_report:
+        cmd.extend(['--mbias_report', args.mbias_report])
+    if args.nucleotide_report:
+        cmd.extend(['--nucleotide_report', args.nucleotide_report])
+
+    logger.info("Generating report with: '%s'", " ".join(cmd))
+    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+    with process.stdout:
+        log_subprocess_output(logger, process.stdout)
+    exitcode = process.wait()
+    if exitcode != 0:
+        stop_err(logger, "Bismark pretty report error (also check the log file if any)!\n%s" % process.stderr)
+
+
+if __name__ == "__main__": __main__()