highspeed_bids_participants.m 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. %% HIGHSPEED: GET DATA OF THE HIGHSPEED TASK
  2. clear variables; clc; % clear workspace and command window
  3. path_base = strsplit(pwd,'code');
  4. path_base = path_base{1};
  5. path_input = fullfile(path_base, 'input', 'behavior', 'main');
  6. path_output = path_base;
  7. path_digitspan = fullfile(...
  8. path_base, 'input', 'behavior', 'digitspan');
  9. allID = dlmread(fullfile(...
  10. path_base, 'code', 'heudiconv', 'highspeed-participant-list.txt'));
  11. num_subs = length(allID);
  12. % get data
  13. dirData = dir(path_input);
  14. dirData = {dirData.name};
  15. dataFiles = dirData(...
  16. contains(dirData,'session_1_run_4') & ...
  17. contains(dirData,cellstr(num2str(allID))));
  18. covariates = table;
  19. covariates.participant_id = cell(num_subs,1);
  20. covariates.age = nan(num_subs,1);
  21. covariates.sex = cell(num_subs,1);
  22. covariates.handedness = cell(num_subs,1);
  23. covariates.digit_span = nan(num_subs,1);
  24. covariates.randomization = nan(num_subs,1);
  25. covariates.session_interval = nan(num_subs,1);
  26. % study intervals, ordered by participant ids:
  27. intervals = {
  28. 1, 13, 4, 4, 17, 8, 14, 6, 7, 10, ...
  29. 7, 6, 18, 4, 8, 5, 23, 3, 1, 12, ...
  30. 9, 8, 24, 21, 17, 21, 14, 4, 4, 9, ...
  31. 7, 7, 11, 7, 14, 2, 1, 5, 3, 3};
  32. % create a dictionary that maps IDs to intervals:
  33. interval_dict = containers.Map(allID,intervals);
  34. filetemplate = 'highspeed_task_mri_sub_%d_session_%d_run_%d.mat';
  35. fprintf('List of missing data:\n')
  36. for sub = 1:num_subs
  37. % get correct ids:
  38. id_orig = allID(sub);
  39. id_new = sprintf('sub-%02d', sub);
  40. % load task statistics
  41. session = 1; run = 4;
  42. filename = sprintf(filetemplate,allID(sub),session,run);
  43. dataframe = dirData(contains(dirData,filename));
  44. if ~isempty(dataframe)
  45. load(fullfile(path_input,filename));
  46. covariates.participant_id{sub} = id_new;
  47. covariates.age(sub) = Parameters.subjectInfo.age;
  48. covariates.sex{sub} = Parameters.subjectInfo.gender;
  49. covariates.handedness{sub} = 'right';
  50. covariates.randomization(sub) = Parameters.subjectInfo.cbal;
  51. covariates.session_interval(sub) = interval_dict(id_orig);
  52. else
  53. str = strcat(str,'- all behavioral data\n');
  54. end
  55. % digit span
  56. digitspan_file = sprintf('DigitSpan_%d.mat',allID(sub));
  57. digitspan_dir = dir(fullfile(path_digitspan));
  58. if any(contains({digitspan_dir.name},digitspan_file))
  59. load(fullfile(path_digitspan,digitspan_file))
  60. covariates.digit_span(sub) = nansum(Data.acc);
  61. end
  62. end
  63. % WRITE DATA
  64. writetable(covariates,fullfile(path_output,'participants.csv'), ...
  65. 'Delimiter','\t','WriteRowNames',true, ...
  66. 'QuoteStrings',true,'WriteVariableNames',true)
  67. copyfile(fullfile(path_output,'participants.csv'), ...
  68. fullfile(path_output,'participants.tsv'));
  69. delete(fullfile(path_output,'participants.csv'));