Skip to content

Commit 6a72118

Browse files
author
Zack Michael
committed
Finished new error mapping strategy, added verbosity argument and updated CLI
1 parent e6b764d commit 6a72118

File tree

6 files changed

+172
-146
lines changed

6 files changed

+172
-146
lines changed

bin/bids-validator

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ var argv = require('yargs')
99
.describe('ignoreWarnings', 'disregard non-critical issues')
1010
.boolean('ignoreNiftiHeaders')
1111
.describe('ignoreNiftiHeaders', 'disregard NIfTI header content during validation')
12+
.boolean('verbose')
13+
.describe('verbose', 'Log more extensive infomation about issues.')
1214
.epilogue("This tool checks if a dataset in a given directory is \
1315
compatible with the Brain Imaging Data Structure specification. To learn \
1416
more about Brain Imaging Data Structure visit http://bids.neuroimaging.io")
1517
.argv;
1618

1719
// import and init command line interface
18-
require('../cli')(argv._[0], {ignoreWarnings: argv.ignoreWarnings, ignoreNiftiHeaders: argv.ignoreNiftiHeaders});
20+
require('../cli')(argv._[0], argv);

cli.js

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,44 +5,42 @@ var fs = require('fs')
55
module.exports = function (dir, options) {
66
if (fs.existsSync(dir)) {
77
validate.BIDS(dir, options, function (errors, warnings) {
8-
console.log(errors);
9-
console.log(warnings);
10-
console.log(errors.length);
11-
console.log(warnings.length);
12-
// if (errors === 'Invalid') {
13-
// console.log(colors.red("This does not appear to be a BIDS dataset. For more info go to http://bids.neuroimaging.io/"));
14-
// } else if (errors.length >= 1 || warnings.length >= 1) {
15-
// logIssues(errors, 'red');
16-
// logIssues(warnings, 'yellow');
17-
// }
18-
// else {
19-
// console.log(colors.green("This dataset appears to be BIDS compatible."));
20-
// }
8+
if (errors === 'Invalid') {
9+
console.log(colors.red("This does not appear to be a BIDS dataset. For more info go to http://bids.neuroimaging.io/"));
10+
} else if (errors.length >= 1 || warnings.length >= 1) {
11+
logIssues(errors, 'red', options);
12+
logIssues(warnings, 'yellow', options);
13+
}
14+
else {
15+
console.log(colors.green("This dataset appears to be BIDS compatible."));
16+
}
2117
});
2218
} else {
2319
console.log(colors.red(dir + " does not exits"))
2420
}
2521
};
2622

27-
function logIssues (issues, color) {
23+
function logIssues (issues, color, options) {
2824
for (var i = 0; i < issues.length; i++) {
29-
console.log('\t' + colors[color](issues[i].path));
30-
for (var j = 0; j < issues[i].errors.length; j++) {
31-
var error = issues[i].errors[j];
32-
if (!error) {continue;}
33-
console.log('\t' + error.reason);
34-
if (error.line) {
35-
var msg = '\t@ line: ' + error.line
36-
if (error.character) {
37-
msg += ' character: ' + error.character
25+
var issue = issues[i];
26+
console.log('\t' + colors[color]((i + 1) + ': ' + issue.reason + ' (code: ' + issue.code + ')'));
27+
for (var j = 0; j < issue.files.length; j++) {
28+
var file = issues[i].files[j];
29+
if (!file) {continue;}
30+
console.log('\t\t' + file.path);
31+
if (options.verbose) {console.log('\t\t\t' + file.reason);}
32+
if (file.line) {
33+
var msg = '\t\t\t@ line: ' + file.line
34+
if (file.character) {
35+
msg += ' character: ' + file.character
3836
}
3937
console.log(msg)
4038
}
41-
if (error.evidence) {
42-
console.log('\tEvidence: ' + error.evidence);
39+
if (file.evidence) {
40+
console.log('\t\t\tEvidence: ' + file.evidence);
4341
}
44-
console.log('\tSeverity: ' + error.severity);
45-
console.log();
42+
// console.log('\tSeverity: ' + file.severity);
43+
// console.log();
4644
}
4745
}
4846
}

utils/index.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
require('./prototype');
2-
var type = require('./type');
3-
var files = require('./files');
4-
var Issue = require('./issue');
2+
var type = require('./type');
3+
var files = require('./files');
4+
var Issue = require('./issue');
5+
var issues = require('./issues');
56

67
module.exports = {
78
files: files,
89
type: type,
9-
Issue: Issue
10+
Issue: Issue,
11+
issues: issues
1012
};

utils/issue.js

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var issues = require('./issues');
2+
13
/**
24
* Issue
35
*
@@ -7,122 +9,12 @@ module.exports = function (options) {
79
var code = options.hasOwnProperty('code') ? options.code : null;
810
var issue = issues[code];
911

12+
this.code = code;
1013
this.filename = options.hasOwnProperty('file') ? options.file.name : null;
1114
this.path = options.hasOwnProperty('path') ? options.path : options.file.relativePath;
1215
this.evidence = options.hasOwnProperty('evidence') ? options.evidence : null;
1316
this.line = options.hasOwnProperty('line') ? options.line : null;
1417
this.character = options.hasOwnProperty('character') ? options.character : null;
1518
this.severity = options.hasOwnProperty('severity') ? options.severity : issue.severity;
1619
this.reason = options.hasOwnProperty('reason') ? options.reason : issue.reason;
17-
};
18-
19-
var issues = {
20-
1: {
21-
severity: 'warning',
22-
reason: "This file is not part of the BIDS specification, make sure it isn't included in the dataset by accident. Data derivatives (processed data) should be placed in /derivatives folder."
23-
},
24-
2: {
25-
severity: 'warning',
26-
reason: "'RepetitionTime' is greater than 100 are you sure it's expressed in seconds?"
27-
},
28-
3: {
29-
severity: 'warning',
30-
reason: "'EchoTime' is greater than 1 are you sure it's expressed in seconds?"
31-
},
32-
4: {
33-
severity: 'warning',
34-
reason: "'EchoTimeDifference' is greater than 1 are you sure it's expressed in seconds?"
35-
},
36-
5: {
37-
severity: 'warning',
38-
reason: "'TotalReadoutTime' is greater than 10 are you sure it's expressed in seconds?"
39-
},
40-
6: {
41-
severity: 'warning',
42-
reason: "You should should define 'EchoTime' for this file. If you don't provide this information field map correction will not be possible."
43-
},
44-
7: {
45-
severity: 'warning',
46-
reason: "You should should define 'PhaseEncodingDirection' for this file. If you don't provide this information field map correction will not be possible."
47-
},
48-
8: {
49-
severity: 'warning',
50-
reason: "You should should define 'EffectiveEchoSpacing' for this file. If you don't provide this information field map correction will not be possible."
51-
},
52-
9: {
53-
severity: 'warning',
54-
reason: "You should should define 'TotalReadoutTime' for this file. If you don't provide this information field map correction using TOPUP might not be possible."
55-
},
56-
10: {
57-
severity: 'error',
58-
reason: "You have to define 'RepetitionTime' for this file."
59-
},
60-
11: {
61-
severity: 'error',
62-
reason: "Repetition time was not defined in seconds, milliseconds or microseconds in the scan's header."
63-
},
64-
12: {
65-
severity: 'error',
66-
reason: "Repetition time did not match between the scan's header and the associated JSON metadata file."
67-
},
68-
13: {
69-
severity: 'warning',
70-
reason: "You should should define 'SliceTiming' for this file. If you don't provide this information slice time correction will not be possible."
71-
},
72-
14: {
73-
severity: 'warning',
74-
reason: "You should should define 'SliceEncodingDirection' for this file. If you don't provide this information slice time correction will not be possible."
75-
},
76-
15: {
77-
severity: 'error',
78-
reason: "You have to define 'EchoTimeDifference' for this file."
79-
},
80-
16: {
81-
severity: 'error',
82-
reason: "You have to define 'EchoTime' for this file."
83-
},
84-
17: {
85-
severity: 'error',
86-
reason: "You have to define 'Units' for this file."
87-
},
88-
18: {
89-
severity: 'error',
90-
reason: "You have to define 'PhaseEncodingDirection' for this file."
91-
},
92-
19: {
93-
severity: 'error',
94-
reason: "You have to define 'TotalReadoutTime' for this file."
95-
},
96-
20: {
97-
severity: 'error',
98-
reason: "First column of the events file must be named 'onset'"
99-
},
100-
21: {
101-
severity: 'error',
102-
reason: "Second column of the events file must be named 'duration'"
103-
},
104-
22: {
105-
severity: 'error',
106-
reason: 'All rows must have the same number of columns as there are headers.'
107-
},
108-
23: {
109-
severity: 'error',
110-
reason: 'Values may not contain adjacent spaces.'
111-
},
112-
24: {
113-
severity: 'warning',
114-
reason: 'A proper way of labeling missing values is "n/a".'
115-
},
116-
25: {
117-
severity: 'warning',
118-
reason: 'Task scans should have a correspondings events.tsv file.'
119-
},
120-
26: {
121-
severity: 'error',
122-
reason: "We were unable to read the contents of this file."
123-
},
124-
27: {
125-
serverity: 'error',
126-
reason: "Not a valid JSON file."
127-
}
128-
}
20+
};

utils/issues.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/**
2+
* Issues
3+
*
4+
* A list of all possible issues organized by
5+
* issue code and including severity and reason
6+
* agnostic to file specifics.
7+
*/
8+
module.exports = {
9+
1: {
10+
severity: 'warning',
11+
reason: "This file is not part of the BIDS specification, make sure it isn't included in the dataset by accident. Data derivatives (processed data) should be placed in /derivatives folder."
12+
},
13+
2: {
14+
severity: 'warning',
15+
reason: "'RepetitionTime' is greater than 100 are you sure it's expressed in seconds?"
16+
},
17+
3: {
18+
severity: 'warning',
19+
reason: "'EchoTime' is greater than 1 are you sure it's expressed in seconds?"
20+
},
21+
4: {
22+
severity: 'warning',
23+
reason: "'EchoTimeDifference' is greater than 1 are you sure it's expressed in seconds?"
24+
},
25+
5: {
26+
severity: 'warning',
27+
reason: "'TotalReadoutTime' is greater than 10 are you sure it's expressed in seconds?"
28+
},
29+
6: {
30+
severity: 'warning',
31+
reason: "You should should define 'EchoTime' for this file. If you don't provide this information field map correction will not be possible."
32+
},
33+
7: {
34+
severity: 'warning',
35+
reason: "You should should define 'PhaseEncodingDirection' for this file. If you don't provide this information field map correction will not be possible."
36+
},
37+
8: {
38+
severity: 'warning',
39+
reason: "You should should define 'EffectiveEchoSpacing' for this file. If you don't provide this information field map correction will not be possible."
40+
},
41+
9: {
42+
severity: 'warning',
43+
reason: "You should should define 'TotalReadoutTime' for this file. If you don't provide this information field map correction using TOPUP might not be possible."
44+
},
45+
10: {
46+
severity: 'error',
47+
reason: "You have to define 'RepetitionTime' for this file."
48+
},
49+
11: {
50+
severity: 'error',
51+
reason: "Repetition time was not defined in seconds, milliseconds or microseconds in the scan's header."
52+
},
53+
12: {
54+
severity: 'error',
55+
reason: "Repetition time did not match between the scan's header and the associated JSON metadata file."
56+
},
57+
13: {
58+
severity: 'warning',
59+
reason: "You should should define 'SliceTiming' for this file. If you don't provide this information slice time correction will not be possible."
60+
},
61+
14: {
62+
severity: 'warning',
63+
reason: "You should should define 'SliceEncodingDirection' for this file. If you don't provide this information slice time correction will not be possible."
64+
},
65+
15: {
66+
severity: 'error',
67+
reason: "You have to define 'EchoTimeDifference' for this file."
68+
},
69+
16: {
70+
severity: 'error',
71+
reason: "You have to define 'EchoTime' for this file."
72+
},
73+
17: {
74+
severity: 'error',
75+
reason: "You have to define 'Units' for this file."
76+
},
77+
18: {
78+
severity: 'error',
79+
reason: "You have to define 'PhaseEncodingDirection' for this file."
80+
},
81+
19: {
82+
severity: 'error',
83+
reason: "You have to define 'TotalReadoutTime' for this file."
84+
},
85+
20: {
86+
severity: 'error',
87+
reason: "First column of the events file must be named 'onset'"
88+
},
89+
21: {
90+
severity: 'error',
91+
reason: "Second column of the events file must be named 'duration'"
92+
},
93+
22: {
94+
severity: 'error',
95+
reason: 'All rows must have the same number of columns as there are headers.'
96+
},
97+
23: {
98+
severity: 'error',
99+
reason: 'Values may not contain adjacent spaces.'
100+
},
101+
24: {
102+
severity: 'warning',
103+
reason: 'A proper way of labeling missing values is "n/a".'
104+
},
105+
25: {
106+
severity: 'warning',
107+
reason: 'Task scans should have a correspondings events.tsv file.'
108+
},
109+
26: {
110+
severity: 'error',
111+
reason: "We were unable to read the contents of this file."
112+
},
113+
27: {
114+
serverity: 'error',
115+
reason: "Not a valid JSON file."
116+
}
117+
};

0 commit comments

Comments
 (0)