ashs.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  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. # pylint: disable=too-few-public-methods
  12. class HippocampalSubfieldsVolumeFile:
  13. # https://sites.google.com/site/hipposubfields/tutorial#TOC-Viewing-ASHS-Segmentation-Results
  14. FILENAME_PATTERN = r'^(?P<s>\w+)_(?P<h>left|right)' \
  15. r'_(heur|corr_(?P<c>nogray|usegray))_volumes.txt$'
  16. FILENAME_REGEX = re.compile(FILENAME_PATTERN)
  17. def __init__(self, path: str):
  18. self._absolute_path = os.path.abspath(path)
  19. filename_match = self.FILENAME_REGEX.match(os.path.basename(path))
  20. assert filename_match, self._absolute_path
  21. filename_groups = filename_match.groupdict()
  22. self.subject = filename_groups['s']
  23. self.hemisphere = filename_groups['h']
  24. self.correction = filename_groups['c']
  25. @property
  26. def absolute_path(self):
  27. return self._absolute_path