transform_data2BIDS.m 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. parent_path = "E:\Projects\CBIrep_Imaging\Raw";
  2. cd (parent_path)
  3. addpath("..\scripts\toolbox\DVARS-master\")
  4. addpath("..\scripts\toolbox\DVARS-master\Nifti_Util\")
  5. addpath("..\scripts")
  6. addpath("..\scripts\toolbox\spm12")
  7. addpath("..\scripts\toolbox\fMRI-Quality-Checker-master")
  8. addpath("..\scripts\toolbox\spm12\matlabbatch")
  9. addpath("..\scripts\toolbox\nifti_utils-master\")
  10. %% Preps
  11. BIDS_path = "E:\Projects\CBIrep_Imaging\subjects";
  12. % physio_files = "F:\Projects\StrokePT_tDCS_rsfmri\physio";
  13. % cd (physio_files)
  14. % phx = dir("SB*");
  15. timeX = {'tpA','tpB','tpC','tpD','tpE','tpF','tpG'};
  16. %% level1: subjects
  17. cd (parent_path)
  18. gx = dir("sub*");
  19. for g = 18:length(gx)
  20. subject = gx(g).name;
  21. cd (fullfile(gx(g).folder,gx(g).name,"MRI/"))
  22. %% level2: timepoints
  23. tx = dir('tp*');
  24. for t = 1:length(tx)
  25. time = tx(t).name;
  26. cd (fullfile(tx(t).folder,tx(t).name))
  27. session = strcat('ses-',num2str(find(strcmp(time,timeX))));
  28. %% level3: scans
  29. % copy data to BIDS
  30. folder_from = pwd;
  31. folder_to = fullfile(BIDS_path,subject,session);
  32. if ~exist(folder_to,"dir")
  33. mkdir(folder_to)
  34. end
  35. % copy MRI data
  36. copyfile(folder_from,folder_to)
  37. % % % % % copy physio data
  38. % % % % if exist("physiofolder","var")
  39. % % % % physio_to = fullfile(folder_to,"physio",phx(physioID).name);
  40. % % % % if ~exist(physio_to,"dir")
  41. % % % % mkdir(physio_to)
  42. % % % % end
  43. % % % % copyfile(physiofolder,physio_to);
  44. % % % % end
  45. %%
  46. cd (folder_to)
  47. if exist("fMRI","dir")==7
  48. movefile("fMRI","func")
  49. end
  50. if exist("T2w\","dir")==7
  51. movefile("T2w","anat")
  52. end
  53. end
  54. end