Skip to content

Commit f9281a1

Browse files
committed
fix extra tab added at the end of tsv lines
1 parent 8fcc3cd commit f9281a1

File tree

10 files changed

+190
-64
lines changed

10 files changed

+190
-64
lines changed

.pre-commit-config.yaml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
repos:
2+
3+
- repo: local
4+
5+
hooks:
6+
7+
- id: mh_version
8+
name: mh_version
9+
entry: mh_style
10+
args: [-v]
11+
verbose: true
12+
language: python
13+
additional_dependencies: [miss_hit_core]
14+
15+
# - id: mh_style
16+
# name: mh_style
17+
# entry: mh_style
18+
# args: [--process-slx, --fix]
19+
# files: ^(.*\.(m|slx))$
20+
# language: python
21+
# additional_dependencies: [miss_hit_core]
22+
23+
# - id: mh_metric
24+
# name: mh_metric
25+
# entry: mh_metric
26+
# args: [--ci]
27+
# files: ^(.*\.(m|slx))$
28+
# language: python
29+
# additional_dependencies: [miss_hit_core]
30+
31+
# - id: mh_lint
32+
# name: mh_lint
33+
# entry: mh_lint
34+
# files: ^(.*\.(m|slx))$
35+
# language: python
36+
# additional_dependencies: [miss_hit]
37+
38+
- repo: https://github.com/pre-commit/pre-commit-hooks
39+
rev: v2.0.0
40+
hooks:
41+
- id: trailing-whitespace
42+
- id: end-of-file-fixer
43+
- id: check-yaml
44+
- id: check-added-large-files

checkCppBidsDependencies.m

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
% (C) Copyright 2020 CPP_BIDS developers
2+
3+
function checkCppBidsDependencies(cfg)
4+
%
5+
% Adds dependencies to the Matlab / Octave path and make sure we got all of them.
6+
%
7+
% USAGE::
8+
%
9+
% checkCppBidsDependencies(cfg)
10+
%
11+
% :param cfg: Configuration. See ``checkCFG()``.
12+
% :type cfg: structure
13+
14+
if nargin < 1
15+
cfg.verbose = 2;
16+
end
17+
18+
global CPP_BIDS_INITIALIZED
19+
20+
if isempty(CPP_BIDS_INITIALIZED)
21+
22+
GITHUB_WORKSPACE = getenv('GITHUB_WORKSPACE');
23+
24+
if strcmp(GITHUB_WORKSPACE, '/github/workspace')
25+
26+
pth = GITHUB_WORKSPACE;
27+
addpath(genpath(fullfile(pth, 'lib')));
28+
29+
elseif isempty(GITHUB_WORKSPACE) % local
30+
31+
pth = fullfile(fileparts(mfilename('fullpath')));
32+
33+
addpath(pth);
34+
35+
addpath(fullfile(pth, 'lib', 'utils'));
36+
37+
checkSubmodule(fullfile(pth, 'lib', 'JSONio'));
38+
checkSubmodule(fullfile(pth, 'lib', 'bids-matlab'));
39+
40+
addpath(genpath(fullfile(pth, 'src')));
41+
42+
end
43+
44+
printCreditsCppBids(cfg);
45+
46+
CPP_BIDS_INITIALIZED = true();
47+
48+
else
49+
fprintf(1, '\n\nCPP_BIDS already initialized\n\n');
50+
51+
end
52+
53+
end
54+
55+
function checkSubmodule(pth)
56+
% If external dir is empty throw an exception
57+
% and ask user to update submodules.
58+
if numel(dir(pth)) <= 2 % Means that the external is empty
59+
error(['Git submodules are not cloned!', ...
60+
'Try this in your terminal:', ...
61+
' git submodule update --recursive ']);
62+
else
63+
addpath(pth);
64+
end
65+
end

miss_hit.cfg

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
22
line_length: 100
33
regex_function_name: "[a-z]+(([A-Z]){1}[A-Za-z]+)*"
4+
regex_parameter_name: "[a-z0-9]+(([A-Z]){1}[A-Za-z]+)*"
5+
46
exclude_dir: "lib"
57
copyright_entity: "CPP_BIDS developers"
68

79
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
810
metric "cnest": limit 4
911
metric "file_length": limit 500
1012
metric "cyc": limit 15
11-
metric "parameters": limit 6
13+
metric "parameters": limit 6

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ Sphinx
22
sphinxcontrib-matlabdomain
33
sphinxcontrib-napoleon
44
sphinx_rtd_theme
5-
miss_hit==0.9.15
5+
miss_hit==0.9.29
66
notebook
7-
octave_kernel
7+
octave_kernel

src/saveEventsFile.m

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -378,9 +378,9 @@ function printToFile(cfg, logFile, skipEvent, iEvent)
378378
if ~skipEvent
379379

380380
if ~logFile(1).isStim
381-
printData(logFile(1).fileID, logFile(iEvent).onset, cfg);
382-
printData(logFile(1).fileID, logFile(iEvent).duration, cfg);
383-
printData(logFile(1).fileID, logFile(iEvent).trial_type, cfg);
381+
printData(logFile(1).fileID, logFile(iEvent).onset, cfg, true);
382+
printData(logFile(1).fileID, logFile(iEvent).duration, cfg, true);
383+
printData(logFile(1).fileID, logFile(iEvent).trial_type, cfg, false);
384384
end
385385

386386
printExtraColumns(logFile, iEvent, cfg);
@@ -394,26 +394,41 @@ function printToFile(cfg, logFile, skipEvent, iEvent)
394394
function printExtraColumns(logFile, iEvent, cfg)
395395
% loops through the extra columns and print them
396396
namesExtraColumns = returnNamesExtraColumns(logFile);
397+
if ~logFile(1).isStim && numel(namesExtraColumns) > 0
398+
fprintf(logFile(1).fileID, '\t');
399+
talkToMe(cfg, '\t');
400+
end
401+
addTab = true;
397402
for iExtraColumn = 1:numel(namesExtraColumns)
398403
data = logFile(iEvent).(namesExtraColumns{iExtraColumn});
399-
printData(logFile(1).fileID, data, cfg);
404+
if iExtraColumn == numel(namesExtraColumns)
405+
addTab = false;
406+
end
407+
printData(logFile(1).fileID, data, cfg, addTab);
400408
end
401409
end
402410

403-
function printData(output, data, cfg)
411+
function printData(output, data, cfg, addTab)
404412
% write char
405413
% for numeric data we replace any nan by n/a
414+
415+
if addTab
416+
separator = '\t';
417+
else
418+
separator = '';
419+
end
420+
406421
if ischar(data)
407-
content = sprintf('%s\t', data);
422+
content = sprintf('%s%s', data, separator);
408423
fprintf(output, content);
409424
talkToMe(cfg, content);
410425

411426
else
412427
for i = 1:numel(data)
413428
if isnan(data(i))
414-
content = sprintf('%s\t', 'n/a');
429+
content = sprintf('%s%s', 'n/a', separator);
415430
else
416-
content = sprintf('%f\t', data(i));
431+
content = sprintf('%f%s', data(i), separator);
417432
end
418433
fprintf(output, content);
419434
talkToMe(cfg, content);

src/templates/miss_hit.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
22
line_length: 100
33
regex_function_name: "((test_[a-z]+)|[a-z]+)(([A-Z]){1}[A-Za-z]+)*"
4+
regex_parameter_name: "test_suite|[a-z0-9]+(([A-Z]){1}[A-Za-z]+)*"
45

56
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
67
metric "cnest": limit 4
78
metric "file_length": limit 500
89
metric "cyc": limit 15
9-
metric "parameters": limit 5
10+
metric "parameters": limit 5

src/utils/checkCppBidsDependencies.m

Lines changed: 0 additions & 50 deletions
This file was deleted.

tests/miss_hit.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
# style guide (https://florianschanda.github.io/miss_hit/style_checker.html)
22
line_length: 100
33
regex_function_name: "((test_[a-z]+)|[a-z]+)(([A-Z]){1}[A-Za-z]+)*"
4+
regex_parameter_name: "test_suite|[a-z0-9]+(([A-Z]){1}[A-Za-z]+)*"
45

56
# metrics limit for the code quality (https://florianschanda.github.io/miss_hit/metrics.html)
67
metric "cnest": limit 4
78
metric "file_length": limit 500
89
metric "cyc": limit 15
9-
metric "parameters": limit 5
10+
metric "parameters": limit 5

tests/test_saveEventsFileSave.m

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,54 @@ function test_saveEventsFileSaveBasic()
4646

4747
end
4848

49+
function test_saveEventsFileSaveNoExtraTab()
50+
51+
cfg.verbose = 2;
52+
53+
cfg.subject.subjectNb = 1;
54+
cfg.subject.runNb = 1;
55+
56+
cfg.task.name = 'testtask';
57+
58+
cfg = createFilename(cfg);
59+
60+
logFile.extraColumns.Speed.length = 1;
61+
logFile.extraColumns.LHL24.length = 3;
62+
logFile.extraColumns.is_Fixation.length = 1;
63+
64+
logFile = saveEventsFile('init', cfg, logFile);
65+
logFile = saveEventsFile('open', cfg, logFile);
66+
67+
% logFile.onset = 2;
68+
% logFile.duration = 3;
69+
70+
% ROW 2: normal events : all info is there
71+
logFile(1, 1).onset = 2;
72+
logFile(end, 1).trial_type = 'MotionUp';
73+
logFile(end, 1).duration = 3;
74+
logFile(end, 1).Speed = 2;
75+
logFile(end, 1).is_Fixation = true;
76+
logFile(end, 1).LHL24 = 1:3;
77+
78+
logFile = saveEventsFile('save', cfg, logFile);
79+
80+
saveEventsFile('close', cfg, logFile);
81+
82+
funcDir = fullfile(cfg.dir.outputSubject, cfg.fileName.modality);
83+
eventFilename = cfg.fileName.events;
84+
85+
% FID = fopen(fullfile(funcDir, eventFilename), 'r');
86+
% content = fread(FID, 900, 'uint8=>char')
87+
88+
FID = fopen(fullfile(funcDir, eventFilename), 'r');
89+
content = fread(FID, 900);
90+
tab = 9;
91+
eol = 10;
92+
assert(content(end) == 10);
93+
assert(content(end - 1) ~= 9);
94+
95+
end
96+
4997
function test_saveEventsFileSaveStim()
5098

5199
%% set up

tests/utils/setUp.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
function [cfg, logFile] = setUp()
44

5-
cfg.verbose = 2;
5+
cfg.verbose = 0;
66

77
cfg.subject.subjectNb = 1;
88
cfg.subject.runNb = 1;

0 commit comments

Comments
 (0)