Skip to content

Commit

Permalink
Update to match neurodatascience/nipoppy:main (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
michellewang authored Jun 13, 2024
2 parents 307dbbd + 3f02887 commit eaad57a
Show file tree
Hide file tree
Showing 71 changed files with 1,162 additions and 1,127 deletions.
17 changes: 5 additions & 12 deletions nipoppy_cli/nipoppy/cli/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,7 @@
from pathlib import Path

from nipoppy.layout import DEFAULT_LAYOUT_INFO
from nipoppy.utils import (
BIDS_SESSION_PREFIX,
BIDS_SUBJECT_PREFIX,
check_participant,
check_session,
)
from nipoppy.utils import BIDS_SESSION_PREFIX, BIDS_SUBJECT_PREFIX

PROGRAM_NAME = "nipoppy"
COMMAND_INIT = "init"
Expand Down Expand Up @@ -51,16 +46,14 @@ def add_arg_simulate(parser: _ActionsContainer) -> _ActionsContainer:


def add_args_participant_and_session(parser: _ActionsContainer) -> _ActionsContainer:
"""Add --participant and --session arguments to the parser."""
"""Add --participant-id and --session-id arguments to the parser."""
parser.add_argument(
"--participant",
type=check_participant,
"--participant-id",
required=False,
help=f"Participant ID (with or without the {BIDS_SUBJECT_PREFIX} prefix).",
)
parser.add_argument(
"--session",
type=check_session,
"--session-id",
required=False,
help=f"Session ID (with or without the {BIDS_SESSION_PREFIX} prefix).",
)
Expand Down Expand Up @@ -211,7 +204,7 @@ def add_subparser_dicom_reorg(
"""Add subparser for reorg command."""
description = (
"(Re)organize raw (DICOM) files, from the raw DICOM directory "
f"({DEFAULT_LAYOUT_INFO.dpath_raw_dicom}) to the organized "
f"({DEFAULT_LAYOUT_INFO.dpath_raw_imaging}) to the organized "
f"sourcedata directory ({DEFAULT_LAYOUT_INFO.dpath_sourcedata})."
)
parser = subparsers.add_parser(
Expand Down
12 changes: 6 additions & 6 deletions nipoppy_cli/nipoppy/cli/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def cli(argv: Sequence[str] = None) -> None:
pipeline_name=args.pipeline,
pipeline_version=args.pipeline_version,
pipeline_step=args.pipeline_step,
participant=args.participant,
session=args.session,
participant_id=args.participant_id,
session_id=args.session_id,
simulate=args.simulate,
**workflow_kwargs,
)
Expand All @@ -78,8 +78,8 @@ def cli(argv: Sequence[str] = None) -> None:
pipeline_name=args.pipeline,
pipeline_version=args.pipeline_version,
pipeline_step=args.pipeline_step,
participant=args.participant,
session=args.session,
participant_id=args.participant_id,
session_id=args.session_id,
simulate=args.simulate,
**workflow_kwargs,
)
Expand All @@ -88,8 +88,8 @@ def cli(argv: Sequence[str] = None) -> None:
dpath_root=dpath_root,
pipeline_name=args.pipeline,
pipeline_version=args.pipeline_version,
participant=args.participant,
session=args.session,
participant_id=args.participant_id,
session_id=args.session_id,
**workflow_kwargs,
)
else:
Expand Down
34 changes: 14 additions & 20 deletions nipoppy_cli/nipoppy/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
BIDS_SESSION_PREFIX,
StrOrPathLike,
apply_substitutions_to_json,
check_session,
check_session_strict,
load_json,
)

Expand All @@ -26,8 +24,13 @@ class Config(SchemaWithContainerConfig):
"""Schema for dataset configuration."""

DATASET_NAME: str = Field(description="Name of the dataset")
VISITS: list[str] = Field(description="List of visits available in the study")
SESSIONS: Optional[list[str]] = Field(
VISIT_IDS: list[str] = Field(
description=(
"List of visits available in the study. A visit ID is an identifier "
"for a data collection event, not restricted to imaging data."
)
)
SESSION_IDS: Optional[list[str]] = Field(
default=None, # will be a list after validation
description=(
"List of BIDS-compliant sessions available in the study"
Expand All @@ -42,15 +45,15 @@ class Config(SchemaWithContainerConfig):
", to be used in the DICOM reorg step. Note: this field and "
"DICOM_DIR_PARTICIPANT_FIRST cannot both be specified"
f'. The CSV should have three columns: "{DicomDirMap.col_participant_id}"'
f' , "{DicomDirMap.col_session}"'
f' , "{DicomDirMap.col_session_id}"'
f', and "{DicomDirMap.col_participant_dicom_dir}"'
),
)
DICOM_DIR_PARTICIPANT_FIRST: Optional[bool] = Field(
default=None,
description=(
"Whether subdirectories under the raw dicom directory (default: "
f"{DEFAULT_LAYOUT_INFO.dpath_raw_dicom}) follow the pattern "
f"{DEFAULT_LAYOUT_INFO.dpath_raw_imaging}) follow the pattern "
"<PARTICIPANT>/<SESSION> (default) or <SESSION>/<PARTICIPANT>. Note: "
"this field and and DICOM_DIR_MAP_FILE cannot both be specified"
),
Expand All @@ -76,12 +79,6 @@ class Config(SchemaWithContainerConfig):

model_config = ConfigDict(extra="forbid")

def _check_sessions_have_prefix(self) -> Self:
"""Check that sessions have the BIDS prefix."""
for session in self.SESSIONS:
check_session_strict(session)
return self

def _check_dicom_dir_options(self) -> Self:
"""Check that only one DICOM directory mapping option is given."""
if (
Expand Down Expand Up @@ -137,21 +134,18 @@ def _propagate(pipeline_configs: list[PipelineConfig]):
@classmethod
def check_input(cls, data: Any):
"""Validate the raw input."""
key_sessions = "SESSIONS"
key_visits = "VISITS"
key_session_ids = "SESSION_IDS"
key_visit_ids = "VISIT_IDS"
if isinstance(data, dict):
# if sessions are not given, infer from visits
if key_sessions not in data:
data[key_sessions] = [
check_session(visit) for visit in data[key_visits]
]
# if session_ids is not given, set to be the same as visit_ids
if key_session_ids not in data:
data[key_session_ids] = data[key_visit_ids]

return data

@model_validator(mode="after")
def validate_and_process(self) -> Self:
"""Validate and process the configuration."""
self._check_sessions_have_prefix()
self._check_dicom_dir_options()
self._check_no_duplicate_pipeline()
return self
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"command-line-flag": "-d",
"value-key": "[DICOM_DIR]",
"default-value": [
"[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT]]/[[NIPOPPY_SESSION]]"
"[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT_ID]]/[[NIPOPPY_BIDS_SESSION]]"
]
},
{
Expand All @@ -26,7 +26,7 @@
"optional": false,
"command-line-flag": "-p",
"value-key": "[PARTICIPANT]",
"default-value": "[[NIPOPPY_PARTICIPANT]]"
"default-value": "[[NIPOPPY_PARTICIPANT_ID]]"
},
{
"name": "session",
Expand All @@ -36,7 +36,7 @@
"optional": true,
"command-line-flag": "-s",
"value-key": "[SESSION]",
"default-value": "[[NIPOPPY_SESSION_SHORT]]"
"default-value": "[[NIPOPPY_SESSION_ID]]"
},
{
"name": "config",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"command-line-flag": "-d",
"value-key": "[DICOM_DIR]",
"default-value": [
"[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT]]/[[NIPOPPY_SESSION]]"
"[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT_ID]]/[[NIPOPPY_BIDS_SESSION]]"
]
},
{
Expand Down
10 changes: 5 additions & 5 deletions nipoppy_cli/nipoppy/data/descriptors/fmriprep-20.2.7.json
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
"list": true,
"command-line-flag": "--participant-label",
"default-value": [
"[[NIPOPPY_PARTICIPANT]]"
"[[NIPOPPY_PARTICIPANT_ID]]"
]
},
{
Expand Down Expand Up @@ -451,7 +451,7 @@
"type": "String",
"value-key": "[FS_SUBJECTS_DIR]",
"command-line-flag": "--fs-subjects-dir",
"default-value": "[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/6.0.1/output/[[NIPOPPY_SESSION]]"
"default-value": "[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/6.0.1/output/[[NIPOPPY_BIDS_SESSION]]"
},
{
"id": "hires",
Expand Down Expand Up @@ -606,14 +606,14 @@
"CONTAINER_CONFIG": {
"ARGS": [
"--bind",
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/6.0.1/output/[[NIPOPPY_SESSION]]"
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/6.0.1/output/[[NIPOPPY_BIDS_SESSION]]"
]
}
},
"nipoppy_old": {
"paths_to_tar": [
"[[NIPOPPY_DPATH_PIPELINE_OUTPUT]]/fmriprep/sub-[[NIPOPPY_PARTICIPANT]]/ses-[[NIPOPPY_SESSION]]",
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/6.0.1/output/[[NIPOPPY_SESSION]]/sub-[[NIPOPPY_PARTICIPANT]]"
"[[NIPOPPY_DPATH_PIPELINE_OUTPUT]]/fmriprep/sub-[[NIPOPPY_PARTICIPANT_ID]]/ses-[[NIPOPPY_BIDS_SESSION]]",
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/6.0.1/output/[[NIPOPPY_BIDS_SESSION]]/sub-[[NIPOPPY_PARTICIPANT_ID]]"
]
}
}
Expand Down
10 changes: 5 additions & 5 deletions nipoppy_cli/nipoppy/data/descriptors/fmriprep-23.1.3.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"list": true,
"command-line-flag": "--participant-label",
"default-value": [
"[[NIPOPPY_PARTICIPANT]]"
"[[NIPOPPY_PARTICIPANT_ID]]"
]
},
{
Expand Down Expand Up @@ -509,7 +509,7 @@
"type": "String",
"value-key": "[FS_SUBJECTS_DIR]",
"command-line-flag": "--fs-subjects-dir",
"default-value": "[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/7.3.2/output/[[NIPOPPY_SESSION]]"
"default-value": "[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/7.3.2/output/[[NIPOPPY_BIDS_SESSION]]"
},
{
"id": "hires",
Expand Down Expand Up @@ -663,14 +663,14 @@
"CONTAINER_CONFIG": {
"ARGS": [
"--bind",
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/7.3.2/output/[[NIPOPPY_SESSION]]"
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/7.3.2/output/[[NIPOPPY_BIDS_SESSION]]"
]
}
},
"nipoppy_old": {
"paths_to_tar": [
"[[NIPOPPY_DPATH_PIPELINE_OUTPUT]]/sub-[[NIPOPPY_PARTICIPANT]]/ses-[[NIPOPPY_SESSION]]",
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/7.3.2/output/[[NIPOPPY_SESSION]]/sub-[[NIPOPPY_PARTICIPANT]]"
"[[NIPOPPY_DPATH_PIPELINE_OUTPUT]]/sub-[[NIPOPPY_PARTICIPANT_ID]]/ses-[[NIPOPPY_BIDS_SESSION]]",
"[[NIPOPPY_DPATH_DERIVATIVES]]/freesurfer/7.3.2/output/[[NIPOPPY_BIDS_SESSION]]/sub-[[NIPOPPY_PARTICIPANT_ID]]"
]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"optional": true,
"command-line-flag": "-d",
"value-key": "[DICOM_DIR_TEMPLATE]",
"default-value": "[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT]]/[[NIPOPPY_SESSION]]/*"
"default-value": "[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT_ID]]/[[NIPOPPY_BIDS_SESSION]]/*"
},
{
"name": "files",
Expand All @@ -41,7 +41,7 @@
"optional": true,
"command-line-flag": "-s",
"value-key": "[SUBJS]",
"default-value": "[[NIPOPPY_PARTICIPANT]]"
"default-value": "[[NIPOPPY_PARTICIPANT_ID]]"
},
{
"name": "converter",
Expand Down Expand Up @@ -120,7 +120,7 @@
"optional": true,
"command-line-flag": "-ss",
"value-key": "[SESSION]",
"default-value": "[[NIPOPPY_SESSION]]"
"default-value": "[[NIPOPPY_BIDS_SESSION]]"
},
{
"name": "bids_options",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"optional": true,
"command-line-flag": "-d",
"value-key": "[DICOM_DIR_TEMPLATE]",
"default-value": "[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT]]/[[NIPOPPY_SESSION]]/*"
"default-value": "[[NIPOPPY_DPATH_SOURCEDATA]]/[[NIPOPPY_PARTICIPANT_ID]]/[[NIPOPPY_BIDS_SESSION]]/*"
},
{
"name": "files",
Expand All @@ -41,7 +41,7 @@
"optional": true,
"command-line-flag": "-s",
"value-key": "[SUBJS]",
"default-value": "[[NIPOPPY_PARTICIPANT]]"
"default-value": "[[NIPOPPY_PARTICIPANT_ID]]"
},
{
"name": "converter",
Expand Down Expand Up @@ -121,7 +121,7 @@
"optional": true,
"command-line-flag": "-ss",
"value-key": "[SESSION]",
"default-value": "[[NIPOPPY_SESSION]]"
"default-value": "[[NIPOPPY_BIDS_SESSION]]"
},
{
"name": "bids_options",
Expand Down
4 changes: 2 additions & 2 deletions nipoppy_cli/nipoppy/data/descriptors/mriqc-23.1.0.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"list": true,
"command-line-flag": "--participant-label",
"default-value": [
"[[NIPOPPY_PARTICIPANT]]"
"[[NIPOPPY_PARTICIPANT_ID]]"
]
},
{
Expand All @@ -93,7 +93,7 @@
"type": "String",
"value-key": "[SESSION_ID]",
"command-line-flag": "--session-id",
"default-value": "[[NIPOPPY_SESSION_SHORT]]"
"default-value": "[[NIPOPPY_SESSION_ID]]"
},
{
"id": "run_id",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"DATASET_NAME": "<DATASET_NAME>",
"VISITS": [
"VISIT_IDS": [
"<VISIT_LABEL>",
"<OTHER_VISIT_LABEL>"
],
"SESSIONS": [
"ses-<SESSION_LABEL>",
"ses-<OTHER_SESSION_LABEL>"
"SESSION_IDS": [
"<SESSION_LABEL>",
"<OTHER_SESSION_LABEL>"
],
"SUBSTITUTIONS": {
"[[NIPOPPY_DPATH_CONTAINERS]]": "<PATH_TO_CONTAINER_STORE_DIRECTORY>",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"DATASET_NAME": "<DATASET_NAME>",
"VISITS": [
"VISIT_IDS": [
"<VISIT_LABEL>",
"<OTHER_VISIT_LABEL>"
],
"SESSIONS": [
"ses-<SESSION_LABEL>",
"ses-<OTHER_SESSION_LABEL>"
"SESSION_IDS": [
"<SESSION_LABEL>",
"<OTHER_SESSION_LABEL>"
],
"SUBSTITUTIONS": {
"[[NIPOPPY_DPATH_CONTAINERS]]": "<PATH_TO_CONTAINER_STORE_DIRECTORY>",
Expand Down
10 changes: 5 additions & 5 deletions nipoppy_cli/nipoppy/data/examples/sample_manifest.csv
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
participant_id,visit,session,datatype
01,BL,ses-BL,"['anat']"
participant_id,visit_id,session_id,datatype
01,BL,BL,"['anat']"
01,M06,,
01,M12,ses-M12,"['anat']"
02,BL,ses-BL,"['anat','dwi']"
01,M12,M12,"['anat']"
02,BL,BL,"['anat','dwi']"
02,M06,,
02,M12,ses-M12,"['anat','dwi']"
02,M12,M12,"['anat','dwi']"
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
{
"NAME": "pipeline_complete",
"PATHS": [
"[[NIPOPPY_BIDS_ID]]/[[NIPOPPY_SESSION]]/anat/[[NIPOPPY_BIDS_ID]]_[[NIPOPPY_SESSION]]_*_T1w.json",
"[[NIPOPPY_BIDS_ID]]_[[NIPOPPY_SESSION]]_*_T1w.html"
"[[NIPOPPY_BIDS_PARTICIPANT]]/[[NIPOPPY_BIDS_SESSION]]/anat/[[NIPOPPY_BIDS_PARTICIPANT]]_[[NIPOPPY_BIDS_SESSION]]_*_T1w.json",
"[[NIPOPPY_BIDS_PARTICIPANT]]_[[NIPOPPY_BIDS_SESSION]]_*_T1w.html"
]
}
]
Loading

0 comments on commit eaad57a

Please sign in to comment.