Guest User

Untitled

a guest
Nov 14th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. from __future__ import print_function
  2. import csv
  3. from subprocess import call
  4. try:
  5. import pathlib
  6. except ImportError:
  7. import pathlib2 as pathlib
  8. import argparse
  9. import os
  10. from ashlar import reg, thumbnail
  11.  
  12. def text_to_bool(text):
  13. return False \
  14. if not str(text) \
  15. else str(text).lower() in '1,yes,y,true,t'
  16. def path_to_date(path):
  17. return os.path.getmtime(str(path))
  18.  
  19. parser = argparse.ArgumentParser(
  20. description='Read a csv config file and run ashlar'
  21. )
  22. parser.add_argument(
  23. 'csv_filepath', metavar='CSVFILE',
  24. help='a csv file with header row: Directory, Correction, Pyramid'
  25. )
  26. parser.add_argument(
  27. '-f', '--from-dir', dest='from_dir', default=0, type=int, metavar='FROM',
  28. help=('starting directory; numbering starts at 0')
  29. )
  30. parser.add_argument(
  31. '-t', '--to-dir', dest='to_dir', default=None, type=int, metavar='TO',
  32. help=('ending directory; numbering starts at 0')
  33. )
  34. args = parser.parse_args()
  35.  
  36. csv_path = pathlib.Path(args.csv_filepath)
  37. if not csv_path.is_file() or csv_path.suffix != '.csv':
  38. print('A csv file is required to proceed.')
  39. parser.print_usage()
  40. parser.exit()
  41.  
  42. with open(str(csv_path)) as exp_config:
  43. exp_config_reader = csv.DictReader(exp_config)
  44. exps = [dict(row) for row in exp_config_reader]
  45.  
  46.  
  47. for exp in exps[args.from_dir : args.to_dir]:
  48. path_exp = pathlib.Path(exp['Directory'])
  49. files_exp = sorted(path_exp.glob('*rcpnl'))
  50. files_exp.sort(key=path_to_date)
  51.  
  52. if len(files_exp) == 0:
  53. print('No rcpnl files found in', str(path_exp))
  54. continue
  55.  
  56. print('Processing files in', str(path_exp))
  57. rcpnl_files = [f for f in files_exp]
  58. print('\r ' + 'Generating thumbnail')
  59. for rcpnl_file in rcpnl_files:
  60. print('\r ' + rcpnl_file.name)
  61. thumbnail.thumbnail(reg.BioformatsReader(str(rcpnl_file)))
Add Comment
Please, Sign In to add comment