Skip to content

Commit b93c698

Browse files
committed
first draft
1 parent 059b2da commit b93c698

12 files changed

Lines changed: 226 additions & 34 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*DS_Store
22

3+
output
4+
35
## virtual env
46
cpp_spm/*
57
env/*

init_env.m

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
%
2-
% 1 - Check if version requirements
3-
% are satisfied and the packages are
4-
% are installed/loaded:
5-
% Octave > 4
6-
% - image
7-
% - optim
8-
% - struct
9-
% - statistics
10-
%
11-
% MATLAB >= R2015b
12-
%
13-
% 2 - Add project to the O/M path
14-
15-
function initEnv
1+
function init_env()
2+
%
3+
% 1 - Check if version requirements
4+
% are satisfied and the packages are
5+
% are installed/loaded:
6+
% Octave > 4
7+
% - image
8+
% - optim
9+
% - struct
10+
% - statistics
11+
%
12+
% MATLAB >= R2015b
13+
%
14+
% 2 - Add project to the O/M path
15+
% (C) Copyright 2021 Remi Gau
1616

1717
octaveVersion = '4.0.3';
1818
matlabVersion = '8.6.0';
1919

2020
installlist = {'io', 'statistics', 'image'};
2121

22-
if isOctave
22+
if is_octave
2323

2424
% Exit if min version is not satisfied
2525
if ~compare_versions(OCTAVE_VERSION, octaveVersion, '>=')
@@ -28,16 +28,16 @@
2828

2929
for ii = 1:length(installlist)
3030

31-
packageName = installlist{ii};
31+
package_name = installlist{ii};
3232

3333
try
3434
% Try loading Octave packages
35-
disp(['loading ' packageName]);
36-
pkg('load', packageName);
35+
disp(['loading ' package_name]);
36+
pkg('load', package_name);
3737

3838
catch
3939

40-
tryInstallFromForge(packageName);
40+
try_install_from_forge(package_name);
4141

4242
end
4343
end
@@ -59,14 +59,14 @@
5959
'Try this in your terminal:', ...
6060
' git submodule update --recursive ']);
6161
else
62-
addDependencies();
62+
add_dependencies();
6363
end
6464

6565
disp('Correct matlab/octave verions and added to the path!');
6666

6767
end
6868

69-
function retval = isOctave
69+
function retval = is_octave
7070
% Return: true if the environment is Octave.
7171
persistent cacheval % speeds up repeated calls
7272

@@ -78,13 +78,13 @@
7878

7979
end
8080

81-
function tryInstallFromForge(packageName)
81+
function try_install_from_forge(package_name)
8282

8383
errorcount = 1;
8484
while errorcount % Attempt twice in case installation fails
8585
try
86-
pkg('install', '-forge', packageName);
87-
pkg('load', packageName);
86+
pkg('install', '-forge', package_name);
87+
pkg('load', package_name);
8888
errorcount = 0;
8989
catch err
9090
errorcount = errorcount + 1;
@@ -96,10 +96,10 @@ function tryInstallFromForge(packageName)
9696

9797
end
9898

99-
function addDependencies()
99+
function add_dependencies()
100100

101101
pth = fileparts(mfilename('fullpath'));
102-
addpath(genpath(fullfile(pth, 'lib')));
102+
addpath(fullfile(pth, 'lib', 'bids-matlab'));
103103
addpath(genpath(fullfile(pth, 'src')));
104104

105105
end

lib/bids-matlab

Submodule bids-matlab updated 547 files

miss_hit.cfg

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# styly guide (https://florianschanda.github.io/miss_hit/style_checker.html)
22
project_root
33

4-
line_length: 100
5-
regex_function_name: "[a-z]+(([A-Z]){1}[A-Za-z]+)*"
6-
suppress_rule: "copyright_notice"
4+
line_length: 120
5+
regex_function_name: "[a-z]+(_[A-Za-z]+)*"
6+
regex_parameter_name: "[a-z]+(_[A-Za-z]+)*"
77
exclude_dir: "lib"
88

99
# metric for code quality

src/importBids.m

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
function import_bids(cfg)
2+
%
3+
%
4+
%
5+
% USAGE
6+
%
7+
% EXAMPLE
8+
%
9+
% (C) Copyright 2021 Remi Gau
10+
11+
cfg.force = true;
12+
cfg.skip_dep = true;
13+
cfg.verbose = true;
14+
cfg.use_schema = true;
15+
16+
cfg.filter = struct();
17+
18+
BIDS = bids.layout(cfg.bidsroot);
19+
20+
pipeline_name = 'letswave_bids_import';
21+
22+
bids.copy_to_derivative(BIDS, pipeline_name, ...
23+
cfg.out_path, ...
24+
cfg.filter, ...
25+
'unzip', false, ...
26+
'force', cfg.force, ...
27+
'skip_dep', cfg.skip_dep, ...
28+
'use_schema', cfg.use_schema, ...
29+
'verbose', cfg.verbose);
30+
31+
BIDS = bids.layout(fullfile(cfg.out_path, pipeline_name));
32+
33+
BIDS.description.GeneratedBy.Version = getVersion();
34+
BIDS.description.GeneratedBy.Description = 'Import data and convert to lets wave format';
35+
BIDS.description.GeneratedBy.CodeURL = repoURL();
36+
37+
bids.util.jsonwrite(fullfile(cfg.out_path, pipeline_name, 'dataset_description.json'), ...
38+
BIDS.description);
39+
40+
files = bids.query(BIDS, 'data', ...
41+
'suffix', 'eeg', ...
42+
'extension', {'.set', '.bdf', '.edf', '.eeg'});
43+
44+
for iFile = 1:size(files, 1)
45+
46+
[~, ~, ext] = fileparts(files{iFile});
47+
48+
switch ext
49+
case '.set'
50+
configuration = LW_import_SET('default');
51+
52+
configuration.parameters.filenames = {files{iFile}};
53+
54+
[~, datasets] = LW_import_BDF('process', configuration);
55+
56+
save_data(files{iFile}, datasets);
57+
58+
delete(files{iFile});
59+
60+
otherwise
61+
% TODO
62+
warning('FORMAT NOT YET SUPPORTED');
63+
64+
end
65+
end
66+
67+
end
68+
69+
function save_data(filename, datasets)
70+
71+
% save header
72+
header = datasets.header; %#ok<*NASGU>
73+
new_filename = bids.internal.file_utils(filename, 'ext', '.lw5');
74+
disp(['saving ', new_filename]);
75+
save(new_filename, '-MAT', 'header');
76+
77+
% save data
78+
data = datasets.data;
79+
new_filename = bids.internal.file_utils(filename, 'ext', '.mat');
80+
save(new_filename, '-MAT', 'data');
81+
82+
end

src/utils/getRootDir.m

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
function root_dir = getroot_dir()
2+
%
3+
% (C) Copyright 2021 Remi Gau
4+
5+
root_dir = fullfile(fileparts(mfilename('fullpath')), '..', '..');
6+
7+
end

src/utils/getVersion.m

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
function version_number = getVersion()
2+
%
3+
% Reads the version number of the pipeline from the txt file in the root of the
4+
% repository.
5+
%
6+
% USAGE::
7+
%
8+
% version_number = getVersion()
9+
%
10+
% :returns: :version_number: (string) Use semantic versioning format (like v0.1.0)
11+
%
12+
% (C) Copyright 2021 Remi Gau
13+
14+
try
15+
version_number = fileread(getroot_dir(), 'version.txt');
16+
catch
17+
version_number = 'v0.1.0';
18+
end
19+
end

src/utils/printCredits.m

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
function repoURL = printCredits(cfg)
2+
%
3+
% TODO: use the .zenodo.json to load contributors
4+
%
5+
% (C) Copyright 2021 Remi Gau
6+
7+
version_number = getVersion();
8+
9+
contributors = {'Remi Gau'};
10+
11+
% DOI_URL = 'https://doi.org/';
12+
13+
if cfg.verbose
14+
15+
splash = 'Thank you for using lets wave bids import - version %s. ';
16+
fprintf(splash, version_number);
17+
fprintf('\n\n');
18+
19+
fprintf('Current list of contributors includes\n');
20+
for iCont = 1:numel(contributors)
21+
fprintf(' %s\n', contributors{iCont});
22+
end
23+
fprintf('\b\n\n');
24+
25+
% fprintf('Please cite using the following DOI: \n %s\n\n', DOI_URL);
26+
27+
fprintf('For bug report & suggestions see our github repo: \n %s\n\n', repoURL());
28+
29+
disp('___________________________________________________________________________');
30+
disp('___________________________________________________________________________');
31+
32+
fprintf('\n\n');
33+
34+
end
35+
36+
end

src/utils/repoURL.m

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
function s = repoURL()
2+
% (C) Copyright 2021 Remi Gau
3+
4+
s = 'https://github.com/cpp-lln-lab/letswave_bids_import';
5+
6+
end

tests/miss_hit.cfg

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

0 commit comments

Comments
 (0)