Skip to content

Commit 37924a1

Browse files
authored
Merge pull request #402 from chrisfilo/enh/hierachyRefactor
Refactor inheritance principle implementation
2 parents e6364d0 + 3c9ad58 commit 37924a1

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

utils/type.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ module.exports = {
3939
var fixedTopLevelNames = ["/README", "/CHANGES", "/dataset_description.json", "/participants.tsv",
4040
"/participants.json", "/phasediff.json", "/phase1.json", "/phase2.json", "/fieldmap.json"];
4141

42-
var funcTopRe = new RegExp('^\\/(?:ses-[a-zA-Z0-9]+_)?(?:recording-[a-zA-Z0-9]+_)?task-[a-zA-Z0-9]+(?:_acq-[a-zA-Z0-9]+)?(?:_rec-[a-zA-Z0-9]+)?(?:_run-[0-9]+)?(?:_echo-[0-9]+)?'
43-
+ '(_bold.json|_sbref.json|_events.json|_events.tsv|_physio.json|_stim.json|_beh.json)$');
42+
var funcTopRe = new RegExp('^\\/(?:ses-[a-zA-Z0-9]+_)?(?:recording-[a-zA-Z0-9]+_)?(?:task-[a-zA-Z0-9]+_)?(?:acq-[a-zA-Z0-9]+_)?(?:rec-[a-zA-Z0-9]+_)?(?:run-[0-9]+_)?(?:echo-[0-9]+_)?'
43+
+ '(bold.json|sbref.json|events.json|events.tsv|physio.json|stim.json|beh.json)$');
4444

4545
var anatTopRe = new RegExp('^\\/(?:ses-[a-zA-Z0-9]+_)?(?:acq-[a-zA-Z0-9]+_)?(?:rec-[a-zA-Z0-9]+_)?(?:run-[0-9]+_)?'
4646
+ '(' + anatSuffixes.join("|") + ').json$');

validators/nii.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -315,21 +315,23 @@ function potentialLocations(path) {
315315
});
316316

317317
if (ses) {
318-
var sessionLevelPath= "/" + sub + "/" + ses + "/" + sessionLevelComponentList.join("_");
319-
potentialPaths.push(sessionLevelPath);
318+
addPotentialPaths(sessionLevelComponentList, potentialPaths, 2, "/" + sub + "/" + ses + "/");
320319
}
321-
322-
var subjectLevelPath = "/" + sub + "/" + subjectLevelComponentList.join("_");
323-
potentialPaths.push(subjectLevelPath);
324-
325-
var topLevelPath = "/" + topLevelComponentList.join("_");
326-
potentialPaths.push(topLevelPath);
327-
320+
addPotentialPaths(subjectLevelComponentList, potentialPaths, 1, "/" + sub + "/");
321+
addPotentialPaths(topLevelComponentList, potentialPaths, 0, "/");
328322
potentialPaths.reverse();
329323

330324
return potentialPaths;
331325
}
332326

327+
function addPotentialPaths(componentList, potentialPaths, offset, prefix) {
328+
for (var i = componentList.length; i > offset; i--) {
329+
var tmpList = componentList.slice(0, i-1).concat([componentList[componentList.length-1]]);
330+
var sessionLevelPath = prefix + tmpList.join("_");
331+
potentialPaths.push(sessionLevelPath);
332+
}
333+
}
334+
333335
/**
334336
* Generate Merged Sidecar Dictionary
335337
*

0 commit comments

Comments
 (0)