Skip to content

Commit

Permalink
Merge pull request #631 from olgn/fix-missing-trims
Browse files Browse the repository at this point in the history
Fix missing trims
  • Loading branch information
chrisgorgo authored Oct 17, 2018
2 parents 6d9264f + a89f2d4 commit cbcb0d3
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 19 deletions.
13 changes: 0 additions & 13 deletions tests/bids.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,19 +147,6 @@ describe('BIDS example datasets ', function() {
})
})

it('checks for tabular files with custom columns not described in a data dictionary', function(isdone) {
var options = { ignoreNiftiHeaders: true }
validate.BIDS(
'tests/data/bids-examples-' + global.test_version + '/ds001',
//'tests/data/ds001344-1.0.0',
options,
function(issues) {
assert(issues.warnings.length === 2 && issues.warnings[1].code === '82')
isdone()
},
)
})

it('validates MRI modalities', function(isdone) {
var options = { ignoreNiftiHeaders: true }
validate.BIDS(
Expand Down
2 changes: 1 addition & 1 deletion validators/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ const checkDesignLength = function(events, headers, jsonContents) {
.filter(row => !(!row || /^\s*$/.test(row)))

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

// check if lastEventOnset > longDurationThreshold - append issue if so
if (lastEventOnset > longDurationThreshold) {
Expand Down
58 changes: 58 additions & 0 deletions validators/tsv/__tests__/validateTsvColumns.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const assert = require('chai').assert
const validateTsvColumns = require('../validateTsvColumns')

describe('validateTsvColumns', () => {
const file = {
name: 'participants.tsv',
relativePath: '/participants.tsv',
}
const jsonContentsDict = {
'/participants.json': { NewColumn: 'description' },
}

it('allows for tabular files with columns that are described in the bids spec', () => {
const tsvs = [
{
contents: 'participant_id\n',
file: file,
},
]
const issues = validateTsvColumns(tsvs, {})
assert.lengthOf(issues, 0)
})
it('checks for tabular files with custom columns not described in a data dictionary', () => {
const tsvs = [
{
contents: 'header1\n',
file: file,
},
]
const issues = validateTsvColumns(tsvs, {})
assert.lengthOf(issues, 1)
assert.equal(issues[0].code, 82)
})
it('allows custom columns if they are described in a data dictionary', () => {
const tsvs = [
{
contents: 'NewColumn\n',
file: file,
},
]
const issues = validateTsvColumns(tsvs, jsonContentsDict)
assert.lengthOf(issues, 0)
})
it('should trim the new line carriages created by windows tabular files,', () => {
const tsvs = [
{
contents: 'participant_id\t\r\n',
file: file,
},
{
contents: 'participant_id\r\n',
file: file,
},
]
const issues = validateTsvColumns(tsvs, {})
assert.lengthOf(issues, 0)
})
})
10 changes: 6 additions & 4 deletions validators/tsv/tsv.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const TSV = (file, contents, fileList, callback) => {
}

const rows = contents.split('\n')
const headers = rows[0].split('\t')
const headers = rows[0].trim().split('\t')

// generic checks -----------------------------------------------------------

Expand All @@ -46,7 +46,7 @@ const TSV = (file, contents, fileList, callback) => {
continue
}

const values = row.split('\t')
const values = row.trim().split('\t')

// check for different length rows
if (values.length !== headers.length && !columnMismatch) {
Expand Down Expand Up @@ -150,7 +150,9 @@ const TSV = (file, contents, fileList, callback) => {
const stimFiles = []
if (headers.indexOf('stim_file') > -1) {
for (let k = 0; k < rows.length; k++) {
const stimFile = rows[k].split('\t')[headers.indexOf('stim_file')]
const stimFile = rows[k].trim().split('\t')[
headers.indexOf('stim_file')
]
const stimPath = '/stimuli/' + stimFile
if (
stimFile &&
Expand Down Expand Up @@ -199,7 +201,7 @@ const TSV = (file, contents, fileList, callback) => {
} else {
participants = []
for (let l = 1; l < rows.length; l++) {
const row = rows[l].split('\t')
const row = rows[l].trim().split('\t')
// skip empty rows
if (!row || /^\s*$/.test(row)) {
continue
Expand Down
5 changes: 4 additions & 1 deletion validators/tsv/validateTsvColumns.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ const validateTsvColumns = function(tsvs, jsonContentsDict) {
const tsvIssues = []
tsvs.map(tsv => {
const customColumns = getCustomColumns(
tsv.contents.split('\n')[0].split('\t'),
tsv.contents
.split('\n')[0]
.trim()
.split('\t'),
getTsvType(tsv.file),
)
if (customColumns.length > 0) {
Expand Down

0 comments on commit cbcb0d3

Please sign in to comment.