Mercurial > repos > dsobral > breseq
comparison breseq_wrapper.py @ 3:77c1ee3bad82 draft
Uploaded
| author | dsobral |
|---|---|
| date | Sat, 03 Mar 2018 11:44:15 -0500 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 2:2fd7f01d1909 | 3:77c1ee3bad82 |
|---|---|
| 1 # -*- coding: utf-8 -*- | |
| 2 | |
| 3 from __future__ import print_function | |
| 4 import sys | |
| 5 import os | |
| 6 import shutil | |
| 7 from subprocess import call | |
| 8 from glob import glob | |
| 9 | |
| 10 """ | |
| 11 Expected input format: | |
| 12 ./thiscript output_file output_folder zipfile (args) | |
| 13 """ | |
| 14 | |
| 15 | |
| 16 def fail(exitcode): | |
| 17 sys.stderr.write("Breseq did not finish successfully\n") | |
| 18 sys.stderr.write("Exit code was: {0}\n".format(exitcode)) | |
| 19 sys.exit(1) | |
| 20 | |
| 21 | |
| 22 def main(args): | |
| 23 output, outdir = args[1:3] | |
| 24 cmd = ["breseq"] + args[3:] | |
| 25 | |
| 26 returncode = call(cmd) | |
| 27 | |
| 28 if returncode != 0: | |
| 29 fail(returncode) | |
| 30 | |
| 31 # the short HTML report | |
| 32 summary = "output/summary.html" | |
| 33 if not os.path.isfile(summary): | |
| 34 fail(returncode) | |
| 35 | |
| 36 # Data will be in the zipfile together will all the content of "output" | |
| 37 shutil.move("data", "output/") | |
| 38 | |
| 39 if not os.path.isfile(outdir): | |
| 40 os.mkdir(outdir) | |
| 41 | |
| 42 # Zip the whole folder | |
| 43 shutil.make_archive("results", "zip", os.path.dirname(outdir), "output/") | |
| 44 shutil.move("results.zip", outdir) | |
| 45 | |
| 46 shutil.copy(summary, output) | |
| 47 | |
| 48 # move all the files needed for preview of HTML | |
| 49 for file in glob("output/*"): | |
| 50 dest = file.split("/", 1)[1] | |
| 51 # Folder "data" only needs to go in the zipfile not the HTML preview | |
| 52 if file == "data": | |
| 53 continue | |
| 54 | |
| 55 shutil.move(file, os.path.join(outdir, dest)) | |
| 56 | |
| 57 | |
| 58 def usage(): | |
| 59 err = sys.stderr | |
| 60 err.write("Usage:\n") | |
| 61 err.write(" {0} output_filename output_folder [args]\n".format( | |
| 62 sys.argv[0])) | |
| 63 sys.exit(1) | |
| 64 | |
| 65 if __name__ == "__main__": | |
| 66 args = sys.argv | |
| 67 | |
| 68 if len(args) <= 3: | |
| 69 usage() | |
| 70 | |
| 71 main(args) | |
| 72 | |
| 73 # vim: ai sts=4 et sw=4 |
