From 52f303961b99f5e7cc380d0dadc9ca27bc282329 Mon Sep 17 00:00:00 2001 From: Remi Gau Date: Mon, 5 Oct 2020 17:14:18 +0200 Subject: [PATCH] [FIX] make data saving after filtering all the relevant lines #105 --- src/readAndFilterLogfile.m | 20 ++++++++++++++++++++ src/subfun/utilsForTests/setUp.m | 4 ---- tests/test_readAndFilterLogfile.m | 19 ++++++++++++++++++- 3 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/readAndFilterLogfile.m b/src/readAndFilterLogfile.m index 6929ae27..0e8269b8 100644 --- a/src/readAndFilterLogfile.m +++ b/src/readAndFilterLogfile.m @@ -63,6 +63,8 @@ for iField = 1:numel(listFields) output.(listFields{iField})(~filterIdx) = []; end + + output = convertStruct(output); % Convert the structure to dataset try @@ -79,3 +81,21 @@ end end + +function structure = convertStruct(structure) + % changes the structure + % + % from struct.field(i,1) to struct(i,1).field(1) + + fieldsList = fieldnames(structure); + tmp = struct(); + + for iField = 1:numel(fieldsList) + for i = 1:numel(structure.(fieldsList{iField})) + tmp(i,1).(fieldsList{iField}) = structure.(fieldsList{iField})(i,1); + end + end + + structure = tmp; + +end diff --git a/src/subfun/utilsForTests/setUp.m b/src/subfun/utilsForTests/setUp.m index 405c3477..fa29d4f4 100644 --- a/src/subfun/utilsForTests/setUp.m +++ b/src/subfun/utilsForTests/setUp.m @@ -2,8 +2,6 @@ function [cfg, logFile] = setUp() - outputDir = fullfile(fileparts(mfilename('fullpath')), 'output'); - cfg.verbose = true; cfg.subject.subjectNb = 1; @@ -11,8 +9,6 @@ cfg.task.name = 'testtask'; - cfg.dir.output = outputDir; - cfg.testingDevice = 'mri'; cfg = createFilename(cfg); diff --git a/tests/test_readAndFilterLogfile.m b/tests/test_readAndFilterLogfile.m index e1b3fbee..9f01f124 100644 --- a/tests/test_readAndFilterLogfile.m +++ b/tests/test_readAndFilterLogfile.m @@ -9,7 +9,7 @@ function test_readAndFilterLogfileBasic() %% set up - + cfg.dir.output = fullfile(fileparts(mfilename('fullpath')), '..', 'output'); [cfg, logFile] = setUp(); % create the events file and header @@ -29,6 +29,20 @@ function test_readAndFilterLogfileBasic() logFile(end, 1).Speed = 2; logFile(end, 1).is_Fixation = true; logFile(end, 1).LHL24 = 2:13; + + logFile(3, 1).onset = 2; + logFile(end, 1).trial_type = 'motion_up'; + logFile(end, 1).duration = 3; + logFile(end, 1).Speed = 2; + logFile(end, 1).is_Fixation = true; + logFile(end, 1).LHL24 = 1:12; + + logFile(4, 1).onset = 2; + logFile(end, 1).trial_type = 'motion_down'; + logFile(end, 1).duration = 3; + logFile(end, 1).Speed = 2; + logFile(end, 1).is_Fixation = true; + logFile(end, 1).LHL24 = 2:13; logFile = saveEventsFile('save', cfg, logFile); @@ -48,8 +62,11 @@ function test_readAndFilterLogfileBasic() assertEqual(exist(expectedFile, 'file'), 2); content = bids.util.tsvread(expectedFile); + + assertEqual(size(content.trial_type), [2, 1]); assertEqual(content.trial_type{1}, 'motion_down'); + assertEqual(content.trial_type{2}, 'motion_down'); end