Skip to content

Commit f7ac6f8

Browse files
author
Brian
committed
Fix bug #600 and add a couple tests
1 parent 935fb5e commit f7ac6f8

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

utils/__tests__/bids_files.spec.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const assert = require('chai').assert
2+
const { checkSidecarForDatafiles } = require('../bids_files.js')
3+
4+
describe('bids_files', () => {
5+
describe('checkSidecarForDatafiles()', () => {
6+
it('matches .tsv datafile to sidecar', () => {
7+
const file = {
8+
relativePath:
9+
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.json',
10+
}
11+
const fileList = {
12+
'1': {
13+
name: 'sub-02_task-balloonanalogrisktask_run-01_events.tsv',
14+
relativePath:
15+
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.tsv',
16+
},
17+
}
18+
const match = checkSidecarForDatafiles(file, fileList)
19+
assert(match == true)
20+
})
21+
22+
it('does not match invalid datafile formats', () => {
23+
const file = {
24+
relativePath:
25+
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.json',
26+
}
27+
const fileList = {
28+
'1': {
29+
name: 'sub-02_task-balloonanalogrisktask_run-01_events.tsv',
30+
relativePath:
31+
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.tsn',
32+
},
33+
}
34+
const match = checkSidecarForDatafiles(file, fileList)
35+
assert(match == false)
36+
})
37+
})
38+
})

utils/bids_files.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ function verifyDatafileMatch(sidecarPath, noExt, matchFile) {
6464
let megDs = false
6565
// Make sure it's not the data dictionary itself
6666
const isSelf = matchFile.relativePath === sidecarPath
67-
if (!isSelf && type.file.isModality(matchFile.name)) {
67+
if (!isSelf && type.file.isDatafile(matchFile.relativePath)) {
6868
match = true
6969
}
70+
7071
// MEG datafiles may be a folder, therefore not contained in fileList, will need to look in paths
7172
if (
7273
!isSelf &&

utils/type.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,40 @@ module.exports = {
104104
)
105105
},
106106

107+
/**
108+
* Check if file is a data file
109+
*/
110+
isDatafile: function(path) {
111+
return (
112+
this.isAssociatedData(path) ||
113+
this.isTSV(path) ||
114+
this.isStimuliData(path) ||
115+
this.isPhenotypic(path) ||
116+
this.isModality(path) ||
117+
this.isAnat(path) ||
118+
this.isDWI(path) ||
119+
this.isFieldMap(path) ||
120+
this.isFieldMapMainNii(path) ||
121+
this.isFunc(path) ||
122+
this.isMeg(path) ||
123+
this.isEeg(path) ||
124+
this.isIEEG(path) ||
125+
this.isBehavioral(path) ||
126+
this.isFuncBold(path) ||
127+
this.isCont(path)
128+
)
129+
},
107130
/**
108131
* Check if file is appropriate associated data.
109132
*/
110133
isAssociatedData: function(path) {
111134
return associatedData.test(path)
112135
},
113136

137+
isTSV: function(path) {
138+
return path.endsWith('.tsv')
139+
},
140+
114141
isStimuliData: function(path) {
115142
return stimuliData.test(path)
116143
},

0 commit comments

Comments
 (0)