__main__.py 833 B

1234567891011121314151617181920212223
  1. import argparse
  2. import csv
  3. import sys
  4. from freesurfer_surface import Annotation
  5. def annotation_labels():
  6. """
  7. List Labels Stored in Freesurfer's Annotation File
  8. (i.e., label/lh.aparc.annot)
  9. """
  10. argparser = argparse.ArgumentParser(
  11. description=annotation_labels.__doc__.strip())
  12. argparser.add_argument('--delimiter', default='\t',
  13. help='default: %(default)r')
  14. argparser.add_argument('annotation_file_path')
  15. args = argparser.parse_args()
  16. annotation = Annotation.read(args.annotation_file_path)
  17. csv_writer = csv.writer(sys.stdout, delimiter=args.delimiter)
  18. csv_writer.writerow(('index', 'color', 'name'))
  19. labels = sorted(annotation.labels.values(), key=lambda l: l.index)
  20. csv_writer.writerows((l.index, l.hex_color_code, l.name,) for l in labels)