cromwell_run_uows_tar.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import argparse
  2. import collections
  3. import glob
  4. import logging
  5. import os
  6. import sys
  7. import pypeflow.do_task
  8. from .. import io
  9. LOG = logging.getLogger()
  10. def dir_from_tar(tar_fn):
  11. # standard convention for tar-files
  12. return os.path.splitext(os.path.basename(tar_fn))[0]
  13. def run(tool, uows_tar_fn, nproc):
  14. cmd = 'tar --strip-components=1 -xvf {}'.format(uows_tar_fn)
  15. io.syscall(cmd)
  16. #uows_dn = dir_from_tar(uows_tar_fn)
  17. uows_dn = '.'
  18. uows = list(sorted(glob.glob('{}/uow-*'.format(uows_dn))))
  19. print(uows)
  20. las_fns = list()
  21. for uow in uows:
  22. with io.cd(uow):
  23. cmd = 'bash -vex uow.sh'
  24. io.syscall(cmd)
  25. #las_fns.extend(sorted(glob.glob('{}/*.las'.format(uow))))
  26. #cmd = 'LAmerge {} {}'.format(
  27. # result_fn, ' '.join(las_fns))
  28. #io.syscall(cmd)
  29. #io.rm(*las_fns)
  30. class HelpF(argparse.RawTextHelpFormatter, argparse.ArgumentDefaultsHelpFormatter):
  31. pass
  32. def parse_args(argv):
  33. description = 'Run a bash script once for each unit-of-work, in its own sub-dir. Handle results case-by-case, according to "tool".'
  34. epilog = '''For now, runs will be in series, since we do not know how many processors we can use.
  35. For tool=daligner, we merge .las files into a single .las
  36. '''
  37. parser = argparse.ArgumentParser(
  38. description=description,
  39. epilog=epilog,
  40. formatter_class=HelpF,
  41. )
  42. parser.add_argument(
  43. '--nproc',
  44. help='Number of processors to be used.')
  45. parser.add_argument(
  46. '--uows-tar-fn',
  47. help='Input. Tarfile of directories of unit-of-work.')
  48. parser.add_argument(
  49. '--tool', default='daligner', choices=['daligner', 'datander'],
  50. help='The tool for each unit of work. (Currently ignored.)')
  51. args = parser.parse_args(argv[1:])
  52. return args
  53. def main(argv=sys.argv):
  54. args = parse_args(argv)
  55. logging.basicConfig(level=logging.INFO)
  56. run(**vars(args))
  57. if __name__ == '__main__': # pragma: no cover
  58. main()