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

Apply transforms to raw data when MNI6 derivatives aren't available #58

Merged
merged 12 commits into from
Sep 3, 2024

Conversation

tsalo
Copy link
Collaborator

@tsalo tsalo commented Aug 29, 2024

Closes #57. I tested this locally against running with MNI6 derivatives, and the results are different. I am a little worried that I didn't implement the transforms properly or something.

To do:

Changes proposed in this pull request

  • Add ignore to the Config object so users can actually ignore stuff.
  • Ignore fieldmaps by default, since I don't know how to grab them yet. Will revert this later.
  • Add mem_gb to SUSAN and MELODIC nodes (closes Add mem_gb to SUSAN and MELODIC nodes to avoid memory errors #11).
  • Allow processing of raw BOLD data when MNI6 derivatives aren't available.
    • We still need an anat-to-MNI6 transform.
    • This runs STC, then init_bold_volumetric_resample_wf, using raw BOLD and derivatives I think should be available at least in full mode with --cifti-output.

@tsalo tsalo added the enhancement New feature or request label Aug 29, 2024
Comment on lines +440 to +446
# Resample BOLD to MNI152NLin6Asym, may duplicate bold_std_wf above
# XXX: Ignoring the field map for now
# (inputnode, bold_MNI6_wf, [
# ('fmap_ref', 'inputnode.fmap_ref'),
# ('fmap_coeff', 'inputnode.fmap_coeff'),
# ('fmap_id', 'inputnode.fmap_id'),
# ]),
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to figure out how to grab the field map

Copy link

codecov bot commented Aug 29, 2024

Codecov Report

Attention: Patch coverage is 15.29412% with 72 lines in your changes missing coverage. Please review.

Project coverage is 31.08%. Comparing base (d3f8b26) to head (0754dbb).

Files with missing lines Patch % Lines
src/fmripost_aroma/workflows/base.py 0.00% 45 Missing ⚠️
src/fmripost_aroma/workflows/outputs.py 33.33% 18 Missing ⚠️
src/fmripost_aroma/interfaces/nilearn.py 0.00% 9 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #58      +/-   ##
==========================================
- Coverage   31.40%   31.08%   -0.32%     
==========================================
  Files          26       26              
  Lines        2277     2329      +52     
  Branches      360      362       +2     
==========================================
+ Hits          715      724       +9     
- Misses       1541     1584      +43     
  Partials       21       21              

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

@tsalo
Copy link
Collaborator Author

tsalo commented Aug 29, 2024

With MNI6

image

Without MNI6 (i.e., warping raw)

That first component really throws me.

image

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 1, 2024

I realized I wasn't passing along the STCed BOLD data to the MNI6 workflow, so I fixed that, but it didn't bring the results in line with the MNI6-derivatives outputs.

@tsalo tsalo requested a review from effigies September 1, 2024 16:21
@tsalo
Copy link
Collaborator Author

tsalo commented Sep 2, 2024

I finally took a look at the warped data from my PR and the data are in the wrong space. The MNI-space BOLD from fMRIPrep is in red and overlaps well with the brain mask. The warped BOLD from this PR is in blue and does not overlap with the brain mask.

image

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 2, 2024

The transforms being used for the resample (ResampleSeries) step of bold_MNI6_wf (init_bold_volumetric_resample_wf) seem right to me:

  1. sub-01/ses-01/func/sub-01_ses-01_task-rest_from-orig_to-boldref_mode-image_desc-hmc_xfm.txt
  2. sub-01/ses-01/func/sub-01_ses-01_task-rest_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt
  3. sub-01/ses-01/anat/sub-01_ses-01_from-T1w_to-MNI152NLin6Asym_mode-image_xfm.h5

Comparing to what's in the fMRIPrep working directory (they're the same!):

  1. sub-01/ses-01/func/sub-01_ses-01_task-rest_from-orig_to-boldref_mode-image_desc-hmc_xfm.txt
  2. sub-01/ses-01/func/sub-01_ses-01_task-rest_from-boldref_to-T1w_mode-image_desc-coreg_xfm.txt
  3. sub-01/ses-01/anat/sub-01_ses-01_from-T1w_to-MNI152NLin6Asym_mode-image_xfm.h5

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 2, 2024

Okay, I think it's an issue in the Docker image. I ran ResampleSeries locally and the results look good for boldref-to-T1w-to-MNI6 and orig-to-boldref-to-T1w-to-MNI6. I then tried it on the same files, with the same commands, in the Docker image, and, while boldref-to-T1w-to-MNI6 looks good, orig-to-boldref-to-T1w-to-MNI6 does not. So basically the HMC part is not operating correctly within the Docker image.

I assume the problem is buried in one of the Python dependencies in my Docker image.

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 3, 2024

@effigies I bumped my local nitransforms from 23.0.1 to 24.0.0 and the orig-to-boldref-to-T1w-to-MNI6 result started looking bad. Is there some chance an issue with using fMRIPrep's HMC transforms was introduced in nitransforms 24.0.0?

@effigies
Copy link
Member

effigies commented Sep 3, 2024

Can you decompose that? I don't think anything should have changed in HMC, but we did fix the parsing of the ITK warps, which might have broken our workaround in nipreps...

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 3, 2024

I can create a minimal reproducible example, probably.

Here's a more linear summary:

  1. I ran fMRIPrep 24.0.0 on a single BOLD run with 100 volumes. I included func and MNI152NLin6Asym:res-2 as output spaces.
  2. I pulled the fMRIPost-AROMA Docker image, which has nitransforms 24.0.0 installed.
  3. I created a Python 3.10 environment on my laptop with nitransforms 23.0.1.
  4. I applied the coregistration and normalization transforms to the func-space derivatives from fMRIPrep with ResampleSeries, both in my Docker container and in my local environment. Both produce reasonable MNI152NLin6Asym-space outputs.
  5. I also applied the motion correction, coregistration, and normalization transforms to the raw BOLD file with ResampleSeries in both the Docker and environment. The Docker container (nitransforms 24.0.0) produced an output that looks like the blue brain in the above figure. The local environment (nitransforms 23.0.1) produced an output that looks good.
  6. Then I updated my local environment's version of nitransforms to 24.0.0 and re-ran my ResampleSeries command. The output now looks like the bad Docker-produced one.

@effigies
Copy link
Member

effigies commented Sep 3, 2024

Okay. Damn. We probably need to roll back nitransforms in the fmriprep 24.1.0 branch.

@effigies
Copy link
Member

effigies commented Sep 3, 2024

Actually, would you mind re-testing with fmriprep 24.1.0rc0, to verify that the problem exhibits there as well?

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 3, 2024

I can run the subject through the full pipeline later today, but in case it's informative, I pulled nipreps/fmriprep:24.0.0 and nipreps/fmriprep:24.1.0rc0 and ran just the ResampleSeries command with those. The results look good for 24.0.0, but not for 24.1.0rc0.

@tsalo
Copy link
Collaborator Author

tsalo commented Sep 3, 2024

I've got fMRIPrep running with 24.1.0rc0 and I'll update this thread with my results once it finishes.

The good news is that I pinned nitransforms to 23.0.1 and rebuilt the fMRIPost-AROMA container, and the results look solid to me, so I'm going to merge this PR.

@tsalo tsalo merged commit d84d680 into nipreps:main Sep 3, 2024
10 of 12 checks passed
@tsalo tsalo deleted the minimal-resampling branch September 3, 2024 16:04
@tsalo
Copy link
Collaborator Author

tsalo commented Sep 4, 2024

We're having server issues right now so it might be a few days before I can resubmit my fMRIPrep 24.1.0rc0 job.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants