-
Notifications
You must be signed in to change notification settings - Fork 72
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
[ENH] Improve BIDS compatibility of PetLinear
CAPS output
#935
Merged
NicolasGensollen
merged 8 commits into
aramis-lab:dev
from
NicolasGensollen:fix-pet-linear-caps-output
Jun 9, 2023
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
315350a
refactor rename_into_caps
NicolasGensollen 480d350
add unit tests
NicolasGensollen 50576f1
fix double pet suffix issue
NicolasGensollen 686fee8
fix path
NicolasGensollen 139ba90
update pipeline connections
NicolasGensollen cd2258f
fix missing imports
NicolasGensollen fa42338
fix writing of outputs in BIDS folder
NicolasGensollen 5bbd017
_get_pet_suffix --> _get_pet_bids_components
NicolasGensollen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
test/unittests/pipelines/pet_linear/test_pet_linear_utils.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
from pathlib import Path | ||
|
||
import pytest | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"cropped,suvr_reference_region,expected", | ||
[ | ||
(False, "foo", "_space-MNI152NLin2009cSym_res-1x1x1_suvr-foo_pet.nii.gz"), | ||
( | ||
True, | ||
"bar", | ||
"_space-MNI152NLin2009cSym_desc-Crop_res-1x1x1_suvr-bar_pet.nii.gz", | ||
), | ||
], | ||
) | ||
def test_get_pet_bids_components(cropped, suvr_reference_region, expected): | ||
from clinica.pipelines.pet_linear.pet_linear_utils import _get_pet_bids_components | ||
|
||
assert _get_pet_bids_components(cropped, suvr_reference_region) == expected | ||
|
||
|
||
def test_rename(tmp_path): | ||
from clinica.pipelines.pet_linear.pet_linear_utils import _rename | ||
|
||
file_to_rename = tmp_path / "foo.nii.gz" | ||
file_to_rename.touch() | ||
source_file = tmp_path / "sub-01_ses-M000_run-01_pet.json" | ||
source_file.touch() | ||
|
||
output_file = _rename( | ||
str(file_to_rename), str(tmp_path / "sub-01_ses-M000_run-01"), "_pet.nii.gz" | ||
) | ||
assert file_to_rename.exists() | ||
assert source_file.exists() | ||
assert Path(output_file) == tmp_path / "sub-01_ses-M000_run-01_pet.nii.gz" | ||
assert Path(output_file).exists() | ||
|
||
|
||
def test_rename_into_caps(tmp_path): | ||
from clinica.pipelines.pet_linear.pet_linear_utils import rename_into_caps | ||
|
||
pet_file_to_rename = tmp_path / "foobarbaz.nii.gz" | ||
pet_file_to_rename.touch() | ||
transformation_file_to_rename = tmp_path / "transformation.mat" | ||
transformation_file_to_rename.touch() | ||
source_file = tmp_path / "sub-01_ses-M000_run-01_pet.nii.gz" | ||
source_file.touch() | ||
a, b, c = rename_into_caps( | ||
str(source_file), | ||
str(pet_file_to_rename), | ||
str(transformation_file_to_rename), | ||
"suvrfoo", | ||
True, | ||
output_dir=tmp_path, # Force the writing to tmp_path instead of current folder... | ||
) | ||
assert ( | ||
Path(a) | ||
== tmp_path | ||
/ "sub-01_ses-M000_run-01_space-MNI152NLin2009cSym_res-1x1x1_suvr-suvrfoo_pet.nii.gz" | ||
) | ||
assert Path(b) == tmp_path / "sub-01_ses-M000_run-01_space-T1w_rigid.mat" | ||
assert c is None |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a comment that we could achieve further compliance by adopting BEP014 which specifies a naming scheme for transformation files, i.e.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably require more surgery to
t1-linear
andpet-linear
though, so it's probably better to leave it for another time. It was just a reminder.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, let's keep that for another PR.
Thanks for the reminder !