Skip to content

Commit a9bb399

Browse files
authored
Merge pull request #375 from chrisfilo/enh/no_data_test
Added check for no compatible data.
2 parents d43a96c + 7b294af commit a9bb399

File tree

7 files changed

+74
-0
lines changed

7 files changed

+74
-0
lines changed

tests/bids.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,14 @@ var suite = describe('BIDS example datasets ', function() {
138138
});
139139
});
140140
});
141+
142+
it('checks for subjects with no valid data', function (isdone) {
143+
var options = {ignoreNiftiHeaders: true};
144+
validate.BIDS("tests/data/no_valid_data", options, function (issues) {
145+
var errors = issues.errors;
146+
assert(errors.length === 1);
147+
assert(errors[0].code === '67');
148+
isdone();
149+
});
150+
});
141151
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"License": "This dataset is made available under the Public Domain Dedication and License \nv1.0, whose full text can be found at \nhttp://www.opendatacommons.org/licenses/pddl/1.0/. \nWe hope that all users will follow the ODC Attribution/Share-Alike \nCommunity Norms (http://www.opendatacommons.org/norms/odc-by-sa/); \nin particular, while not legally required, we hope that all users \nof the data will acknowledge the OpenfMRI project and NSF Grant \nOCI-1131441 (R. Poldrack, PI) in any publications.",
3+
"Name": "Rhyme judgment",
4+
"BIDSVersion": "1.0.1"
5+
}
304 KB
Binary file not shown.
304 KB
Binary file not shown.

utils/issues/list.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,5 +331,10 @@ module.exports = {
331331
key: 'SLICETIMING_VALUES_GREATOR_THAN_REPETITION_TIME',
332332
severity: 'error',
333333
reason: '"SliceTiming" value/s contains invalid value as it is greater than RepetitionTime. SliceTiming values should be in seconds not milliseconds (common mistake).'
334+
},
335+
67: {
336+
key: 'NO_VALID_DATA_FOUND_FOR_SUBJECT',
337+
severity: 'error',
338+
reason: 'No BIDS compatible data found for at least one subject.'
334339
}
335340
};

validators/bids.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ var NIFTI = require('./nii');
1010
var bval = require('./bval');
1111
var bvec = require('./bvec');
1212
var session = require('./session');
13+
var checkAnyDataPresent = require('./checkAnyDataPresent');
1314
var headerFields = require('./headerFields');
1415

1516
var BIDS;
@@ -436,6 +437,7 @@ BIDS = {
436437
}
437438
self.issues = self.issues.concat(headerFields(headers));
438439
self.issues = self.issues.concat(session(fileList));
440+
self.issues = self.issues.concat(checkAnyDataPresent(fileList, summary.subjects));
439441
summary.modalities = utils.modalities.group(summary.modalities);
440442
var issues = utils.issues.format(self.issues, summary, self.options);
441443
callback(issues, summary);

validators/checkAnyDataPresent.js

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
var utils = require('../utils');
2+
var Issue = utils.issues.Issue;
3+
4+
function addIfNotPresent(folderSubjects, subject) {
5+
if (folderSubjects.indexOf(subject) == -1) {
6+
folderSubjects.push(subject);
7+
}
8+
}
9+
10+
function getFolderSubjects(fileList) {
11+
var folderSubjects = [];
12+
for (var key in fileList) {
13+
var file = fileList[key];
14+
var match = file.relativePath.match(/sub-(.*?)(?=\/)/);
15+
if (match) {
16+
addIfNotPresent(folderSubjects, match[1]);
17+
}
18+
}
19+
return folderSubjects;
20+
}
21+
22+
/**
23+
* checkAnyDataPresent
24+
*
25+
* Takes a list of files and participants with valid data. Checks if they match.
26+
*/
27+
var checkAnyDataPresent = function checkAnyDataPresent(fileList, summarySubjects) {
28+
var issues = [];
29+
var folderSubjects = getFolderSubjects(fileList);
30+
31+
var subjectsWithoutAnyValidData = folderSubjects.filter(function (i) {
32+
return summarySubjects.indexOf(i) < 0;
33+
});
34+
35+
for (var i = 0; i < subjectsWithoutAnyValidData.length; i++) {
36+
var missingSubject = subjectsWithoutAnyValidData[i];
37+
var subFolder = "/sub-" + missingSubject;
38+
issues.push(new Issue({
39+
file: {
40+
relativePath: subFolder,
41+
webkitRelativePath: subFolder,
42+
name: subFolder,
43+
path: subFolder
44+
},
45+
reason: "No BIDS compatible data found for subject " + missingSubject,
46+
code: 67
47+
}));
48+
}
49+
return issues;
50+
};
51+
52+
module.exports = checkAnyDataPresent;

0 commit comments

Comments
 (0)