From 414447af1d6900d13f5dccfcf0c363c38609fd3a Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 08:24:13 +0200 Subject: [PATCH 1/8] improve creation of stim file and their conversion to raw - creates test for remove date suffix - improves removing date suffix for zipped files like the stim ones --- .gitignore | 1 + manualTests/test_makeRawDataset.m | 20 +++++++- src/convertSourceToRaw.m | 37 +-------------- src/saveEventsFile.m | 13 ++--- src/subfun/parseFunc.m | 45 ++++++++++++++++++ src/subfun/removeDateSuffix.m | 33 +++++++++++++ tests/test_removeDateSuffix.m | 79 +++++++++++++++++++++++++++++++ tests/test_saveEventsFileOpen.m | 44 +++++++++++++++++ 8 files changed, 228 insertions(+), 44 deletions(-) create mode 100644 src/subfun/parseFunc.m create mode 100644 src/subfun/removeDateSuffix.m create mode 100644 tests/test_removeDateSuffix.m diff --git a/.gitignore b/.gitignore index 51fd1392..bdac3462 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,7 @@ output/* tests/coverage* tests/test_code_report.txt test_code_report.txt +*/coverage_html/* # exclude report from check_my_code check_my_code_report.txt diff --git a/manualTests/test_makeRawDataset.m b/manualTests/test_makeRawDataset.m index 9e4c8000..4997f6a1 100644 --- a/manualTests/test_makeRawDataset.m +++ b/manualTests/test_makeRawDataset.m @@ -68,6 +68,19 @@ function test_makeRawDataset() % close the file saveEventsFile('close', cfg, logFile); + % add dummy stim data + stimLogFile = saveEventsFile('open_stim', cfg, logFile); + for i = 1:100 + stimLogFile(i, 1).onset = cfg.mri.repetitionTime * i; + stimLogFile(i, 1).trial_type = 'test'; + stimLogFile(i, 1).duration = 1; + stimLogFile(i, 1).Speed = rand(1); + stimLogFile(i, 1).is_Fixation = rand > 0.5; + stimLogFile(i, 1).LHL24 = randn(1, 3); + end + saveEventsFile('save', cfg, stimLogFile); + saveEventsFile('close', cfg, stimLogFile); + % add dummy functional data funcDir = fullfile(cfg.dir.output, 'source', 'sub-001', 'ses-001', 'func'); boldFilename = 'sub-001_ses-001_task-testtask_run-001_bold.nii.gz'; @@ -87,6 +100,7 @@ function test_makeRawDataset() cfg.subject.sessionNb = 3; cfg.subject.runNb = 4; + % deal with MRI suffixes cfg.mri.reconstruction = 'fast recon'; cfg.mri.contrastEnhancement = 'test'; cfg.mri.phaseEncodingDirection = 'y pos'; @@ -100,7 +114,7 @@ function test_makeRawDataset() createBoldJson(cfg); - % add dummy functional data + %% add dummy functional data funcDir = fullfile(cfg.dir.output, 'source', 'sub-002', 'ses-003', 'func'); boldFilename = ['sub-002_ses-003_task-rest', ... '_acq-newTYpe_ce-test_dir-yPos_rec-fastRecon', ... @@ -110,9 +124,11 @@ function test_makeRawDataset() fullfile('..', 'dummyData', 'dummyData.nii.gz'), ... fullfile(funcDir, boldFilename)); - %% + %% actually do the conversion of the source data thus created clear; + outputDir = fullfile(fileparts(mfilename('fullpath')), 'output'); cfg.dir.output = outputDir; convertSourceToRaw(cfg); + end diff --git a/src/convertSourceToRaw.m b/src/convertSourceToRaw.m index 28e228a3..3ef05560 100644 --- a/src/convertSourceToRaw.m +++ b/src/convertSourceToRaw.m @@ -7,6 +7,7 @@ function convertSourceToRaw(cfg) % - copy source dir to raw dir % - remove the date suffix (_date-YYYYMMDDHHMM) from the files where it is present % + % Only covers func folder at the moment sourceDir = fullfile(cfg.dir.output, 'source'); rawDir = fullfile(cfg.dir.output, 'rawdata'); @@ -41,42 +42,6 @@ function convertSourceToRaw(cfg) end -function parseFunc(rawDir, subjName, sesName) - subjectPath = fullfile(rawDir, subjName, sesName, 'func'); - if exist(subjectPath, 'dir') - % do events - filenames = file_utils('List', subjectPath, ... - sprintf('^%s.*_task-.*_events_date-.*$', subjName)); - - removeDateSuffix(filenames, subjectPath); - - % do bold - filenames = file_utils('List', subjectPath, ... - sprintf('^%s.*_task-.*_bold_date-.*$', subjName)); - - removeDateSuffix(filenames, subjectPath); - - end -end - -function removeDateSuffix(filenames, subjectPath) - if isempty(filenames) - filenames = {}; - else - filenames = cellstr(filenames); - end - - for i = 1:numel(filenames) - - [~, name, ext] = fileparts(filenames{i}); - - [parts, ~] = regexp(name, '(?:_date-)+', 'split', 'match'); - - movefile(fullfile(subjectPath, filenames{i}), ... - fullfile(subjectPath, [parts{1} ext])); - - end -end diff --git a/src/saveEventsFile.m b/src/saveEventsFile.m index 1960359c..680f8398 100644 --- a/src/saveEventsFile.m +++ b/src/saveEventsFile.m @@ -64,13 +64,13 @@ case 'open' - logFile.filename = cfg.fileName.events; + logFile(1).filename = cfg.fileName.events; logFile = initializeFile(cfg, logFile); case 'open_stim' - logFile.filename = cfg.fileName.stim; + logFile(1).filename = cfg.fileName.stim; logFile = initializeFile(cfg, logFile); @@ -143,7 +143,7 @@ % Initialize txt logfiles and empty fields for the standard BIDS % event file - logFile.fileID = fopen( ... + logFile(1).fileID = fopen( ... fullfile( ... cfg.dir.outputSubject, ... cfg.fileName.modality, ... @@ -151,13 +151,14 @@ 'w'); % print the basic BIDS columns - fprintf(logFile.fileID, '%s\t%s\t%s', 'onset', 'duration', 'trial_type'); + fprintf(logFile(1).fileID, '%s\t%s\t%s', 'onset', 'duration', 'trial_type'); fprintf(1, '%s\t%s\t%s', 'onset', 'duration', 'trial_type'); printHeaderExtraColumns(logFile); % next line so we start printing at the right place - fprintf(logFile.fileID, '\n'); + fprintf(logFile(1).fileID, '\n'); + fprintf(1, '\n'); end @@ -174,7 +175,7 @@ function printHeaderExtraColumns(logFile) headerName = returnHeaderName(namesExtraColumns{iExtraColumn}, nbCol, iCol); - fprintf(logFile.fileID, '\t%s', headerName); + fprintf(logFile(1).fileID, '\t%s', headerName); fprintf(1, '\t%s', headerName); end diff --git a/src/subfun/parseFunc.m b/src/subfun/parseFunc.m new file mode 100644 index 00000000..a521cdbe --- /dev/null +++ b/src/subfun/parseFunc.m @@ -0,0 +1,45 @@ +function parseFunc(rawDir, subjName, sesName) + % parseFunc(rawDir, subjName, sesName) + % + + subjectPath = fullfile(rawDir, subjName, sesName, 'func'); + + if exist(subjectPath, 'dir') + + % do events + filenames = file_utils('List', subjectPath, ... + sprintf('^%s.*_task-.*_events_date-.*$', subjName)); + + removeDateSuffix(filenames, subjectPath); + + % do bold + filenames = file_utils('List', subjectPath, ... + sprintf('^%s.*_task-.*_bold_date-.*$', subjName)); + + removeDateSuffix(filenames, subjectPath); + + % do stim + filenames = file_utils('List', subjectPath, ... + sprintf('^%s.*_task-.*_stim_date-.*tsv$', subjName)); + compressFiles(filenames, subjectPath); + filenames = file_utils('List', subjectPath, ... + sprintf('^%s.*_task-.*_stim_date-.*tsv.gz$', subjName)); + removeDateSuffix(filenames, subjectPath); + + end +end + +function compressFiles(filenames, subjectPath) + if isempty(filenames) + filenames = {}; + else + filenames = cellstr(filenames); + end + + for i = 1:numel(filenames) + + gzip(fullfile(subjectPath, filenames{i})) + delete(fullfile(subjectPath, filenames{i})) + + end +end \ No newline at end of file diff --git a/src/subfun/removeDateSuffix.m b/src/subfun/removeDateSuffix.m new file mode 100644 index 00000000..5c65ca0f --- /dev/null +++ b/src/subfun/removeDateSuffix.m @@ -0,0 +1,33 @@ +function removeDateSuffix(filenames, subjectPath) + % removeDateSuffix(filenames, subjectPath) + % + % + + if isempty(filenames) + filenames = {}; + else + filenames = cellstr(filenames); + end + + for i = 1:numel(filenames) + + [~, name, ext] = fileparts(filenames{i}); + + if strcmp(ext, '.gz') + [~, name, ext2] = fileparts(name); + ext = [ext2, ext]; %#ok + end + + [parts, ~] = regexp(name, '(?:_date-)+', 'split', 'match'); + + % remove suffix file if there was one + if ~strcmp(filenames{i}, [parts{1} ext]) + movefile(fullfile(subjectPath, filenames{i}), ... + fullfile(subjectPath, [parts{1} ext])); + end + + end + + + +end \ No newline at end of file diff --git a/tests/test_removeDateSuffix.m b/tests/test_removeDateSuffix.m new file mode 100644 index 00000000..9a586118 --- /dev/null +++ b/tests/test_removeDateSuffix.m @@ -0,0 +1,79 @@ +function test_suite = test_removeDateSuffix %#ok<*STOUT> + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end + + +function test_removeDateSuffixBasic() + + %% set up + cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); + + % clean up + if isdir(cfg.dir.output) + rmdir(cfg.dir.output, 's'); + end + [~, ~, ~] = mkdir(cfg.dir.output); + + % TODO + % make sure we use the default date parameter (to implement?) + % cfg = checkCFG(cfg); + + %% set up + boldName = 'test_bold_date-202008050730.nii.gz'; + boldName2 = 'test2_bold.nii.gz'; + boldName3 = 'test3_bold_date-202008050730.nii'; + jsonName = 'test_bold_date-202008050730.json'; + eventsName = 'test_events_date-202008050730.tsv'; + stimName = 'test_stim_date-202008050730.tsv'; + stimNameZipped = 'test2_stim_date-202008050730.tsv.gz'; + + filesToProcess = { ... + boldName ; + boldName2 ; + boldName3 ; + jsonName ; + eventsName ; + stimName ; + stimNameZipped ; + }; + + for iFile = 1:numel(filesToProcess) + copyfile( ... + fullfile('..', 'dummyData', 'dummyData.nii.gz'), ... + fullfile(cfg.dir.output, filesToProcess{iFile})); + end + + %% do stuff + filenames = file_utils('List', cfg.dir.output, '^test.*$'); + + removeDateSuffix(filenames, cfg.dir.output); + + %% expected data + expectedBoldName = 'test_bold.nii.gz'; + expectedBoldName2 = 'test2_bold.nii.gz'; + expectedBoldName3 = 'test3_bold.nii'; + expectedJsonName = 'test_bold.json'; + expectedEventsName = 'test_events.tsv'; + expectedStimName = 'test_stim.tsv'; + expectedStimNameZipped = 'test2_stim.tsv.gz'; + + %% test + assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName3), 'file'), 2); + assertEqual(exist(fullfile(cfg.dir.output, expectedJsonName), 'file'), 2); + assertEqual(exist(fullfile(cfg.dir.output, expectedEventsName), 'file'), 2); + assertEqual(exist(fullfile(cfg.dir.output, expectedStimName), 'file'), 2); + assertEqual(exist(fullfile(cfg.dir.output, expectedStimNameZipped), 'file'), 2); + assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName2), 'file'), 2); + assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName), 'file'), 2); + +end + + + + + + diff --git a/tests/test_saveEventsFileOpen.m b/tests/test_saveEventsFileOpen.m index 134f6ffe..d04b2874 100644 --- a/tests/test_saveEventsFileOpen.m +++ b/tests/test_saveEventsFileOpen.m @@ -50,6 +50,50 @@ function test_saveEventsFileOpenBasic() end +function test_saveEventsFileOpenStimfile() + + outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); + + %% set up + + cfg.verbose = false; + + cfg.subject.subjectNb = 1; + cfg.subject.runNb = 1; + + cfg.task.name = 'testtask'; + + cfg.dir.output = outputDir; + + cfg.testingDevice = 'mri'; + + cfg = createFilename(cfg); + + % create the events file and header + logFile = saveEventsFile('open_stim', cfg); + + % close the file + saveEventsFile('close', cfg, logFile); + + %% data to test against + funcDir = fullfile(outputDir, 'source', 'sub-001', 'ses-001', 'func'); + eventFilename = ['sub-001_ses-001_task-testtask_run-001_stim_date-' ... + cfg.fileName.date '.tsv']; + + % check that the file has the right path and name + assert(exist(fullfile(funcDir, eventFilename), 'file') == 2); + + FID = fopen(fullfile(funcDir, eventFilename), 'r'); + C = textscan(FID, repmat('%s', 1, 3), 'Delimiter', '\t', 'EndOfLine', '\n'); + + %% test + % check the extra columns of the header + assertEqual(C{1}{1}, 'onset'); + assertEqual(C{2}{1}, 'duration'); + assertEqual(C{3}{1}, 'trial_type'); + +end + function test_saveEventsFileOpenExtraColumns() outputDir = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); From baf1665a7206a7a38d07964a455f5e37709223ca Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 08:31:03 +0200 Subject: [PATCH 2/8] mh autofix --- manualTests/test_makeRawDataset.m | 4 ++-- src/convertSourceToRaw.m | 4 ---- src/subfun/parseFunc.m | 10 +++++----- src/subfun/removeDateSuffix.m | 20 +++++++++----------- tests/test_removeDateSuffix.m | 17 +++++------------ 5 files changed, 21 insertions(+), 34 deletions(-) diff --git a/manualTests/test_makeRawDataset.m b/manualTests/test_makeRawDataset.m index 4997f6a1..d5520422 100644 --- a/manualTests/test_makeRawDataset.m +++ b/manualTests/test_makeRawDataset.m @@ -126,9 +126,9 @@ function test_makeRawDataset() %% actually do the conversion of the source data thus created clear; - + outputDir = fullfile(fileparts(mfilename('fullpath')), 'output'); cfg.dir.output = outputDir; convertSourceToRaw(cfg); - + end diff --git a/src/convertSourceToRaw.m b/src/convertSourceToRaw.m index 3ef05560..407ce6fc 100644 --- a/src/convertSourceToRaw.m +++ b/src/convertSourceToRaw.m @@ -41,7 +41,3 @@ function convertSourceToRaw(cfg) end end - - - - diff --git a/src/subfun/parseFunc.m b/src/subfun/parseFunc.m index a521cdbe..524ae0cd 100644 --- a/src/subfun/parseFunc.m +++ b/src/subfun/parseFunc.m @@ -17,7 +17,7 @@ function parseFunc(rawDir, subjName, sesName) sprintf('^%s.*_task-.*_bold_date-.*$', subjName)); removeDateSuffix(filenames, subjectPath); - + % do stim filenames = file_utils('List', subjectPath, ... sprintf('^%s.*_task-.*_stim_date-.*tsv$', subjName)); @@ -37,9 +37,9 @@ function compressFiles(filenames, subjectPath) end for i = 1:numel(filenames) - - gzip(fullfile(subjectPath, filenames{i})) - delete(fullfile(subjectPath, filenames{i})) + + gzip(fullfile(subjectPath, filenames{i})); + delete(fullfile(subjectPath, filenames{i})); end -end \ No newline at end of file +end diff --git a/src/subfun/removeDateSuffix.m b/src/subfun/removeDateSuffix.m index 5c65ca0f..d06af305 100644 --- a/src/subfun/removeDateSuffix.m +++ b/src/subfun/removeDateSuffix.m @@ -2,32 +2,30 @@ function removeDateSuffix(filenames, subjectPath) % removeDateSuffix(filenames, subjectPath) % % - + if isempty(filenames) filenames = {}; else filenames = cellstr(filenames); end - + for i = 1:numel(filenames) - + [~, name, ext] = fileparts(filenames{i}); - + if strcmp(ext, '.gz') [~, name, ext2] = fileparts(name); ext = [ext2, ext]; %#ok end - + [parts, ~] = regexp(name, '(?:_date-)+', 'split', 'match'); - + % remove suffix file if there was one if ~strcmp(filenames{i}, [parts{1} ext]) movefile(fullfile(subjectPath, filenames{i}), ... fullfile(subjectPath, [parts{1} ext])); end - + end - - - -end \ No newline at end of file + +end diff --git a/tests/test_removeDateSuffix.m b/tests/test_removeDateSuffix.m index 9a586118..34912c4f 100644 --- a/tests/test_removeDateSuffix.m +++ b/tests/test_removeDateSuffix.m @@ -6,18 +6,17 @@ initTestSuite; end - function test_removeDateSuffixBasic() %% set up cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); - + % clean up if isdir(cfg.dir.output) rmdir(cfg.dir.output, 's'); end [~, ~, ~] = mkdir(cfg.dir.output); - + % TODO % make sure we use the default date parameter (to implement?) % cfg = checkCFG(cfg); @@ -30,7 +29,7 @@ function test_removeDateSuffixBasic() eventsName = 'test_events_date-202008050730.tsv'; stimName = 'test_stim_date-202008050730.tsv'; stimNameZipped = 'test2_stim_date-202008050730.tsv.gz'; - + filesToProcess = { ... boldName ; boldName2 ; @@ -46,12 +45,12 @@ function test_removeDateSuffixBasic() fullfile('..', 'dummyData', 'dummyData.nii.gz'), ... fullfile(cfg.dir.output, filesToProcess{iFile})); end - + %% do stuff filenames = file_utils('List', cfg.dir.output, '^test.*$'); removeDateSuffix(filenames, cfg.dir.output); - + %% expected data expectedBoldName = 'test_bold.nii.gz'; expectedBoldName2 = 'test2_bold.nii.gz'; @@ -71,9 +70,3 @@ function test_removeDateSuffixBasic() assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName), 'file'), 2); end - - - - - - From 067ee0b4b8b95a3448e0551745767acc1417aa4a Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 08:36:34 +0200 Subject: [PATCH 3/8] improves test for transfer to BIDS --- tests/test_transferInfoToBids.m | 46 ++++++++++++++++++++++----------- 1 file changed, 31 insertions(+), 15 deletions(-) diff --git a/tests/test_transferInfoToBids.m b/tests/test_transferInfoToBids.m index 5af1816f..f8080e29 100644 --- a/tests/test_transferInfoToBids.m +++ b/tests/test_transferInfoToBids.m @@ -1,35 +1,51 @@ -function test_transferInfoToBids() +function test_suite = test_transferInfoToBids %#ok<*STOUT> + try % assignment of 'localfunctions' is necessary in Matlab >= 2016 + test_functions = localfunctions(); %#ok<*NASGU> + catch % no problem; early Matlab versions can use initTestSuite fine + end + initTestSuite; +end - %% +function test_transferInfoToBidsBasic() + % basic behavior + cfg = struct(); fieldsToSet = struct(); cfg = transferInfoToBids(fieldsToSet, cfg); - + expectedStruct = struct(); - + assert(isequal(expectedStruct, fieldsToSet)); + +end - %% +function test_transferInfoToBidsTaskname() + % make sure the file name gets trasnferred where it should + cfg.task.name = 'foo bar'; - + + fieldsToSet = struct(); fieldsToSet = transferInfoToBids(fieldsToSet, cfg); - + expectedStruct.fileName.task = 'fooBar'; expectedStruct.bids.meg.TaskName = 'foo Bar'; expectedStruct.bids.mri.TaskName = 'foo Bar'; - + assert(isequal(expectedStruct, fieldsToSet)); + +end - %% - clear cfg fieldsToSet expectedStruct; - +function test_transferInfoToBidsMRI() + % make sure the file name gets trasnferred where it should + cfg.mri.repetitionTime = 1.56; - + fieldsToSet = struct(); fieldsToSet = transferInfoToBids(fieldsToSet, cfg); - + expectedStruct.bids.mri.RepetitionTime = 1.56; - + assert(isequal(expectedStruct, fieldsToSet)); - + end + From beb0466424e82411437c7599785ade3665773a50 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 08:36:51 +0200 Subject: [PATCH 4/8] mh autofix --- tests/test_transferInfoToBids.m | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/test_transferInfoToBids.m b/tests/test_transferInfoToBids.m index f8080e29..3ba4fdd6 100644 --- a/tests/test_transferInfoToBids.m +++ b/tests/test_transferInfoToBids.m @@ -8,44 +8,43 @@ function test_transferInfoToBidsBasic() % basic behavior - + cfg = struct(); fieldsToSet = struct(); cfg = transferInfoToBids(fieldsToSet, cfg); - + expectedStruct = struct(); - + assert(isequal(expectedStruct, fieldsToSet)); - + end function test_transferInfoToBidsTaskname() % make sure the file name gets trasnferred where it should - + cfg.task.name = 'foo bar'; - + fieldsToSet = struct(); fieldsToSet = transferInfoToBids(fieldsToSet, cfg); - + expectedStruct.fileName.task = 'fooBar'; expectedStruct.bids.meg.TaskName = 'foo Bar'; expectedStruct.bids.mri.TaskName = 'foo Bar'; - + assert(isequal(expectedStruct, fieldsToSet)); - + end function test_transferInfoToBidsMRI() % make sure the file name gets trasnferred where it should - + cfg.mri.repetitionTime = 1.56; - + fieldsToSet = struct(); fieldsToSet = transferInfoToBids(fieldsToSet, cfg); - + expectedStruct.bids.mri.RepetitionTime = 1.56; - + assert(isequal(expectedStruct, fieldsToSet)); - -end +end From 1e956bb4c98aad6e496d552c2d7e04f0c72921c1 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 10:45:15 +0200 Subject: [PATCH 5/8] improve tests for remove date suffix --- .gitignore | 14 ++--- {dummyData => manualTests/dummyData}/CHANGES | 0 {dummyData => manualTests/dummyData}/README | 0 .../dummyData}/dummyData.nii.gz | 0 manualTests/test_makeRawDataset.m | 4 +- src/convertSourceToRaw.m | 4 +- tests/test_removeDateSuffix.m | 60 +++++++++---------- 7 files changed, 38 insertions(+), 44 deletions(-) rename {dummyData => manualTests/dummyData}/CHANGES (100%) rename {dummyData => manualTests/dummyData}/README (100%) rename {dummyData => manualTests/dummyData}/dummyData.nii.gz (100%) diff --git a/.gitignore b/.gitignore index bdac3462..7a456211 100644 --- a/.gitignore +++ b/.gitignore @@ -6,17 +6,17 @@ *octave-workspace # exclude content of logfiles folders -tests/output/* -manualTests/output/* -output/* +*output* *.tsv *.mat # exclude temp files from tests and coverage -tests/coverage* -tests/test_code_report.txt -test_code_report.txt -*/coverage_html/* +*test_code_report.txt +*coverage* + +tests/*.nii* +tests/*.json* +tests/*.tsv* # exclude report from check_my_code check_my_code_report.txt diff --git a/dummyData/CHANGES b/manualTests/dummyData/CHANGES similarity index 100% rename from dummyData/CHANGES rename to manualTests/dummyData/CHANGES diff --git a/dummyData/README b/manualTests/dummyData/README similarity index 100% rename from dummyData/README rename to manualTests/dummyData/README diff --git a/dummyData/dummyData.nii.gz b/manualTests/dummyData/dummyData.nii.gz similarity index 100% rename from dummyData/dummyData.nii.gz rename to manualTests/dummyData/dummyData.nii.gz diff --git a/manualTests/test_makeRawDataset.m b/manualTests/test_makeRawDataset.m index d5520422..20b99ca7 100644 --- a/manualTests/test_makeRawDataset.m +++ b/manualTests/test_makeRawDataset.m @@ -86,7 +86,7 @@ function test_makeRawDataset() boldFilename = 'sub-001_ses-001_task-testtask_run-001_bold.nii.gz'; copyfile( ... - fullfile('..', 'dummyData', 'dummyData.nii.gz'), ... + fullfile('dummyData', 'dummyData.nii.gz'), ... fullfile(funcDir, boldFilename)); %% MRI bold rest data and fancy suffixes @@ -121,7 +121,7 @@ function test_makeRawDataset() '_run-004_echo-1_bold.nii.gz']; copyfile( ... - fullfile('..', 'dummyData', 'dummyData.nii.gz'), ... + fullfile('dummyData', 'dummyData.nii.gz'), ... fullfile(funcDir, boldFilename)); %% actually do the conversion of the source data thus created diff --git a/src/convertSourceToRaw.m b/src/convertSourceToRaw.m index 407ce6fc..179b7167 100644 --- a/src/convertSourceToRaw.m +++ b/src/convertSourceToRaw.m @@ -14,10 +14,10 @@ function convertSourceToRaw(cfg) % add dummy README and CHANGE file copyfile(fullfile( ... - fileparts(mfilename('fullpath')), '..', 'dummyData', 'README'), ... + fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', 'README'), ... sourceDir); copyfile(fullfile( ... - fileparts(mfilename('fullpath')), '..', 'dummyData', 'CHANGES'), ... + fileparts(mfilename('fullpath')), '..', 'manualTests', 'dummyData', 'CHANGES'), ... sourceDir); copyfile(sourceDir, rawDir); diff --git a/tests/test_removeDateSuffix.m b/tests/test_removeDateSuffix.m index 34912c4f..56065b87 100644 --- a/tests/test_removeDateSuffix.m +++ b/tests/test_removeDateSuffix.m @@ -7,20 +7,12 @@ end function test_removeDateSuffixBasic() - - %% set up - cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); - - % clean up - if isdir(cfg.dir.output) - rmdir(cfg.dir.output, 's'); - end - [~, ~, ~] = mkdir(cfg.dir.output); - - % TODO - % make sure we use the default date parameter (to implement?) - % cfg = checkCFG(cfg); - + + outputDir = pwd; + + createFiles = 0; + testDo = 1; + %% set up boldName = 'test_bold_date-202008050730.nii.gz'; boldName2 = 'test2_bold.nii.gz'; @@ -29,7 +21,7 @@ function test_removeDateSuffixBasic() eventsName = 'test_events_date-202008050730.tsv'; stimName = 'test_stim_date-202008050730.tsv'; stimNameZipped = 'test2_stim_date-202008050730.tsv.gz'; - + filesToProcess = { ... boldName ; boldName2 ; @@ -39,18 +31,16 @@ function test_removeDateSuffixBasic() stimName ; stimNameZipped ; }; - + + % create new files for new tests for iFile = 1:numel(filesToProcess) - copyfile( ... - fullfile('..', 'dummyData', 'dummyData.nii.gz'), ... - fullfile(cfg.dir.output, filesToProcess{iFile})); + system(sprintf('touch %s', filesToProcess{iFile})); end - + + %% do stuff - filenames = file_utils('List', cfg.dir.output, '^test.*$'); - - removeDateSuffix(filenames, cfg.dir.output); - + filenames = file_utils('List', outputDir, '^test.*$'); + %% expected data expectedBoldName = 'test_bold.nii.gz'; expectedBoldName2 = 'test2_bold.nii.gz'; @@ -59,14 +49,18 @@ function test_removeDateSuffixBasic() expectedEventsName = 'test_events.tsv'; expectedStimName = 'test_stim.tsv'; expectedStimNameZipped = 'test2_stim.tsv.gz'; - + + removeDateSuffix(filenames, outputDir); + %% test - assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName3), 'file'), 2); - assertEqual(exist(fullfile(cfg.dir.output, expectedJsonName), 'file'), 2); - assertEqual(exist(fullfile(cfg.dir.output, expectedEventsName), 'file'), 2); - assertEqual(exist(fullfile(cfg.dir.output, expectedStimName), 'file'), 2); - assertEqual(exist(fullfile(cfg.dir.output, expectedStimNameZipped), 'file'), 2); - assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName2), 'file'), 2); - assertEqual(exist(fullfile(cfg.dir.output, expectedBoldName), 'file'), 2); - + fprintf(1, fullfile(outputDir, expectedBoldName3)); + assertEqual(exist(fullfile(outputDir, expectedBoldName3), 'file'), 2); + assertEqual(exist(fullfile(outputDir, expectedJsonName), 'file'), 2); + fprintf(1, fullfile(outputDir, expectedEventsName)); + assertEqual(exist(fullfile(outputDir, expectedEventsName), 'file'), 2); + assertEqual(exist(fullfile(outputDir, expectedStimName), 'file'), 2); + assertEqual(exist(fullfile(outputDir, expectedStimNameZipped), 'file'), 2); + assertEqual(exist(fullfile(outputDir, expectedBoldName2), 'file'), 2); + assertEqual(exist(fullfile(outputDir, expectedBoldName), 'file'), 2); + end From ee81d49453e517310deca8dda385598897a7c548 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 10:48:01 +0200 Subject: [PATCH 6/8] add clean up after test --- tests/test_removeDateSuffix.m | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/test_removeDateSuffix.m b/tests/test_removeDateSuffix.m index 56065b87..d0ac1258 100644 --- a/tests/test_removeDateSuffix.m +++ b/tests/test_removeDateSuffix.m @@ -63,4 +63,9 @@ function test_removeDateSuffixBasic() assertEqual(exist(fullfile(outputDir, expectedBoldName2), 'file'), 2); assertEqual(exist(fullfile(outputDir, expectedBoldName), 'file'), 2); + % clean up + delete('*.nii*') + delete('*.tsv*') + delete('*.json') + end From fe6690c949a9ff35275ddba3f756a50341c46d5c Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 10:48:25 +0200 Subject: [PATCH 7/8] mh autofix --- tests/test_removeDateSuffix.m | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/tests/test_removeDateSuffix.m b/tests/test_removeDateSuffix.m index d0ac1258..13c25e1a 100644 --- a/tests/test_removeDateSuffix.m +++ b/tests/test_removeDateSuffix.m @@ -7,12 +7,12 @@ end function test_removeDateSuffixBasic() - + outputDir = pwd; - + createFiles = 0; testDo = 1; - + %% set up boldName = 'test_bold_date-202008050730.nii.gz'; boldName2 = 'test2_bold.nii.gz'; @@ -21,7 +21,7 @@ function test_removeDateSuffixBasic() eventsName = 'test_events_date-202008050730.tsv'; stimName = 'test_stim_date-202008050730.tsv'; stimNameZipped = 'test2_stim_date-202008050730.tsv.gz'; - + filesToProcess = { ... boldName ; boldName2 ; @@ -31,16 +31,15 @@ function test_removeDateSuffixBasic() stimName ; stimNameZipped ; }; - + % create new files for new tests for iFile = 1:numel(filesToProcess) system(sprintf('touch %s', filesToProcess{iFile})); end - - + %% do stuff filenames = file_utils('List', outputDir, '^test.*$'); - + %% expected data expectedBoldName = 'test_bold.nii.gz'; expectedBoldName2 = 'test2_bold.nii.gz'; @@ -49,9 +48,9 @@ function test_removeDateSuffixBasic() expectedEventsName = 'test_events.tsv'; expectedStimName = 'test_stim.tsv'; expectedStimNameZipped = 'test2_stim.tsv.gz'; - + removeDateSuffix(filenames, outputDir); - + %% test fprintf(1, fullfile(outputDir, expectedBoldName3)); assertEqual(exist(fullfile(outputDir, expectedBoldName3), 'file'), 2); @@ -62,10 +61,10 @@ function test_removeDateSuffixBasic() assertEqual(exist(fullfile(outputDir, expectedStimNameZipped), 'file'), 2); assertEqual(exist(fullfile(outputDir, expectedBoldName2), 'file'), 2); assertEqual(exist(fullfile(outputDir, expectedBoldName), 'file'), 2); - + % clean up - delete('*.nii*') - delete('*.tsv*') - delete('*.json') - + delete('*.nii*'); + delete('*.tsv*'); + delete('*.json'); + end From 1bd5a4e6580e5daf33acba6a0e1f65f7b0dc44de Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Wed, 5 Aug 2020 10:55:18 +0200 Subject: [PATCH 8/8] add code coverage badge --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 152d1244..035a693f 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,13 @@ [![Build Status](https://travis-ci.com/cpp-lln-lab/CPP_BIDS.svg?branch=master)](https://travis-ci.com/cpp-lln-lab/CPP_BIDS) -**Unit tests** +**Unit tests and coverage** [![](https://img.shields.io/badge/Octave-CI-blue?logo=Octave&logoColor=white)](https://github.com/cpp-lln-lab/CPP_BIDS/actions) ![](https://github.com/cpp-lln-lab/CPP_BIDS/workflows/CI/badge.svg) +[![codecov](https://codecov.io/gh/cpp-lln-lab/CPP_BIDS/branch/master/graph/badge.svg)](https://codecov.io/gh/cpp-lln-lab/CPP_BIDS) + **Contributors** [![All Contributors](https://img.shields.io/badge/all_contributors-3-orange.svg?style=flat-square)](#contributors-)