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

[ENH] Change long_id format #1416

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
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
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
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
Loading