Skip to content

Commit 59456ff

Browse files
authored
[FIX] allow flexible derivatives location (#247)
* check if derivatives directory exists * make the docstring clearer * allow flexibility in where the derivatives directory is * test derivatives directory error
1 parent 2a47927 commit 59456ff

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

src/nibetaseries/cli/run.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ def get_parser():
4343
formatter_class=RawTextHelpFormatter)
4444
parser.add_argument('bids_dir', help='The directory with the input dataset '
4545
'formatted according to the BIDS standard.')
46-
parser.add_argument('derivatives_pipeline', help='The pipeline that contains '
47-
'minimally preprocessed img, brainmask, and confounds.tsv')
46+
parser.add_argument('derivatives_pipeline', help='Either the name of the pipeline '
47+
'(e.g., fmriprep) or the directory path to the pipeline '
48+
'(e.g., /some/dir/fmriprep) that contains the minimally preprocessed '
49+
'img, brainmask, and confounds.tsv. '
50+
'If you only give the name of the pipeline, it is assumed to be under '
51+
'a derivatives directory within the bids directory '
52+
'(e.g., /my/bids/derivatives).')
4853
parser.add_argument('output_dir', help='The directory where the output directory '
4954
'and files should be stored. If you are running group level analysis '
5055
'this folder should be prepopulated with the results of the'
@@ -153,8 +158,14 @@ def main():
153158
# Set up directories
154159
# TODO: set up some sort of versioning system
155160
bids_dir = os.path.abspath(opts.bids_dir)
161+
if os.path.isdir(opts.derivatives_pipeline):
162+
derivatives_pipeline_dir = os.path.abspath(opts.derivatives_pipeline)
163+
else:
164+
derivatives_pipeline_dir = os.path.join(bids_dir, 'derivatives', opts.derivatives_pipeline)
156165

157-
derivatives_pipeline_dir = os.path.join(bids_dir, 'derivatives', opts.derivatives_pipeline)
166+
if not os.path.isdir(derivatives_pipeline_dir):
167+
msg = "{dir} is not an available directory".format(dir=derivatives_pipeline_dir)
168+
raise NotADirectoryError(msg)
158169

159170
output_dir = os.path.abspath(opts.output_dir)
160171
os.makedirs(output_dir, exist_ok=True)

src/nibetaseries/cli/tests/test_run.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33

44
import pytest
5-
from ..run import get_parser
5+
from ..run import get_parser, main
66

77

88
def test_get_parser():
@@ -112,3 +112,22 @@ def test_init(monkeypatch):
112112
monkeypatch.setattr(run, "__name__", "__main__")
113113
with pytest.raises(RuntimeError):
114114
run.init()
115+
116+
117+
def test_main(monkeypatch):
118+
import sys
119+
120+
parser_args = [
121+
'nibs',
122+
'bids_dir',
123+
'derivatives_pipeline',
124+
'output_dir',
125+
'participant',
126+
'-l', 'lut',
127+
'-a', 'img',
128+
]
129+
monkeypatch.setattr(sys, 'argv', parser_args)
130+
with pytest.raises(NotADirectoryError) as no_dir:
131+
main()
132+
133+
assert "is not an available directory" in str(no_dir.value)

0 commit comments

Comments
 (0)