cromwell_write_json.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. """Given a FOFN, write JSON list.
  2. Cromwell write_json() does not work as we would expect.
  3. https://github.com/broadinstitute/cromwell/issues/4625
  4. So we use write_lines() instead.
  5. Then, this little program can convert those lines into JSON.
  6. """
  7. import argparse
  8. import logging
  9. import os
  10. import sys
  11. from .. import io
  12. LOG = logging.getLogger()
  13. def run(lines_fn, json_fn):
  14. with open(lines_fn) as sin:
  15. fns = [line.strip() for line in sin]
  16. io.serialize(json_fn, fns)
  17. class HelpF(argparse.RawTextHelpFormatter, argparse.ArgumentDefaultsHelpFormatter):
  18. pass
  19. def parse_args(argv):
  20. description = 'Symlink into current directory. This helps keep command-lines short later.'
  21. epilog = ''
  22. parser = argparse.ArgumentParser(
  23. description=description,
  24. epilog=epilog,
  25. formatter_class=HelpF,
  26. )
  27. parser.add_argument(
  28. '--lines-fn',
  29. help='Input. Result of WDL write_lines().')
  30. parser.add_argument(
  31. '--json-fn',
  32. help='Output. Should have been result of WDL write_json().')
  33. args = parser.parse_args(argv[1:])
  34. return args
  35. def main(argv=sys.argv):
  36. args = parse_args(argv)
  37. logging.basicConfig(level=logging.INFO)
  38. run(**vars(args))
  39. if __name__ == '__main__': # pragma: no cover
  40. main()