ashs.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """
  2. Read hippocampal subfield volumes computed by ASHS
  3. https://sites.google.com/site/hipposubfields/home
  4. >>> from freesurfer_volume_reader.ashs import HippocampalSubfieldsVolumeFile
  5. >>>
  6. >>> volume_file = HippocampalSubfieldsVolumeFile('ashs/final/bert_right_corr_nogray_volumes.txt')
  7. >>> print(volume_file.subject, volume_file.hemisphere, volume_file.correction)
  8. """
  9. import os
  10. import re
  11. import freesurfer_volume_reader
  12. # pylint: disable=too-few-public-methods
  13. class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.VolumeFile):
  14. # https://sites.google.com/site/hipposubfields/tutorial#TOC-Viewing-ASHS-Segmentation-Results
  15. FILENAME_PATTERN = r'^(?P<s>\w+)_(?P<h>left|right)' \
  16. r'_(heur|corr_(?P<c>nogray|usegray))_volumes.txt$'
  17. FILENAME_REGEX = re.compile(FILENAME_PATTERN)
  18. def __init__(self, path: str):
  19. self._absolute_path = os.path.abspath(path)
  20. filename_match = self.FILENAME_REGEX.match(os.path.basename(path))
  21. assert filename_match, self._absolute_path
  22. filename_groups = filename_match.groupdict()
  23. self.subject = filename_groups['s']
  24. self.hemisphere = filename_groups['h']
  25. self.correction = filename_groups['c']
  26. @property
  27. def absolute_path(self):
  28. return self._absolute_path