From 7e1ecbc16f1448fa83703a0d0229c695d6bea890 Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Sat, 3 Feb 2018 15:09:06 -0800 Subject: [PATCH 1/6] Fixes for intendedfor validator --- tests/nii.spec.js | 2 +- validators/nii.js | 33 +++++++++++++++++---------------- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tests/nii.spec.js b/tests/nii.spec.js index bd904210a..8a392f9f5 100644 --- a/tests/nii.spec.js +++ b/tests/nii.spec.js @@ -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/validators/nii.js b/validators/nii.js index ed981f1e8..420c4ec1c 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -224,25 +224,26 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict, var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor']; for(var key = 0; key Date: Sat, 3 Feb 2018 15:11:02 -0800 Subject: [PATCH 2/6] cleanup --- validators/nii.js | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/validators/nii.js b/validators/nii.js index 420c4ec1c..75213b21f 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -219,33 +219,33 @@ 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")){ + 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 Date: Sat, 3 Feb 2018 15:17:18 -0800 Subject: [PATCH 3/6] refactor --- validators/nii.js | 49 +++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/validators/nii.js b/validators/nii.js index 75213b21f..67e85772c 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -1,4 +1,3 @@ -var async = require('async'); var utils = require('../utils'); var Issue = utils.issues.Issue; @@ -219,32 +218,32 @@ 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 = intendedFor[key]; - var intendedForFileFull = "/" + path.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 ('" + path + - "') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " + - "('/" + path.split("/")[1] + "/').", - evidence: intendedForFile - })); + path.includes("_phase2.nii") || path.includes("_fieldmap.nii") || path.includes("_epi.nii") && + mergedDictionary.hasOwnProperty('IntendedFor')) { + var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor']; + + for (var key = 0; key < intendedFor.length; key++) { + var intendedForFile = intendedFor[key]; + var intendedForFileFull = "/" + path.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 ('" + path + + "') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " + + "('/" + path.split("/")[1] + "/').", + evidence: intendedForFile + })); + } + } } } } From 3415c5c92f8db306b526dd370537a241c20cfffe Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Sat, 3 Feb 2018 15:24:25 -0800 Subject: [PATCH 4/6] refactor2 --- validators/nii.js | 43 +++++++++++++++++++++++-------------------- 1 file changed, 23 insertions(+), 20 deletions(-) diff --git a/validators/nii.js b/validators/nii.js index 67e85772c..09bda61f3 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -1,6 +1,28 @@ var utils = require('../utils'); var Issue = utils.issues.Issue; +function checkIfIntendedExists(path, intendedForFile, fileList, issues, file) { + var intendedForFileFull = "/" + path.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 ('" + path + + "') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " + + "('/" + path.split("/")[1] + "/').", + evidence: intendedForFile + })); + } +} + /** * NIFTI * @@ -224,26 +246,7 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict, for (var key = 0; key < intendedFor.length; key++) { var intendedForFile = intendedFor[key]; - var intendedForFileFull = "/" + path.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 ('" + path + - "') does not point to an existing file('" + intendedForFile + "'). Please mind that this value should not include subject level directory " + - "('/" + path.split("/")[1] + "/').", - evidence: intendedForFile - })); - } - } + checkIfIntendedExists(path, intendedForFile, fileList, issues, file); } } } From 342bc0f5027a9bd894cb5b53bce43d324dfa3f4c Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Sun, 4 Feb 2018 15:01:11 -0800 Subject: [PATCH 5/6] refactor3 --- validators/nii.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/validators/nii.js b/validators/nii.js index 09bda61f3..3c5e504b4 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -1,8 +1,8 @@ var utils = require('../utils'); var Issue = utils.issues.Issue; -function checkIfIntendedExists(path, intendedForFile, fileList, issues, file) { - var intendedForFileFull = "/" + path.split("/")[1] + "/" + intendedForFile; +function checkIfIntendedExists(intendedForFile, fileList, issues, file) { + var intendedForFileFull = "/" + file.relativePath.split("/")[1] + "/" + intendedForFile; var onTheList = false; for (var key2 in fileList) { @@ -15,9 +15,9 @@ function checkIfIntendedExists(path, intendedForFile, fileList, issues, file) { issues.push(new Issue({ file: file, code: 37, - reason: "'IntendedFor' property of this fieldmap ('" + path + + 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 " + - "('/" + path.split("/")[1] + "/').", + "('/" + file.relativePath.split("/")[1] + "/').", evidence: intendedForFile })); } @@ -246,7 +246,7 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict, for (var key = 0; key < intendedFor.length; key++) { var intendedForFile = intendedFor[key]; - checkIfIntendedExists(path, intendedForFile, fileList, issues, file); + checkIfIntendedExists(intendedForFile, fileList, issues, file); } } } From 205d0f684b3249f20ef695a0fce2ec5b3e890341 Mon Sep 17 00:00:00 2001 From: Chris Gorgolewski Date: Sun, 4 Feb 2018 15:44:21 -0800 Subject: [PATCH 6/6] refactor4 --- tests/nii.spec.js | 6 +++--- utils/type.js | 11 +++++++++++ validators/nii.js | 4 +--- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/tests/nii.spec.js b/tests/nii.spec.js index 8a392f9f5..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' ] 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 3c5e504b4..d3f08f2fd 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -239,9 +239,7 @@ 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") && - mergedDictionary.hasOwnProperty('IntendedFor')) { + if (utils.type.isFieldMapMainNii(path) && mergedDictionary.hasOwnProperty('IntendedFor')) { var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor']; for (var key = 0; key < intendedFor.length; key++) {