diff --git a/tests/nii.spec.js b/tests/nii.spec.js index bd904210a..de5872066 100644 --- a/tests/nii.spec.js +++ b/tests/nii.spec.js @@ -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' ] @@ -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, []); }); diff --git a/utils/type.js b/utils/type.js index 8fe0bc235..c90bee7e3 100644 --- a/utils/type.js +++ b/utils/type.js @@ -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 */ diff --git a/validators/nii.js b/validators/nii.js index ed981f1e8..d3f08f2fd 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -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 * @@ -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