Browse Source

format code with black

Fabian Peter Hammerle 3 years ago
parent
commit
8a94f3b2e1

+ 1 - 0
.gitignore

@@ -1,5 +1,6 @@
 .coverage
 .ipynb_checkpoints/
+.mypy_cache/
 build/
 dist/
 tags

+ 3 - 1
.pylintrc

@@ -1,6 +1,8 @@
 [MESSAGES CONTROL]
 
-disable=missing-docstring
+disable=bad-continuation, # black
+        missing-class-docstring,
+        missing-function-docstring
 
 
 [SIMILARITIES]

+ 7 - 11
freesurfer_volume_reader/__init__.py

@@ -29,11 +29,11 @@ except ImportError:  # pragma: no cover
 
 
 def parse_version_string(version_string: str) -> typing.Tuple[typing.Union[int, str]]:
-    return tuple(int(p) if p.isdigit() else p for p in version_string.split('.'))
+    return tuple(int(p) if p.isdigit() else p for p in version_string.split("."))
 
 
 def remove_group_names_from_regex(regex_pattern: str) -> str:
-    return re.sub(r'\?P<.+?>', '', regex_pattern)
+    return re.sub(r"\?P<.+?>", "", regex_pattern)
 
 
 class VolumeFile(metaclass=abc.ABCMeta):
@@ -46,9 +46,9 @@ class VolumeFile(metaclass=abc.ABCMeta):
         raise NotImplementedError()
 
     @classmethod
-    def find(cls, root_dir_path: str,
-             filename_regex: typing.Optional[typing.Pattern] = None,
-             ) -> typing.Iterator['SubfieldVolumeFile']:
+    def find(
+        cls, root_dir_path: str, filename_regex: typing.Optional[typing.Pattern] = None
+    ) -> typing.Iterator["SubfieldVolumeFile"]:
         if not filename_regex:
             filename_regex = cls.FILENAME_REGEX
         for dirpath, _, filenames in os.walk(root_dir_path):
@@ -57,7 +57,6 @@ class VolumeFile(metaclass=abc.ABCMeta):
 
 
 class SubfieldVolumeFile(VolumeFile):
-
     @abc.abstractmethod
     def read_volumes_mm3(self) -> typing.Dict[str, float]:
         raise NotImplementedError()
@@ -70,9 +69,6 @@ class SubfieldVolumeFile(VolumeFile):
         subfield_volumes = self.read_volumes_mm3()
         return pandas.Series(
             data=list(subfield_volumes.values()),
-            name='volume_mm^3',
-            index=pandas.Index(
-                data=subfield_volumes.keys(),
-                name='subfield',
-            ),
+            name="volume_mm^3",
+            index=pandas.Index(data=subfield_volumes.keys(), name="subfield"),
         )

+ 58 - 32
freesurfer_volume_reader/__main__.py

@@ -11,11 +11,18 @@ import typing
 
 import pandas
 
-from freesurfer_volume_reader import __version__, ashs, freesurfer, parse_version_string, \
-                                     remove_group_names_from_regex
+from freesurfer_volume_reader import (
+    __version__,
+    ashs,
+    freesurfer,
+    parse_version_string,
+    remove_group_names_from_regex,
+)
 
-def concat_dataframes(dataframes: typing.Iterable[pandas.DataFrame]
-                      ) -> pandas.DataFrame:  # pragma: no cover
+
+def concat_dataframes(
+    dataframes: typing.Iterable[pandas.DataFrame]
+) -> pandas.DataFrame:  # pragma: no cover
     # pylint: disable=unexpected-keyword-arg
     if parse_version_string(pandas.__version__) < (0, 23):
         return pandas.concat(dataframes, ignore_index=True)
@@ -23,52 +30,71 @@ def concat_dataframes(dataframes: typing.Iterable[pandas.DataFrame]
 
 
 VOLUME_FILE_FINDERS = {
-    'ashs': ashs.HippocampalSubfieldsVolumeFile,
+    "ashs": ashs.HippocampalSubfieldsVolumeFile,
     # https://github.com/freesurfer/freesurfer/tree/release_6_0_0/HippoSF
-    'freesurfer-hipposf': freesurfer.HippocampalSubfieldsVolumeFile,
+    "freesurfer-hipposf": freesurfer.HippocampalSubfieldsVolumeFile,
 }
 
 
 def main():
-    argparser = argparse.ArgumentParser(description=__doc__,
-                                        formatter_class=argparse.RawDescriptionHelpFormatter)
-    argparser.add_argument('--source-types', nargs='+', default=['freesurfer-hipposf'],
-                           choices=VOLUME_FILE_FINDERS.keys(),
-                           help='default: [freesurfer-hipposf]')
+    argparser = argparse.ArgumentParser(
+        description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter
+    )
+    argparser.add_argument(
+        "--source-types",
+        nargs="+",
+        default=["freesurfer-hipposf"],
+        choices=VOLUME_FILE_FINDERS.keys(),
+        help="default: [freesurfer-hipposf]",
+    )
     for source_type, file_class in VOLUME_FILE_FINDERS.items():
-        argparser.add_argument('--{}-filename-regex'.format(source_type),
-                               dest='filename_regex.{}'.format(source_type),
-                               metavar='REGULAR_EXPRESSION', type=re.compile,
-                               default=remove_group_names_from_regex(file_class.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))
-    argparser.add_argument('--version', action='version', version=__version__)
+        argparser.add_argument(
+            "--{}-filename-regex".format(source_type),
+            dest="filename_regex.{}".format(source_type),
+            metavar="REGULAR_EXPRESSION",
+            type=re.compile,
+            default=remove_group_names_from_regex(file_class.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),
+    )
+    argparser.add_argument("--version", action="version", version=__version__)
     args = argparser.parse_args()
-    filename_regexs = {k[len('filename_regex.'):]: v for k, v in vars(args).items()
-                       if k.startswith('filename_regex.')}
+    filename_regexs = {
+        k[len("filename_regex.") :]: v
+        for k, v in vars(args).items()
+        if k.startswith("filename_regex.")
+    }
     volume_frames = []
     for source_type in args.source_types:
         find_volume_files = lambda dir_path: VOLUME_FILE_FINDERS[source_type].find(
-            root_dir_path=dir_path, filename_regex=filename_regexs[source_type])
+            root_dir_path=dir_path, filename_regex=filename_regexs[source_type]
+        )
         for root_dir_path in args.root_dir_paths:
             for volume_file in find_volume_files(root_dir_path):
                 volume_frame = volume_file.read_volumes_dataframe()
-                volume_frame['source_type'] = source_type
-                volume_frame['source_path'] = volume_file.absolute_path
+                volume_frame["source_type"] = source_type
+                volume_frame["source_path"] = volume_file.absolute_path
                 volume_frames.append(volume_frame)
     if not volume_frames:
-        print('Did not find any volume files matching the specified criteria.', file=sys.stderr)
+        print(
+            "Did not find any volume files matching the specified criteria.",
+            file=sys.stderr,
+        )
         return os.EX_NOINPUT
     united_volume_frame = concat_dataframes(volume_frames)
     print(united_volume_frame.to_csv(index=False))
     return os.EX_OK
 
-if __name__ == '__main__':
+
+if __name__ == "__main__":
     sys.exit(main())

+ 21 - 21
freesurfer_volume_reader/ashs.py

@@ -29,40 +29,39 @@ import freesurfer_volume_reader
 
 class IntracranialVolumeFile(freesurfer_volume_reader.VolumeFile):
 
-    FILENAME_REGEX = re.compile(r'^(?P<s>\w+)_icv.txt$')
+    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']
+        self.subject = filename_match.groupdict()["s"]
 
     @property
     def absolute_path(self):
         return self._absolute_path
 
     def read_volume_mm3(self) -> float:
-        with open(self.absolute_path, 'r') as volume_file:
-            subject, icv = volume_file.read().rstrip().split(' ')
+        with open(self.absolute_path, "r") as volume_file:
+            subject, icv = volume_file.read().rstrip().split(" ")
             assert subject == self.subject, (subject, self.subject)
             return float(icv)
 
     def read_volume_series(self) -> pandas.Series:
         return pandas.Series(
             data=[self.read_volume_mm3()],
-            name='intercranial_volume_mm^3',
-            index=pandas.Index(
-                data=[self.subject],
-                name='subject',
-            ),
+            name="intercranial_volume_mm^3",
+            index=pandas.Index(data=[self.subject], name="subject"),
         )
 
 
 class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile):
 
     # 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_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):
@@ -70,9 +69,9 @@ class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile
         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']
+        self.subject = filename_groups["s"]
+        self.hemisphere = filename_groups["h"]
+        self.correction = filename_groups["c"]
 
     @property
     def absolute_path(self):
@@ -80,12 +79,13 @@ class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile
 
     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'):
+        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(' ')
+                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
@@ -94,7 +94,7 @@ class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile
 
     def read_volumes_dataframe(self) -> pandas.DataFrame:
         volumes_frame = self._read_volume_series().reset_index()
-        volumes_frame['subject'] = self.subject
-        volumes_frame['hemisphere'] = self.hemisphere
-        volumes_frame['correction'] = self.correction
+        volumes_frame["subject"] = self.subject
+        volumes_frame["hemisphere"] = self.hemisphere
+        volumes_frame["correction"] = self.correction
         return volumes_frame

+ 18 - 14
freesurfer_volume_reader/freesurfer.py

@@ -23,11 +23,13 @@ import freesurfer_volume_reader
 class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile):
 
     # https://surfer.nmr.mgh.harvard.edu/fswiki/HippocampalSubfields
-    FILENAME_PATTERN = r'^(?P<h>[lr])h\.hippoSfVolumes' \
-                       r'(?P<T1>-T1)?(-(?P<analysis_id>.+?))?\.v10.txt$'
+    FILENAME_PATTERN = (
+        r"^(?P<h>[lr])h\.hippoSfVolumes"
+        r"(?P<T1>-T1)?(-(?P<analysis_id>.+?))?\.v10.txt$"
+    )
     FILENAME_REGEX = re.compile(FILENAME_PATTERN)
 
-    FILENAME_HEMISPHERE_PREFIX_MAP = {'l': 'left', 'r': 'right'}
+    FILENAME_HEMISPHERE_PREFIX_MAP = {"l": "left", "r": "right"}
 
     def __init__(self, path: str):
         self._absolute_path = os.path.abspath(path)
@@ -36,10 +38,12 @@ class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile
         filename_match = self.FILENAME_REGEX.match(os.path.basename(path))
         assert filename_match, self._absolute_path
         filename_groups = filename_match.groupdict()
-        assert filename_groups['T1'] or filename_groups['analysis_id'], self._absolute_path
-        self.hemisphere = self.FILENAME_HEMISPHERE_PREFIX_MAP[filename_groups['h']]
-        self.t1_input = filename_groups['T1'] is not None
-        self.analysis_id = filename_groups['analysis_id']
+        assert (
+            filename_groups["T1"] or filename_groups["analysis_id"]
+        ), self._absolute_path
+        self.hemisphere = self.FILENAME_HEMISPHERE_PREFIX_MAP[filename_groups["h"]]
+        self.t1_input = filename_groups["T1"] is not None
+        self.analysis_id = filename_groups["analysis_id"]
 
     @property
     def absolute_path(self):
@@ -47,19 +51,19 @@ class HippocampalSubfieldsVolumeFile(freesurfer_volume_reader.SubfieldVolumeFile
 
     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'):
+        with open(self.absolute_path, "r") as volume_file:
+            for line in volume_file.read().rstrip().split("\n"):
                 # https://github.com/freesurfer/freesurfer/blob/release_6_0_0/HippoSF/src/segmentSubjectT1T2_autoEstimateAlveusML.m#L8
                 # https://github.com/freesurfer/freesurfer/blob/release_6_0_0/HippoSF/src/segmentSubjectT1T2_autoEstimateAlveusML.m#L1946
-                subfield_name, subfield_volume_mm3_str = line.split(' ')
+                subfield_name, subfield_volume_mm3_str = line.split(" ")
                 subfield_volumes[subfield_name] = float(subfield_volume_mm3_str)
         return subfield_volumes
 
     def read_volumes_dataframe(self) -> pandas.DataFrame:
         volumes_frame = self._read_volume_series().reset_index()
-        volumes_frame['subject'] = self.subject
-        volumes_frame['hemisphere'] = self.hemisphere
+        volumes_frame["subject"] = self.subject
+        volumes_frame["hemisphere"] = self.hemisphere
         # volumes_frame['hemisphere'] = volumes_frame['hemisphere'].astype('category')
-        volumes_frame['T1_input'] = self.t1_input
-        volumes_frame['analysis_id'] = self.analysis_id
+        volumes_frame["T1_input"] = self.t1_input
+        volumes_frame["analysis_id"] = self.analysis_id
         return volumes_frame

+ 33 - 32
setup.py

@@ -3,48 +3,49 @@ import os
 import setuptools
 
 
-with open('README.rst', 'r') as readme:
+with open("README.rst", "r") as readme:
     LONG_DESCRIPTION = readme.read()
 
 setuptools.setup(
-    name='freesurfer-volume-reader',
+    name="freesurfer-volume-reader",
     use_scm_version={
-        'write_to': os.path.join('freesurfer_volume_reader', 'version.py'),
+        "write_to": os.path.join("freesurfer_volume_reader", "version.py"),
         # `version` triggers pylint C0103
-        'write_to_template': "__version__ = '{version}'\n",
+        "write_to_template": "# pylint: disable=missing-module-docstring\n"
+        + "__version__ = '{version}'\n",
     },
-    description='Python script & library to read hippocampal subfield volumes'
-        'computed by Freesurfer & ASHS',
+    description="Python script & library to read hippocampal subfield volumes"
+    "computed by Freesurfer & ASHS",
     long_description=LONG_DESCRIPTION,
-    author='Fabian Peter Hammerle',
-    author_email='fabian@hammerle.me',
-    url='https://github.com/fphammerle/freesurfer-volume-reader',
+    author="Fabian Peter Hammerle",
+    author_email="fabian@hammerle.me",
+    url="https://github.com/fphammerle/freesurfer-volume-reader",
     # TODO add license
     keywords=[
-        'brain',
-        'freesurfer',
-        'hippocampus',
-        'neuroimaging',
-        'reader',
-        'subfields',
+        "brain",
+        "freesurfer",
+        "hippocampus",
+        "neuroimaging",
+        "reader",
+        "subfields",
     ],
     classifiers=[
-        'Development Status :: 3 - Alpha',
-        'Intended Audience :: Healthcare Industry',
-        'Intended Audience :: Science/Research',
-        'Programming Language :: Python :: 3.5',
-        'Programming Language :: Python :: 3.6',
-        'Programming Language :: Python :: 3.7',
-        'Programming Language :: Python :: 3.8',
-        'Topic :: Scientific/Engineering :: Information Analysis',
-        'Topic :: Scientific/Engineering :: Medical Science Apps.',
-        'Topic :: Utilities',
+        "Development Status :: 3 - Alpha",
+        "Intended Audience :: Healthcare Industry",
+        "Intended Audience :: Science/Research",
+        "Programming Language :: Python :: 3.5",
+        "Programming Language :: Python :: 3.6",
+        "Programming Language :: Python :: 3.7",
+        "Programming Language :: Python :: 3.8",
+        "Topic :: Scientific/Engineering :: Information Analysis",
+        "Topic :: Scientific/Engineering :: Medical Science Apps.",
+        "Topic :: Utilities",
     ],
     packages=setuptools.find_packages(),
     entry_points={
-        'console_scripts': [
-            'freesurfer-volume-reader = freesurfer_volume_reader.__main__:main',
-        ],
+        "console_scripts": [
+            "freesurfer-volume-reader = freesurfer_volume_reader.__main__:main"
+        ]
     },
     install_requires=[
         # >=0.21.0 pandas.DataFrame.drop(columns=[...], ...)
@@ -52,9 +53,9 @@ setuptools.setup(
     ],
     setup_requires=["setuptools_scm"],
     tests_require=[
-        'pylint>=2.3.0,<3',
-        'pytest<5',
-        'pytest-cov<3,>=2',
-        'pytest-timeout<2',
+        "pylint>=2.3.0,<3",
+        "pytest<5",
+        "pytest-cov<3,>=2",
+        "pytest-timeout<2",
     ],
 )

+ 347 - 175
tests/ashs_test.py

@@ -1,73 +1,96 @@
+# pylint: disable=missing-module-docstring
+
 import os
 import re
 
 import pandas
 import pytest
 
-from freesurfer_volume_reader.ashs import IntracranialVolumeFile, 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'),
-])
+@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', [
-    '_icv.txt',
-    'bert_ICV.txt',
-    'bert_icv.csv',
-    'bert_ICV.txt.zip',
-])
+@pytest.mark.parametrize(
+    "volume_file_path", ["_icv.txt", "bert_ICV.txt", "bert_icv.csv", "bert_ICV.txt.zip"]
+)
 def test_intracranial_volume_file_init_invalid_filename(volume_file_path):
     with pytest.raises(Exception):
         IntracranialVolumeFile(path=volume_file_path)
 
 
-@pytest.mark.parametrize(('volume_file_path', 'expected_volume'), [
-    (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'), 1234560),
-    (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'), 1.23456e06),
-    (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'), 1.23456e+06),
-    (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'), float('1.23456e+06')),
-    (os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt'), 1543200),
-])
+@pytest.mark.parametrize(
+    ("volume_file_path", "expected_volume"),
+    [
+        (os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"), 1234560),
+        (os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"), 1.23456e06),
+        (os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"), 1.23456e06),
+        (
+            os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"),
+            float("1.23456e+06"),
+        ),
+        (os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt"), 1543200),
+    ],
+)
 def test_intracranial_volume_file_read_volume_mm3(volume_file_path, expected_volume):
     volume_file = IntracranialVolumeFile(path=volume_file_path)
     assert expected_volume == pytest.approx(volume_file.read_volume_mm3())
 
 
-@pytest.mark.parametrize('volume_file_path', [
-    os.path.join(SUBJECTS_DIR, 'noone', 'final', 'noone_icv.txt'),
-])
+@pytest.mark.parametrize(
+    "volume_file_path", [os.path.join(SUBJECTS_DIR, "noone", "final", "noone_icv.txt")]
+)
 def test_intracranial_volume_file_read_volume_mm3_not_found(volume_file_path):
     volume_file = IntracranialVolumeFile(path=volume_file_path)
     with pytest.raises(FileNotFoundError):
         volume_file.read_volume_mm3()
 
 
-@pytest.mark.parametrize(('volume_file_path', 'expected_series'), [
-    (os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'),
-     pandas.Series(
-         data=[1234560.0],
-         name='intercranial_volume_mm^3',
-         index=pandas.Index(data=['bert'], name='subject'),
-     )),
-    (os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt'),
-     pandas.Series(
-         data=[1543200.0],
-         name='intercranial_volume_mm^3',
-         index=pandas.Index(data=['alice'], name='subject'),
-     )),
-])
-def test_intracranial_volume_file_read_volume_series_single(volume_file_path, expected_series):
+@pytest.mark.parametrize(
+    ("volume_file_path", "expected_series"),
+    [
+        (
+            os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"),
+            pandas.Series(
+                data=[1234560.0],
+                name="intercranial_volume_mm^3",
+                index=pandas.Index(data=["bert"], name="subject"),
+            ),
+        ),
+        (
+            os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt"),
+            pandas.Series(
+                data=[1543200.0],
+                name="intercranial_volume_mm^3",
+                index=pandas.Index(data=["alice"], name="subject"),
+            ),
+        ),
+    ],
+)
+def test_intracranial_volume_file_read_volume_series_single(
+    volume_file_path, expected_series
+):
     volume_file = IntracranialVolumeFile(path=volume_file_path)
     pandas.testing.assert_series_equal(
         left=expected_series,
@@ -77,94 +100,144 @@ def test_intracranial_volume_file_read_volume_series_single(volume_file_path, ex
     )
 
 
-@pytest.mark.parametrize(('volume_file_paths', 'expected_series'), [
-    ([os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt'),
-      os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt')],
-     pandas.Series(
-         data=[1234560.0, 1543200.0],
-         name='intercranial_volume_mm^3',
-         index=pandas.Index(data=['bert', 'alice'], name='subject'),
-     )),
-])
-def test_intracranial_volume_file_read_volume_series_concat(volume_file_paths, expected_series):
+@pytest.mark.parametrize(
+    ("volume_file_paths", "expected_series"),
+    [
+        (
+            [
+                os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"),
+                os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt"),
+            ],
+            pandas.Series(
+                data=[1234560.0, 1543200.0],
+                name="intercranial_volume_mm^3",
+                index=pandas.Index(data=["bert", "alice"], name="subject"),
+            ),
+        )
+    ],
+)
+def test_intracranial_volume_file_read_volume_series_concat(
+    volume_file_paths, expected_series
+):
     volume_series = pandas.concat(
-        IntracranialVolumeFile(path=p).read_volume_series()
-        for p in volume_file_paths)
+        IntracranialVolumeFile(path=p).read_volume_series() for p in volume_file_paths
+    )
     pandas.testing.assert_series_equal(
-        left=expected_series,
-        right=volume_series,
-        check_dtype=True,
-        check_names=True,
+        left=expected_series, right=volume_series, check_dtype=True, check_names=True
     )
 
 
-@pytest.mark.parametrize('volume_file_path', [
-    os.path.join(SUBJECTS_DIR, 'bert', 'final', 'BERT_icv.txt'),
-])
+@pytest.mark.parametrize(
+    "volume_file_path", [os.path.join(SUBJECTS_DIR, "bert", "final", "BERT_icv.txt")]
+)
 def test_intracranial_volume_file_read_volume_series_not_found(volume_file_path):
     volume_file = IntracranialVolumeFile(path=volume_file_path)
     with pytest.raises(FileNotFoundError):
         volume_file.read_volume_series()
 
 
-@pytest.mark.parametrize(('root_dir_path', 'expected_file_paths'), [
-    (os.path.join(SUBJECTS_DIR, 'bert'),
-     {os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt')}),
-    (os.path.join(SUBJECTS_DIR, 'alice'),
-     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt')}),
-    (SUBJECTS_DIR,
-     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt')}),
-])
+@pytest.mark.parametrize(
+    ("root_dir_path", "expected_file_paths"),
+    [
+        (
+            os.path.join(SUBJECTS_DIR, "bert"),
+            {os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt")},
+        ),
+        (
+            os.path.join(SUBJECTS_DIR, "alice"),
+            {os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt")},
+        ),
+        (
+            SUBJECTS_DIR,
+            {
+                os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt"),
+                os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"),
+            },
+        ),
+    ],
+)
 def test_intracranial_volume_file_find(root_dir_path, expected_file_paths):
-    volume_files_iterator = IntracranialVolumeFile.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'^\w{4,6}_icv.txt$',
-     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_icv.txt')}),
-    (SUBJECTS_DIR,
-     r'^\w{5,6}_icv.txt$',
-     {os.path.join(SUBJECTS_DIR, 'alice', 'final', 'alice_icv.txt')}),
-    (SUBJECTS_DIR,
-     r'^\w{7,}_icv.txt$',
-     set()),
-])
+    volume_files_iterator = IntracranialVolumeFile.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"^\w{4,6}_icv.txt$",
+            {
+                os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt"),
+                os.path.join(SUBJECTS_DIR, "bert", "final", "bert_icv.txt"),
+            },
+        ),
+        (
+            SUBJECTS_DIR,
+            r"^\w{5,6}_icv.txt$",
+            {os.path.join(SUBJECTS_DIR, "alice", "final", "alice_icv.txt")},
+        ),
+        (SUBJECTS_DIR, r"^\w{7,}_icv.txt$", set()),
+    ],
+)
 def test_intracranial_volume_file_find_pattern(
-        root_dir_path, filename_pattern, expected_file_paths):
+    root_dir_path, filename_pattern, expected_file_paths
+):
     volume_files_iterator = IntracranialVolumeFile.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)
-
-
-@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'}),
-])
+        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)
+
+
+@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
@@ -172,97 +245,196 @@ def test_hippocampal_subfields_volume_file_init(volume_file_path, expected_attrs
         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',
-])
+@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': 789.012,
-      'PHC': 2345.876,
-      'PRC': 2345.678,
-      'SUB': 457.789}),
-])
-def test_hippocampal_subfields_volume_file_read_volumes_mm3(volume_file_path, expected_volumes):
+@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": 789.012,
+                "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'))
+        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,
-     })),
-])
+@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_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())
+    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'))
+        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_left_heur_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_left_heur_volumes.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'final', 'bert_right_corr_nogray_volumes.txt')}),
-])
+@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_left_heur_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_left_heur_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)
+    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):
+@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))
+        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)

+ 8 - 3
tests/conftest.py

@@ -1,13 +1,18 @@
+# pylint: disable=missing-module-docstring
+
 import os
 
 import pandas
 
-SUBJECTS_DIR = os.path.join(os.path.dirname(__file__), 'subjects')
+SUBJECTS_DIR = os.path.join(os.path.dirname(__file__), "subjects")
 
 
 def assert_volume_frames_equal(left: pandas.DataFrame, right: pandas.DataFrame):
-    sort_by = list(filter(lambda n: n in left,
-                          ['subject', 'volume_mm^3', 'analysis_id', 'correction']))
+    sort_by = list(
+        filter(
+            lambda n: n in left, ["subject", "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)

+ 277 - 95
tests/freesurfer_test.py

@@ -1,3 +1,5 @@
+# pylint: disable=missing-module-docstring
+
 import os
 import re
 
@@ -9,132 +11,312 @@ from freesurfer_volume_reader.freesurfer import HippocampalSubfieldsVolumeFile
 from conftest import SUBJECTS_DIR, assert_volume_frames_equal
 
 
-@pytest.mark.parametrize(('volume_file_path', 'expected_attrs'), [
-    ('bert/mri/lh.hippoSfVolumes-T1.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': True, 'analysis_id': None}),
-    ('bert/mri/lh.hippoSfVolumes-T1-T2.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': True, 'analysis_id': 'T2'}),
-    ('bert/mri/lh.hippoSfVolumes-T2.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': False, 'analysis_id': 'T2'}),
-    ('bert/mri/lh.hippoSfVolumes-T1-T2-high-res.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': True, 'analysis_id': 'T2-high-res'}),
-    ('bert/mri/lh.hippoSfVolumes-T2-high-res.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': False, 'analysis_id': 'T2-high-res'}),
-    ('bert/mri/lh.hippoSfVolumes-PD.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': False, 'analysis_id': 'PD'}),
-    ('bert/mri/rh.hippoSfVolumes-T1.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'right', 't1_input': True, 'analysis_id': None}),
-    ('bert/mri/rh.hippoSfVolumes-T1-T2.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'right', 't1_input': True, 'analysis_id': 'T2'}),
-    ('freesurfer/subjects/bert/mri/lh.hippoSfVolumes-T1.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': True, 'analysis_id': None}),
-    ('../../bert/mri/lh.hippoSfVolumes-T1.v10.txt',
-     {'subject': 'bert', 'hemisphere': 'left', 't1_input': True, 'analysis_id': None}),
-])
+@pytest.mark.parametrize(
+    ("volume_file_path", "expected_attrs"),
+    [
+        (
+            "bert/mri/lh.hippoSfVolumes-T1.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": True,
+                "analysis_id": None,
+            },
+        ),
+        (
+            "bert/mri/lh.hippoSfVolumes-T1-T2.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": True,
+                "analysis_id": "T2",
+            },
+        ),
+        (
+            "bert/mri/lh.hippoSfVolumes-T2.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": False,
+                "analysis_id": "T2",
+            },
+        ),
+        (
+            "bert/mri/lh.hippoSfVolumes-T1-T2-high-res.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": True,
+                "analysis_id": "T2-high-res",
+            },
+        ),
+        (
+            "bert/mri/lh.hippoSfVolumes-T2-high-res.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": False,
+                "analysis_id": "T2-high-res",
+            },
+        ),
+        (
+            "bert/mri/lh.hippoSfVolumes-PD.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": False,
+                "analysis_id": "PD",
+            },
+        ),
+        (
+            "bert/mri/rh.hippoSfVolumes-T1.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "right",
+                "t1_input": True,
+                "analysis_id": None,
+            },
+        ),
+        (
+            "bert/mri/rh.hippoSfVolumes-T1-T2.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "right",
+                "t1_input": True,
+                "analysis_id": "T2",
+            },
+        ),
+        (
+            "freesurfer/subjects/bert/mri/lh.hippoSfVolumes-T1.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": True,
+                "analysis_id": None,
+            },
+        ),
+        (
+            "../../bert/mri/lh.hippoSfVolumes-T1.v10.txt",
+            {
+                "subject": "bert",
+                "hemisphere": "left",
+                "t1_input": True,
+                "analysis_id": None,
+            },
+        ),
+    ],
+)
 def test_hippocampal_subfields_volume_file_init(volume_file_path, expected_attrs):
     volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
-    assert os.path.basename(volume_file_path) == os.path.basename(volume_file.absolute_path)
+    assert os.path.basename(volume_file_path) == os.path.basename(
+        volume_file.absolute_path
+    )
     for attr, value in expected_attrs.items():
         assert value == getattr(volume_file, attr)
 
 
-@pytest.mark.parametrize('volume_file_path', [
-    'bert/mri/lh.hippoSfLabels-T1.v10.mgz',
-    'bert/mri/lh.hippoSfVolumes-T1.v9.txt',
-    'bert/mri/lh.hippoSfVolumes.v10.txt',
-    'bert/mri/mh.hippoSfVolumes-T1.v10.txt',
-])
-def test_hippocampal_subfields_volume_file_init_invalid(volume_file_path):
+@pytest.mark.parametrize(
+    "volume_file_path",
+    [
+        "bert/mri/lh.hippoSfLabels-T1.v10.mgz",
+        "bert/mri/lh.hippoSfVolumes-T1.v9.txt",
+        "bert/mri/lh.hippoSfVolumes.v10.txt",
+        "bert/mri/mh.hippoSfVolumes-T1.v10.txt",
+        "bert_left_corr_nogray_volumes.txt",
+    ],
+)
+def test_hippocampal_subfields_volume_file_init_invalid_path(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/mri/lh.hippoSfVolumes-T1.v10.txt'),
-     {'Hippocampal_tail': 123.456789,
-      'subiculum': 234.567891,
-      'CA1': 34.567891,
-      'hippocampal-fissure': 345.678912,
-      'presubiculum': 456.789123,
-      'parasubiculum': 45.678912,
-      'molecular_layer_HP': 56.789123,
-      'GC-ML-DG': 567.891234,
-      'CA3': 678.912345,
-      'CA4': 789.123456,
-      'fimbria': 89.123456,
-      'HATA': 91.234567,
-      'Whole_hippocampus': 1234.567899}),
-])
-def test_hippocampal_subfields_volume_file_read_volumes_mm3(volume_file_path, expected_volumes):
+@pytest.mark.parametrize(
+    ("volume_file_path", "expected_volumes"),
+    [
+        (
+            os.path.join(SUBJECTS_DIR, "bert/mri/lh.hippoSfVolumes-T1.v10.txt"),
+            {
+                "Hippocampal_tail": 123.456789,
+                "subiculum": 234.567891,
+                "CA1": 34.567891,
+                "hippocampal-fissure": 345.678912,
+                "presubiculum": 456.789123,
+                "parasubiculum": 45.678912,
+                "molecular_layer_HP": 56.789123,
+                "GC-ML-DG": 567.891234,
+                "CA3": 678.912345,
+                "CA4": 789.123456,
+                "fimbria": 89.123456,
+                "HATA": 91.234567,
+                "Whole_hippocampus": 1234.567899,
+            },
+        )
+    ],
+)
+def test_hippocampal_subfields_volume_file_read_volumes_mm3(
+    volume_file_path, expected_volumes
+):
     volume_file = HippocampalSubfieldsVolumeFile(path=volume_file_path)
+    assert volume_file.t1_input
     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, 'non-existing', 'lh.hippoSfVolumes-T1.v10.txt'))
+        path=os.path.join(SUBJECTS_DIR, "non-existing", "lh.hippoSfVolumes-T1.v10.txt")
+    )
     with pytest.raises(FileNotFoundError):
         volume_file.read_volumes_mm3()
 
 
-@pytest.mark.parametrize(('volume_file_path', 'expected_dataframe'), [
-    (os.path.join(SUBJECTS_DIR, 'alice', 'mri', 'lh.hippoSfVolumes-T1.v10.txt'),
-     pandas.DataFrame({
-         'subfield': ['Hippocampal_tail', 'subiculum', 'CA1', 'hippocampal-fissure',
-                      'presubiculum', 'parasubiculum', 'molecular_layer_HP', 'GC-ML-DG',
-                      'CA3', 'CA4', 'fimbria', 'HATA', 'Whole_hippocampus'],
-         'volume_mm^3': [173.456789, 734.567891, 34.567891, 345.678917, 456.789173, 45.678917,
-                         56.789173, 567.891734, 678.917345, 789.173456, 89.173456, 91.734567,
-                         1734.567899],
-         'subject': 'alice',
-         'hemisphere': 'left',
-         'T1_input': True,
-         'analysis_id': None,
-     })),
-])
+@pytest.mark.parametrize(
+    ("volume_file_path", "expected_dataframe"),
+    [
+        (
+            os.path.join(SUBJECTS_DIR, "alice", "mri", "lh.hippoSfVolumes-T1.v10.txt"),
+            pandas.DataFrame(
+                {
+                    "subfield": [
+                        "Hippocampal_tail",
+                        "subiculum",
+                        "CA1",
+                        "hippocampal-fissure",
+                        "presubiculum",
+                        "parasubiculum",
+                        "molecular_layer_HP",
+                        "GC-ML-DG",
+                        "CA3",
+                        "CA4",
+                        "fimbria",
+                        "HATA",
+                        "Whole_hippocampus",
+                    ],
+                    "volume_mm^3": [
+                        173.456789,
+                        734.567891,
+                        34.567891,
+                        345.678917,
+                        456.789173,
+                        45.678917,
+                        56.789173,
+                        567.891734,
+                        678.917345,
+                        789.173456,
+                        89.173456,
+                        91.734567,
+                        1734.567899,
+                    ],
+                    "subject": "alice",
+                    "hemisphere": "left",
+                    "T1_input": True,
+                    "analysis_id": None,
+                }
+            ),
+        )
+    ],
+)
 def test_hippocampal_subfields_volume_file_read_volumes_dataframe(
-        volume_file_path: str, expected_dataframe: pandas.DataFrame):
+    volume_file_path: str, expected_dataframe: pandas.DataFrame
+):
     assert_volume_frames_equal(
         left=expected_dataframe,
-        right=HippocampalSubfieldsVolumeFile(path=volume_file_path).read_volumes_dataframe(),
+        right=HippocampalSubfieldsVolumeFile(
+            path=volume_file_path
+        ).read_volumes_dataframe(),
     )
 
 
 def test_hippocampal_subfields_volume_file_read_volumes_dataframe_not_found():
     volume_file = HippocampalSubfieldsVolumeFile(
-        path=os.path.join(SUBJECTS_DIR, 'non-existing', 'lh.hippoSfVolumes-T1.v10.txt'))
+        path=os.path.join(SUBJECTS_DIR, "non-existing", "lh.hippoSfVolumes-T1.v10.txt")
+    )
     with pytest.raises(FileNotFoundError):
         volume_file.read_volumes_dataframe()
 
 
-@pytest.mark.parametrize(('root_dir_path', 'expected_file_paths'), [
-    (SUBJECTS_DIR,
-     {os.path.join(SUBJECTS_DIR, 'alice', 'mri', 'lh.hippoSfVolumes-T1.v10.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
-    (os.path.join(SUBJECTS_DIR, 'bert'),
-     {os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
-    (os.path.join(SUBJECTS_DIR, 'bert', 'mri'),
-     {os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
-])
+@pytest.mark.parametrize(
+    ("root_dir_path", "expected_file_paths"),
+    [
+        (
+            SUBJECTS_DIR,
+            {
+                os.path.join(
+                    SUBJECTS_DIR, "alice", "mri", "lh.hippoSfVolumes-T1.v10.txt"
+                ),
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1-T2.v10.txt"
+                ),
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1.v10.txt"
+                ),
+            },
+        ),
+        (
+            os.path.join(SUBJECTS_DIR, "bert"),
+            {
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1-T2.v10.txt"
+                ),
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1.v10.txt"
+                ),
+            },
+        ),
+        (
+            os.path.join(SUBJECTS_DIR, "bert", "mri"),
+            {
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1-T2.v10.txt"
+                ),
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1.v10.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'hippoSfVolumes-T1\.v10',
-     {os.path.join(SUBJECTS_DIR, 'alice', 'mri', 'lh.hippoSfVolumes-T1.v10.txt'),
-      os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1.v10.txt')}),
-    (os.path.join(SUBJECTS_DIR, 'bert'),
-     r'hippoSfVolumes-T1-T2',
-     {os.path.join(SUBJECTS_DIR, 'bert', 'mri', 'lh.hippoSfVolumes-T1-T2.v10.txt')}),
-])
-def test_hippocampal_subfields_volume_file_find_pattern(root_dir_path, filename_pattern,
-                                                        expected_file_paths):
+    volume_files = list(
+        HippocampalSubfieldsVolumeFile.find(root_dir_path=root_dir_path)
+    )
+    assert all(
+        "hippoSfVolumes" in os.path.basename(f.absolute_path) for f in volume_files
+    )
+    assert expected_file_paths == set(f.absolute_path for f in volume_files)
+
+
+@pytest.mark.parametrize(
+    ("root_dir_path", "filename_pattern", "expected_file_paths"),
+    [
+        (
+            SUBJECTS_DIR,
+            r"hippoSfVolumes-T1\.v10",
+            {
+                os.path.join(
+                    SUBJECTS_DIR, "alice", "mri", "lh.hippoSfVolumes-T1.v10.txt"
+                ),
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1.v10.txt"
+                ),
+            },
+        ),
+        (
+            os.path.join(SUBJECTS_DIR, "bert"),
+            r"hippoSfVolumes-T1-T2",
+            {
+                os.path.join(
+                    SUBJECTS_DIR, "bert", "mri", "lh.hippoSfVolumes-T1-T2.v10.txt"
+                )
+            },
+        ),
+    ],
+)
+def test_hippocampal_subfields_volume_file_find_pattern(
+    root_dir_path, filename_pattern, expected_file_paths
+):
     assert expected_file_paths == set(
-        f.absolute_path for f in HippocampalSubfieldsVolumeFile.find(
-            root_dir_path=root_dir_path, filename_regex=re.compile(filename_pattern)))
+        f.absolute_path
+        for f in HippocampalSubfieldsVolumeFile.find(
+            root_dir_path=root_dir_path, filename_regex=re.compile(filename_pattern)
+        )
+    )

+ 39 - 25
tests/init_test.py

@@ -1,41 +1,55 @@
+# pylint: disable=missing-module-docstring
+
 import pytest
 
-from freesurfer_volume_reader import \
-    __version__, parse_version_string, remove_group_names_from_regex, \
-    VolumeFile, SubfieldVolumeFile
+from freesurfer_volume_reader import (
+    __version__,
+    parse_version_string,
+    remove_group_names_from_regex,
+    VolumeFile,
+    SubfieldVolumeFile,
+)
 
 
 def test_module_version():
-    assert len(__version__) >= len('0.1.0')
+    assert len(__version__) >= len("0.1.0")
 
 
-@pytest.mark.parametrize(('version_string', 'expected_tuple'), [
-    ('0.24.2', (0, 24, 2)),
-    ('0.21.0', (0, 21, 0)),
-    ('0.2.2.dev28+g526f05c.d20190504', (0, 2, 2, 'dev28+g526f05c', 'd20190504')),
-])
+@pytest.mark.parametrize(
+    ("version_string", "expected_tuple"),
+    [
+        ("0.24.2", (0, 24, 2)),
+        ("0.21.0", (0, 21, 0)),
+        ("0.2.2.dev28+g526f05c.d20190504", (0, 2, 2, "dev28+g526f05c", "d20190504")),
+    ],
+)
 def test_parse_version_string(version_string, expected_tuple):
     assert expected_tuple == parse_version_string(version_string)
 
 
 def test_parse_version_string_comparison():
-    assert parse_version_string('0.24.2') == (0, 24, 2)
-    assert parse_version_string('0.24.2') < (0, 25)
-    assert parse_version_string('0.24.2') < (0, 24, 3)
-    assert parse_version_string('0.24.2') <= (0, 24, 2)
-    assert parse_version_string('0.24.2') >= (0, 24, 2)
-    assert parse_version_string('0.24.2') > (0, 24, 1)
-    assert parse_version_string('0.24.2') > (0, 24)
-    assert parse_version_string('0.2.2.dev28+g526f05c.d20190504') > (0, 2, 2)
-    assert parse_version_string('0.2.2.dev28+g526f05c.d20190504') < (0, 2, 3)
-
-
-@pytest.mark.parametrize(('source_pattern', 'expected_pattern'), [
-    (r'^(?P<h>[lr])h\.hippoSfVolumes', r'^([lr])h\.hippoSfVolumes'),
-    (r'(?P<a>a(?P<b>b))', r'(a(b))'),
-])
+    assert parse_version_string("0.24.2") == (0, 24, 2)
+    assert parse_version_string("0.24.2") < (0, 25)
+    assert parse_version_string("0.24.2") < (0, 24, 3)
+    assert parse_version_string("0.24.2") <= (0, 24, 2)
+    assert parse_version_string("0.24.2") >= (0, 24, 2)
+    assert parse_version_string("0.24.2") > (0, 24, 1)
+    assert parse_version_string("0.24.2") > (0, 24)
+    assert parse_version_string("0.2.2.dev28+g526f05c.d20190504") > (0, 2, 2)
+    assert parse_version_string("0.2.2.dev28+g526f05c.d20190504") < (0, 2, 3)
+
+
+@pytest.mark.parametrize(
+    ("source_pattern", "expected_pattern"),
+    [
+        (r"^(?P<h>[lr])h\.hippoSfVolumes", r"^([lr])h\.hippoSfVolumes"),
+        (r"(?P<a>a(?P<b>b))", r"(a(b))"),
+    ],
+)
 def test_remove_group_names_from_regex(source_pattern, expected_pattern):
-    assert expected_pattern == remove_group_names_from_regex(regex_pattern=source_pattern)
+    assert expected_pattern == remove_group_names_from_regex(
+        regex_pattern=source_pattern
+    )
 
 
 class DummyVolumeFile(VolumeFile):

+ 264 - 146
tests/main_test.py

@@ -1,3 +1,5 @@
+# pylint: disable=missing-module-docstring
+
 import io
 import os
 import subprocess
@@ -14,18 +16,22 @@ import freesurfer_volume_reader.__main__
 from conftest import SUBJECTS_DIR, assert_volume_frames_equal
 
 
-def assert_main_volume_frame_equals(capsys, argv: list, expected_frame: pandas.DataFrame,
-                                    subjects_dir: typing.Optional[str] = None):
+def assert_main_volume_frame_equals(
+    capsys,
+    argv: list,
+    expected_frame: pandas.DataFrame,
+    subjects_dir: typing.Optional[str] = None,
+):
     if subjects_dir:
-        os.environ['SUBJECTS_DIR'] = subjects_dir
-    elif 'SUBJECTS_DIR' in os.environ:
-        del os.environ['SUBJECTS_DIR']
-    with unittest.mock.patch('sys.argv', [''] + argv):
+        os.environ["SUBJECTS_DIR"] = subjects_dir
+    elif "SUBJECTS_DIR" in os.environ:
+        del os.environ["SUBJECTS_DIR"]
+    with unittest.mock.patch("sys.argv", [""] + argv):
         assert freesurfer_volume_reader.__main__.main() == 0
     out, _ = capsys.readouterr()
-    resulted_frame = pandas.read_csv(io.StringIO(out)).drop(columns=['source_path'])
-    if 'correction' in resulted_frame:
-        resulted_frame['correction'] = resulted_frame['correction'].astype('object')
+    resulted_frame = pandas.read_csv(io.StringIO(out)).drop(columns=["source_path"])
+    if "correction" in resulted_frame:
+        resulted_frame["correction"] = resulted_frame["correction"].astype("object")
     assert_volume_frames_equal(
         left=expected_frame,
         # pandas.DataFrame.drop(columns=[...], ...) >= pandas0.21.0
@@ -33,99 +39,154 @@ def assert_main_volume_frame_equals(capsys, argv: list, expected_frame: pandas.D
     )
 
 
-@pytest.mark.parametrize(('args', 'root_dir_paths', 'expected_csv_path'), [
-    ([],
-     [os.path.join(SUBJECTS_DIR, 'alice')],
-     os.path.join(SUBJECTS_DIR, 'alice', 'freesurfer-hippocampal-volumes.csv')),
-    ([],
-     [os.path.join(SUBJECTS_DIR, 'bert')],
-     os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv')),
-    ([],
-     [os.path.join(SUBJECTS_DIR, 'alice'),
-      os.path.join(SUBJECTS_DIR, 'bert')],
-     os.path.join(SUBJECTS_DIR, 'freesurfer-hippocampal-volumes.csv')),
-    ([],
-     [SUBJECTS_DIR],
-     os.path.join(SUBJECTS_DIR, 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf'],
-     [os.path.join(SUBJECTS_DIR, 'alice')],
-     os.path.join(SUBJECTS_DIR, 'alice', 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf'],
-     [SUBJECTS_DIR],
-     os.path.join(SUBJECTS_DIR, 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     [os.path.join(SUBJECTS_DIR, 'alice')],
-     os.path.join(SUBJECTS_DIR, 'alice', 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     [os.path.join(SUBJECTS_DIR, 'bert')],
-     os.path.join(SUBJECTS_DIR, 'bert', 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     [os.path.join(SUBJECTS_DIR, 'alice'),
-      os.path.join(SUBJECTS_DIR, 'bert')],
-     os.path.join(SUBJECTS_DIR, 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     [SUBJECTS_DIR],
-     os.path.join(SUBJECTS_DIR, 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs', 'freesurfer-hipposf'],
-     [os.path.join(SUBJECTS_DIR, 'alice')],
-     os.path.join(SUBJECTS_DIR, 'alice', 'all-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf', 'ashs'],
-     [os.path.join(SUBJECTS_DIR, 'alice')],
-     os.path.join(SUBJECTS_DIR, 'alice', 'all-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs', 'freesurfer-hipposf'],
-     [os.path.join(SUBJECTS_DIR, 'alice'),
-      os.path.join(SUBJECTS_DIR, 'bert')],
-     os.path.join(SUBJECTS_DIR, 'all-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs', 'freesurfer-hipposf'],
-     [SUBJECTS_DIR],
-     os.path.join(SUBJECTS_DIR, 'all-hippocampal-volumes.csv')),
-])
+@pytest.mark.parametrize(
+    ("args", "root_dir_paths", "expected_csv_path"),
+    [
+        (
+            [],
+            [os.path.join(SUBJECTS_DIR, "alice")],
+            os.path.join(SUBJECTS_DIR, "alice", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            [],
+            [os.path.join(SUBJECTS_DIR, "bert")],
+            os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            [],
+            [os.path.join(SUBJECTS_DIR, "alice"), os.path.join(SUBJECTS_DIR, "bert")],
+            os.path.join(SUBJECTS_DIR, "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            [],
+            [SUBJECTS_DIR],
+            os.path.join(SUBJECTS_DIR, "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf"],
+            [os.path.join(SUBJECTS_DIR, "alice")],
+            os.path.join(SUBJECTS_DIR, "alice", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf"],
+            [SUBJECTS_DIR],
+            os.path.join(SUBJECTS_DIR, "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            [os.path.join(SUBJECTS_DIR, "alice")],
+            os.path.join(SUBJECTS_DIR, "alice", "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            [os.path.join(SUBJECTS_DIR, "bert")],
+            os.path.join(SUBJECTS_DIR, "bert", "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            [os.path.join(SUBJECTS_DIR, "alice"), os.path.join(SUBJECTS_DIR, "bert")],
+            os.path.join(SUBJECTS_DIR, "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            [SUBJECTS_DIR],
+            os.path.join(SUBJECTS_DIR, "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs", "freesurfer-hipposf"],
+            [os.path.join(SUBJECTS_DIR, "alice")],
+            os.path.join(SUBJECTS_DIR, "alice", "all-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf", "ashs"],
+            [os.path.join(SUBJECTS_DIR, "alice")],
+            os.path.join(SUBJECTS_DIR, "alice", "all-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs", "freesurfer-hipposf"],
+            [os.path.join(SUBJECTS_DIR, "alice"), os.path.join(SUBJECTS_DIR, "bert")],
+            os.path.join(SUBJECTS_DIR, "all-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs", "freesurfer-hipposf"],
+            [SUBJECTS_DIR],
+            os.path.join(SUBJECTS_DIR, "all-hippocampal-volumes.csv"),
+        ),
+    ],
+)
 def test_main_root_dir_param(capsys, args, root_dir_paths: list, expected_csv_path):
     assert_main_volume_frame_equals(
-        argv=args + ['--'] + root_dir_paths,
+        argv=args + ["--"] + root_dir_paths,
         expected_frame=pandas.read_csv(expected_csv_path),
         capsys=capsys,
     )
 
 
-@pytest.mark.parametrize(('args', 'root_dir_path', 'expected_csv_path'), [
-    ([],
-     SUBJECTS_DIR,
-     os.path.join(SUBJECTS_DIR, 'freesurfer-hippocampal-volumes.csv')),
-    ([],
-     os.path.join(SUBJECTS_DIR, 'bert'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf'],
-     SUBJECTS_DIR,
-     os.path.join(SUBJECTS_DIR, 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf'],
-     os.path.join(SUBJECTS_DIR, 'bert'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf'],
-     os.path.join(SUBJECTS_DIR, 'bert', 'mri'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     SUBJECTS_DIR,
-     os.path.join(SUBJECTS_DIR, 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     os.path.join(SUBJECTS_DIR, 'bert'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     os.path.join(SUBJECTS_DIR, 'bert', 'final'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     os.path.join(SUBJECTS_DIR, 'alice'),
-     os.path.join(SUBJECTS_DIR, 'alice', 'ashs-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs', 'freesurfer-hipposf'],
-     os.path.join(SUBJECTS_DIR, 'alice'),
-     os.path.join(SUBJECTS_DIR, 'alice', 'all-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf', 'ashs'],
-     os.path.join(SUBJECTS_DIR, 'alice'),
-     os.path.join(SUBJECTS_DIR, 'alice', 'all-hippocampal-volumes.csv')),
-    (['--source-types', 'freesurfer-hipposf', 'ashs'],
-     SUBJECTS_DIR,
-     os.path.join(SUBJECTS_DIR, 'all-hippocampal-volumes.csv')),
-])
+@pytest.mark.parametrize(
+    ("args", "root_dir_path", "expected_csv_path"),
+    [
+        (
+            [],
+            SUBJECTS_DIR,
+            os.path.join(SUBJECTS_DIR, "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            [],
+            os.path.join(SUBJECTS_DIR, "bert"),
+            os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf"],
+            SUBJECTS_DIR,
+            os.path.join(SUBJECTS_DIR, "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf"],
+            os.path.join(SUBJECTS_DIR, "bert"),
+            os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf"],
+            os.path.join(SUBJECTS_DIR, "bert", "mri"),
+            os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            SUBJECTS_DIR,
+            os.path.join(SUBJECTS_DIR, "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            os.path.join(SUBJECTS_DIR, "bert"),
+            os.path.join(SUBJECTS_DIR, "bert", "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            os.path.join(SUBJECTS_DIR, "bert", "final"),
+            os.path.join(SUBJECTS_DIR, "bert", "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            os.path.join(SUBJECTS_DIR, "alice"),
+            os.path.join(SUBJECTS_DIR, "alice", "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs", "freesurfer-hipposf"],
+            os.path.join(SUBJECTS_DIR, "alice"),
+            os.path.join(SUBJECTS_DIR, "alice", "all-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf", "ashs"],
+            os.path.join(SUBJECTS_DIR, "alice"),
+            os.path.join(SUBJECTS_DIR, "alice", "all-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "freesurfer-hipposf", "ashs"],
+            SUBJECTS_DIR,
+            os.path.join(SUBJECTS_DIR, "all-hippocampal-volumes.csv"),
+        ),
+    ],
+)
 def test_main_root_dir_env(capsys, args, root_dir_path, expected_csv_path):
     assert_main_volume_frame_equals(
         argv=args,
@@ -136,23 +197,34 @@ def test_main_root_dir_env(capsys, args, root_dir_path, expected_csv_path):
 
 
 @pytest.mark.timeout(8)
-@pytest.mark.parametrize(('args', 'root_dir_path', 'subjects_dir', 'expected_csv_path'), [
-    ([],
-     os.path.join(SUBJECTS_DIR, 'bert'),
-     os.path.join(SUBJECTS_DIR, 'alice'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv')),
-    (['--source-types', 'ashs'],
-     os.path.join(SUBJECTS_DIR, 'bert'),
-     os.path.join(SUBJECTS_DIR, 'alice'),
-     os.path.join(SUBJECTS_DIR, 'bert', 'ashs-hippocampal-volumes.csv')),
-    ([],
-     os.path.join(SUBJECTS_DIR, 'bert'),
-     os.path.abspath(os.sep),
-     os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv')),
-])
-def test_main_root_dir_overwrite_env(capsys, args, root_dir_path, subjects_dir, expected_csv_path):
+@pytest.mark.parametrize(
+    ("args", "root_dir_path", "subjects_dir", "expected_csv_path"),
+    [
+        (
+            [],
+            os.path.join(SUBJECTS_DIR, "bert"),
+            os.path.join(SUBJECTS_DIR, "alice"),
+            os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv"),
+        ),
+        (
+            ["--source-types", "ashs"],
+            os.path.join(SUBJECTS_DIR, "bert"),
+            os.path.join(SUBJECTS_DIR, "alice"),
+            os.path.join(SUBJECTS_DIR, "bert", "ashs-hippocampal-volumes.csv"),
+        ),
+        (
+            [],
+            os.path.join(SUBJECTS_DIR, "bert"),
+            os.path.abspath(os.sep),
+            os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv"),
+        ),
+    ],
+)
+def test_main_root_dir_overwrite_env(
+    capsys, args, root_dir_path, subjects_dir, expected_csv_path
+):
     assert_main_volume_frame_equals(
-        argv=args + ['--', root_dir_path],
+        argv=args + ["--", root_dir_path],
         subjects_dir=subjects_dir,
         expected_frame=pandas.read_csv(expected_csv_path),
         capsys=capsys,
@@ -161,83 +233,129 @@ def test_main_root_dir_overwrite_env(capsys, args, root_dir_path, subjects_dir,
 
 def test_main_root_dir_filename_regex_freesurfer(capsys):
     expected_volume_frame = pandas.read_csv(
-        os.path.join(SUBJECTS_DIR, 'bert', 'freesurfer-hippocampal-volumes.csv'))
+        os.path.join(SUBJECTS_DIR, "bert", "freesurfer-hippocampal-volumes.csv")
+    )
     assert_main_volume_frame_equals(
-        argv=['--freesurfer-hipposf-filename-regex', r'^.*-T1-T2\.v10\.txt$',
-              os.path.join(SUBJECTS_DIR, 'bert')],
-        expected_frame=expected_volume_frame[expected_volume_frame['analysis_id'] == 'T2'].copy(),
+        argv=[
+            "--freesurfer-hipposf-filename-regex",
+            r"^.*-T1-T2\.v10\.txt$",
+            os.path.join(SUBJECTS_DIR, "bert"),
+        ],
+        expected_frame=expected_volume_frame[
+            expected_volume_frame["analysis_id"] == "T2"
+        ].copy(),
         capsys=capsys,
     )
 
 
 def test_main_root_dir_filename_regex_ashs(capsys):
     expected_volume_frame = pandas.read_csv(
-        os.path.join(SUBJECTS_DIR, 'bert', 'ashs-hippocampal-volumes.csv'))
+        os.path.join(SUBJECTS_DIR, "bert", "ashs-hippocampal-volumes.csv")
+    )
     assert_main_volume_frame_equals(
-        argv=['--ashs-filename-regex', r'_nogray_volumes.txt$',
-              '--source-types', 'ashs', '--',
-              os.path.join(SUBJECTS_DIR, 'bert')],
-        expected_frame=expected_volume_frame[expected_volume_frame['correction']
-                                             == 'nogray'].copy(),
+        argv=[
+            "--ashs-filename-regex",
+            r"_nogray_volumes.txt$",
+            "--source-types",
+            "ashs",
+            "--",
+            os.path.join(SUBJECTS_DIR, "bert"),
+        ],
+        expected_frame=expected_volume_frame[
+            expected_volume_frame["correction"] == "nogray"
+        ].copy(),
         capsys=capsys,
     )
 
 
 def test_main_root_dir_filename_regex_combined(capsys):
     expected_volume_frame = pandas.read_csv(
-        os.path.join(SUBJECTS_DIR, 'alice', 'all-hippocampal-volumes.csv'))
+        os.path.join(SUBJECTS_DIR, "alice", "all-hippocampal-volumes.csv")
+    )
     expected_volume_frame = expected_volume_frame[
         # pylint: disable=singleton-comparison
-        (expected_volume_frame['T1_input'] == True)
-        | ((expected_volume_frame['source_type'] == 'ashs')
-           & expected_volume_frame['correction'].isnull())
+        (expected_volume_frame["T1_input"] == True)
+        | (
+            (expected_volume_frame["source_type"] == "ashs")
+            & expected_volume_frame["correction"].isnull()
+        )
     ]
     assert_main_volume_frame_equals(
-        argv=['--ashs-filename-regex', r'^alice_left_heur_',
-              '--freesurfer-hipposf-filename-regex', r'hippoSfVolumes-T1.v10.txt$',
-              '--source-types', 'ashs', 'freesurfer-hipposf',
-              '--', os.path.join(SUBJECTS_DIR, 'alice')],
+        argv=[
+            "--ashs-filename-regex",
+            r"^alice_left_heur_",
+            "--freesurfer-hipposf-filename-regex",
+            r"hippoSfVolumes-T1.v10.txt$",
+            "--source-types",
+            "ashs",
+            "freesurfer-hipposf",
+            "--",
+            os.path.join(SUBJECTS_DIR, "alice"),
+        ],
         expected_frame=expected_volume_frame.copy(),
         capsys=capsys,
     )
 
 
 def test_main_no_files_found(capsys):
-    with unittest.mock.patch('sys.argv', ['', '--freesurfer-hipposf-filename-regex', r'^21$',
-                                          '--', SUBJECTS_DIR]):
+    with unittest.mock.patch(
+        "sys.argv",
+        ["", "--freesurfer-hipposf-filename-regex", r"^21$", "--", SUBJECTS_DIR],
+    ):
         assert os.EX_NOINPUT == freesurfer_volume_reader.__main__.main()
     out, err = capsys.readouterr()
     assert not out
-    assert err == 'Did not find any volume files matching the specified criteria.\n'
+    assert err == "Did not find any volume files matching the specified criteria.\n"
 
 
 def test_main_module_script_no_files_found():
-    proc_info = subprocess.run(['python', '-m', 'freesurfer_volume_reader',
-                                '--freesurfer-hipposf-filename-regex', r'^21$',
-                                '--', SUBJECTS_DIR],
-                               check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    proc_info = subprocess.run(
+        [
+            "python",
+            "-m",
+            "freesurfer_volume_reader",
+            "--freesurfer-hipposf-filename-regex",
+            r"^21$",
+            "--",
+            SUBJECTS_DIR,
+        ],
+        check=False,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+    )
     assert os.EX_NOINPUT == proc_info.returncode
     assert not proc_info.stdout
-    assert 'not find any volume files' in proc_info.stderr.rstrip().decode()
+    assert "not find any volume files" in proc_info.stderr.rstrip().decode()
 
 
 def test_script_no_files_found():
-    proc_info = subprocess.run(['freesurfer-volume-reader',
-                                '--freesurfer-hipposf-filename-regex', r'^21$',
-                                '--', SUBJECTS_DIR],
-                               check=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    proc_info = subprocess.run(
+        [
+            "freesurfer-volume-reader",
+            "--freesurfer-hipposf-filename-regex",
+            r"^21$",
+            "--",
+            SUBJECTS_DIR,
+        ],
+        check=False,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+    )
     assert os.EX_NOINPUT == proc_info.returncode
     assert not proc_info.stdout
-    assert 'not find any volume files' in proc_info.stderr.rstrip().decode()
+    assert "not find any volume files" in proc_info.stderr.rstrip().decode()
 
 
 def test_main_module_script_help():
-    subprocess.run(['python', '-m', 'freesurfer_volume_reader', '--help'],
-                   check=True)
+    subprocess.run(["python", "-m", "freesurfer_volume_reader", "--help"], check=True)
 
 
 def test_main_module_script_version():
-    proc_info = subprocess.run(['python', '-m', 'freesurfer_volume_reader', '--version'],
-                               check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    proc_info = subprocess.run(
+        ["python", "-m", "freesurfer_volume_reader", "--version"],
+        check=True,
+        stdout=subprocess.PIPE,
+        stderr=subprocess.PIPE,
+    )
     assert proc_info.stdout.rstrip() == freesurfer_volume_reader.__version__.encode()
     assert not proc_info.stderr