pRF_avg_BOLD_tseries.m 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. function pRF_avg_BOLD_tseries(monkey,sess)
  2. %% load the equal length files
  3. % manual for now
  4. startfld=pwd;
  5. cd ../../
  6. SHARED_ROOT_FLD = pwd;
  7. cd(startfld)
  8. load(fullfile(SHARED_ROOT_FLD,'Raw_data','MRI','Raw_matlab',...
  9. 'us-padded',monkey,['ses-' sess '-230vols'])); %#ok<*LOAD>
  10. fprintf(['Processing ses-' sess '-230vols\n']); %#ok<*LOAD>
  11. %% average
  12. % stim normal of inverted
  13. r_fw=[]; r_inv=[];
  14. for r=1:length(p_run)
  15. if p_run(r).stim{11}(10,80)
  16. r_fw=[r_fw r];
  17. else
  18. r_inv=[r_inv r];
  19. end
  20. end
  21. %% FW stim
  22. fprintf('Adressing regular stimuli \n')
  23. % pre-allocate collection arrays
  24. run_fw=nan([size(p_run(1).vol{1}) length(p_run(r).vol) length(r_fw)]);
  25. % collect
  26. for r=r_fw
  27. fprintf(['Processing r = ' num2str(r) '\n']);
  28. nanvol = nan(size(p_run(r).vol{1}));
  29. vol = p_run(r).vol;
  30. %vol(p_run(r).excvol) = {nanvol};
  31. for t=1:length(vol)
  32. run_fw(:,:,:,t,r) = vol{t};
  33. end
  34. % convert to percentage BOLD change
  35. mSig=nanmean(run_fw(:,:,:,:,r),4);
  36. for d4=1:size(run_fw,4)
  37. NormVol=100.*((run_fw(:,:,:,d4,r)-mSig)./mSig);
  38. NormVol(isnan(NormVol))=0;
  39. run_fw(:,:,:,d4,r)=NormVol;
  40. end
  41. % select timepoints to include
  42. for v=find(p_run(r).inc==0)
  43. run_fw(:,:,:,v,r)=nanvol;
  44. end
  45. end
  46. fprintf('Getting the median BOLD signal for all voxels\n');
  47. medianBOLD = nanmedian(run_fw,5); %#ok<*NASGU>
  48. nRuns = sum(~isnan(run_fw),5);
  49. stim = p_run(r).stim;
  50. clear run_fw
  51. %% INV stim
  52. fprintf('Adressing inverse stimuli\n')
  53. if ~isempty(r_inv)
  54. % pre-allocate collection arrays
  55. run_inv=nan([size(p_run(1).vol{1}) length(p_run(r).vol) length(r_inv)]);
  56. % collect
  57. for r=r_inv
  58. fprintf(['Processing r = ' num2str(r) '\n']);
  59. nanvol = nan(size(p_run(r).vol{1}));
  60. vol = p_run(r).vol;
  61. %vol(p_run(r).excvol) = {nanvol};
  62. for t=1:length(vol)
  63. run_inv(:,:,:,t,r) = vol{t};
  64. end
  65. % convert to percentage BOLD change
  66. mSig=nanmean(run_inv(:,:,:,:,r),4);
  67. for d4=1:size(run_inv,4)
  68. NormVol=100.*((run_inv(:,:,:,d4,r)-mSig)./mSig);
  69. NormVol(isnan(NormVol))=0;
  70. run_inv(:,:,:,d4,r)=NormVol;
  71. end
  72. % select timepoints to include
  73. for v=find(p_run(r).inc==0)
  74. run_inv(:,:,:,v,r)=nanvol;
  75. end
  76. end
  77. fprintf('Getting the median BOLD signal for all voxels\n');
  78. medianBOLD_inv = nanmedian(run_inv,5);
  79. nRuns_inv = sum(~isnan(run_inv),5);
  80. stim_inv = p_run(r).stim;
  81. clear run_inv
  82. else
  83. fprintf('Does not exist for this session\n')
  84. end
  85. %% save
  86. fprintf('Saving the result\n');
  87. [~,~]=mkdir(fullfile(SHARED_ROOT_FLD,...
  88. 'Raw_data','MRI','Raw_matlab','us-padded',monkey));
  89. filename = fullfile(SHARED_ROOT_FLD,'Raw_data','MRI','Raw_matlab',...
  90. 'us-padded',monkey,['medianBOLD_sess-' sess]);
  91. if ~isempty(r_inv)
  92. save(filename,'medianBOLD','medianBOLD_inv',...
  93. 'nRuns','nRuns_inv','stim','stim_inv','-v7.3');
  94. else
  95. save(filename,'medianBOLD','stim','nRuns','-v7.3');
  96. end