ck_GetMRI_pRF.m 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. function ck_GetMRI_pRF(monkeys,models,output)
  2. if nargin < 2
  3. fprintf('ERROR: Not enough arguments specified\n');
  4. return
  5. end
  6. clc;
  7. %% Add nifti reading toolbox ==============================================
  8. % location of this script
  9. homefld = pwd;
  10. % Get the root folder path for the hared data/code
  11. cd ../../../
  12. SHARED_ROOT_FLD = pwd;
  13. cd(homefld)
  14. tool_basepath = fullfile(SHARED_ROOT_FLD,'Toolboxes');
  15. addpath(genpath(fullfile(tool_basepath, 'NIfTI')));
  16. %% Set fMRI paths =========================================================
  17. fitres_path = fullfile(SHARED_ROOT_FLD,'FitResults','MRI');
  18. bids_path = fullfile(SHARED_ROOT_FLD,'Preprocessed_data','manual-masks');
  19. %% collect the fit results ================================================
  20. fprintf('Collecting MRI retinotopic maps...\n');
  21. for m = 1:length(monkeys)
  22. fprintf(['Processing monkey: ' monkeys{m} '\n']);
  23. cMonkey = monkeys{m}; cMonkey(1)=upper(cMonkey(1));
  24. R(m).monkey = monkeys{m};
  25. R(m).mode = 'MRI';
  26. for mm = 1:length(models)
  27. fprintf(['Model: ' models{mm} '\n']);
  28. RES = load(fullfile(fitres_path,monkeys{m},models{mm},...
  29. ['pRF_Sess-' models{mm}]),'result');
  30. R(m).model(mm).prfmodel = models{mm};
  31. R(m).model(mm).hrf = RES.result.options.hrf;
  32. R(m).model(mm).voldim = size(RES.result.R2,4);
  33. for i = 1:size(RES.result.R2,4)
  34. R(m).model(mm).ang(i,:) = reshape(RES.result.ang(:,:,:,i),...
  35. [numel(RES.result.ang(:,:,:,i)),1]);
  36. R(m).model(mm).ecc(i,:) = reshape(RES.result.ecc(:,:,:,i),...
  37. [numel(RES.result.ang(:,:,:,i)),1]);
  38. R(m).model(mm).rfs(i,:) = reshape(RES.result.rfsize(:,:,:,i),...
  39. [numel(RES.result.ang(:,:,:,i)),1]);
  40. R(m).model(mm).gain(i,:) = reshape(RES.result.gain(:,:,:,i),...
  41. [numel(RES.result.ang(:,:,:,i)),1]);
  42. R(m).model(mm).R2(i,:) = reshape(RES.result.R2(:,:,:,i),...
  43. [numel(RES.result.ang(:,:,:,i)),1]);
  44. R(m).model(mm).fwhm(i,:) = reshape(RES.result.fwhm(:,:,:,i),...
  45. [numel(RES.result.ang(:,:,:,i)),1]);
  46. if models{mm}(1:3) == 'dog'
  47. R(m).model(mm).sdratio(i,:) = reshape(RES.result.sdratio(:,:,:,i),...
  48. [numel(RES.result.ang(:,:,:,i)),1]);
  49. R(m).model(mm).normamp(i,:) = reshape(RES.result.normamp(:,:,:,i),...
  50. [numel(RES.result.ang(:,:,:,i)),1]);
  51. else
  52. R(m).model(mm).sdratio = [];
  53. R(m).model(mm).normamp = [];
  54. end
  55. if models{mm}(1:3) == 'css'
  56. R(m).model(mm).expt(i,:) = reshape(RES.result.expt(:,:,:,i),...
  57. [numel(RES.result.ang(:,:,:,i)),1]);
  58. else
  59. R(m).model(mm).expt = [];
  60. end
  61. end
  62. end
  63. clear RES
  64. %% Get ROI info =======================================================
  65. fprintf(['Processing atlas for monkey: ' monkeys{m} '\n']);
  66. labelfile = fullfile(bids_path,['sub-' monkeys{m}],'atlas','D99_labeltable.txt');
  67. D99 = ck_GetAtlasTable(labelfile);
  68. atlasfile = fullfile(bids_path,['sub-' monkeys{m}],'atlas',...
  69. ['D99_in_' cMonkey '_adj_inFunc.nii']);
  70. brainmaskfile = fullfile(bids_path,['sub-' monkeys{m}],'func',...
  71. ['sub-' monkeys{m} '_ref_func_mask_res-1x1x1.nii']);
  72. V1_maskfile = fullfile(bids_path,['sub-' monkeys{m}],'atlas',...
  73. 'ROI_ELECTRODES', 'ELECTRODES_LH_V1.nii');
  74. V4_maskfile = fullfile(bids_path,['sub-' monkeys{m}],'atlas',...
  75. 'ROI_ELECTRODES', 'ELECTRODES_LH_V4.nii');
  76. BRAINMASK = load_nii(brainmaskfile);
  77. R(m).BRAIN = reshape(BRAINMASK.img, [numel(BRAINMASK.img),1]);
  78. ROI = load_nii(atlasfile);
  79. R(m).ROI = reshape(ROI.img, [numel(ROI.img),1]);
  80. % additional ROI for approximate electrode locations
  81. ROI_V1 = load_nii(V1_maskfile);
  82. R(m).ELECTR_V1 = reshape(ROI_V1.img, [numel(ROI_V1.img),1]);
  83. ROI_V4 = load_nii(V4_maskfile);
  84. R(m).ELECTR_V4 = reshape(ROI_V4.img, [numel(ROI_V4.img),1]);
  85. end
  86. %% Save the combined results ==============================================
  87. fprintf('Saving the combined MRI result-file\n');
  88. [~,~,~] = mkdir(fullfile(fitres_path,'Combined'));
  89. save(fullfile(fitres_path,'Combined',output),'R','D99')