-
Notifications
You must be signed in to change notification settings - Fork 11
[WIP] refactor narrowing, add test, run narrow before copying #29
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
Open
WillForan
wants to merge
12
commits into
bids-apps:master
Choose a base branch
from
WillForan:copy_needed_only
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7ae2ed6
[BUG] only one el in BIDS.participants.meta
WillForan cabf8a0
[WIP] narrow_participants.m and test, run before copy
WillForan a73da7c
Update narrow_participants.m
Remi-Gau a79effc
fix(narrow): skip participant field if empty
WillForan 0405e6c
fix(Dockerfile): track narrow_participants.m
WillForan 0e7b4df
wip: global BIDS on pipeline
WillForan 13c7b86
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] c2c4b5e
'precommit_update'
Remi-Gau ff36d8c
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] 9b51ea6
autoupdate_precommit
Remi-Gau 1277dab
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] f72e7c1
[pre-commit.ci] pre-commit autoupdate
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| function BIDS = narrow_participants(BIDS, labels) | ||
| % NARROW_PARTICIPANTS - restrict BIDS struct to only requested labels | ||
| % | ||
|
|
||
| % nothing to do if no labels to change? | ||
| if isempty(labels) | ||
| return | ||
| end | ||
|
|
||
| idx = ismember({BIDS.subjects.name},labels); | ||
| BIDS.subjects = BIDS.subjects(idx); | ||
|
|
||
| if isempty(BIDS.participants) | ||
| warning('no participants information. missing participants.csv?') | ||
| else | ||
| if ~ismember(fieldnames(BIDS.participants), 'participant_id') | ||
| error('participants.tsv does not contain a participant_id column') | ||
| end | ||
| idx = ismember(BIDS.participants.participant_id, labels); | ||
| for fn=fieldnames(BIDS.participants)' | ||
| replace = BIDS.participants.(char(fn)); | ||
| % BIDS.participants.meta is 1x1. other fields are 1xN | ||
| if(length(replace) < length(idx)) | ||
| warning('BIDS participants field "%s" too short: ID idx len %d > number of field values %d; ignored', ... | ||
| char(fn), length(idx), length(replace)) | ||
| continue | ||
| end | ||
| BIDS.participants.(char(fn)) = replace(idx); | ||
| end | ||
| end | ||
|
|
||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| % | ||
| % script based testing for narrow_participants | ||
| % participants.json adds a 'meta' field that can be avoided when selecting only some participants | ||
| % | ||
|
|
||
| bids_dir = [tempname '_bids_test']; | ||
| try | ||
| % build minimal BIDS filesystem: participants.json and 1 anat file pair | ||
| system(['mkdir -p ' bids_dir '/sub-{a,b}/ses-{1,2}/anat/']); | ||
| system([ 'touch ' bids_dir '/sub-{a,b}/ses-{1,2}/anat/T1.{json,nii.gz}']); | ||
| system(['echo -e ''participant_id\nsub-a\nsub-a\nsub-b\nsub-b'' > ' bids_dir '/participants.tsv']); | ||
| system(['echo ''{ "Name": "test", "BIDSVersion": "1.4.1"}'' > ' bids_dir '/dataset_description.json']); | ||
| system(['echo ''{ "age": { "Description": "xyz" } }'' > ' bids_dir '/participants.json']); | ||
|
|
||
| % get what we built -- matches expectations | ||
| BIDS = spm_BIDS(bids_dir); | ||
| assert(length(BIDS.participants.participant_id) == 4) | ||
|
|
||
| % narrowing works | ||
| BIDS_narrow = narrow_participants(BIDS, {'sub-a'}) | ||
| assert(length(BIDS_narrow.participants.participant_id) == 2) | ||
|
|
||
| % no change on empty | ||
| BIDS_nochange = narrow_participants(BIDS, {}); % TODO: {{}}? | ||
| assert(length(BIDS_nochange.participants.participant_id) == 4) | ||
|
|
||
| catch me | ||
| rmdir(bids_dir,'s') | ||
| rethrow(me) | ||
| end |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think you could rewrite this test to be used directly by matlab testing framework?
Ideally with setup and teardown functions.
https://nl.mathworks.com/help/matlab/matlab_prog/write-test-using-setup-and-teardown-functions.html
If you don't have the bandwidth, let me know and I can give it a go