Skip to content

Commit 205d0f6

Browse files
committed
refactor4
1 parent 342bc0f commit 205d0f6

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

tests/nii.spec.js

Lines changed: 3 additions & 3 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
]

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: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict,
239239
}
240240
}
241241

242-
if (path.includes("_phasediff.nii") || path.includes("_phase1.nii") ||
243-
path.includes("_phase2.nii") || path.includes("_fieldmap.nii") || path.includes("_epi.nii") &&
244-
mergedDictionary.hasOwnProperty('IntendedFor')) {
242+
if (utils.type.isFieldMapMainNii(path) && mergedDictionary.hasOwnProperty('IntendedFor')) {
245243
var intendedFor = typeof mergedDictionary['IntendedFor'] == "string" ? [mergedDictionary['IntendedFor']] : mergedDictionary['IntendedFor'];
246244

247245
for (var key = 0; key < intendedFor.length; key++) {

0 commit comments

Comments
 (0)