diff --git a/AFQ/api.py b/AFQ/api.py index 1fe183e41..76a22265a 100644 --- a/AFQ/api.py +++ b/AFQ/api.py @@ -388,6 +388,12 @@ def __init__(self, json.dump(pipeline_description, outfile) self.subjects = bids_layout.get(return_type='id', target='subject') + if not len(self.subjects): + raise ValueError( + "`bids_path` contains no subjects in derivatives folders." + + " This could be caused by derivatives folders not following" + + " the BIDS format.") + sessions = bids_layout.get(return_type='id', target='session') if len(sessions): self.sessions = sessions diff --git a/AFQ/tests/test_api.py b/AFQ/tests/test_api.py index 953821231..b5a54d18d 100644 --- a/AFQ/tests/test_api.py +++ b/AFQ/tests/test_api.py @@ -180,6 +180,23 @@ def test_AFQ_custom_tract(): @pytest.mark.nightly2 +def test_AFQ_no_derivs(): + """ + Test the initialization of the AFQ object + """ + bids_path = create_dummy_bids_path(1, 1) + os.remove(op.join( + bids_path, "derivatives", "dmriprep", "dataset_description.json")) + with pytest.raises( + ValueError, + match="`bids_path` contains no subjects in derivatives folders." + + " This could be caused by derivatives folders not" + + " following the BIDS format."): + my_afq = api.AFQ(bids_path, + dmriprep="synthetic") + + +@pytest.mark.nightly3 def test_AFQ_init(): """ Test the initialization of the AFQ object