Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Catch no subject error early #463

Merged
merged 3 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions AFQ/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions AFQ/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ def test_AFQ_custom_tract():


@pytest.mark.nightly2
def test_AFQ_no_derivs():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this test really be marked as nightly? It probably runs pretty quickly (?)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test_AFQ_init is also marked nightly. Initializing an afq object takes about a minute I think, and if we have a lot of these tests, they can add up. To reduce time to make afq object, see: #448

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK - that makes sense. Merging!

"""
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
Expand Down