Skip to content

Commit

Permalink
[ENH] use sub commands for python CLI (#1292)
Browse files Browse the repository at this point in the history
* start adding sub commands

* preproc subcommand

* deal with create roi parser

* deal with default_model sub command

* deal with bms action

* deal with stats actions

* start adapting cli

* add test for command building

* add test for CLI for preproc, smooth...

* add test for command building for stats

* add test for command building for bms

* rename function

* start switching CLI

* several fixes

* more fix

* keep switchingµ

* fix

* fix

* linti

* fixes

* fixes

* minor fixes

* additional fixes

* fix output ROI

* visualize output in circle ci
  • Loading branch information
Remi-Gau authored Jul 24, 2024
1 parent 344838e commit f4b986f
Show file tree
Hide file tree
Showing 26 changed files with 1,305 additions and 482 deletions.
23 changes: 13 additions & 10 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,11 @@ jobs:
/bids_dataset \
/outputs/ds000001 \
subject \
--action default_model \
default_model \
--task balloonanalogrisktask \
--space MNI152NLin2009cAsym \
--verbosity 3
--verbosity 3 \
--skip_validation
cat /home/circleci/outputs/ds000001/derivatives/models/*.json
Expand All @@ -130,10 +131,11 @@ jobs:
/bids_dataset \
/outputs/ds000001 \
dataset \
--action default_model \
default_model \
--task balloonanalogrisktask \
--space MNI152NLin2009cAsym \
--verbosity 3
--verbosity 3 \
--skip_validation
cat /home/circleci/outputs/ds000001/derivatives/models/*.json
Expand All @@ -147,15 +149,17 @@ jobs:
-v /tmp/workspace/data/ds000001:/bids_dataset \
-v /home/circleci/outputs:/outputs \
<< parameters.dh_orga >>/<< parameters.dh_repo >> \
/outputs/ds000001 \
/bids_dataset \
/outputs/ds000001 \
dataset \
--action create_roi \
create_roi \
--roi_atlas wang \
--roi_name V1v V1d \
--space IXI549Space \
--verbosity 3
cat /home/circleci/outputs
- store_artifacts:
path: /home/circleci/outputs

Expand Down Expand Up @@ -190,7 +194,7 @@ jobs:
/bids_dataset \
/outputs/ds000001 \
subject \
--action smooth \
smooth \
--task balloonanalogrisktask \
--participant_label 01 02 \
--space MNI152NLin2009cAsym \
Expand All @@ -212,10 +216,9 @@ jobs:
/bids_dataset \
/outputs/ds000001 \
subject \
--action stats \
stats \
--preproc_dir /outputs/ds000001/derivatives/bidspm-preproc \
--model_file /models/model-balloonanalogrisktaskDefault_smdl.json \
--ignore slicetiming \
--space MNI152NLin2009cAsym \
--skip_validation \
--fwhm 0 \
Expand All @@ -235,7 +238,7 @@ jobs:
/bids_dataset \
/outputs/ds000001 \
dataset \
--action stats \
stats \
--preproc_dir /outputs/ds000001/derivatives/bidspm-preproc \
--model_file /models/model-balloonanalogrisktaskDefault_smdl.json \
--space MNI152NLin2009cAsym \
Expand Down
4 changes: 2 additions & 2 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[flake8]
max-line-length = 110
max-complexity = 10
max-line-length = 90
max-complexity = 11
ignore = F841, D100, D101, D103, D104
exclude =
*build
Expand Down
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- allow inter session contrasts to be computed at the subject level
- improve naming of contrast to mention bids ses and run

* [ENH] add Bayesian model selection to the python CLI #1292 @Remi-Gau

### Changed


* [ENH] align specification of F contrasts on the BIDS stats model: they should now be specified as a 2D matrix and not a 1D vector. #1276 @Remi-Gau
* [DOC] change theme and structure of the documentation #1256 @Remi-Gau
* [REF] Refactor and update CLI in #1096 @Remi-Gau
* [ENH] {func}`getData` only loads anat data when requested #1257 @Remi-Gau
* [ENH] the python CLI now uses sub-commands instead of the named parameter `--action` #1292 @Remi-Gau

### Deprecated

Expand Down
14 changes: 7 additions & 7 deletions demos/MoAE/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ bidspm \
$PWD/inputs/raw \
$PWD/outputs/derivatives \
subject \
--action preprocess \
preprocess \
--participant_label 01 \
--space individual IXI549Space \
--task auditory \
Expand All @@ -37,7 +37,7 @@ bidspm \
$PWD/inputs/fmriprep \
$PWD/outputs/derivatives \
subject \
--action smooth \
smooth \
--participant_label 01 \
--space '^.*MNI.*$' \
--task auditory \
Expand All @@ -52,7 +52,7 @@ bidspm \
$PWD/inputs/raw \
$PWD/outputs/derivatives \
dataset \
--action default_model \
default_model \
--space IXI549Space \
--task auditory \
--verbosity 2 \
Expand All @@ -66,7 +66,7 @@ bidspm \
$PWD/inputs/raw \
$PWD/outputs/derivatives \
subject \
--action stats \
stats \
--preproc_dir $PWD/outputs/derivatives/bidspm-preproc \
--model_file $PWD/models/model-MoAE_smdl.json \
--fwhm 6
Expand All @@ -77,7 +77,7 @@ bidspm \
$PWD/inputs/raw \
$PWD/outputs/derivatives \
subject \
--action stats \
stats \
--preproc_dir $PWD/outputs/derivatives/bidspm-preproc \
--model_file $PWD/outputs/derivatives/models/model-defaultAuditory_smdl.json \
--fwhm 6
Expand All @@ -96,7 +96,7 @@ docker run -it --rm \
/derivatives \
subject \
--task auditory \
--action preprocess \
preprocess \
--fwhm 8
```

Expand All @@ -111,7 +111,7 @@ docker run -it --rm \
/raw \
/derivatives \
subject \
--action stats \
stats \
--preproc_dir /derivatives/bidspm-preproc \
--model_file /models/model-MoAE_smdl.json \
--fwhm 6
Expand Down
29 changes: 16 additions & 13 deletions demos/MoAE/test_moae.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,18 @@

optionsFile = fullfile(WD, 'options', 'options_task-auditory.json');

space = {'individual'
space = {
'IXI549Space'
'individual'
'IXI549Space'
'individual'};
ignore = {{'unwarp'}
{'unwarp', 'qa'}
ignore = {{'unwarp', 'qa'}
{'unwarp'}
{''}
{''}};

models = {fullfile(WD, 'models', 'model-MoAEindividual_smdl.json')
models = {
fullfile(WD, 'models', 'model-MoAE_smdl.json')
fullfile(WD, 'models', 'model-MoAEindividual_smdl.json')
fullfile(WD, 'models', 'model-MoAE_smdl.json')
fullfile(WD, 'models', 'model-MoAEindividual_smdl.json')};

Expand All @@ -65,14 +66,16 @@
%% stats
preproc_dir = fullfile(output_dir, 'bidspm-preproc');

% only specify the subject level model
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {'01'}, ...
'action', 'stats', ...
'preproc_dir', preproc_dir, ...
'model_file', models{iOption}, ...
'options', optionsFile, ...
'design_only', true);
if ~bids.internal.is_octave() && ~ispc()
% only specify the subject level model
bidspm(bids_dir, output_dir, 'subject', ...
'participant_label', {'01'}, ...
'action', 'stats', ...
'preproc_dir', preproc_dir, ...
'model_file', models{iOption}, ...
'options', optionsFile, ...
'design_only', true);
end

% specify, estimate model and contrasts, and view results
bidspm(bids_dir, output_dir, 'subject', ...
Expand Down
10 changes: 5 additions & 5 deletions demos/face_repetition/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ bidspm \
$PWD/outputs/raw \
$PWD/outputs/derivatives \
subject \
--action preprocess \
preprocess \
--participant_label 01 \
--space individual IXI549Space \
--task facerepetition \
Expand All @@ -25,7 +25,7 @@ bidspm \
$PWD/outputs/raw \
$PWD/outputs/derivatives \
subject \
--action preprocess \
preprocess \
--space individual IXI549Space \
--anat_only \
--skip_validation
Expand All @@ -38,7 +38,7 @@ bidspm \
$PWD/outputs/raw \
$PWD/outputs/derivatives \
subject \
--action create_roi \
create_roi \
--roi_atlas wang \
--roi_name MST hMT
```
Expand All @@ -48,7 +48,7 @@ bidspm \
$PWD/outputs/raw \
$PWD/outputs/derivatives \
subject \
--action create_roi \
create_roi \
--roi_atlas hpcex \
--roi_name MST MT
```
Expand All @@ -65,7 +65,7 @@ docker run -it --rm \
/raw \
/derivatives \
subject \
--action create_roi \
create_roi \
--roi_atlas hcpex \
--roi_name MST MT
```
8 changes: 5 additions & 3 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,13 @@
}

# We recommend adding the following config value.
# Sphinx defaults to automatically resolve *unresolved* labels using all your Intersphinx mappings.
# This behavior has unintended side-effects, namely that documentations local references can
# Sphinx defaults to automatically resolve *unresolved* labels
# using all your Intersphinx mappings.
# This behavior has unintended side-effects,
# namely that documentations local references can
# suddenly resolve to an external location.
# See also:
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_disabled_reftypes
# https://www.sphinx-doc.org/en/master/usage/extensions/intersphinx.html#confval-intersphinx_disabled_reftypes # noqa
# intersphinx_disabled_reftypes = ["*"]

coverage_show_missing_items = True
Expand Down
2 changes: 1 addition & 1 deletion docs/source/images/mermaid.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ graph TD
batch_02 --> E[SPM12]
end

CLI -->|--action results\n--participant-label 01 02\n--model_file smdl.json| bidsResults
CLI -->|results\n--participant-label 01 02\n--model_file smdl.json| bidsResults
4 changes: 2 additions & 2 deletions docs/source/installation/containers.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ docker run -it --rm \
/derivatives \
subject \
--task auditory \
--action preprocess \
preprocess \
--fwhm 8
```

Expand All @@ -68,7 +68,7 @@ docker run -it --rm \
/raw \
/derivatives \
subject \
--action stats \
stats \
--preproc_dir /derivatives/bidspm-preproc \
--model_file /models/smdl.json \
--fwhm 8
Expand Down
2 changes: 1 addition & 1 deletion docs/source/stats/bids_stats_model.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ Subject level contrast averaging beta across runs

```{figure} ./images/gui_contrast_cross_session.png
---
name: contrast_subject
name: contrast_subject_cross_sessions
align: center
---
Subject level contrast averaging beta across runs
Expand Down
2 changes: 1 addition & 1 deletion docs/source/usage_notes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ Command line API
================

.. argparse::
:ref: src.bidspm.parsers.common_parser
:ref: src.bidspm.parsers.sub_command_parser
:prog: bidspm
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ test = [

[project.scripts]
bidspm = "bidspm.cli:cli"
bidspm_2 = "bidspm.cli:new_cli"
validate_model = "bidspm.validate:cli"

[project.urls]
Expand Down
5 changes: 2 additions & 3 deletions src/IO/overwriteDir.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ function overwriteDir(directory, opt)

% (C) Copyright 2021 bidspm developers

directory = bids.internal.format_path(directory);

if exist(directory, 'dir') == 7
msg = sprintf('\noverwriting directory:\n\t%s\n\n', directory);
formatted_directory = bids.internal.format_path(directory);
msg = sprintf('\noverwriting directory:\n\t%s\n\n', formatted_directory);
id = 'overWritingDir';
logger('WARNING', msg, 'id', id, 'filename', mfilename(), 'options', opt);
rmdir(directory, 's');
Expand Down
Loading

0 comments on commit f4b986f

Please sign in to comment.