add_context.m 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. % Adds a context.tsv file for each vaso file
  2. % specifying the volume type of each volume
  3. %
  4. % requires bids-matlab: https://github.com/bids-standard/bids-matlab
  5. %
  6. %
  7. clear;
  8. root_dir = fullfile(fileparts(mfilename('fullpath')), '..');
  9. % this is hard coded here
  10. % but obviously would have to be adapted dynamically to each file
  11. volume_order = {'non_nulled'; 'nulled'};
  12. AcquisitionDuration
  13. nb_volumes = 200;
  14. %%
  15. BIDS = bids.layout(root_dir, 'use_schema', false);
  16. files = bids.query(BIDS, 'data', 'suffix', 'vaso');
  17. for i = 1:numel(files)
  18. context = struct('volume_type', {{}});
  19. context_filename = bids.File(files{i});
  20. context_filename.extension = '.tsv';
  21. context_filename.suffix = 'context';
  22. context.volume_type = repmat(volume_order, nb_volumes / numel(volume_order), 1);
  23. output_file = fullfile(BIDS.pth, ...
  24. context_filename.bids_path, ...
  25. 'func', ...
  26. context_filename.filename);
  27. bids.util.tsvwrite(output_file, context);
  28. end