Skip to content

Commit

Permalink
Merge pull request #607 from bGrass/bugfix_600
Browse files Browse the repository at this point in the history
Fix bug #600 and add a couple tests
  • Loading branch information
nellh authored Oct 4, 2018
2 parents 44460ce + 57c839b commit 70062aa
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
38 changes: 38 additions & 0 deletions utils/__tests__/bids_files.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const assert = require('chai').assert
const { checkSidecarForDatafiles } = require('../bids_files.js')

describe('bids_files', () => {
describe('checkSidecarForDatafiles()', () => {
it('matches .tsv datafile to sidecar', () => {
const file = {
relativePath:
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.json',
}
const fileList = {
'1': {
name: 'sub-02_task-balloonanalogrisktask_run-01_events.tsv',
relativePath:
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.tsv',
},
}
const match = checkSidecarForDatafiles(file, fileList)
assert.isTrue(match)
})

it('does not match invalid datafile formats', () => {
const file = {
relativePath:
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.json',
}
const fileList = {
'1': {
name: 'sub-02_task-balloonanalogrisktask_run-01_events.tsv',
relativePath:
'ds001/sub-02/func/sub-02_task-balloonanalogrisktask_run-01_events.tsn',
},
}
const match = checkSidecarForDatafiles(file, fileList)
assert.isFalse(match)
})
})
})
3 changes: 2 additions & 1 deletion utils/bids_files.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,10 @@ function verifyDatafileMatch(sidecarPath, noExt, matchFile) {
let megDs = false
// Make sure it's not the data dictionary itself
const isSelf = matchFile.relativePath === sidecarPath
if (!isSelf && type.file.isModality(matchFile.name)) {
if (!isSelf && type.file.isDatafile(matchFile.relativePath)) {
match = true
}

// MEG datafiles may be a folder, therefore not contained in fileList, will need to look in paths
if (
!isSelf &&
Expand Down
27 changes: 27 additions & 0 deletions utils/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,40 @@ module.exports = {
)
},

/**
* Check if file is a data file
*/
isDatafile: function(path) {
return (
this.isAssociatedData(path) ||
this.isTSV(path) ||
this.isStimuliData(path) ||
this.isPhenotypic(path) ||
this.isModality(path) ||
this.isAnat(path) ||
this.isDWI(path) ||
this.isFieldMap(path) ||
this.isFieldMapMainNii(path) ||
this.isFunc(path) ||
this.isMeg(path) ||
this.isEeg(path) ||
this.isIEEG(path) ||
this.isBehavioral(path) ||
this.isFuncBold(path) ||
this.isCont(path)
)
},
/**
* Check if file is appropriate associated data.
*/
isAssociatedData: function(path) {
return associatedData.test(path)
},

isTSV: function(path) {
return path.endsWith('.tsv')
},

isStimuliData: function(path) {
return stimuliData.test(path)
},
Expand Down

0 comments on commit 70062aa

Please sign in to comment.