__main__.py 797 B

123456789101112131415161718192021
  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(description=annotation_labels.__doc__.strip())
  11. argparser.add_argument('--delimiter', default='\t', help='default: %(default)r')
  12. argparser.add_argument('annotation_file_path')
  13. args = argparser.parse_args()
  14. annotation = Annotation.read(args.annotation_file_path)
  15. csv_writer = csv.writer(sys.stdout, delimiter=args.delimiter)
  16. csv_writer.writerow(('index', 'color', 'name'))
  17. labels = sorted(annotation.labels.values(), key=lambda l: l.index)
  18. csv_writer.writerows((l.index, l.hex_color_code, l.name,) for l in labels)