|
| 1 | +"""``rbc longitudinal all`` subcommand (placeholder for Stage 6).""" |
| 2 | + |
| 3 | +from __future__ import annotations |
| 4 | + |
| 5 | +from dataclasses import dataclass |
| 6 | +from typing import TYPE_CHECKING |
| 7 | + |
| 8 | +from rbc.cli.base import _or_default, _validate_nifti_path, _validate_positive |
| 9 | +from rbc.cli.longitudinal._base import LongitudinalBaseArgs, add_fs_license_argument |
| 10 | +from rbc.cli.metrics import _resolve_atlas_args |
| 11 | +from rbc.orchestration import Filters, RunnerConfig |
| 12 | +from rbc.orchestration.longitudinal.all import run |
| 13 | +from rbc_resources import ATLAS_REGISTRY, REGISTRATION_TEMPLATES |
| 14 | + |
| 15 | +if TYPE_CHECKING: |
| 16 | + import argparse |
| 17 | + from collections.abc import Sequence |
| 18 | + from pathlib import Path |
| 19 | + |
| 20 | + |
| 21 | +@dataclass(frozen=True) |
| 22 | +class AllLongArgs(LongitudinalBaseArgs): |
| 23 | + """Arguments for ``rbc longitudinal all``.""" |
| 24 | + |
| 25 | + registration_template: Path |
| 26 | + atlas_files: dict[str, Path] |
| 27 | + fwhm: float |
| 28 | + |
| 29 | + @classmethod |
| 30 | + def validate_namespace(cls, ns: argparse.Namespace) -> AllLongArgs: |
| 31 | + """Validate namespace for the full longitudinal pipeline subcommand.""" |
| 32 | + _validate_positive(ns.fwhm, "FWHM") |
| 33 | + return cls( |
| 34 | + **LongitudinalBaseArgs.validate_namespace(ns).__dict__, |
| 35 | + registration_template=_or_default( |
| 36 | + ns.anat_template, REGISTRATION_TEMPLATES.brain_1mm |
| 37 | + ), |
| 38 | + atlas_files=_resolve_atlas_args(ns.atlas), |
| 39 | + fwhm=ns.fwhm, |
| 40 | + ) |
| 41 | + |
| 42 | + |
| 43 | +def main(args: AllLongArgs) -> int: |
| 44 | + """Run the combined longitudinal pipeline.""" |
| 45 | + run( |
| 46 | + input_dirs=args.input_dirs, |
| 47 | + output_dir=args.output_dir, |
| 48 | + filters=Filters( |
| 49 | + participant_label=args.participant_label, |
| 50 | + session_label=args.session_label, |
| 51 | + ), |
| 52 | + fs_license=args.fs_license, |
| 53 | + atlas_files=args.atlas_files, |
| 54 | + fwhm=args.fwhm, |
| 55 | + runner_config=RunnerConfig( |
| 56 | + runner=args.runner, |
| 57 | + verbose=bool(args.verbose), |
| 58 | + tmp_dir=args.tmp_dir, |
| 59 | + ants_threads=args.ants_threads, |
| 60 | + ), |
| 61 | + ) |
| 62 | + return 0 |
| 63 | + |
| 64 | + |
| 65 | +def register_command( |
| 66 | + subparsers: argparse._SubParsersAction, |
| 67 | + parents: Sequence[argparse.ArgumentParser], |
| 68 | +) -> None: |
| 69 | + """Register ``rbc longitudinal all`` (Stage 6 placeholder).""" |
| 70 | + parser = subparsers.add_parser( |
| 71 | + "all", |
| 72 | + parents=parents, |
| 73 | + description=( |
| 74 | + "Run the full longitudinal pipeline (template → anat → func → " |
| 75 | + "metrics → qc). Placeholder wired up by Stage 3; full " |
| 76 | + "implementation ships in Stage 6." |
| 77 | + ), |
| 78 | + help="Full longitudinal pipeline (Stage 6)", |
| 79 | + usage=( |
| 80 | + "rbc longitudinal all INPUT_DIR [INPUT_DIR ...] -o OUTPUT_DIR [options]" |
| 81 | + ), |
| 82 | + ) |
| 83 | + add_fs_license_argument(parser) |
| 84 | + parser.add_argument( |
| 85 | + "--atlas", |
| 86 | + nargs="+", |
| 87 | + default=["schaefer_200"], |
| 88 | + metavar="ATLAS", |
| 89 | + help=( |
| 90 | + "Atlas(es) for timeseries extraction. Accepts registry names " |
| 91 | + f"({', '.join(sorted(ATLAS_REGISTRY))}) or paths to custom NIfTI " |
| 92 | + "atlas files." |
| 93 | + ), |
| 94 | + ) |
| 95 | + parser.add_argument( |
| 96 | + "--fwhm", |
| 97 | + type=float, |
| 98 | + default=6.0, |
| 99 | + help="Smoothing kernel FWHM in mm.", |
| 100 | + ) |
| 101 | + |
| 102 | + templates = parser.add_argument_group("template overrides") |
| 103 | + templates.add_argument( |
| 104 | + "--anat-template", |
| 105 | + type=_validate_nifti_path, |
| 106 | + default=None, |
| 107 | + help="Custom brain template for anatomical registration.", |
| 108 | + ) |
| 109 | + |
| 110 | + parser.set_defaults(func=lambda args: main(AllLongArgs.validate_namespace(args))) |
0 commit comments