Browse Source

added class ashs.IntracranialVolumeFile

Fabian Peter Hammerle 4 years ago
parent
commit
5bff373f3a
2 changed files with 28 additions and 1 deletions
  1. 15 0
      freesurfer_volume_reader/ashs.py
  2. 13 1
      tests/ashs_test.py

+ 15 - 0
freesurfer_volume_reader/ashs.py

@@ -20,6 +20,21 @@ import pandas
 import freesurfer_volume_reader
 
 
+class IntracranialVolumeFile(freesurfer_volume_reader.VolumeFile):
+
+    FILENAME_REGEX = re.compile(r'^(?P<s>\w+)_icv.txt$')
+
+    def __init__(self, path: str):
+        self._absolute_path = os.path.abspath(path)
+        filename_match = self.FILENAME_REGEX.match(os.path.basename(path))
+        assert filename_match, self._absolute_path
+        self.subject = filename_match.groupdict()['s']
+
+    @property
+    def absolute_path(self):
+        return self._absolute_path
+
+
 class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile):
 
     # https://sites.google.com/site/hipposubfields/tutorial#TOC-Viewing-ASHS-Segmentation-Results

+ 13 - 1
tests/ashs_test.py

@@ -4,11 +4,23 @@ import re
 import pandas
 import pytest
 
-from freesurfer_volume_reader.ashs import HippocampalSubfieldsVolumeFile
+from freesurfer_volume_reader.ashs import IntracranialVolumeFile, HippocampalSubfieldsVolumeFile
 
 from conftest import SUBJECTS_DIR, assert_volume_frames_equal
 
 
+@pytest.mark.parametrize(('volume_file_path', 'expected_subject'), [
+    ('bert_icv.txt', 'bert'),
+    ('final/bert_icv.txt', 'bert'),
+    ('ashs/subjects/bert/final/bert_icv.txt', 'bert'),
+    ('ashs/subjects/alice/final/long_subject_name_42_icv.txt', 'long_subject_name_42'),
+])
+def test_intracranial_volume_file_init(volume_file_path, expected_subject):
+    volume_file = IntracranialVolumeFile(path=volume_file_path)
+    assert os.path.abspath(volume_file_path) == volume_file.absolute_path
+    assert expected_subject == volume_file.subject
+
+
 @pytest.mark.parametrize(('volume_file_path', 'expected_attrs'), [
     ('ashs/final/bert_left_heur_volumes.txt',
      {'subject': 'bert', 'hemisphere': 'left', 'correction': None}),