Skip to content

Commit

Permalink
T1Linear 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 2e2b6e3 commit 6b284c7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
47 changes: 35 additions & 12 deletions clinica/pipelines/t1_linear/anat_linear_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,45 @@ def __init__(
)

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 T1w image registered
to the MNI152NLin2009cSym template and the affine transformation estimated with ANTs
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 T1W_LINEAR, T1W_LINEAR_CROPPED
from clinica.utils.input_files import (
T1W_LINEAR,
T1W_LINEAR_CROPPED,
T1W_TO_MNI_TRANSFORM,
)
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,
T1W_LINEAR
if self.parameters.get("uncropped_image", False)
else T1W_LINEAR_CROPPED,
if not self.caps_directory.is_dir():
return []
images, _ = clinica_file_reader(
self.subjects,
self.sessions,
self.caps_directory,
T1W_LINEAR
if self.parameters.get("uncropped_image", False)
else T1W_LINEAR_CROPPED,
)
visits_having_image = extract_visits(images)
transformation, _ = clinica_file_reader(
self.subjects,
self.sessions,
self.caps_directory,
T1W_TO_MNI_TRANSFORM,
)
visits_having_transformation = extract_visits(transformation)
return sorted(
list(
set(visits_having_image).intersection(set(visits_having_transformation))
)
processed_visits.extend(extract_visits(cropped_files))
return processed_visits
)

def _check_custom_dependencies(self) -> None:
"""Check dependencies that can not be listed in the `info.json` file."""
Expand Down
13 changes: 5 additions & 8 deletions clinica/utils/testing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,14 +223,11 @@ def _build_subjects(directory: Path, configuration: dict) -> None:
def _build_t1_linear(directory: Path, sub: str, ses: str, config: dict) -> None:
"""Build a fake t1-linear file structure in a CAPS directory."""
uncropped = config.get("uncropped_image", False)
(
directory
/ "subjects"
/ sub
/ ses
/ "t1_linear"
/ f"{sub}_{ses}_space-MNI152NLin2009cSym{'' if uncropped else '_desc-Crop'}_res-1x1x1_T1w.nii.gz"
).touch()
for filename in (
f"{sub}_{ses}_space-MNI152NLin2009cSym{'' if uncropped else '_desc-Crop'}_res-1x1x1_T1w.nii.gz",
f"{sub}_{ses}_space-MNI152NLin2009cSym_res-1x1x1_affine.mat",
):
(directory / "subjects" / sub / ses / "t1_linear" / filename).touch()


def _build_pet_linear(directory: Path, sub: str, ses: str, config: dict) -> None:
Expand Down

0 comments on commit 6b284c7

Please sign in to comment.