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

Iterating over multiple pairs of PET and T1w files #13

Merged
merged 7 commits into from
Aug 31, 2023

Conversation

bilgelm
Copy link
Contributor

@bilgelm bilgelm commented Aug 26, 2023

Fixes #6 by throwing RuntimeError if there are no T1w images for a given participant.

Resolves #8 by implementing init_single_subject_wf. (This also fixes #5.) I couldn't get this approach to work with create_weighted_average_pet and create_apply_str, so I wrote the wrappers WeightedAverage and ApplyMideface. I replaced shutil file copying with nipype's DataSink, but only the "derivatives" option of PetDeface's placement argument is currently implemented.

Minor bug fix for weighted average PET: previous implementation used the sum of mid time points in the denominator, but this should instead be the range of mid time points (i.e., the duration over which TAC is specified). This change should not affect PET-MR coregistration as mutual information is invariant to scaling.

This pull request simplifies the dependency list by omitting redundant modules from pyproject.toml.

This pull request also implements code formatting with black, flake8, and isort, and sets up pre-commit hooks for these formatting checks.

Copy link
Collaborator

@mnoergaard mnoergaard left a comment

Choose a reason for hiding this comment

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

Many thanks for making this PR, @bilgelm! I am still not quite convinced that the updated data grabbing is the most ideal (I would rather try to make a main workflow grabbing subjects, and then a subsequent subject workflow grabbing all sessions. Because there you can grab just a single MR for a given subject, and then use this to iterate over multiple PET sessions. It also accommodates the inheritance principle). Nevertheless, I am quite happy with the remaining parts of your PR, so many thanks for these edits/comments!

petdeface/petdeface.py Outdated Show resolved Hide resolved
) # better solution would be to add this properly in niworkflows collect_data queries

# Check that PET and T1w files are matched
match_error = "Make sure that each PET has a corresponding T1w in the same session."
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess this goes against the inheritance principle, as you will often see just one anat directory above several session directories with PET data in them. Or if only one MRI is present in a test-retest setting, we should just grab that MRI and use it for both PET files.

Copy link
Contributor Author

@bilgelm bilgelm Aug 30, 2023

Choose a reason for hiding this comment

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

I think my latest commit achieves the desired behavior. My testing has been limited, so hopefully the code covers all possible situations 🤞.

There are ambiguous cases. Let's say a subject has t1w for sessions 1, 2, and 4. Which t1w should be used for pet in session 3? I didn't add anything in my code to "break ties" and favor one of these sessions over the others. (In current implementation, all of these t1ws are tied for best match, and the code would pick ses-01_t1w to process ses-03_pet just because it comes first in the list.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Awesome - thanks @bilgelm! @bendhouseart we should go ahead and make the test cases to verify that this indeed covers the different cases. Regarding the ambiguous cases, workflows like fmriprep and smriprep go ahead an create a single anatomical image using mri_robust_register if more than one anatomical file is available. Difficult to say what would be the optimal usage here, but I would be fine if there is match within a session between PET and anatomical then use that, and if there is no anatomical present, then use the first available anatomical.

@bendhouseart bendhouseart self-requested a review August 28, 2023 13:46
petdeface/pet.py Outdated Show resolved Hide resolved
pyproject.toml Outdated Show resolved Hide resolved
@bendhouseart
Copy link
Collaborator

I'm happy with this barring the committed changes to the pyproject.toml, and as far as the formula I commented on above I defer to you two when it comes to anything relating to TAC's.

Copy link
Collaborator

@bendhouseart bendhouseart left a comment

Choose a reason for hiding this comment

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

LGTM

@mnoergaard
Copy link
Collaborator

This also looks good to me! Thank you so much, Murat! We should, however, still move ahead and create the necessary tests and include them in the repo.

@bendhouseart
Copy link
Collaborator

bendhouseart commented Aug 30, 2023

This also looks good to me! Thank you so much, Murat! We should, however, still move ahead and create the necessary tests and include them in the repo.

Do you want to merge this or create the tests first? We're going to be limited to really simple unit tests unless we do one or more of the following:

  1. set up a self hosted runner
  2. collect faced data that we can distribute off premises
  3. downsample an open faced (hehe) MR image until it looks as good as a pet image or something.

@mnoergaard mnoergaard merged commit 552fb12 into openneuropet:main Aug 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants