Advertisement
Guest User

Untitled

a guest
Jun 20th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 5.14 KB | None | 0 0
  1. %% DEMO4_RSAsearchlight_sim
  2. % simulates fMRI data for a number of subjects and runs searchlight
  3. % analysis using RSA, computes the similarity maps for each subject
  4. % and does group level inference.
  5.  
  6. %% SETUP
  7. % Add RSA Toolbox components to the path. This will allow matlab to find
  8. % the functions defined within the toolbox when we ask to use them.
  9. rootDir = pwd();
  10. addpath(fullfile(rootDir,'rsatoolbox-develop'));
  11. addpath(fullfile(rootDir,'rsatoolbox-develop','DEMOS'));
  12. addpath(fullfile(rootDir,'HelperFunctions'));
  13. addpath(fullfile(rootDir,'Patches'));
  14.  
  15. % Some of the important Network RSA functions reference a unified set of
  16. % "User Options". This helper-function will get us started.
  17. userOptions = BarebonesRSASetup('DEMO_20June');
  18. userOptions.voxelSize = [3 3 3];
  19.  
  20. % Define the path to the Demo Data distributed with the RSA Toolbox.
  21. DemoSupplementalDataDir = fullfile(rootDir,'rsatoolbox','Demos');
  22.  
  23. % Generate a simulationOptions structure
  24. % --------------------------------------
  25. % I pre-ran all the data simulation and searchlights to save time. We'll
  26. % jump in at the point of having "information maps" that can be submitted
  27. % to statistical analysis.
  28. simulationOptions = simulationOptions_demo_SL();
  29.  
  30. % Generate a searchlightOptions structure
  31. % ---------------------------------------
  32. % I pre-ran all the data simulation and searchlights to save time. We'll
  33. % jump in at the point of having "information maps" that can be submitted
  34. % to statistical analysis.
  35. userOptions.searchlightRadius = 9;
  36. searchlightOptions.monitor = false;
  37. searchlightOptions.fisher = true;
  38. searchlightOptions.nSessions = 1;
  39. searchlightOptions.nConditions = 40;
  40.  
  41. nii = load_nii(fullfile(userOptions.rootPath,'Nifti','brainmask.nii'));
  42. SLMetadata.mask = nii.img > 0;
  43.  
  44. nii = load_nii(fullfile(userOptions.rootPath,'Nifti','T1.nii'));
  45. SLMetadata.anatVol = nii.img;
  46.  
  47. Nsubjects = 20;
  48.  
  49. %% Second-order analysis
  50. % Which similarity-measure is used for the second-order comparison.
  51. userOptions.distanceMeasure = 'Spearman';
  52. ReadChrisNotesAbout('userOptions.distanceMeasure');
  53.  
  54. % How many permutations should be used to test the significance of the fits?  (10,000 highly recommended.)
  55. userOptions.significanceTestPermutations = 1000; % for the sake of time
  56.  
  57. % Should RDMs' entries be rank transformed into [0,1] before they're displayed?
  58. userOptions.rankTransform = true;
  59.  
  60. % RDM Colourscheme
  61. % userOptions.colourScheme = jet(64);
  62. %
  63. % % Should rubber bands be shown on the MDS plot?
  64. % userOptions.rubberbands = true;
  65. %
  66. % % What criterion shoud be minimised in MDS display?
  67. % userOptions.criterion = 'metricstress';
  68.  
  69. % How should figures be output?
  70. userOptions.displayFigures = true;
  71. userOptions.saveFiguresPDF = true;
  72. userOptions.saveFiguresFig = false;
  73. userOptions.saveFiguresPS = false;
  74. userOptions.saveFiguresEps = false;
  75.  
  76. % Bootstrap options
  77. userOptions.nResamplings = 1000;
  78. userOptions.resampleSubjects = true;
  79. userOptions.resampleConditions = true;
  80.  
  81. userOptions.RDMname = 'referenceRDM';
  82. userOptions.plottingStyle = 2;
  83.  
  84. %% Generate a categorical RDM
  85. tmp = modelRDMs_SL_sim();
  86. x = csvread(fullfile('DEMO_20June','Metadata','FeatureVectors.csv'));
  87. tmp.features = squareform(pdist(x, 'cosine'));
  88. x = csvread(fullfile('DEMO_20June','Metadata','Components.csv'));
  89. tmp.components = squareform(pdist(x, 'cosine'));
  90. Models = rsa.constructModelRDMs(tmp, userOptions);
  91.  
  92. %% display the design matrix, model RDMs and simulated RDMs and the SL
  93. load(fullfile(userOptions.rootPath,'RDMs','DEMO_20June_Models.mat'),'Models');
  94. load(fullfile(userOptions.rootPath,'Maps','SimulationMetadata.mat'), 'fMRI_sub');
  95.  
  96. rsa.fig.showRDMs(Models);
  97. PlotSimulationDesign( fMRI_sub.X, fMRI_sub.groundTruth, Models(1), userOptions, simulationOptions );
  98.  
  99. %% If we were to run the searchlights, it would look something like this:
  100. mask = SLMetadata.mask;
  101. userOptions.searchlightRadius = 9;
  102. for i = 1 %:Nsubjects
  103.     fname = sprintf('beta_subject%d.nii', i);
  104.     nii = load_nii(fullfile(userOptions.rootPath,'Nifti',fname));
  105.     singleSubjectVols = reshape(nii.img, numel(mask), size(nii.img, 5));
  106.     fprintf('computing correlation maps for subject %d \n', i)
  107.     [rs, ps, ns, searchlightRDMs.(i)] = rsa.fmri.searchlightMapping_fMRI(singleSubjectVols, Models, mask, userOptions, searchlightOptions);
  108.     %     save(['rs_',subject,'.mat'],'rs');
  109. end
  110.  
  111. %% load the previously computed rMaps and concatenate across subjects
  112. rMaps = cell(Nsubjects,1);
  113. for subjectI = 1:Nsubjects
  114.     load(fullfile(userOptions.rootPath,'Maps',sprintf('rs_subject%d.mat',subjectI)))
  115.     rMaps{subjectI} = rs;
  116.     fprintf('loading the correlation maps for subject %d\n',subjectI);
  117. end
  118.  
  119. %% Run statistical tests at each voxel
  120. [pMap_ttest, pMap_signrank] = TestAllVoxels(rMaps,SLMetadata);
  121.  
  122. %% Plot solutions
  123. load(fullfile(userOptions.rootPath,'Maps','SimulationMetadata.mat'), 'MaskFromSimulation');
  124. SLMetadata.MaskFromSimulation = MaskFromSimulation;
  125.  
  126. PlotSearchlightResults( pMap_ttest, 'ttest', SLMetadata, userOptions, 'PlotSimulatedEffect', true, 'SimFigureNumber',2, 'FigureNumber',3);
  127. PlotSearchlightResults( pMap_signrank, 'signedrank', SLMetadata, userOptions, 'PlotSimulatedEffect', false,'FigureNumber',4 );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement