From 63c4cea10085c049661e611cf24bbeb9c54fd3e1 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 24 Jul 2024 09:26:07 +0200 Subject: [PATCH] fix output ROI --- src/bidspm/bidspm.py | 12 ------------ src/bidspm/parsers.py | 22 ++++++++-------------- src/cli/getOptionsFromCliArgument.m | 6 +++++- src/cli/inputParserForCreateRoi.m | 1 - tests/test_bidspm.py | 3 --- 5 files changed, 13 insertions(+), 31 deletions(-) diff --git a/src/bidspm/bidspm.py b/src/bidspm/bidspm.py index 06f5d8a12..035c9588a 100755 --- a/src/bidspm/bidspm.py +++ b/src/bidspm/bidspm.py @@ -194,7 +194,6 @@ def create_roi( preproc_dir: Path | None = None, verbosity: str | int = 2, participant_label: list[str] | None = None, - roi_dir: Path | None = None, roi_atlas: str | None = "neuromorphometrics", roi_name: str | list[str] | None = None, space: list[str] | None = None, @@ -202,8 +201,6 @@ def create_roi( options: Path | None = None, ) -> str: roi_name = _cellify(roi_name) if roi_name is not None else None - if roi_dir is None: - roi_dir = output_dir cmd = generate_cmd( bids_dir=bids_dir, @@ -222,8 +219,6 @@ def create_roi( ) cmd += f"{new_line}'roi_atlas', '{roi_atlas}'" cmd += f"{new_line}'roi_name', {roi_name}" - if roi_dir: - cmd += f"{new_line}'roi_dir', '{roi_dir}'" if preproc_dir: cmd += f"{new_line}'preproc_dir', '{preproc_dir}'" cmd = end_cmd(cmd) @@ -393,12 +388,6 @@ def generate_command_create_roi(argv: Any) -> str: parser = sub_command_parser() args = parser.parse_args(argv[1:]) - if args.roi_dir is None or args.roi_dir[0] is None: - roi_dir = args.output_dir[0] - else: - roi_dir = args.roi_dir[0] - roi_dir = Path(roi_dir).absolute() - cmd = create_roi( bids_dir=Path(args.bids_dir[0]).absolute(), output_dir=Path(args.output_dir[0]).absolute(), @@ -406,7 +395,6 @@ def generate_command_create_roi(argv: Any) -> str: preproc_dir=_get_preproc_dir(args), verbosity=_get_verbosity(args), participant_label=args.participant_label, - roi_dir=roi_dir, roi_atlas=_get_roi_atlas(args), roi_name=args.roi_name, space=args.space, diff --git a/src/bidspm/parsers.py b/src/bidspm/parsers.py index c66be9227..3fd0b3939 100644 --- a/src/bidspm/parsers.py +++ b/src/bidspm/parsers.py @@ -234,7 +234,6 @@ def sub_command_parser() -> ArgumentParser: roi_parser = _add_common_arguments(roi_parser) roi_parser = _add_boilerplate_only(roi_parser) roi_parser = _add_space(roi_parser) - roi_parser = _add_roi_dir(roi_parser) roi_parser.add_argument( "--roi_name", help=""" @@ -290,7 +289,14 @@ def sub_command_parser() -> ArgumentParser: action="store_true", default=False, ) - stats_parser = _add_roi_dir(stats_parser) + stats_parser.add_argument( + "--roi_dir", + help=""" + Fullpath to the directory with the regions of interest. + """, + type=str, + nargs=1, + ) stats_parser.add_argument( "--roi_name", help=""" @@ -419,18 +425,6 @@ def _add_skip_validation(parser: ArgumentParser) -> ArgumentParser: return parser -def _add_roi_dir(parser: ArgumentParser) -> ArgumentParser: - parser.add_argument( - "--roi_dir", - help=""" - Fullpath to the directory with the regions of interest. - """, - type=str, - nargs=1, - ) - return parser - - def _add_task(parser: ArgumentParser) -> ArgumentParser: parser.add_argument( "--task", diff --git a/src/cli/getOptionsFromCliArgument.m b/src/cli/getOptionsFromCliArgument.m index 27b55f387..b47089237 100644 --- a/src/cli/getOptionsFromCliArgument.m +++ b/src/cli/getOptionsFromCliArgument.m @@ -150,8 +150,12 @@ end function opt = roiOptions(opt, args) + if isfield(args.Results, 'roi_dir') - opt.dir.roi = args.Results.roi_dir; + opt.dir.roi = args.Results.output_dir; + end + if ismember(lower(args.Results.action), {'create_roi'}) + opt.dir.roi = fullfile(args.Results.output_dir, 'derivatives', 'bidspm-roi'); end if isfield(args.Results, 'roi_atlas') opt.roi.atlas = args.Results.roi_atlas; diff --git a/src/cli/inputParserForCreateRoi.m b/src/cli/inputParserForCreateRoi.m index 597a75697..efd748465 100644 --- a/src/cli/inputParserForCreateRoi.m +++ b/src/cli/inputParserForCreateRoi.m @@ -17,7 +17,6 @@ isLogical = @(x) islogical(x) && numel(x) == 1; addParameter(args, 'space', {}, isCellStr); - addParameter(args, 'roi_dir', '', isDir); addParameter(args, 'preproc_dir', '', isDir); addParameter(args, 'hemisphere', {'L', 'R'}, isCellStr); addParameter(args, 'roi_atlas', 'neuromorphometrics', isInAvailableAtlas); diff --git a/tests/test_bidspm.py b/tests/test_bidspm.py index 378ac4c31..50b3b3e2f 100644 --- a/tests/test_bidspm.py +++ b/tests/test_bidspm.py @@ -180,7 +180,6 @@ def test_create_roi(): preproc_dir=Path(), verbosity=2, participant_label=["01"], - roi_dir=Path(), roi_atlas="neuromorphometrics", roi_name=["foo", "bar"], space=["MNI"], @@ -263,8 +262,6 @@ def test_generate_command_create_roi(analysis_level): "--space", "IXI549Space", "--boilerplate_only", - "--roi_dir", - str(Path().absolute()), "--preproc_dir", str(Path().absolute()), "--hemisphere",