Skip to content

Commit

Permalink
Merge pull request #393 from chrisfilo/fix/intendedfor
Browse files Browse the repository at this point in the history
Fixes for IntendedFor validator
  • Loading branch information
chrisgorgo authored Feb 4, 2018
2 parents 24b688e + 205d0f6 commit 54fc2b9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 30 deletions.
8 changes: 4 additions & 4 deletions tests/nii.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,12 @@ describe('NIFTI', function(){
it('should generate warning if files listed in IntendedFor of fieldmap json do not exist', function() {
var file = {
name: 'sub-09_ses-test_run-01_fieldmap.nii.gz',
path: '/ds114/sub-09/ses-test/dwi/sub-09_ses-test_run-01_fieldmap.nii.gz',
relativePath: '/sub-09/ses-test/dwi/sub-09_ses-test_run-01_fieldmap.nii.gz'
path: '/ds114/sub-09/ses-test/fmap/sub-09_ses-test_run-01_fieldmap.nii.gz',
relativePath: '/sub-09/ses-test/fmap/sub-09_ses-test_run-01_fieldmap.nii.gz'
};

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

var fileList = [{ name:'sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz',
path: 'sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz',
relativePath: '/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz'}];
relativePath: '/sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz'}];
validate.NIFTI(null, file, jsonContentsDict, {}, fileList, [], function (issues) {
assert.deepEqual(issues, []);
});
Expand Down
11 changes: 11 additions & 0 deletions utils/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ module.exports = {
return conditionalMatch(anatRe, path);
},

isFieldMapMainNii: function (path) {
var suffixes = ["phasediff", "phase1", "phase2", "fieldmap", "epi"];
var anatRe = new RegExp('^\\/(sub-[a-zA-Z0-9]+)' +
'\\/(?:(ses-[a-zA-Z0-9]+)' +
'\\/)?fmap' +
'\\/\\1(_\\2)?(?:_acq-[a-zA-Z0-9]+)?(?:_rec-[a-zA-Z0-9]+)?(?:_dir-[a-zA-Z0-9]+)?(?:_run-[0-9]+)?_(?:'
+ suffixes.join("|")
+ ').(nii.gz|nii)$');
return conditionalMatch(anatRe, path);
},

/**
* Check if the file has a name appropriate for a functional scan
*/
Expand Down
53 changes: 27 additions & 26 deletions validators/nii.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,28 @@
var async = require('async');
var utils = require('../utils');
var Issue = utils.issues.Issue;

function checkIfIntendedExists(intendedForFile, fileList, issues, file) {
var intendedForFileFull = "/" + file.relativePath.split("/")[1] + "/" + intendedForFile;
var onTheList = false;

for (var key2 in fileList) {
var filePath = fileList[key2].relativePath;
if (filePath === intendedForFileFull) {
onTheList = true;
}
}
if (!onTheList) {
issues.push(new Issue({
file: file,
code: 37,
reason: "'IntendedFor' property of this fieldmap ('" + file.relativePath +
"') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " +
"('/" + file.relativePath.split("/")[1] + "/').",
evidence: intendedForFile
}));
}
}

/**
* NIFTI
*
Expand Down Expand Up @@ -218,33 +239,13 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict,
}
}

if (path.includes("_phasediff.nii") || path.includes("_phase1.nii") ||
path.includes("_phase2.nii") || path.includes("_fieldmap.nii") || path.includes("_epi.nii")){
if (mergedDictionary.hasOwnProperty('IntendedFor')) {
var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor'];

for(var key = 0; key<intendedFor.length; key++){
var intendedForFile = path.split("/")[1] + "/" + intendedFor[key];
var onTheList = false;
async.eachOfLimit(fileList, 200, function (file) {
var filePath = file.relativePath;
if (filePath.endsWith(intendedForFile)){
onTheList = true;
}
if (utils.type.isFieldMapMainNii(path) && mergedDictionary.hasOwnProperty('IntendedFor')) {
var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor'];

}, function(){
if (!onTheList) {
issues.push(new Issue({
file: file,
code: 37,
reason: "'IntendedFor' property of this fieldmap ('" + path +
"') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " +
"('/" + path.split("/")[1] + "/')."
}));
}
});
for (var key = 0; key < intendedFor.length; key++) {
var intendedForFile = intendedFor[key];
checkIfIntendedExists(intendedForFile, fileList, issues, file);
}
}
}
}

Expand Down

0 comments on commit 54fc2b9

Please sign in to comment.