Skip to content

Commit

Permalink
[FIX] pass dataset level to stats actions when using python CLI (#1258)
Browse files Browse the repository at this point in the history
* refactor to improve testing python CLI

* fix links

* add dataset level analysis using docker

* pin dependencies for containers and pass options to ignore nidm in circle ci

* use local files to build apptainer image

* fci

* fix path

* pass options through CLI

* typo

* run default model in CI

* add README to apptainer def

* fix default

* add submodules

* glob

* fci

* python CLI fixes

* use absolute path

* fix test

* fix tests

* show options in debug mode

* fix saveOptions

* fix

* do not use nidm for run and subject level for ds000001

* mount options
  • Loading branch information
Remi-Gau authored Jul 7, 2024
1 parent c29610e commit b617880
Show file tree
Hide file tree
Showing 32 changed files with 509 additions and 116 deletions.
90 changes: 78 additions & 12 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
- data/ds000001
- data/ds000001-fmriprep

test:
default_model:
machine:
image: ubuntu-2204:2022.10.2

Expand All @@ -87,13 +87,53 @@ jobs:
- run: mkdir -p ${HOME}/outputs/ds000001/derivatives

- run:
name: print version
name: default model subject level
command: |
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds000001:/bids_dataset \
${user_name}/${repo_name} --version
-v ${HOME}/outputs:/outputs \
${user_name}/${repo_name} \
/bids_dataset \
/outputs/ds000001 \
subject \
--action default_model \
--task balloonanalogrisktask \
--space MNI152NLin2009cAsym \
--verbosity 3
cat ${HOME}/outputs/ds000001/derivatives/models/*.json
- run:
name: default model dataset level
command: |
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds000001:/bids_dataset \
-v ${HOME}/outputs:/outputs \
${user_name}/${repo_name} \
/bids_dataset \
/outputs/ds000001 \
dataset \
--action default_model \
--task balloonanalogrisktask \
--space MNI152NLin2009cAsym \
--verbosity 3
cat ${HOME}/outputs/ds000001/derivatives/models/*.json
stats:
machine:
image: ubuntu-2204:2022.10.2

steps:
- attach_workspace:
at: /tmp/workspace
- run: docker load -i /tmp/workspace/docker/image.tar

- run: mkdir -p ${HOME}/outputs/ds000001/derivatives

- run:
name: smooth
Expand All @@ -112,21 +152,21 @@ jobs:
--participant_label 01 02 \
--space MNI152NLin2009cAsym \
--fwhm 8 \
--verbosity 2
no_output_timeout: 6h
--verbosity 3
# needed to access the model
# needed to access the model
- checkout

- run:
name: stats
name: stats subject level
command: |
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds000001:/bids_dataset \
-v ${HOME}/outputs:/outputs \
-v ~/project/demos/openneuro/models:/models \
-v ~/project/demos/openneuro/options:/options \
${user_name}/${repo_name} \
/bids_dataset \
/outputs/ds000001 \
Expand All @@ -137,11 +177,33 @@ jobs:
--ignore slicetiming \
--space MNI152NLin2009cAsym \
--skip_validation \
--fwhm 8 \
--fwhm 0 \
--participant_label 01 02 \
--verbosity 2
no_output_timeout: 6h
--verbosity 3 \
--options /options/ds000001.json
- run:
name: stats group level
command: |
user_name=cpplab
repo_name=$(echo "${CIRCLE_PROJECT_REPONAME}" | tr '[:upper:]' '[:lower:]')
docker run -ti --rm \
-v /tmp/workspace/data/ds000001:/bids_dataset \
-v ${HOME}/outputs:/outputs \
-v ~/project/demos/openneuro/models:/models \
-v ~/project/demos/openneuro/options:/options \
${user_name}/${repo_name} \
/bids_dataset \
/outputs/ds000001 \
dataset \
--action stats \
--preproc_dir /outputs/ds000001/derivatives/bidspm-preproc \
--model_file /models/model-balloonanalogrisktaskDefault_smdl.json \
--space MNI152NLin2009cAsym \
--skip_validation \
--fwhm 0 \
--verbosity 3 \
--options /options/ds000001.json
deploy:

Expand Down Expand Up @@ -187,14 +249,18 @@ workflows:
jobs:
- build
- get_data
- test:
- default_model:
requires:
- build
- get_data
- stats:
requires:
- build
- get_data
- deploy:
context:
- DOCKER_HUB
requires:
- test
- build

# VS Code Extension Version: 1.5.1
3 changes: 3 additions & 0 deletions .github/workflows/apptainer_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
fetch-depth: 0

- uses: eWaterCycle/setup-apptainer@v2
with:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
matlab: R2023b
mode: slow
- test_type: unit
os: macos-latest
os: macos-13
matlab: R2023b
mode: fast
fail-fast: false
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ skipped_roi_*.tsv
CHANGES
README
tests/data/tsv_files/moae_results_table.tsv
htmlcov

# Project specific
onsets*_events.mat
Expand All @@ -48,6 +49,8 @@ src/bidspm/_version.py
**/__pycache__
**/build
.coverage
.pytest_cache
.tox

.mypy_cache

Expand Down
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM bids/base_validator
FROM bids/base_validator:1.13.1

ARG DEBIAN_FRONTEND="noninteractive"

Expand Down Expand Up @@ -48,6 +48,7 @@ WORKDIR /home/neuro
COPY . /home/neuro/bidspm
WORKDIR /home/neuro/bidspm
RUN pip install --no-cache-dir --upgrade pip && \
pip3 --no-cache-dir install -r requirements.txt && \
pip3 --no-cache-dir install . && \
octave --no-gui --eval "addpath('/opt/spm12/'); savepath ();" && \
octave --no-gui --eval "addpath(pwd); savepath(); bidspm(); path"
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ coverage: ## use coverage
coverage erase
coverage run --source src -m pytest
coverage report -m
coverage html

################################################################################
# DOCKER
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ To start using bidspm, you just need to initialize it for the current MATLAB / O
bidspm()
```

Please see our [documentation](https://bidspm.readthedocs.io/en/latest/installation.html) for more info.
Please see our [documentation](https://bidspm.readthedocs.io/en/latest/installation/index.html) for more info.

## Usage

Expand Down
18 changes: 13 additions & 5 deletions bidspm.def
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
BootStrap: docker
From: bids/base_validator
From: bids/base_validator:1.13.1

%files
pyproject.toml /opt/bidspm/pyproject.toml
requirements.txt /opt/bidspm/requirements.txt
README.md /opt/bidspm/README.md
bidspm.m /opt/bidspm/bidspm.m
src /opt/bidspm/src
lib /opt/bidspm/lib
.git /opt/bidspm/.git

%post
apt-get -qq update
Expand Down Expand Up @@ -38,10 +47,9 @@ From: bids/base_validator
make -C /opt/spm12/src PLATFORM=octave install
ln -s /opt/spm12/bin/spm12-octave /usr/local/bin/spm12

mkdir /opt/bidspm
git clone --recurse-submodules https://github.com/cpp-lln-lab/bidspm.git /opt/bidspm
pip install --no-cache-dir --upgrade pip && \
pip3 --no-cache-dir install /opt/bidspm && \
pip install --upgrade pip
pip install -r /opt/bidspm/requirements.txt
pip install /opt/bidspm
octave --no-gui --eval "addpath('/opt/spm12/'); savepath ('/usr/share/octave/site/m/startup/octaverc');" && \
octave --no-gui --eval "addpath('/opt/bidspm/'); savepath('/usr/share/octave/site/m/startup/octaverc'); bidspm(); path"

Expand Down
11 changes: 1 addition & 10 deletions bidspm.m
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,6 @@ function initBidspm(dev)
pathSep, ...
genpath(fullfile(rootDir(), 'src', 'workflows', 'stats')));

% add library that do not have an set up script
libList = {'spmup'};

for i = 1:numel(libList)
BIDSPM_PATHS = cat(2, BIDSPM_PATHS, ...
pathSep, ...
genpath(fullfile(rootDir(), 'lib', libList{i})));
end

libList = {'mancoreg', ...
'bids-matlab', ...
'slice_display', ...
Expand Down Expand Up @@ -270,7 +261,7 @@ function updateMacstoolbox()
end

if exist(target_dir, 'dir') == 7
msg = sprintf('updating MACS toolbox: ');
msg = sprintf('updating MACS toolbox\n');
fprintf(1, msg);
[status, cmdout] = system(sprintf('git -C %s pull', target_dir));
if status ~= 0
Expand Down
11 changes: 6 additions & 5 deletions demos/openneuro/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@ data_ds000001:
mkdir -p inputs
cd inputs && datalad install ///openneuro/ds000001
cd inputs && datalad install ///openneuro-derivatives/ds000001-fmriprep
cd inputs/ds000001 && datalad get sub-0[1-5] -J 3
cd inputs/ds000001-fmriprep && datalad get sub-0[1-5]/func/*tsv -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-5]/func/*json -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-5]/func/*MNI*desc-*bold.nii.gz -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-5]/anat/*MNI*desc-preproc*.nii.gz -J 12
cd inputs/ds000001 && datalad get sub-0[1-2] -J 3
cd inputs/ds000001-fmriprep && datalad get sub-0[1-2]/func/*tsv -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-2]/func/*json -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-2]/anat/*MNI*desc-preproc*.nii.gz -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-2]/func/*MNI*desc-preproc*.nii.gz -J 12
cd inputs/ds000001-fmriprep && datalad get sub-0[1-2]/func/*MNI*desc-*bold.nii.gz -J 12

data_ds000114:
mkdir -p inputs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@
{
"name": [
"cash_demean"
]
],
"nidm": false
}
]
}
Expand Down
5 changes: 5 additions & 0 deletions demos/openneuro/options/ds000001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"results": {
"nidm": false
}
}
2 changes: 0 additions & 2 deletions demos/validate_models.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
% AND it will run some extra checks implemented in bids-matlab
% and bidspm.
%
% See also: https://bidspm.readthedocs.io/en/latest/bids_stats_model.html#using-the-bids-stats-model-python-package
%

this_dir = fileparts(mfilename('fullpath'));

Expand Down
2 changes: 1 addition & 1 deletion docs/faq/stats/naming-conditions.question.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ So for example:
If your BIDS dataset has conditions that do not follow this rule,
then you can use
the [`Replace` variable transform](https://github.com/bids-standard/variable-transform/blob/main/spec/munge.md#replace)
in your [BIDS statistical model](https://bidspm.readthedocs.io/en/latest/bids_stats_model.html#transformation')
in your [BIDS statistical model](https://bidspm.readthedocs.io/en/latest/stats/bids_stats_model.html#transformation')
to rename them on the fly without having to manually edit potentially dozens of files.

See also example below.
Expand Down
2 changes: 1 addition & 1 deletion docs/source/installation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ After installing bidspm python package, you can get access to extra validation o

#### BIDS stats model validation

Please see [the documentation](https://bidspm.readthedocs.io/en/latest/bids_stats_model.html#using-the-bids-stats-model-python-package)
Please see [the documentation](https://bidspm.readthedocs.io/en/latest/stats/bids_stats_model.html#using-the-bids-stats-model-python-package)

#### BIDS dataset validation

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.parsers.common_parser
:ref: src.bidspm.parsers.common_parser
:prog: bidspm
2 changes: 1 addition & 1 deletion lib/bids-matlab
Submodule bids-matlab updated 40 files
+6 −0 +bids/+internal/list_all_trial_types.m
+0 −33 +bids/+transformers_list/Assign.m
+0 −35 +bids/+transformers_list/Basic.m
+0 −39 +bids/+transformers_list/Concatenate.m
+0 −24 +bids/+transformers_list/Constant.m
+0 −33 +bids/+transformers_list/Copy.m
+0 −29 +bids/+transformers_list/Delete.m
+0 −31 +bids/+transformers_list/Drop_na.m
+0 −29 +bids/+transformers_list/Factor.m
+0 −35 +bids/+transformers_list/Filter.m
+0 −26 +bids/+transformers_list/Label_identical_rows.m
+0 −32 +bids/+transformers_list/Logical.m
+0 −50 +bids/+transformers_list/Merge_identical_rows.m
+0 −25 +bids/+transformers_list/Product.m
+0 −32 +bids/+transformers_list/Rename.m
+1 −61 +bids/+transformers_list/Replace.m
+0 −33 +bids/+transformers_list/Scale.m
+0 −31 +bids/+transformers_list/Select.m
+0 −34 +bids/+transformers_list/Split.m
+0 −29 +bids/+transformers_list/Std.m
+0 −32 +bids/+transformers_list/Sum.m
+0 −30 +bids/+transformers_list/Threshold.m
+1 −1 +bids/layout.m
+2 −2 .github/workflows/run_examples.yml
+3 −3 .github/workflows/run_tests_matlab.yml
+0 −29 .github/workflows/validate.yml
+4 −0 .gitmodules
+1 −2 .pre-commit-config.yaml
+1 −1 docs/requirements.txt
+1 −1 docs/source/index.rst
+9 −10 docs/source/variable_transformations.rst
+1 −1 schema.json
+28 −2 tests/test_bids_model.m
+4 −1 tests/test_bids_schema.m
+144 −0 tests/test_transformers/test_transformers.m
+1 −373 tests/test_transformers/test_transformers_compute.m
+0 −97 tests/test_transformers/test_transformers_compute_logical.m
+69 −595 tests/test_transformers/test_transformers_munge.m
+0 −136 tests/test_transformers/test_transformers_munge_multi.m
+1 −0 tests/variable-transform
2 changes: 1 addition & 1 deletion lib/utils/unfold.m
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function unfold(input, varargin)
for i = 1:NF

if NS > 1
size_ = size_e(input);
size_ = size(input);
if show
name_i = [name '(' indToStr(size_, h) ').' F{i}];
else
Expand Down
12 changes: 9 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ style = [
]

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

[project.urls]
Homepage = "https://bidspm.readthedocs.io"
Expand Down Expand Up @@ -133,4 +133,10 @@ module = [
]

[tool.pytest.ini_options]
addopts = "-ra -vv"
addopts = "-ra -q -vv --showlocals --strict-markers --strict-config"
# filterwarnings = ["error"]
# log_cli_level = "warning"
minversion = "6.0.0"
norecursedirs = "data"
testpaths = ["tests/"]
xfail_strict = true
Loading

0 comments on commit b617880

Please sign in to comment.