highspeed-bids-participants.m 2.8 KB

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