Skip to content

Commit 54fc2b9

Browse files
authored
Merge pull request #393 from chrisfilo/fix/intendedfor
Fixes for IntendedFor validator
2 parents 24b688e + 205d0f6 commit 54fc2b9

File tree

3 files changed

+42
-30
lines changed

3 files changed

+42
-30
lines changed

tests/nii.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,12 @@ describe('NIFTI', function(){
9191
it('should generate warning if files listed in IntendedFor of fieldmap json do not exist', function() {
9292
var file = {
9393
name: 'sub-09_ses-test_run-01_fieldmap.nii.gz',
94-
path: '/ds114/sub-09/ses-test/dwi/sub-09_ses-test_run-01_fieldmap.nii.gz',
95-
relativePath: '/sub-09/ses-test/dwi/sub-09_ses-test_run-01_fieldmap.nii.gz'
94+
path: '/ds114/sub-09/ses-test/fmap/sub-09_ses-test_run-01_fieldmap.nii.gz',
95+
relativePath: '/sub-09/ses-test/fmap/sub-09_ses-test_run-01_fieldmap.nii.gz'
9696
};
9797

9898
var jsonContentsDict = {
99-
'/sub-09/ses-test/dwi/sub-09_ses-test_run-01_fieldmap.json': {
99+
'/sub-09/ses-test/fmap/sub-09_ses-test_run-01_fieldmap.json': {
100100
TaskName: 'Mixed Event Related Probe',
101101
IntendedFor: ['func/sub-15_task-mixedeventrelatedprobe_run-05_bold.nii.gz','func/sub-15_task-mixedeventrelatedprobe_run-02_bold.nii.gz'
102102
]
@@ -129,7 +129,7 @@ describe('NIFTI', function(){
129129

130130
var fileList = [{ name:'sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz',
131131
path: 'sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz',
132-
relativePath: '/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz'}];
132+
relativePath: '/sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz'}];
133133
validate.NIFTI(null, file, jsonContentsDict, {}, fileList, [], function (issues) {
134134
assert.deepEqual(issues, []);
135135
});

utils/type.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,17 @@ module.exports = {
155155
return conditionalMatch(anatRe, path);
156156
},
157157

158+
isFieldMapMainNii: function (path) {
159+
var suffixes = ["phasediff", "phase1", "phase2", "fieldmap", "epi"];
160+
var anatRe = new RegExp('^\\/(sub-[a-zA-Z0-9]+)' +
161+
'\\/(?:(ses-[a-zA-Z0-9]+)' +
162+
'\\/)?fmap' +
163+
'\\/\\1(_\\2)?(?:_acq-[a-zA-Z0-9]+)?(?:_rec-[a-zA-Z0-9]+)?(?:_dir-[a-zA-Z0-9]+)?(?:_run-[0-9]+)?_(?:'
164+
+ suffixes.join("|")
165+
+ ').(nii.gz|nii)$');
166+
return conditionalMatch(anatRe, path);
167+
},
168+
158169
/**
159170
* Check if the file has a name appropriate for a functional scan
160171
*/

validators/nii.js

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
1-
var async = require('async');
21
var utils = require('../utils');
32
var Issue = utils.issues.Issue;
43

4+
function checkIfIntendedExists(intendedForFile, fileList, issues, file) {
5+
var intendedForFileFull = "/" + file.relativePath.split("/")[1] + "/" + intendedForFile;
6+
var onTheList = false;
7+
8+
for (var key2 in fileList) {
9+
var filePath = fileList[key2].relativePath;
10+
if (filePath === intendedForFileFull) {
11+
onTheList = true;
12+
}
13+
}
14+
if (!onTheList) {
15+
issues.push(new Issue({
16+
file: file,
17+
code: 37,
18+
reason: "'IntendedFor' property of this fieldmap ('" + file.relativePath +
19+
"') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " +
20+
"('/" + file.relativePath.split("/")[1] + "/').",
21+
evidence: intendedForFile
22+
}));
23+
}
24+
}
25+
526
/**
627
* NIFTI
728
*
@@ -218,33 +239,13 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict,
218239
}
219240
}
220241

221-
if (path.includes("_phasediff.nii") || path.includes("_phase1.nii") ||
222-
path.includes("_phase2.nii") || path.includes("_fieldmap.nii") || path.includes("_epi.nii")){
223-
if (mergedDictionary.hasOwnProperty('IntendedFor')) {
224-
var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor'];
225-
226-
for(var key = 0; key<intendedFor.length; key++){
227-
var intendedForFile = path.split("/")[1] + "/" + intendedFor[key];
228-
var onTheList = false;
229-
async.eachOfLimit(fileList, 200, function (file) {
230-
var filePath = file.relativePath;
231-
if (filePath.endsWith(intendedForFile)){
232-
onTheList = true;
233-
}
242+
if (utils.type.isFieldMapMainNii(path) && mergedDictionary.hasOwnProperty('IntendedFor')) {
243+
var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor'];
234244

235-
}, function(){
236-
if (!onTheList) {
237-
issues.push(new Issue({
238-
file: file,
239-
code: 37,
240-
reason: "'IntendedFor' property of this fieldmap ('" + path +
241-
"') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " +
242-
"('/" + path.split("/")[1] + "/')."
243-
}));
244-
}
245-
});
245+
for (var key = 0; key < intendedFor.length; key++) {
246+
var intendedForFile = intendedFor[key];
247+
checkIfIntendedExists(intendedForFile, fileList, issues, file);
246248
}
247-
}
248249
}
249250
}
250251

0 commit comments

Comments
 (0)