diff --git a/tests/json.spec.js b/tests/json.spec.js index 7feb2470d..6722f9371 100644 --- a/tests/json.spec.js +++ b/tests/json.spec.js @@ -24,5 +24,4 @@ describe('JSON', function(){ assert(issues && issues.length === 1); }); }); - }); diff --git a/tests/nii.spec.js b/tests/nii.spec.js index d6586e587..bd904210a 100644 --- a/tests/nii.spec.js +++ b/tests/nii.spec.js @@ -135,4 +135,37 @@ describe('NIFTI', function(){ }); }); -}); + it('SliceTiming should not be greater than RepetitionTime', function(){ + var jsonContentsDict_new = { + '/sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.json': { + "RepetitionTime": 1.5, + "TaskName": "AntiSaccade (AS) Rewarded & Neutral with varying dot position", + "EchoTime": 0.025, + "NumberofPhaseEncodingSteps": 64, + "FlipAngle": 70, + "PhaseEncodingDirection": "j", + "SliceTiming": [ + 0.0, + 1.3448, + 1.6207, + 1.3966, + 0.6724, + 1.4483, + 1.7241 + ] + } + }; + var file_new = { + name: 'sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz', + relativePath: '/sub-15/func/sub-15_task-mixedeventrelatedprobe_run-01_bold.nii.gz' + }; + var events = [ + '/sub-15/func/sub-14_task-mixedeventrelatedprobe_run-01_events.tsv', + '/sub-15/run-01_events.tsv' + ]; + validate.NIFTI(null, file_new, jsonContentsDict_new, {}, [], events, function (issues) { + assert(issues[2].code === 66 && issues.length === 3); + }); + }); + +}); \ No newline at end of file diff --git a/utils/issues/list.js b/utils/issues/list.js index 59912fbff..1b1fe556d 100644 --- a/utils/issues/list.js +++ b/utils/issues/list.js @@ -326,5 +326,10 @@ module.exports = { key: 'SESSION_LABEL_IN_FILENAME_DOESNOT_MATCH_DIRECTORY', severity: 'error', reason: 'Session label in the filename doesn\'t match with the path of the file. File seems to be saved in incorrect session directory.' + }, + 66: { + key: 'SLICETIMING_VALUES_GREATOR_THAN_REPETITION_TIME', + severity: 'error', + reason: '"SliceTiming" value/s contains invalid value as it is greator than RepetitionTime. SliceTiming values should be in seconds not milliseconds (common mistake).' } }; diff --git a/validators/nii.js b/validators/nii.js index e57af6eca..2ea1a42e3 100644 --- a/validators/nii.js +++ b/validators/nii.js @@ -164,6 +164,18 @@ module.exports = function NIFTI (header, file, jsonContentsDict, bContentsDict, reason: "You should define 'SliceTiming' for this file. If you don't provide this information slice time correction will not be possible. " + sidecarMessage })); } + + if (mergedDictionary.hasOwnProperty('SliceTiming') && mergedDictionary["SliceTiming"].constructor === Array) { + var SliceTimingArray = mergedDictionary["SliceTiming"]; + var invalid_valuesArray = checkSliceTimingArray(SliceTimingArray, mergedDictionary['RepetitionTime']); + if (invalid_valuesArray.length > 0){ + issues.push(new Issue({ + file: file, + code: 66, + evidence: invalid_valuesArray + })); + } + } } else if (path.includes("_phasediff.nii")){ if (!mergedDictionary.hasOwnProperty('EchoTime1') || !mergedDictionary.hasOwnProperty('EchoTime2')) { @@ -341,7 +353,20 @@ function generateMergedSidecarDict(potentialSidecars, jsonContents) { } return mergedDictionary; } +/** + * Function to check each SoliceTime from SliceTiming Array + * + */ +function checkSliceTimingArray(array, repetitionTime){ + for (var t = 0; t < array.length; t++){ + var invalid_timesArray = []; + if (array[t] > repetitionTime){ + invalid_timesArray.push(array[t]); + } + } + return invalid_timesArray; +} /** * Get B-File Contents *