nipoppy.workflows¶
Classes for running workflows on datasets.
Submodules¶
Package Contents¶
- class nipoppy.workflows.BasePipelineWorkflow(dpath_root, name, pipeline_name, pipeline_version=None, pipeline_step=None, participant_id=None, session_id=None, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.base.BaseWorkflow,abc.ABCA workflow for a pipeline that has a Boutiques descriptor.
- Parameters:
- boutiques_config()¶
Get the Boutiques configuration.
- check_dir(dpath)¶
Create directory if it does not exist.
- Parameters:
dpath (pathlib.Path)
- check_pipeline_version()¶
Set the pipeline version based on the config if it is not given.
- dpath_pipeline()¶
Return the path to the pipeline’s derivatives directory.
- Return type:
- dpath_pipeline_bids_db()¶
Return the path to the pipeline’s BIDS database directory.
- Return type:
- dpath_pipeline_output()¶
Return the path to the pipeline’s output directory.
- Return type:
- dpath_pipeline_work()¶
Return the path to the pipeline’s working directory.
- Return type:
- dpaths_to_check()¶
Directory paths to create if needed during the setup phase.
- Return type:
- fpath_container()¶
Return the full path to the pipeline’s container.
- Return type:
- generate_fpath_log(dnames_parent=None, fname_stem=None)¶
Generate a log file path.
- Parameters:
- Return type:
- abstract get_participants_sessions_to_run(participant_id, session_id)¶
Return participant-session pairs to loop over with run_single().
This is an abstract method that should be defined explicitly in subclasses.
- pipeline_config()¶
Get the user config for the pipeline.
- Return type:
- process_template_json(template_json, participant_id, session_id, bids_participant=None, bids_session=None, objs=None, return_str=False, **kwargs)¶
Replace template strings in a JSON object.
- pybids_ignore_patterns()¶
Load the pipeline step’s PyBIDS ignore pattern list.
Note: this does not apply any substitutions, since the subject/session patterns are always added.
- run_cleanup()¶
Log a summary message.
- run_main()¶
Run the pipeline.
- run_setup()¶
Run pipeline setup.
- abstract run_single(participant_id, session_id)¶
Run on a single participant/session.
This is an abstract method that should be defined explicitly in subclasses.
- class nipoppy.workflows.BaseWorkflow(dpath_root, name, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.base.Base,abc.ABCBase class with logging/subprocess utilities.
- Parameters:
dpath_root (nipoppy.env.StrOrPathLike)
name (str)
fpath_layout (Optional[nipoppy.env.StrOrPathLike])
logger (Optional[logging.Logger])
- log_prefix_run = '[RUN]'¶
- log_prefix_run_stderr = '[RUN STDERR]'¶
- log_prefix_run_stdout = '[RUN STDOUT]'¶
- path_sep = '-'¶
- pipeline_name = '[[NIPOPPY_PIPELINE_NAME]]'¶
- pipeline_version = '[[NIPOPPY_PIPELINE_VERSION]]'¶
- validate_layout = True¶
- config()¶
Load the configuration.
- Return type:
- copy(path_source, path_dest, log_level=logging.INFO, **kwargs)¶
Copy a file or directory.
- create_symlink(path_source, path_dest, log_level=logging.INFO, **kwargs)¶
Create a symlink to another path.
- dicom_dir_map()¶
Get the DICOM directory mapping.
- Return type:
- doughnut()¶
Load the doughnut.
- Return type:
- generate_fpath_log(dnames_parent=None, fname_stem=None)¶
Generate a log file path.
- Parameters:
- Return type:
- manifest()¶
Load the manifest.
- Return type:
- mkdir(dpath, log_level=logging.INFO, **kwargs)¶
Create a directory (by default including parents).
Do nothing if the directory already exists.
- rm(path, log_level=logging.INFO, **kwargs)¶
Remove a file or directory.
- run()¶
Run the workflow.
- run_cleanup()¶
Run the cleanup part of the workflow.
- run_command(command_or_args, check=True, **kwargs)¶
Run a command in a subprocess.
The command’s stdout and stderr outputs are written to the log with special prefixes.
If in “dry run” mode, the command is not executed, and the method returns the command string. Otherwise, the subprocess.Popen object is returned unless capture_output is True.
- Parameters:
- Return type:
- abstract run_main()¶
Run the main part of the workflow.
- run_setup()¶
Run the setup part of the workflow.
- save_tabular_file(tabular, fpath)¶
Save a tabular file.
- Parameters:
tabular (nipoppy.tabular.base.BaseTabular)
fpath (pathlib.Path)
- class nipoppy.workflows.BidsConversionRunner(dpath_root, pipeline_name, pipeline_version=None, pipeline_step=None, participant_id=None, session_id=None, simulate=False, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.runner.PipelineRunnerConvert data to BIDS.
- Parameters:
- dpaths_to_check()¶
Directory paths to create if needed during the setup phase.
- Return type:
- get_participants_sessions_to_run(participant_id, session_id)¶
Return participant-session pairs to run the pipeline on.
- pipeline_config()¶
Get the user config for the BIDS conversion software.
- Return type:
- run_cleanup(**kwargs)¶
Clean up after main BIDS conversion part is run.
Specifically: - Write updated doughnut file
- class nipoppy.workflows.DicomReorgWorkflow(dpath_root, copy_files=False, check_dicoms=False, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.base.BaseWorkflowWorkflow for organizing raw DICOM files.
- Parameters:
dpath_root (nipoppy.env.StrOrPathLike)
copy_files (bool)
check_dicoms (bool)
fpath_layout (Optional[nipoppy.env.StrOrPathLike])
logger (Optional[logging.Logger])
dry_run (bool)
- apply_fname_mapping(fname_source, participant_id, session_id)¶
Apply a mapping to the file name.
This method does not change the file name by default, but it can be overridden if the file names need to be changed during reorganization (e.g. for easier BIDS conversion).
- get_fpaths_to_reorg(participant_id, session_id)¶
Get file paths to reorganize for a single participant and session.
- Parameters:
- Return type:
- get_participants_sessions_to_run()¶
Return participant-session pairs to reorganize.
- run_cleanup()¶
Clean up after main DICOM reorg part is run.
Specifically: - Write updated doughnut file - Log a summary message
- run_main()¶
Reorganize all downloaded DICOM files.
- run_setup()¶
Update the doughnut in case it is not up-to-date.
- class nipoppy.workflows.DoughnutWorkflow(dpath_root, empty=False, regenerate=False, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.base.BaseWorkflowWorkflow for creating/updating a dataset’s doughnut file.
- Parameters:
dpath_root (pathlib.Path)
empty (bool)
regenerate (bool)
fpath_layout (Optional[nipoppy.env.StrOrPathLike])
logger (Optional[logging.Logger])
dry_run (bool)
- run_cleanup()¶
Log a success message.
- run_main()¶
Generate/update the dataset’s doughnut file.
- class nipoppy.workflows.InitWorkflow(dpath_root, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.base.BaseWorkflowWorkflow for init command.
- Parameters:
dpath_root (pathlib.Path)
fpath_layout (Optional[nipoppy.env.StrOrPathLike])
logger (Optional[logging.Logger])
dry_run (bool)
- validate_layout = False¶
- run_cleanup()¶
Log a success message.
- run_main()¶
Create dataset directory structure.
- class nipoppy.workflows.PipelineRunner(dpath_root, pipeline_name, pipeline_version=None, pipeline_step=None, participant_id=None, session_id=None, simulate=False, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.pipeline.BasePipelineWorkflowPipeline runner.
- Parameters:
- dpaths_to_check()¶
Directory paths to create if needed during the setup phase.
- Return type:
- get_participants_sessions_to_run(participant_id, session_id)¶
Generate a list of participant and session IDs to run.
Specifically, this list will include participants who have BIDS data but who have not previously successfully completed the pipeline (according) to the bagel file.
- launch_boutiques_run(participant_id, session_id, objs=None, **kwargs)¶
Launch a pipeline run using Boutiques.
- process_container_config(participant_id, session_id, bind_paths=None)¶
Update container config and generate container command.
- run_cleanup()¶
Run pipeline runner cleanup.
- class nipoppy.workflows.PipelineTracker(dpath_root, pipeline_name, pipeline_version=None, participant_id=None, session_id=None, fpath_layout=None, logger=None, dry_run=False)¶
Bases:
nipoppy.workflows.pipeline.BasePipelineWorkflowPipeline tracker.
- Parameters:
- check_status(relative_paths)¶
Check the processing status based on a list of expected paths.
- Parameters:
relative_paths (nipoppy.env.StrOrPathLike)
- get_participants_sessions_to_run(participant_id, session_id)¶
Get participant-session pairs with BIDS data to run the tracker on.
- run_cleanup()¶
Save the bagel file.
- run_setup()¶
Load/initialize the bagel file.