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 FMAP conversion capability for ADNI #1119

Merged
merged 16 commits into from
May 7, 2024

Conversation

tharpm95
Copy link
Contributor

@tharpm95 tharpm95 commented Apr 3, 2024

Closes #1044

Features:

  • Added FMAP modality flag for ADNI (-m FMAP)
  • Convert field maps present in ADNI source data to match BIDS specifications
  • Fulfills BIDS specification version 1.1.1 section 8.3.5.1 Case 1: Phase difference image and at least one magnitude image
  • Fulfills BIDS specification version 1.1.1 section 8.3.5.2 Case 2: Two phase images and two magnitude images

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks for the PR @tharpm95 !

I started reviewing it but stopped about halfway. I think there are some important points we need to tackle:

  • First of all, the PR is huge and I believe this is mostly due to changes that are unrelated to the functionality you are adding. For example, changing the way CSV files are loaded, or changing the n_jobs option. It is clearly visible when looking at the number of files that are modified (basically all modalities of ADNI were modified while this PR is supposed to add a new one).
  • These unrelated changes are actually undoing things that we did in the recent past (and for good reasons). If you are having issues with some of them, please open a dedicated issue such that we can work on what's going wrong.

I think we should remove all of these unrelated changes to focus on the core of your proposal. On this subject, I was mainly concerned with the giant for loop renaming files (see comment below).

It could be helpful to have a small toy dataset on which we could try the converter.
Do you have a small list of ADNI subjects you used to work on this ?

Do not hesitate if some points are unclear.

.gitignore Outdated Show resolved Hide resolved
clinica/iotools/bids_utils.py Outdated Show resolved Hide resolved
clinica/iotools/bids_utils.py Outdated Show resolved Hide resolved
clinica/iotools/bids_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
@tharpm95
Copy link
Contributor Author

Thanks for the PR @tharpm95 !

I started reviewing it but stopped about halfway. I think there are some important points we need to tackle:

  • First of all, the PR is huge and I believe this is mostly due to changes that are unrelated to the functionality you are adding. For example, changing the way CSV files are loaded, or changing the n_jobs option. It is clearly visible when looking at the number of files that are modified (basically all modalities of ADNI were modified while this PR is supposed to add a new one).
  • These unrelated changes are actually undoing things that we did in the recent past (and for good reasons). If you are having issues with some of them, please open a dedicated issue such that we can work on what's going wrong.

I think we should remove all of these unrelated changes to focus on the core of your proposal. On this subject, I was mainly concerned with the giant for loop renaming files (see comment below).

Apologies for this, you are correct that some changes are unrelated to the specific feature. I will work on removing them and open an issue related to the miscellaneous changes I made (mostly related to an issue where my CSV files contained double quotes which interfered with parsing)

It could be helpful to have a small toy dataset on which we could try the converter. Do you have a small list of ADNI subjects you used to work on this ?

I do have a small set of ADNI subjects I used for this. I used a set of approximately 30 of the most recent scans. I can share these IDs if needed or use another list of subjects if you prefer.

Do not hesitate if some points are unclear.

Thank-you, noted!

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks for your quick response @tharpm95 ! 👍

The diff is already much easier to make sense of. It is still pretty huge in adni_utils.py and I'm not sure to understand why (will try to have a closer look soon).

I made another quick pass with some questions and suggestions along the way.

From what I understand from #1136, you were having some issues with additional double quotes in the CSV files but the load_clinical_csv() function seems to be solving the problem, is that correct ? (Looking at the function it feels weird that it can solve this issue tbh).

Still, if this is the case, there are still a few places where this should be used and the manual cleaning of double quote be removed.
If not, we should definitely investigate this problem.

I think it'd be convenient to have a common toy dataset to try the converter on both sides. If you can send me the list of patient IDs you are using, that'd be perfect ! (My email address is on my profile, you can use either @gmail.com or @inria.fr).

clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
clinica/iotools/converters/adni_to_bids/adni_utils.py Outdated Show resolved Hide resolved
@tharpm95
Copy link
Contributor Author

tharpm95 commented Apr 11, 2024

Thanks for your quick response @tharpm95 ! 👍

The diff is already much easier to make sense of. It is still pretty huge in adni_utils.py and I'm not sure to understand why (will try to have a closer look soon).

Sure thing and sounds good! Yes, the diff is cluttered and difficult to make sense of. Upon looking at my code outside of the diff, it appears that the same functionality is there, but chopped to pieces and moved around, hence the diff confusion. The reason for this is because I wrote a special case to handle the field maps. For some reason, if I go only off the image IDs in MRILIST, then not every field map is captured for each visit. Instead, I take a particular image ID corresponding to a field map, and write a special case to move back a directory and search for other image IDs in that same visit, and use all IDs from the visit. This way we capture all the magnitude and phase scans as opposed to just one of the scans that was being grabbed from MRILIST.

I made another quick pass with some questions and suggestions along the way.

Thank-you, I've now provided comments for these.

From what I understand from #1136, you were having some issues with additional double quotes in the CSV files but the load_clinical_csv() function seems to be solving the problem, is that correct ? (Looking at the function it feels weird that it can solve this issue tbh).

Still, if this is the case, there are still a few places where this should be used and the manual cleaning of double quote be removed. If not, we should definitely investigate this problem.

Yes, I had not seen the load_clinical_csv function previously so I thought that this fixed the double quote issue since it was mentioned as solving CSV inconsistencies, but I think this particular case is not written in the function so code could be added for removing double quotes if they exist. I will reopen the issue.

I think it'd be convenient to have a common toy dataset to try the converter on both sides. If you can send me the list of patient IDs you are using, that'd be perfect ! (My email address is on my profile, you can use either @gmail.com or @inria.fr).

E-mail sent!

@tharpm95
Copy link
Contributor Author

The most recent commit incorrectly references issue #2, I meant to say that its the second round of adjusted comments.

This version of the code ran successfully on the list of participants provided via e-mail.

Copy link
Contributor

@AliceJoubert AliceJoubert left a comment

Choose a reason for hiding this comment

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

Hello @tharpm95 ! I tested your PR and have succeeded in obtaining a BIDS after modifying it a bit. I will be adding my commits to your PR to share those changes with you.

@tharpm95
Copy link
Contributor Author

Hello @tharpm95 ! I tested your PR and have succeeded in obtaining a BIDS after modifying it a bit. I will be adding my commits to your PR to share those changes with you.

Awesome! I will be glad to view those changes once you commit.

@NicolasGensollen
Copy link
Member

Hello @tharpm95 ! I tested your PR and have succeeded in obtaining a BIDS after modifying it a bit. I will be adding my commits to your PR to share those changes with you.

Awesome! I will be glad to view those changes once you commit.

@tharpm95 They are in this PR on your fork: IUSCA#1
Note that dev was merged in to obtain some recent fixes, which is why you have so many changes.

@@ -109,11 +108,8 @@ def compute_t1_paths(source_dir, csv_dir, subjs_list, conversion_dir):
mri_quality = load_clinical_csv(csv_dir, "MRIQUALITY")
mayo_mri_qc = load_clinical_csv(csv_dir, "MAYOADIRL_MRI_IMAGEQC_12_08_15")

# Keep only T1 scans
mayo_mri_qc = mayo_mri_qc[mayo_mri_qc.series_type == "T1"]
Copy link
Member

Choose a reason for hiding this comment

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

@tharpm95 any reasons for removing this line from the T1 converter ?

Copy link
Contributor Author

@tharpm95 tharpm95 May 3, 2024

Choose a reason for hiding this comment

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

I can't recall any reason. Maybe I mistakenly left it removed during debugging to figure out how specific modalities are accessed to build the image list. I will double check this to see if having it caused issues for any reason.

Copy link
Member

Choose a reason for hiding this comment

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

Could you restore it ?

@NicolasGensollen
Copy link
Member

@tharpm95 also, I see that the linter is not happy. Could you install the pre-commit hook to automatically format your code ?

The command is:

$ pre-commit install

from the root folder of clinica.

@tharpm95
Copy link
Contributor Author

tharpm95 commented May 3, 2024

@tharpm95 also, I see that the linter is not happy. Could you install the pre-commit hook to automatically format your code ?

The command is:

$ pre-commit install

from the root folder of clinica.

Sure, I will do this.

@tharpm95
Copy link
Contributor Author

tharpm95 commented May 6, 2024

I have incorporated pre-commit. Hopefully everything looks ok now.

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @tharpm95 !
A few small suggestions.
This PR is starting to grow a lot, I think a possible way forward would be to merge this into dev once the review process is finished, and we will work with @AliceJoubert on refactoring a bit the portions of the code that are likely to become maintenance pain points in the future (thinking about the giant renaming loop for instance).
Would that work for you ?

@@ -109,11 +108,8 @@ def compute_t1_paths(source_dir, csv_dir, subjs_list, conversion_dir):
mri_quality = load_clinical_csv(csv_dir, "MRIQUALITY")
mayo_mri_qc = load_clinical_csv(csv_dir, "MAYOADIRL_MRI_IMAGEQC_12_08_15")

# Keep only T1 scans
mayo_mri_qc = mayo_mri_qc[mayo_mri_qc.series_type == "T1"]
Copy link
Member

Choose a reason for hiding this comment

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

Could you restore it ?

clinica/iotools/bids_utils.py Outdated Show resolved Hide resolved
clinica/iotools/bids_utils.py Outdated Show resolved Hide resolved
test/nonregression/iotools/test_run_converters.py Outdated Show resolved Hide resolved
@tharpm95
Copy link
Contributor Author

tharpm95 commented May 6, 2024

Thanks @tharpm95 ! A few small suggestions. This PR is starting to grow a lot, I think a possible way forward would be to merge this into dev once the review process is finished, and we will work with @AliceJoubert on refactoring a bit the portions of the code that are likely to become maintenance pain points in the future (thinking about the giant renaming loop for instance). Would that work for you ?

Yes, that works for me. I will go ahead and fix those other code issues highlighted above now as well.

try:
conversion_df = converted_dict[converted_mod]
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you move that line again ? (1123 to 1119)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I will move conversion_df to above the try statement

if error_msg:
cprint(msg=error_msg, lvl="error")
raise ValueError(error_msg)
file_without_extension.with_: wqsuffix(".nii").unlink()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
file_without_extension.with_: wqsuffix(".nii").unlink()
file_without_extension.with_suffix(".nii").unlink()

This one is definitely my mistake but it should go back to this, so I would appreciate it if you made the modification

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted

@tharpm95
Copy link
Contributor Author

tharpm95 commented May 6, 2024

I've addressed the additional issues above! Thanks for the collaboration so far.

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

I think those are the last remaining complaints from the linter

@tharpm95
Copy link
Contributor Author

tharpm95 commented May 6, 2024

More linting issues fixed.

Copy link
Member

@NicolasGensollen NicolasGensollen left a comment

Choose a reason for hiding this comment

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

Thanks @tharpm95 !
The two failures on the converter test suite are expected since the ADNI-to-BIDS now produces a fmap.tsv file in the conversion_info folder. I'll update the dataset on the CI machines to reflect that.
The PR LGTM and I think we can merge into dev and iterate on adni_fmap.py in follow-up PRs, but let's wait for @AliceJoubert to approve first (or ask additional changes if needed).

@AliceJoubert
Copy link
Contributor

Thanks @tharpm95 and @NicolasGensollen !

Looks good to me too

@NicolasGensollen NicolasGensollen merged commit f5b6442 into aramis-lab:dev May 7, 2024
14 of 16 checks passed
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.

Does the Clinica ADNI-to-BIDS pipeline build field maps?
3 participants