Skip to content

Commit eea82bf

Browse files
committed
ENH: Add minimum_fs_version input to handle outdated fsaverages
1 parent e707fbd commit eea82bf

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

niworkflows/interfaces/bids.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ class _BIDSFreeSurferDirInputSpec(BaseInterfaceInputSpec):
848848
overwrite_fsaverage = traits.Bool(
849849
False, usedefault=True, desc="Overwrite fsaverage directories, if present"
850850
)
851+
minimum_fs_version = traits.Enum("7.0.0", desc="Minimum FreeSurfer version for compatibility")
851852

852853

853854
class _BIDSFreeSurferDirOutputSpec(TraitedSpec):
@@ -911,6 +912,12 @@ def _run_interface(self, runtime):
911912
else:
912913
raise FileNotFoundError("Expected to find '%s' to copy" % source)
913914

915+
if dest.exists() and self.inputs.minimum_fs_version == "7.0.0":
916+
label = dest / 'label' / 'rh.FG1.mpm.vpnl.label' # new in FS7
917+
if not label.exists():
918+
# remove previous output and let us recopy
919+
shutil.rmtree(dest)
920+
914921
# Finesse is overrated. Either leave it alone or completely clobber it.
915922
if dest.exists() and self.inputs.overwrite_fsaverage:
916923
shutil.rmtree(dest)

niworkflows/interfaces/tests/test_bids.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -697,3 +697,30 @@ def test_fsdir_missing_space(tmp_path):
697697
bintfs.BIDSFreeSurferDir(
698698
derivatives=str(tmp_path), spaces=["fsaverage2"], freesurfer_home=fshome
699699
).run()
700+
701+
702+
@pytest.mark.skipif(not os.getenv("FREESURFER_HOME"), reason="No FreeSurfer")
703+
@pytest.mark.parametrize('min_version', [None, '7.0.0'])
704+
def test_fsdir_min_version(tmp_path, min_version):
705+
fshome = os.environ["FREESURFER_HOME"]
706+
subjects_dir = tmp_path / "freesurfer"
707+
708+
patched_subject_dir = subjects_dir / 'fsaverage6' / 'older'
709+
patched_subject_dir.mkdir(parents=True)
710+
711+
bfsd = bintfs.BIDSFreeSurferDir(
712+
subjects_dir=subjects_dir,
713+
derivatives=str(tmp_path),
714+
spaces=["fsaverage6"],
715+
freesurfer_home=fshome,
716+
)
717+
718+
if min_version:
719+
bfsd.inputs.minimum_fs_version = min_version
720+
721+
bfsd.run()
722+
if min_version:
723+
# should have been overwritten with proper subjects dir
724+
assert not patched_subject_dir.exists()
725+
else:
726+
assert patched_subject_dir.exists()

0 commit comments

Comments
 (0)