Skip to content

Commit

Permalink
PetLinear considers visits processed if both image and transformation…
Browse files Browse the repository at this point in the history
… matrix are found
  • Loading branch information
NicolasGensollen committed Nov 29, 2024
1 parent 9eed12f commit 2e2b6e3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 14 deletions.
51 changes: 37 additions & 14 deletions clinica/pipelines/pet/linear/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,47 @@ def _check_custom_dependencies(self) -> None:
pass

def get_processed_visits(self) -> list[Visit]:
"""Return a list of visits for which the pipeline is assumed to have run already.
Before running the pipeline, for a given visit, if both the PET SUVR registered image
and the rigid transformation files already exist, then the visit is added to this list.
The pipeline will further skip these visits and run processing only for the remaining
visits.
"""
from clinica.utils.filemanip import extract_visits
from clinica.utils.input_files import pet_linear_nii
from clinica.utils.input_files import (
pet_linear_nii,
pet_linear_transformation_matrix,
)
from clinica.utils.inputs import clinica_file_reader

processed_visits: list[Visit] = []
if self.caps_directory.is_dir():
cropped_files, _ = clinica_file_reader(
self.subjects,
self.sessions,
self.caps_directory,
pet_linear_nii(
acq_label=self.parameters["acq_label"],
suvr_reference_region=self.parameters["suvr_reference_region"],
uncropped_image=self.parameters.get("uncropped_image", False),
),
if not self.caps_directory.is_dir():
return []
pet_registered_image, _ = clinica_file_reader(
self.subjects,
self.sessions,
self.caps_directory,
pet_linear_nii(
acq_label=self.parameters["acq_label"],
suvr_reference_region=self.parameters["suvr_reference_region"],
uncropped_image=self.parameters.get("uncropped_image", False),
),
)
visits_having_pet_image = extract_visits(pet_registered_image)
transformation, _ = clinica_file_reader(
self.subjects,
self.sessions,
self.caps_directory,
pet_linear_transformation_matrix(tracer=self.parameters["acq_label"]),
)
visits_having_transformation = extract_visits(transformation)
return sorted(
list(
set(visits_having_pet_image).intersection(
set(visits_having_transformation)
)
)
processed_visits.extend(extract_visits(cropped_files))
return processed_visits
)

def get_input_fields(self) -> List[str]:
"""Specify the list of possible inputs of this pipeline.
Expand Down
14 changes: 14 additions & 0 deletions test/unittests/pipelines/pet/test_pet_linear_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,17 @@ def test_pet_linear_get_processed_visits(tmp_path, mocker):
Visit("sub-01", "ses-M006"),
Visit("sub-02", "ses-M000"),
]

# We remove the transformation matrix of the tracer of interest for sub-01 and session M006
(
caps
/ "subjects"
/ "sub-01"
/ "ses-M006"
/ "pet_linear"
/ "sub-01_ses-M006_trc-18FFDG_pet_space-T1w_rigid.mat"
).unlink()

# The corresponding visit is not considered as "processed" anymore because the transformation is
# missing (even though the pet image is still here...)
assert pipeline.get_processed_visits() == [Visit("sub-02", "ses-M000")]

0 comments on commit 2e2b6e3

Please sign in to comment.