Skip to content

Commit cbcb0d3

Browse files
authored
Merge pull request #631 from olgn/fix-missing-trims
Fix missing trims
2 parents 6d9264f + a89f2d4 commit cbcb0d3

File tree

5 files changed

+69
-19
lines changed

5 files changed

+69
-19
lines changed

tests/bids.spec.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,6 @@ describe('BIDS example datasets ', function() {
147147
})
148148
})
149149

150-
it('checks for tabular files with custom columns not described in a data dictionary', function(isdone) {
151-
var options = { ignoreNiftiHeaders: true }
152-
validate.BIDS(
153-
'tests/data/bids-examples-' + global.test_version + '/ds001',
154-
//'tests/data/ds001344-1.0.0',
155-
options,
156-
function(issues) {
157-
assert(issues.warnings.length === 2 && issues.warnings[1].code === '82')
158-
isdone()
159-
},
160-
)
161-
})
162-
163150
it('validates MRI modalities', function(isdone) {
164151
var options = { ignoreNiftiHeaders: true }
165152
validate.BIDS(

validators/events.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ const checkDesignLength = function(events, headers, jsonContents) {
8585
.filter(row => !(!row || /^\s*$/.test(row)))
8686

8787
// get the 'onset' field of the last event (lastEventOnset)
88-
const lastEventOnset = rows[rows.length - 1].split('\t')[0]
88+
const lastEventOnset = rows[rows.length - 1].trim().split('\t')[0]
8989

9090
// check if lastEventOnset > longDurationThreshold - append issue if so
9191
if (lastEventOnset > longDurationThreshold) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const assert = require('chai').assert
2+
const validateTsvColumns = require('../validateTsvColumns')
3+
4+
describe('validateTsvColumns', () => {
5+
const file = {
6+
name: 'participants.tsv',
7+
relativePath: '/participants.tsv',
8+
}
9+
const jsonContentsDict = {
10+
'/participants.json': { NewColumn: 'description' },
11+
}
12+
13+
it('allows for tabular files with columns that are described in the bids spec', () => {
14+
const tsvs = [
15+
{
16+
contents: 'participant_id\n',
17+
file: file,
18+
},
19+
]
20+
const issues = validateTsvColumns(tsvs, {})
21+
assert.lengthOf(issues, 0)
22+
})
23+
it('checks for tabular files with custom columns not described in a data dictionary', () => {
24+
const tsvs = [
25+
{
26+
contents: 'header1\n',
27+
file: file,
28+
},
29+
]
30+
const issues = validateTsvColumns(tsvs, {})
31+
assert.lengthOf(issues, 1)
32+
assert.equal(issues[0].code, 82)
33+
})
34+
it('allows custom columns if they are described in a data dictionary', () => {
35+
const tsvs = [
36+
{
37+
contents: 'NewColumn\n',
38+
file: file,
39+
},
40+
]
41+
const issues = validateTsvColumns(tsvs, jsonContentsDict)
42+
assert.lengthOf(issues, 0)
43+
})
44+
it('should trim the new line carriages created by windows tabular files,', () => {
45+
const tsvs = [
46+
{
47+
contents: 'participant_id\t\r\n',
48+
file: file,
49+
},
50+
{
51+
contents: 'participant_id\r\n',
52+
file: file,
53+
},
54+
]
55+
const issues = validateTsvColumns(tsvs, {})
56+
assert.lengthOf(issues, 0)
57+
})
58+
})

validators/tsv/tsv.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const TSV = (file, contents, fileList, callback) => {
2727
}
2828

2929
const rows = contents.split('\n')
30-
const headers = rows[0].split('\t')
30+
const headers = rows[0].trim().split('\t')
3131

3232
// generic checks -----------------------------------------------------------
3333

@@ -46,7 +46,7 @@ const TSV = (file, contents, fileList, callback) => {
4646
continue
4747
}
4848

49-
const values = row.split('\t')
49+
const values = row.trim().split('\t')
5050

5151
// check for different length rows
5252
if (values.length !== headers.length && !columnMismatch) {
@@ -150,7 +150,9 @@ const TSV = (file, contents, fileList, callback) => {
150150
const stimFiles = []
151151
if (headers.indexOf('stim_file') > -1) {
152152
for (let k = 0; k < rows.length; k++) {
153-
const stimFile = rows[k].split('\t')[headers.indexOf('stim_file')]
153+
const stimFile = rows[k].trim().split('\t')[
154+
headers.indexOf('stim_file')
155+
]
154156
const stimPath = '/stimuli/' + stimFile
155157
if (
156158
stimFile &&
@@ -199,7 +201,7 @@ const TSV = (file, contents, fileList, callback) => {
199201
} else {
200202
participants = []
201203
for (let l = 1; l < rows.length; l++) {
202-
const row = rows[l].split('\t')
204+
const row = rows[l].trim().split('\t')
203205
// skip empty rows
204206
if (!row || /^\s*$/.test(row)) {
205207
continue

validators/tsv/validateTsvColumns.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ const validateTsvColumns = function(tsvs, jsonContentsDict) {
5252
const tsvIssues = []
5353
tsvs.map(tsv => {
5454
const customColumns = getCustomColumns(
55-
tsv.contents.split('\n')[0].split('\t'),
55+
tsv.contents
56+
.split('\n')[0]
57+
.trim()
58+
.split('\t'),
5659
getTsvType(tsv.file),
5760
)
5861
if (customColumns.length > 0) {

0 commit comments

Comments
 (0)