Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def get_processed_images(
atlas: Optional[str] = None,
) -> list[str]:
"""
Extract image IDs (e.g. ["sub-CLNC01_ses-M000_long-M000M018", "sub-CLNC01_ses-M018_long-M000M018"]) of outputs
Extract image IDs (e.g. ["sub-CLNC01_ses-M000_long-M000+M018", "sub-CLNC01_ses-M018_long-M000+M018"]) of outputs
already processed by T1FreeSurferLongitudinalCorrection pipeline.
"""
image_ids = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_processed_images(
list_participant_id, list_long_id, caps_directory, T1_FS_T_DESTRIEUX
)
image_ids = [
re.search(r"(sub-[a-zA-Z0-9]+)_(long-[a-zA-Z0-9]+)", file).group()
re.search(r"(sub-[a-zA-Z0-9]+)_(long-[a-zA-Z0-9+]+)", file).group()
for file in t1_freesurfer_files
]
return image_ids
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def grab_image_ids_from_caps_directory(

part_ids = ["sub-CLNC01", "sub-CLNC01", "sub-CLNC01" ]
sess_ids = ["ses-M000", "ses-M018", "ses-M036" ]
long_ids = ["long-M000M018", "long-M000M018", "long-M000M018"]
long_ids = ["long-M000+M018", "long-M000+M018", "long-M000+M018"]
(sub-CLNC02 does not have longitudinal ID so it does not appear on the result)

Parameters
Expand Down
8 changes: 4 additions & 4 deletions clinica/utils/longitudinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,16 @@ def get_long_id(session_ids: List[str]) -> str:
>>> get_long_id(['ses-M000'])
'long-M000'
>>> get_long_id(['ses-M000', 'ses-M018', 'ses-M036'])
'long-M000M018M036'
'long-M000+M018+M036'
>>> get_long_id(['ses-M018', 'ses-M036', 'ses-M000'])
'long-M000M018M036'
'long-M000+M018+M036'
"""
if not all([session_id.startswith("ses-") for session_id in session_ids]):
raise ValueError(
"Expected a list of session IDs of the form ses-XXX, "
f"but received {session_ids} instead."
)
return "long-" + "".join(
return "long-" + "+".join(
[session_id.lstrip("ses-") for session_id in sorted(session_ids)]
)

Expand All @@ -62,7 +62,7 @@ def get_participants_long_id(
--------
>>> from clinica.utils.longitudinal import get_participants_long_id
>>> get_participants_long_id(['sub-CLNC01', 'sub-CLNC01', 'sub-CLNC02'], ['ses-M000', 'ses-M018', 'ses-M000'])
['long-M000M018', 'long-M000M018', 'long-M000']
['long-M000+M018', 'long-M000+M018', 'long-M000']
"""
from .participant import get_unique_subjects

Expand Down
20 changes: 10 additions & 10 deletions docs/CAPS/Introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ You will find this notion when working on longitudinal datasets.
This is simply a label that will define the set of sessions considered.
Unlike group, longitudinal template is dedicated to intra-subject analysis.
Besides, the longitudinal label for a participant is defined concatenating the different session labels in alphabetical order so that the longitudinal label will be unique.
For instance, if the intra-subject template is computed on `M018` and `M000` sessions, the longitudinal ID will be `long-M000M018`.
For instance, if the intra-subject template is computed on `M018` and `M000` sessions, the longitudinal ID will be `long-M000+M018`.

## Differences with BIDS

Expand Down Expand Up @@ -123,19 +123,19 @@ groups/

This CAPS folder contains the outputs of longitudinal segmentations performed with [FreeSurfer](../Software/Third-party.md#freesurfer) for a fictional participant `CLNC01` at sessions `M000` and `M018`.
First, the [`t1-freesurfer` pipeline](../Pipelines/T1_FreeSurfer.md) is run on the two sessions.
Then, the [`t1-freesurfer-longitudinal` pipeline](../Pipelines/T1_FreeSurfer_Longitudinal.md) will compute the intra-subject template `sub-CLNC01_long-M000M018` using the `M000` and `M018` sessions.
This template is finally used to longitudinally correct the segmentations, whose results are stored in the `sub-CLNC01_ses-M000.long.sub-CLNC01_long-M000M018` and `sub-CLNC01_ses-M018.long.sub-CLNC01_long-M000M018` folders.
Then, the [`t1-freesurfer-longitudinal` pipeline](../Pipelines/T1_FreeSurfer_Longitudinal.md) will compute the intra-subject template `sub-CLNC01_long-M000+M018` using the `M000` and `M018` sessions.
This template is finally used to longitudinally correct the segmentations, whose results are stored in the `sub-CLNC01_ses-M000.long.sub-CLNC01_long-M000+M018` and `sub-CLNC01_ses-M018.long.sub-CLNC01_long-M000+M018` folders.

Of note, the `<time_point_id>.long.<template_id>` naming comes from [FreeSurfer](../Software/Third-party.md#freesurfer) when running the longitudinal `recon-all` command.

```Text
dataset_description.json
subjects/
├── sub-CLNC01/
│ ├── long-M000M018/
│ │ ├── long-M000M018_sessions.tsv
│ ├── long-M000+M018/
│ │ ├── long-M000+M018_sessions.tsv
│ │ └── freesurfer_unbiased_template/
│ │ └── sub-CLNC01_long-M000M018/
│ │ └── sub-CLNC01_long-M000+M018/
│ │ ├── base-tps/
│ │ ├── label/
│ │ ├── mri/
Expand All @@ -150,10 +150,10 @@ subjects/
│ │ │ ├── mri/
│ │ │ ├── stats/
│ │ │ └── surf/
│ │ └── long-M000M018/
│ │ └── long-M000+M018/
│ │ └── freesurfer_longitudinal/
│ │ ├── regional_measures/
│ │ └── sub-CLNC01_ses-M000.long.sub-CLNC01_long-M000M018/
│ │ └── sub-CLNC01_ses-M000.long.sub-CLNC01_long-M000+M018/
│ │ ├── label/
│ │ ├── mri/
│ │ ├── stats/
Expand All @@ -167,10 +167,10 @@ subjects/
│ │ ├── mri/
│ │ ├── stats/
│ │ └── surf/
│ └── long-M000M018
│ └── long-M000+M018
│ └── freesurfer_longitudinal
│ ├── regional_measures
│ └── sub-CLNC01_ses-M018.long.sub-CLNC01_long-M000M018/
│ └── sub-CLNC01_ses-M018.long.sub-CLNC01_long-M000+M018/
│ ├── label/
│ ├── mri/
│ ├── stats/
Expand Down
2 changes: 1 addition & 1 deletion docs/Pipelines/T1_FreeSurfer_Longitudinal.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ Results stored in the following folder of the
[CAPS hierarchy](../../CAPS/Specifications/#t1-freesurfer-longitudinal-freesurfer-based-longitudinal-processing-of-t1-weighted-mr-images):
`subjects/<participant_id>/<long_id>/freesurfer_unbiased_template/<participant_id>_<long_id>`.

`<long_label>` is an identifier defined by concatenating all the sessions associated with the current `<participant_id>` (e.g. if the template for participant `sub-CLNC01` is built from sessions `M00`, `M01`, `M05`, then `<long_label>` will be `M00M01M05`).
`<long_label>` is an identifier defined by concatenating all the sessions associated with the current `<participant_id>` (e.g. if the template for participant `sub-CLNC01` is built from sessions `M00`, `M01`, `M05`, then `<long_label>` will be `M00+M01+M05`).
See [CAPS specifications](../../CAPS/Introduction/#subject-and-group-naming) for full definition and example of `<long_id>`.

This folder contains the standard output structure of the `recon-all` command (`label/`, `mri/`, `surf/`, etc.) already explained in the [`t1-freesurfer`](../T1_FreeSurfer) pipeline.
Expand Down
12 changes: 6 additions & 6 deletions test/unittests/utils/test_longitudinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"session_ids,expected",
[
(["ses-M000"], "long-M000"),
(["ses-M000", "ses-M018", "ses-M036"], "long-M000M018M036"),
(["ses-M018", "ses-M036", "ses-M000"], "long-M000M018M036"),
(["ses-foo", "ses-bar", "ses-baz", "ses-foobar"], "long-barbazfoofoobar"),
(["ses-M000", "ses-M018", "ses-M036"], "long-M000+M018+M036"),
(["ses-M018", "ses-M036", "ses-M000"], "long-M000+M018+M036"),
(["ses-foo", "ses-bar", "ses-baz", "ses-foobar"], "long-bar+baz+foo+foobar"),
],
)
def test_get_long_id(session_ids, expected):
Expand Down Expand Up @@ -40,7 +40,7 @@ def test_get_long_id_errors(session_ids):
(
["sub-CLNC01", "sub-CLNC01", "sub-CLNC02"],
["ses-M000", "ses-M018", "ses-M000"],
["long-M000M018", "long-M000M018", "long-M000"],
["long-M000+M018", "long-M000+M018", "long-M000"],
)
],
)
Expand All @@ -64,8 +64,8 @@ def test_save_long_id(tmp_path):

save_long_id(["ses-M000", "ses-M018", "ses-M036"], output_dir)

assert (output_dir / "long-M000M018M036_sessions.tsv").exists()
saved_ids = (output_dir / "long-M000M018M036_sessions.tsv").read_text()
assert (output_dir / "long-M000+M018+M036_sessions.tsv").exists()
saved_ids = (output_dir / "long-M000+M018+M036_sessions.tsv").read_text()
assert saved_ids == "session_id\nses-M000\nses-M018\nses-M036\n"


Expand Down