Skip to content

Commit

Permalink
Added function to test for FastSurfer files in --fs-subjects-dir
Browse files Browse the repository at this point in the history
Checks FreeSurfer subjects dir for presence of files in mri/ with names indicating processing with FastSurfer, and returns a boolean fastsurfer_bool to indicate that FastSurfer is being used instead of Freesurfer. For development purposes, this also touches files that are expected outputs of Freesurfer, but not produced by default in FastSurfer. (Addresses nipreps#278 & Deep-MI/FastSurfer#21)
  • Loading branch information
pcamach2 authored Apr 20, 2022
1 parent f8972da commit 1377f4c
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions smriprep/utils/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,44 @@ def fs_isRunning(subjects_dir, subject_id, mtime_tol=86400, logger=None):
if logger:
logger.warn(f'Removed "IsRunning*" files found under {subj_dir}')
return subjects_dir

def check_fastsurfer(subjects_dir, subject_id):
"""
Checks FreeSurfer subjects dir for presence of files in mri/ with names indicating processing with FastSurfer,
and returns a boolean fastsurfer_bool to indicate that FastSurfer is being used instead of Freesurfer.
For development purposes, this also touches files that are expected outputs of Freesurfer,
but not produced by default in FastSurfer.
Parameters
----------
subjects_dir : os.PathLike or None
Existing FreeSurfer subjects directory
subject_id : str
Subject label
Returns
-------
fastsurfer_bool : Boolean
subjects_dir : os.PathLike or None
"""
from pathlib import Path

if subjects_dir is None:
return subjects_dir
subj_dir = Path(subjects_dir) / subject_id
if not subj_dir.exists():

return subjects_dir

fastsurferfiles = tuple(subj_dir.glob("mri/*deep*mgz"))
if not fastsurferfiles:
fastsurfer_bool = False
return fastsurfer_bool, subjects_dir
else:
fastsurfer_bool = True
noCCseglabel = Path(subj_dir / 'mri/aseg.auto_noCCseg.label_intensities.txt')
noCCseglabel.touch(exist_ok=False)
return fastsurfer_bool, subjects_dir

0 comments on commit 1377f4c

Please sign in to comment.