Last active
July 7, 2025 15:46
-
-
Save rcassani/8ea012743ad1494fe82fac32fb4b8e01 to your computer and use it in GitHub Desktop.
Brainstorm, aggregate volume values per anatomical parcellation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| % Brainstorm script to obtain the mean value for a Volume (PET or Neuromap) | |
| % for each of the parcellations in an anatomical parcellation (e.g. Desikan-Killiany) | |
| %% PARAMETERS | |
| % FileName for the Volume to use (Subject/VolFile) | |
| volFileName = 'sub-MTL0002/subjectimage_sub-MTL0002_ses-01_trc-18Fflortaucipir_pet_spm_reslice_volpet.mat'; | |
| % Anatomical parcellation | |
| volAtlasName = 'Desikan-Killiany'; | |
| %% COMPUTATION | |
| % Get Subject | |
| [sSubject, ~, iAnat] = bst_get('MriFile', volFileName); | |
| % Find Desikan-Killiany anatomical parcellation for Subject | |
| iMriAtlas = find(strcmpi({sSubject.Anatomy.Comment}, volAtlasName)); | |
| sMriAtlas = in_mri_bst(sSubject.Anatomy(iMriAtlas).FileName); | |
| % Find cube indices for parcellations | |
| for iParcellation = 1 : size(sMriAtlas.Labels, 1) | |
| sMriAtlas.Labels{iParcellation, 4} = find(sMriAtlas.Cube == sMriAtlas.Labels{iParcellation, 1}); | |
| end | |
| % Initialize parcellation values | |
| parcellationValues = zeros(size(sMriAtlas.Labels, 1), 1); | |
| parcellationNames = sMriAtlas.Labels(:,2); | |
| % Compute parcellation mean values | |
| sVol = in_mri(file_fullpath(volFileName)); | |
| for iParcellation = 1 : size(sMriAtlas.Labels, 1) | |
| parcellationValues(iParcellation) = mean(sVol.Cube(sMriAtlas.Labels{iParcellation, 4})); | |
| end | |
| %% SAVE | |
| % Save parcellation values in matrix file | |
| studyName = ['parcellation_values', volAtlasName]; | |
| iStudy = db_add_condition(sSubject.Name, studyName); | |
| sStudy = bst_get('Study', iStudy); | |
| sMatrixMat = db_template('MatrixMat'); | |
| sMatrixMat.Value = parcellationValues; | |
| sMatrixMat.Description = parcellationNames; | |
| sMatrixMat.Comment = sSubject.Anatomy(iAnat).Comment; | |
| matrixFileName = bst_process('GetNewFilename', bst_fileparts(sStudy.FileName), 'matrix'); | |
| bst_save(matrixFileName, sMatrixMat); | |
| % Register matrix in database | |
| db_add_data(iStudy, matrixFileName, sMatrixMat); | |
| % Update tree | |
| panel_protocols('UpdateNode', 'Study', iStudy); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment