Browse Source

Merge branch 'ashs' of github.com:fphammerle/freesurfer-volume-reader

https://github.com/fphammerle/freesurfer-volume-reader/pull/5
Fabian Peter Hammerle 5 years ago
parent
commit
7ca94fde34

+ 5 - 0
.pylintrc

@@ -1,3 +1,8 @@
 [MESSAGES CONTROL]
 
 disable=missing-docstring
+
+
+[SIMILARITIES]
+
+min-similarity-lines=8

+ 14 - 2
README.md

@@ -31,9 +31,21 @@ freesurfer-volume-reader /my/freesurfer/subjects /other/freesurfer/subjects
 or
 
 ```python
-from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
+from freesurfer_volume_reader import freesurfer
 
-for volume_file in HippocampalSubfieldsVolumeFile.find('/my/freesurfer/subjects'):
+for volume_file in freesurfer.HippocampalSubfieldsVolumeFile.find('/my/freesurfer/subjects'):
+    print(volume_file.subject, volume_file.hemisphere, volume_file.analysis_id)
+    print(volume_file.read_volumes_mm3())
+    print(volume_file.read_volumes_dataframe())
+```
+
+### ASHS
+
+```python
+from freesurfer_volume_reader import ashs
+
+for volume_file in ashs.HippocampalSubfieldsVolumeFile.find('/my/ashs/subjects'):
+    print(volume_file.subject, volume_file.hemisphere, volume_file.correction)
     print(volume_file.read_volumes_mm3())
     print(volume_file.read_volumes_dataframe())
 ```

+ 20 - 20
examples/barplot.py

@@ -4,26 +4,25 @@ from matplotlib import pyplot
 import pandas
 import seaborn
 
-from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
+from freesurfer_volume_reader import freesurfer
 
 
-def abbreviate_analysis_id(analysis_id):
-    return analysis_id.split('_')[0] if analysis_id else None
-
+def generate_freesurfer_mode_label(row):
+    mri_sequences = ['T1' if row['T1_input'] else None,
+                     row['analysis_id'].split('_')[0] if row['analysis_id'] else None]
+    return ' & '.join(filter(None, mri_sequences))
 
 def main():
     argparser = argparse.ArgumentParser()
     argparser.add_argument('--subject', required=True)
     argparser.add_argument('--subjects-dir', dest='subjects_dir_path', required=True)
     args = argparser.parse_args()
-    volume_frame = pandas.concat(f.read_volumes_dataframe() for f in
-                                 HippocampalSubfieldsVolumeFile.find(args.subjects_dir_path))
-    volume_frame = volume_frame[volume_frame['subject'] == args.subject]
+    volume_frame = pandas.concat(
+        f.read_volumes_dataframe() for f in
+        freesurfer.HippocampalSubfieldsVolumeFile.find(args.subjects_dir_path))
     volume_frame['subfield_segmentation_mode'] = volume_frame.apply(
-        lambda row: ' & '.join(filter(None, ('T1' if row['T1_input'] else None,
-                                             abbreviate_analysis_id(row['analysis_id'])))),
-        axis=1,
-    )
+        generate_freesurfer_mode_label, axis=1)
+    volume_frame = volume_frame[volume_frame['subject'] == args.subject]
     volume_frame.to_csv('hippocampal_subfield_volumes_{}.csv'.format(args.subject), index=False)
     volume_frame.drop(columns=['subject', 'T1_input', 'analysis_id'], inplace=True)
     print(volume_frame)
@@ -32,18 +31,19 @@ def main():
     volume_frame_subfields = volume_frame[volume_frame['subfield'] != 'Whole_hippocampus']
     for hemisphere in ['left', 'right']:
         pyplot.ylim(0, 750)
-        ax = seaborn.barplot(data=volume_frame_subfields[volume_frame_subfields['hemisphere'] == hemisphere],
-                             x='subfield', y='volume_mm^3',
-                             hue='subfield_segmentation_mode')
-        ax.set_title('Hippocampal Subfield Volumes of Subject {}'.format(args.subject)
-                     + '\n{} Hemisphere'.format(str.capitalize(hemisphere)))
+        plot_ax = seaborn.barplot(data=volume_frame_subfields[volume_frame_subfields['hemisphere']
+                                                              == hemisphere],
+                                  x='subfield', y='volume_mm^3',
+                                  hue='subfield_segmentation_mode')
+        plot_ax.set_title('Hippocampal Subfield Volumes of Subject {}'.format(args.subject)
+                          + '\n{} Hemisphere'.format(str.capitalize(hemisphere)))
         pyplot.savefig('hippocampal_subfield_volumes_{}_{}.png'.format(args.subject, hemisphere))
         pyplot.clf()
     seaborn.set(font_scale=0.4)
-    ax = seaborn.barplot(data=volume_frame[volume_frame['subfield'] == 'Whole_hippocampus'],
-                         x='hemisphere', y='volume_mm^3',
-                         hue='subfield_segmentation_mode')
-    ax.set_title('Hippocampal Volume of Subject {}'.format(args.subject))
+    plot_ax = seaborn.barplot(data=volume_frame[volume_frame['subfield'] == 'Whole_hippocampus'],
+                              x='hemisphere', y='volume_mm^3',
+                              hue='subfield_segmentation_mode')
+    plot_ax.set_title('Hippocampal Volume of Subject {}'.format(args.subject))
     pyplot.savefig('hippocampal_volume_{}.png'.format(args.subject))
 
 

+ 36 - 41
freesurfer_volume_reader/__init__.py

@@ -1,55 +1,50 @@
 """
-Read hippocampal subfield volumes computed by Freesurfer
+Read hippocampal subfield volumes computed by Freesurfer and/or ASHS
 
+https://sites.google.com/site/hipposubfields/home
 https://surfer.nmr.mgh.harvard.edu/fswiki/HippocampalSubfields
 
->>> from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
+>>> from freesurfer_volume_reader import ashs, freesurfer
 >>>
->>> for volume_file in HippocampalSubfieldsVolumeFile.find('/my/freesurfer/subjects'):
+>>> for volume_file in itertools.chain(
+>>>         ashs.HippocampalSubfieldsVolumeFile.find('/my/ashs/subjects'),
+>>>         freesurfer.HippocampalSubfieldsVolumeFile.find('/my/freesurfer/subjects')):
+>>>     print(volume_file.absolute_path)
+>>>     print(volume_file.subject, volume_file.hemisphere)
 >>>     print(volume_file.read_volumes_mm3())
 >>>     print(volume_file.read_volumes_dataframe())
 """
 
-import argparse
+import abc
 import os
-import re
 import typing
 
 import pandas
 
-from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
-
-
-def remove_group_names_from_regex(regex_pattern: str) -> str:
-    return re.sub(r'\?P<.+?>', '', regex_pattern)
-
-
-def main():
-    argparser = argparse.ArgumentParser(description=__doc__,
-                                        formatter_class=argparse.RawDescriptionHelpFormatter)
-    argparser.add_argument('--filename-regex', type=re.compile,
-                           default=remove_group_names_from_regex(
-                               HippocampalSubfieldsVolumeFile.FILENAME_PATTERN),
-                           help='default: %(default)s')
-    argparser.add_argument('--output-format', choices=['csv'], default='csv',
-                           help='default: %(default)s')
-    subjects_dir_path = os.environ.get('SUBJECTS_DIR', None)
-    argparser.add_argument('root_dir_paths',
-                           metavar='ROOT_DIR',
-                           nargs='*' if subjects_dir_path else '+',
-                           default=[subjects_dir_path],
-                           help='default: $SUBJECTS_DIR ({})'.format(subjects_dir_path))
-    args = argparser.parse_args()
-    volume_files = [f for d in args.root_dir_paths
-                    for f in HippocampalSubfieldsVolumeFile.find(
-                        root_dir_path=d, filename_regex=args.filename_regex)]
-    volume_frames = []
-    for volume_file in volume_files:
-        volume_frame = volume_file.read_volumes_dataframe()
-        volume_frame['source_path'] = volume_file.absolute_path
-        volume_frames.append(volume_frame)
-    united_volume_frame = pandas.concat(volume_frames, ignore_index=True)
-    print(united_volume_frame.to_csv(index=False))
-
-if __name__ == '__main__':
-    main()
+
+class VolumeFile(metaclass=abc.ABCMeta):
+
+    FILENAME_REGEX = NotImplemented
+
+    @property
+    @abc.abstractmethod
+    def absolute_path(self):
+        raise NotImplementedError()
+
+    @abc.abstractmethod
+    def read_volumes_mm3(self) -> typing.Dict[str, float]:
+        raise NotImplementedError()
+
+    @abc.abstractmethod
+    def read_volumes_dataframe(self) -> pandas.DataFrame:
+        raise NotImplementedError()
+
+    @classmethod
+    def find(cls, root_dir_path: str,
+             filename_regex: typing.Optional[typing.Pattern] = None,
+             ) -> typing.Iterator['VolumeFile']:
+        if not filename_regex:
+            filename_regex = cls.FILENAME_REGEX
+        for dirpath, _, filenames in os.walk(root_dir_path):
+            for filename in filter(filename_regex.search, filenames):
+                yield cls(path=os.path.join(dirpath, filename))

+ 47 - 0
freesurfer_volume_reader/__main__.py

@@ -0,0 +1,47 @@
+"""
+Read hippocampal subfield volumes computed by Freesurfer
+and export collected data as CSV.
+"""
+
+import argparse
+import os
+import re
+
+import pandas
+
+from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
+
+
+def remove_group_names_from_regex(regex_pattern: str) -> str:
+    return re.sub(r'\?P<.+?>', '', regex_pattern)
+
+
+def main():
+    argparser = argparse.ArgumentParser(description=__doc__,
+                                        formatter_class=argparse.RawDescriptionHelpFormatter)
+    argparser.add_argument('--filename-regex', type=re.compile,
+                           default=remove_group_names_from_regex(
+                               HippocampalSubfieldsVolumeFile.FILENAME_PATTERN),
+                           help='default: %(default)s')
+    argparser.add_argument('--output-format', choices=['csv'], default='csv',
+                           help='default: %(default)s')
+    subjects_dir_path = os.environ.get('SUBJECTS_DIR', None)
+    argparser.add_argument('root_dir_paths',
+                           metavar='ROOT_DIR',
+                           nargs='*' if subjects_dir_path else '+',
+                           default=[subjects_dir_path],
+                           help='default: $SUBJECTS_DIR ({})'.format(subjects_dir_path))
+    args = argparser.parse_args()
+    volume_files = [f for d in args.root_dir_paths
+                    for f in HippocampalSubfieldsVolumeFile.find(
+                        root_dir_path=d, filename_regex=args.filename_regex)]
+    volume_frames = []
+    for volume_file in volume_files:
+        volume_frame = volume_file.read_volumes_dataframe()
+        volume_frame['source_path'] = volume_file.absolute_path
+        volume_frames.append(volume_frame)
+    united_volume_frame = pandas.concat(volume_frames, ignore_index=True)
+    print(united_volume_frame.to_csv(index=False))
+
+if __name__ == '__main__':
+    main()

+ 65 - 0
freesurfer_volume_reader/ashs.py

@@ -0,0 +1,65 @@
+"""
+Read hippocampal subfield volumes computed by ASHS
+
+https://sites.google.com/site/hipposubfields/home
+
+>>> from freesurfer_volume_reader.ashs import HippocampalSubfieldsVolumeFile
+>>>
+>>> for volume_file in HippocampalSubfieldsVolumeFile('/my/ashs/subjects'):
+>>>     print(volume_file.subject, volume_file.hemisphere, volume_file.correction)
+>>>     print(volume_file.read_volumes_mm3())
+>>>     print(volume_file.read_volumes_dataframe())
+"""
+
+import os
+import re
+import typing
+
+import pandas
+
+import freesurfer_volume_reader
+
+
+class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.VolumeFile):
+
+    # https://sites.google.com/site/hipposubfields/tutorial#TOC-Viewing-ASHS-Segmentation-Results
+    FILENAME_PATTERN = r'^(?P<s>\w+)_(?P<h>left|right)' \
+                       r'_(heur|corr_(?P<c>nogray|usegray))_volumes.txt$'
+    FILENAME_REGEX = re.compile(FILENAME_PATTERN)
+
+    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
+        filename_groups = filename_match.groupdict()
+        self.subject = filename_groups['s']
+        self.hemisphere = filename_groups['h']
+        self.correction = filename_groups['c']
+
+    @property
+    def absolute_path(self):
+        return self._absolute_path
+
+    def read_volumes_mm3(self) -> typing.Dict[str, float]:
+        subfield_volumes = {}
+        with open(self.absolute_path, 'r') as volume_file:
+            for line in volume_file.read().rstrip().split('\n'):
+                # > echo $ASHS_SUBJID $side $SUB $NBODY $VSUB >> $FNBODYVOL
+                # https://github.com/pyushkevich/ashs/blob/515ff7c2f50928adabc4e64bded9a7e76fc750b1/bin/ashs_extractstats_qsub.sh#L94
+                subject, hemisphere, subfield_name, slices_number_str, volume_mm3_str \
+                    = line.split(' ')
+                assert self.subject == subject
+                assert self.hemisphere == hemisphere
+                assert int(slices_number_str) >= 0
+                subfield_volumes[subfield_name] = float(volume_mm3_str)
+        return subfield_volumes
+
+    def read_volumes_dataframe(self) -> pandas.DataFrame:
+        volumes_frame = pandas.DataFrame([
+            {'subfield': s, 'volume_mm^3': v}
+            for s, v in self.read_volumes_mm3().items()
+        ])
+        volumes_frame['subject'] = self.subject
+        volumes_frame['hemisphere'] = self.hemisphere
+        volumes_frame['correction'] = self.correction
+        return volumes_frame

+ 3 - 8
freesurfer_volume_reader/freesurfer.py

@@ -16,8 +16,10 @@ import typing
 
 import pandas
 
+import freesurfer_volume_reader
 
-class HippocampalSubfieldsVolumeFile:
+
+class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.VolumeFile):
 
     # https://surfer.nmr.mgh.harvard.edu/fswiki/HippocampalSubfields
     FILENAME_PATTERN = r'^(?P<h>[lr])h\.hippoSfVolumes' \
@@ -63,10 +65,3 @@ class HippocampalSubfieldsVolumeFile:
         volumes_frame['T1_input'] = self.t1_input
         volumes_frame['analysis_id'] = self.analysis_id
         return volumes_frame
-
-    @classmethod
-    def find(cls, root_dir_path: str,
-             filename_regex: typing.Pattern = FILENAME_REGEX) -> typing.Iterator[str]:
-        for dirpath, _, filenames in os.walk(root_dir_path):
-            for filename in filter(filename_regex.search, filenames):
-                yield cls(path=os.path.join(dirpath, filename))

+ 1 - 1
setup.py

@@ -36,7 +36,7 @@ setuptools.setup(
     packages=setuptools.find_packages(),
     entry_points={
         'console_scripts': [
-            'freesurfer-volume-reader = freesurfer_volume_reader:main',
+            'freesurfer-volume-reader = freesurfer_volume_reader.__main__:main',
         ],
     },
     install_requires=[

+ 132 - 0
tests/ashs_test.py

@@ -0,0 +1,132 @@
+import os
+import re
+
+import pandas
+import pytest
+
+from freesurfer_volume_reader.ashs import HippocampalSubfieldsVolumeFile
+
+from conftest import SUBJECTS_DIR, assert_volume_frames_equal
+
+
+@pytest.mark.parametrize(('volume_file_path', 'expected_attrs'), [
+    ('ashs/final/bert_left_heur_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'left', 'correction': None}),
+    ('ashs/final/bert_left_corr_nogray_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'left', 'correction': 'nogray'}),
+    ('ashs/final/bert_left_corr_usegray_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'left', 'correction': 'usegray'}),
+    ('ashs/final/bert_right_heur_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
+    ('ashs/final/bert_right_corr_nogray_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'right', 'correction': 'nogray'}),
+    ('ashs/final/bert_right_corr_usegray_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'right', 'correction': 'usegray'}),
+    ('somewhere/else/bert_right_heur_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
+    ('somewhere/else/bert_right_corr_nogray_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'right', 'correction': 'nogray'}),
+    ('bert_right_heur_volumes.txt',
+     {'subject': 'bert', 'hemisphere': 'right', 'correction': None}),
+    ('/foo/bar/alice_20190503_right_corr_nogray_volumes.txt',
+     {'subject': 'alice_20190503', 'hemisphere': 'right', 'correction': 'nogray'}),
+])
+def test_hippocampal_subfields_volume_file_init(volume_file_path, expected_attrs):
+    volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
+    assert os.path.abspath(volume_file_path) == volume_file.absolute_path
+    for attr, value in expected_attrs.items():
+        assert value == getattr(volume_file, attr)
+
+
+@pytest.mark.parametrize('volume_file_path', [
+    'bert_middle_heur_volumes.txt',
+    'bert_right_hear_volumes.txt',
+    'bert_right_heur_volumes.nii',
+    'bert_left_lfseg_corr_usegray.nii.gz',
+])
+def test_hippocampal_subfields_volume_file_init_invalid(volume_file_path):
+    with pytest.raises(Exception):
+        HippocampalSubfieldsVolumeFile(path=volume_file_path)
+
+
+@pytest.mark.parametrize(('volume_file_path', 'expected_volumes'), [
+    (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_nogray_volumes.txt'),
+     {'CA1': 678.901,
+      'CA2+3': 123.456,
+      'DG': 901.234,
+      'ERC': 678.901,
+      'PHC': 2345.876,
+      'PRC': 2345.678,
+      'SUB': 457.789}),
+])
+def test_hippocampal_subfields_volume_file_read_volumes_mm3(volume_file_path, expected_volumes):
+    volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
+    assert expected_volumes == volume_file.read_volumes_mm3()
+
+
+def test_hippocampal_subfields_volume_file_read_volumes_mm3_not_found():
+    volume_file = HippocampalSubfieldsVolumeFile(
+        path=os.path.join(SUBJECTS_DIR, 'nobert', 'final', 'bert_left_corr_nogray_volumes.txt'))
+    with pytest.raises(FileNotFoundError):
+        volume_file.read_volumes_mm3()
+
+
+@pytest.mark.parametrize(('volume_file_path', 'expected_dataframe'), [
+    (os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_left_heur_volumes.txt'),
+     pandas.DataFrame({
+         'subfield': ['CA1', 'CA2+3', 'DG', 'ERC', 'PHC', 'PRC', 'SUB'],
+         'volume_mm^3': [679.904, 124.459, 902.237, 789.012, 2346.879, 2346.671, 458.782],
+         'subject': 'alice',
+         'hemisphere': 'left',
+         'correction': None,
+     })),
+])
+def test_hippocampal_subfields_volume_file_read_volumes_dataframe(
+        volume_file_path: str, expected_dataframe: pandas.DataFrame):
+    volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
+    assert_volume_frames_equal(left=expected_dataframe,
+                               right=volume_file.read_volumes_dataframe())
+
+
+def test_hippocampal_subfields_volume_file_read_volumes_dataframe_not_found():
+    volume_file = HippocampalSubfieldsVolumeFile(
+        path=os.path.join(SUBJECTS_DIR, 'nobert', 'final', 'bert_left_corr_nogray_volumes.txt'))
+    with pytest.raises(FileNotFoundError):
+        volume_file.read_volumes_dataframe()
+
+
+@pytest.mark.parametrize(('root_dir_path', 'expected_file_paths'), [
+    (os.path.join(SUBJECTS_DIR, 'alice'),
+     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_left_heur_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_left_corr_nogray_volumes.txt')}),
+    (os.path.join(SUBJECTS_DIR, 'bert'),
+     {os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_nogray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_usegray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_right_corr_nogray_volumes.txt')}),
+    (SUBJECTS_DIR,
+     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_left_heur_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_left_corr_nogray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_nogray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_usegray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_right_corr_nogray_volumes.txt')}),
+])
+def test_hippocampal_subfields_volume_file_find(root_dir_path, expected_file_paths):
+    volume_files_iterator = HippocampalSubfieldsVolumeFile.find(root_dir_path=root_dir_path)
+    assert expected_file_paths == set(f.absolute_path for f in volume_files_iterator)
+
+
+@pytest.mark.parametrize(('root_dir_path', 'filename_pattern', 'expected_file_paths'), [
+    (SUBJECTS_DIR,
+     r'^bert_right_',
+     {os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_right_corr_nogray_volumes.txt')}),
+    (SUBJECTS_DIR,
+     r'_nogray_volumes.txt$',
+     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_left_corr_nogray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_left_corr_nogray_volumes.txt'),
+      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_right_corr_nogray_volumes.txt')}),
+])
+def test_hippocampal_subfields_volume_file_find_pattern(root_dir_path, filename_pattern,
+                                                        expected_file_paths):
+    volume_files_iterator = HippocampalSubfieldsVolumeFile.find(
+        root_dir_path=root_dir_path, filename_regex=re.compile(filename_pattern))
+    assert expected_file_paths == set(f.absolute_path for f in volume_files_iterator)

+ 2 - 1
tests/conftest.py

@@ -6,7 +6,8 @@ SUBJECTS_DIR = os.path.join(os.path.dirname(__file__), 'subjects')
 
 
 def assert_volume_frames_equal(left: pandas.DataFrame, right: pandas.DataFrame):
-    sort_by = ['volume_mm^3', 'analysis_id']
+    sort_by = list(filter(lambda n: n in left,
+                          ['volume_mm^3', 'analysis_id', 'correction']))
     left.sort_values(sort_by, inplace=True)
     right.sort_values(sort_by, inplace=True)
     left.reset_index(inplace=True, drop=True)

+ 3 - 4
tests/hippocampus_test.py → tests/main_test.py

@@ -7,8 +7,7 @@ import pandas
 import pandas.util.testing
 import pytest
 
-import freesurfer_volume_reader
-import freesurfer_volume_reader.freesurfer
+import freesurfer_volume_reader.__main__
 
 from conftest import SUBJECTS_DIR, assert_volume_frames_equal
 
@@ -18,7 +17,7 @@ from conftest import SUBJECTS_DIR, assert_volume_frames_equal
     (r'(?P<a>a(?P<b>b))', r'(a(b))'),
 ])
 def test_remove_group_names_from_regex(source_pattern, expected_pattern):
-    assert expected_pattern == freesurfer_volume_reader.remove_group_names_from_regex(
+    assert expected_pattern == freesurfer_volume_reader.__main__.remove_group_names_from_regex(
         regex_pattern=source_pattern,
     )
 
@@ -30,7 +29,7 @@ def assert_main_volume_frame_equals(capsys, argv: list, expected_frame: pandas.D
     elif 'SUBJECTS_DIR' in os.environ:
         del os.environ['SUBJECTS_DIR']
     with unittest.mock.patch('sys.argv', [''] + argv):
-        freesurfer_volume_reader.main()
+        freesurfer_volume_reader.__main__.main()
     out, _ = capsys.readouterr()
     assert_volume_frames_equal(
         left=expected_frame,

+ 7 - 0
tests/subjects/alice/final/alice_left_corr_nogray_volumes.txt

@@ -0,0 +1,7 @@
+alice left CA1 26 679.903
+alice left CA2+3 26 124.458
+alice left DG 25 902.236
+alice left ERC 18 679.903
+alice left PHC 16 2346.878
+alice left PRC 26 2346.670
+alice left SUB 26 458.781

+ 7 - 0
tests/subjects/alice/final/alice_left_heur_volumes.txt

@@ -0,0 +1,7 @@
+alice left CA1 26 679.904
+alice left CA2+3 26 124.459
+alice left DG 25 902.237
+alice left ERC 18 789.012
+alice left PHC 16 2346.879
+alice left PRC 26 2346.671
+alice left SUB 26 458.782

+ 7 - 0
tests/subjects/bert/final/bert_left_corr_nogray_volumes.txt

@@ -0,0 +1,7 @@
+bert left CA1 26 678.901
+bert left CA2+3 26 123.456
+bert left DG 25 901.234
+bert left ERC 18 678.901
+bert left PHC 16 2345.876
+bert left PRC 26 2345.678
+bert left SUB 26 457.789

+ 7 - 0
tests/subjects/bert/final/bert_left_corr_usegray_volumes.txt

@@ -0,0 +1,7 @@
+bert left CA1 26 678.902
+bert left CA2+3 26 123.457
+bert left DG 25 901.235
+bert left ERC 18 678.902
+bert left PHC 16 2345.877
+bert left PRC 26 2345.679
+bert left SUB 26 457.780

+ 7 - 0
tests/subjects/bert/final/bert_right_corr_nogray_volumes.txt

@@ -0,0 +1,7 @@
+bert right CA1 26 678.903
+bert right CA2+3 26 123.458
+bert right DG 25 901.236
+bert right ERC 18 678.903
+bert right PHC 16 2345.878
+bert right PRC 26 2345.670
+bert right SUB 26 457.781