Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --fs-no-resume option to reuse existing freesurfer outputs without resuming (eg. longitudinal pipeline base) #393

Merged
merged 21 commits into from
Mar 22, 2024

Conversation

bpinsard
Copy link
Contributor

(Reopen of #371)

For now, it is not possible to run f/sMRIPrep with existing longitudinal freesurfer output.
If I understood correctly, the current surface generation workflow:

runs autorecon1 without skullstripping
injects a custom (and more robust) brainmask.mgz
resume to autorecon2/3 without any other tweaks.

The simpler way I found to input the base/template recon-all is to use the FreeSurferSource and reconnect everything appropriately. Does that make sense, or I missed something (like registering the sMRIPrep generated average to the freesurfer one).

@bpinsard bpinsard changed the title Enh/fs long Add a --fs-reuse-base option to reuse existing freesurfer outputs from a longitudinal pipeline Nov 21, 2023
Copy link

codecov bot commented Nov 21, 2023

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 78.54%. Comparing base (c72116a) to head (ba4611b).

Files Patch % Lines
smriprep/workflows/surfaces.py 50.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master     #393       +/-   ##
===========================================
+ Coverage   62.99%   78.54%   +15.54%     
===========================================
  Files          24       30        +6     
  Lines        1927     2093      +166     
  Branches      248      249        +1     
===========================================
+ Hits         1214     1644      +430     
+ Misses        678      417      -261     
+ Partials       35       32        -3     
Flag Coverage Δ
ds005 ∅ <ø> (?)
ds054 46.22% <20.00%> (?)
pytest 67.74% <40.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, getting back to this. Thanks for the patience. As I understand it, instead of trying to correctly wrap longitudinal FreeSurfer in the same way we've been wrapping single-session FreeSurfer, this just give the user a "trust me, I know what I'm doing" button.

If that's the case, I think the better approach is probably to make the flag --fs-no-resume or something like that (open to alternatives), which would allow it to work with any FreeSurfer-like directory structure. This would work equally well with longitudinal FreeSurfer, fastsurfer (#280) or any other technique that comes out.

One thing that would be worth considering in that case is to provide a function to check for necessary files and error out early if they are not found. For example we need {lh,rh}.{white,pial,thickness,sulc,curv,sphere,sphere.reg} as well as T1.mgz, aparc.mgz, aparc+aseg.mgz and either FLAIR.mgz or T2.mgz, if T2w/FLAIR are detected.

That said, since this would be a "power user" feature, I don't think it's critical to write a hand-holder on the first pass.

.circleci/config.yml Outdated Show resolved Hide resolved
Co-authored-by: Chris Markiewicz <effigies@gmail.com>
@bpinsard
Copy link
Contributor Author

bpinsard commented Mar 14, 2024

Okay, getting back to this. Thanks for the patience. As I understand it, instead of trying to correctly wrap longitudinal FreeSurfer in the same way we've been wrapping single-session FreeSurfer, this just give the user a "trust me, I know what I'm doing" button.

Exactly, wrapping longitudinal pipeline is more complex.

If that's the case, I think the better approach is probably to make the flag --fs-no-resume or something like that (open to alternatives), which would allow it to work with any FreeSurfer-like directory structure. This would work equally well with longitudinal FreeSurfer, fastsurfer (#280) or any other technique that comes out.

Happy with renaming the flag, I had not thought about the fastsurfer usecase but that's a very good point.

One thing that would be worth considering in that case is to provide a function to check for necessary files and error out early if they are not found. For example we need {lh,rh}.{white,pial,thickness,sulc,curv,sphere,sphere.reg} as well as T1.mgz, aparc.mgz, aparc+aseg.mgz and either FLAIR.mgz or T2.mgz, if T2w/FLAIR are detected.

Such as a new nipype node that checks that the traits are not undefined?

That said, since this would be a "power user" feature, I don't think it's critical to write a hand-holder on the first pass.

@bpinsard bpinsard changed the title Add a --fs-reuse-base option to reuse existing freesurfer outputs from a longitudinal pipeline Add --fs-no-resume option to reuse existing freesurfer outputs without resuming (eg. longitudinal pipeline base) Mar 15, 2024
Comment on lines 221 to 223
help='Import precomputed freesurfer without resuming '
'(longitudinal or fastsurfer data) '
"!expert option (you know what you're doing)!",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably needs different line break points, but here's some updated wording:

Suggested change
help='Import precomputed freesurfer without resuming '
'(longitudinal or fastsurfer data) '
"!expert option (you know what you're doing)!",
help='EXPERT: Import pre-computed FreeSurfer reconstruction without resuming. '
'The user is responsible for ensuring that all necessary files are present.'

smriprep/workflows/anatomical.py Show resolved Hide resolved
smriprep/workflows/surfaces.py Show resolved Hide resolved
@bpinsard
Copy link
Contributor Author

Interestingly, templateflow/tpl-fsaverage#5 broke the CI run here (and likely any smriprep run?)
https://github.com/nipreps/smriprep/blob/master/smriprep/cli/run.py#L416 should be fixed? or niworkflows.utils.misc._copy_any ?
@oesteban

@effigies
Copy link
Member

I guess we want

dseg_tsv = str(api.get('fsaverage', suffix='dseg', extension=['.tsv']))

to become:

            dseg_tsv = str(api.get('fsaverage', hemi=None, seg='aparc', suffix='dseg', extension=['.tsv']))

@bpinsard
Copy link
Contributor Author

I guess we want

dseg_tsv = str(api.get('fsaverage', suffix='dseg', extension=['.tsv']))

to become:

            dseg_tsv = str(api.get('fsaverage', hemi=None, seg='aparc', suffix='dseg', extension=['.tsv']))

Opened #420
I guess this should be back-ported to the LTS as it will also pull from the latest templateflow version.

Copy link
Member

@effigies effigies left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Added a comment and updated the fmt:<on|off|skip> directives.

smriprep/workflows/surfaces.py Show resolved Hide resolved
smriprep/workflows/surfaces.py Outdated Show resolved Hide resolved
smriprep/workflows/surfaces.py Outdated Show resolved Hide resolved
@effigies effigies added this to the 0.15.0 milestone Mar 22, 2024
@effigies effigies merged commit e682dc7 into nipreps:master Mar 22, 2024
16 of 17 checks passed
effigies added a commit that referenced this pull request Mar 23, 2024
0.15.0 (March 22, 2024)

New feature release in the 0.15.x series.

This release adds the workflow configuration option and CLI option
to reuse existing FreeSurfer outputs without attempting to resume.
This should allow for using longitudinal or non-standard pipelines
(for example, FastSurfer) without additional tooling for each variant.

* FIX: Patch version for smriprep-docker (#424)
* FIX: Require recent templateflow, select correct aparc dseg.tsv (#420)
* ENH: Add --fs-no-resume option to reuse existing FreeSurfer outputs without resuming (#393)
* MNT: set copyright owner in LICENSE file (#426)
* MNT: Apply Repo-Review suggestions (#422)
* CI: Small cleanups to GHA (#423)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants