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

Modifications to generic fMRIVolume and fMRISurface pipelines to run on longitudinal sessions. #319

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

mmilch01
Copy link
Contributor

@mmilch01 mmilch01 commented Dec 29, 2024

This pull request comprises modifications to generic fMRIVolume and fMRISurface to run on longitudinal timepoints. Prerequisites for GenericfMRIVolumeProcessingPipeline are:

  1. All cross-sectional pipelines must have been run up to post-Freesurfer for all timepoints.
  2. All longitudinal pipelines for the corresponding timepoints must have been run up to post-Freesurfer.
  3. GenericfMRIVolumeProcessingPipeline must have been run on all cross-sectional timepoints.
  4. All timepoints must be under the same processing directory.

Prerequisites for fMRISurface are the same plus GenericfMRIVolumeProcessingPipeline must have been run on all longitudinal timepoints.

Note that neither multi-echo fMRI nor fMRIReference is currently supported in longitudinal mode.

@demsarjure
Copy link
Contributor

@mmilch01

  1. I assume that in
Prerequisites for fMRISurface are the same plus GenericfMRIVolumeProcessingPipeline must have been run on all longitudinal timepoints.

GenericfMRIVolumeProcessingPipeline should be GenericfMRISurfaceProcessingPipeline?

  1. It would be probably great, if I ran some tests for this on our end. Misha, can you please paste 2 example calls that you used for tests on your end, one for long volume and one for long surface. Just so I have something to quickly compare my command calls with. Thanks!

@demsarjure
Copy link
Contributor

It looks like this MR now includes changes from Volume + Surface and also changes from the long FS which were already merged into master? So the review tab shows a lot of code that is already tested and reviewed. Maybe it would be best to have a new branch for the new stuff?

Also, the branch is not in sync with the current master, so it would be best to merge the current master into this and resolve the conflicts. Or the cleanest way, which is to create new branch of the master and apply only long volume and long surface changes to it.

Copy link
Contributor

@demsarjure demsarjure left a comment

Choose a reason for hiding this comment

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

I did a somewhat quick review and things look good. As usual I might report some bugs later on, when I actually start running tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is the -0 suffix in GenericfMRIVolumeProcessingPipeline-0.sh?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What is the -0 suffix in GenericfMRIVolumeProcessingPipeline-0.sh?
That's a backup file that somehow made it into one of commits. should be fixed now.

@coalsont
Copy link
Member

It looks like this MR now includes changes from Volume + Surface and also changes from the long FS which were already merged into master? So the review tab shows a lot of code that is already tested and reviewed. Maybe it would be best to have a new branch for the new stuff?

Also, the branch is not in sync with the current master, so it would be best to merge the current master into this and resolve the conflicts. Or the cleanest way, which is to create new branch of the master and apply only long volume and long surface changes to it.

Rebase is a cleaner way to resolve normal conflicts (this situation isn't normal). Merge commits are weird and awkward, and hard to look at diffs of. "In sync" isn't really applicable here, the whole purpose of a PR is to propose changes, conflicts mean that someone else has also made changes to the same files (or, it can be a symptom that your branch's starting point is wrong or contains extra stuff).

I can try to salvage the intended commits.

mmilch01 and others added 17 commits December 30, 2024 16:23
+Work on longitudinal version of fMRIVolume instead.
…es to dependent scripts.

+added options (not finished) to OneStepResampling to output in native space.
+fMRIVolume, longitudinal version, finishes successfully.
+Output not visually verified.
+Example batch script for longitudinal fMRIVolume
+Rename 'Subject' to 'Session' in fMRISurfaceProcessingPipeline and dependencies
@coalsont coalsont force-pushed the feature/longitudinal_fs branch from 30fcc3c to c8a2c88 Compare December 30, 2024 22:44
@mmilch01
Copy link
Contributor Author

mmilch01 commented Dec 31, 2024

  1. I assume that in
Prerequisites for fMRISurface are the same plus GenericfMRIVolumeProcessingPipeline must have been run on all longitudinal timepoints.

GenericfMRIVolumeProcessingPipeline should be GenericfMRISurfaceProcessingPipeline?

Longitudinal fMRISurface needs longitudinal fMRIVolume to have been run on the same timepoint. Cross-sectional fMRISurface is not required to have been run.

  1. It would be probably great, if I ran some tests for this on our end. Misha, can you please paste 2 example calls that you used for tests on your end, one for long volume and one for long surface. Just so I have something to quickly compare my command calls with. Thanks!

You can use corresponding Examples/scripts/*-long.sh batch scripts for call examples. The only difference from my calls are obfuscated paths for StudyFolder and EnvironmentScript.

@mmilch01
Copy link
Contributor Author

It looks like this MR now includes changes from Volume + Surface and also changes from the long FS which were already merged into master? So the review tab shows a lot of code that is already tested and reviewed. Maybe it would be best to have a new branch for the new stuff?

Also, the branch is not in sync with the current master, so it would be best to merge the current master into this and resolve the conflicts. Or the cleanest way, which is to create new branch of the master and apply only long volume and long surface changes to it.

This should have been fixed now.


#Split echos
#Split echos.
Copy link
Contributor

Choose a reason for hiding this comment

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

Only run in cross-sectional.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry, could you expand on what you mean?

Copy link
Contributor

Choose a reason for hiding this comment

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

You should not run this block in longitudinal mode, so please if/then it accordingly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The block between lines (new) 683 and 809 is already only run in cross-sectional mode. Did you mean the next 'split echos' block? For that, I kept statements assigning [tcs/sct]Echoes[..] but put all wb_command commands under conditional.

Copy link
Member

@coalsont coalsont Jan 22, 2025

Choose a reason for hiding this comment

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

At the moment, it will still print "splitting echoes" if multi echo is detected, even though it will then only set some shell variables. If we don't need any of the variables in longitudinal mode, I would put the longitudinal conditional around the entire block instead of buried in the loop, for readability (and avoiding wrong messages).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We do need tcsEchoes* to be set for multi-echo for both longitudinal and non-longitudinal modes. The if clause inside the "for iEcho.." loop prevents re-running wb_command in longitudinal mode.

@@ -940,7 +1010,7 @@ then
${FSLDIR}/bin/fslmaths ${ResultsFolder}/${NameOffMRI}_pseudo_transmit_raw.nii.gz -mas ${fMRIFolder}/${FreeSurferBrainMask}.${FinalfMRIResolution}.nii.gz ${ResultsFolder}/${NameOffMRI}_pseudo_transmit_raw.nii.gz
${FSLDIR}/bin/applywarp --interp=trilinear -i ${DCFolder}/ComputeSpinEchoBiasField/${NameOffMRI}_pseudo_transmit_field.nii.gz -r ${fMRIFolder}/${NameOffMRI}_SBRef_nonlin -w ${AtlasSpaceFolder}/xfms/${AtlasTransform} -o ${ResultsFolder}/${NameOffMRI}_pseudo_transmit_field.nii.gz
${FSLDIR}/bin/fslmaths ${ResultsFolder}/${NameOffMRI}_pseudo_transmit_field.nii.gz -mas ${fMRIFolder}/${FreeSurferBrainMask}.${FinalfMRIResolution}.nii.gz ${ResultsFolder}/${NameOffMRI}_pseudo_transmit_field.nii.gz
else
else #never triggered in Longitudinal mode
Copy link
Contributor

Choose a reason for hiding this comment

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

@demsarjure @sivcek This needs your attention.

Copy link
Contributor

Choose a reason for hiding this comment

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

Like mentioned above, I think this is fine as reference is not needed any more in longitudinal processing.

Copy link
Contributor

@glasserm glasserm left a comment

Choose a reason for hiding this comment

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

I have made various comments. Please address them and also @demsarjure @sivcek please assist with the fMRIReference stuff. Thanks!

+comment out 'output to native' code changes

if (( IsLongitudinal )); then
if [ ! -d "$Path/$SessionLong" ]; then
log_Err_Abort "the --longitudinal-session must be specified and folder must exist in longitudinal mode"
Copy link
Member

Choose a reason for hiding this comment

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

This suggests --longitudinal-session must be specified and non-empty whenever --is-longitudinal=TRUE. So, do we really even need the --is-longitudinal option, or should it simply test if --longitudinal-session gave an empty string?

Copy link
Contributor Author

@mmilch01 mmilch01 Jan 15, 2025

Choose a reason for hiding this comment

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

Correct. But, I am inclined to leave is-longitudinal option as standard way to point to longitudinal session across scripts, instead of forcing the user to guess it is not required here.


if (( $IsLongitudinal )); then
if [ ! -f "$T1wCross2LongXfm" ]; then
log_Err_Abort "--t1w-cross2long-xfm must point to a valid file when --is-longitudinal is used"
Copy link
Member

Choose a reason for hiding this comment

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

It could be argued that --is-longitudinal is redundant here also (you wouldn't supply --t1w-cross2long-xfm in cross-sectional mode).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, trying to be consistent across longitudinal /cross-sectional parameters

@glasserm
Copy link
Contributor

glasserm commented Jan 7, 2025

Since my attempt at e-mail-based comments didn't work, I deleted them and moved them to the appropriate threads.

mmilch01 and others added 2 commits January 16, 2025 09:06
FreeSurferBrainMaskFile=`basename "$FreeSurferBrainMask"`
BiasFieldFile=$(basename "$BiasField")
T1wImageFile=$(basename $T1wImage)
#T1wImageFileNative=$(basename $T1wImageNative)
Copy link
Member

Choose a reason for hiding this comment

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

This line also looks like a native volume space change, commented out.

Comment on lines +820 to +823
if (( ! IsLongitudinal )); then
wb_command -volume-merge "${fMRIFolder}/${tcsEchoesOrig[iEcho]}.nii.gz" -volume "${fMRIFolder}/${OrigTCSName}.nii.gz" \
-subvolume $((1 + FramesPerEcho * iEcho)) -up-to $((FramesPerEcho * (iEcho + 1)))
wb_command -volume-merge "${fMRIFolder}/${sctEchoesOrig[iEcho]}.nii.gz" -volume "${fMRIFolder}/${OrigScoutName}.nii.gz" \
Copy link
Member

Choose a reason for hiding this comment

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

This section is using tabs when the surrounding is using spaces.

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.

4 participants