| addpath('./CIFTI_read_save') |
| clear;close all;clc; |
|
|
| |
| img_size = 192; |
| mask_path = './mask'; |
| output_path = './data'; |
| data_full_path = './Example_Lynch2024_Priors/Lynch_2024_Nature_Priors.mat' |
| namestr = 'Lynch2024_45subj_Prior' |
| parcelname = '20NetsParcel' |
| sampleinterval = 1; |
| randpermutation = false; |
| cifti_type = 'parcel_dconn'; |
| h5file_path = ['./data/',namestr,'_',parcelname,'.h5']; |
|
|
| if ~isfolder(output_path) |
| mkdir(output_path); |
| disp(['Target directory does not exist and is created: ', output_path]); |
| else |
| disp(['Target directory exists: ', output_path]); |
| end |
|
|
| |
| LeftMask = load(fullfile(mask_path, 'MSE_Mask.mat')).Regular_Grid_Left_Mask; |
| RightMask = load(fullfile(mask_path, 'MSE_Mask.mat')).Regular_Grid_Right_Mask; |
|
|
| left_transmat = load(fullfile(mask_path, 'Left_fMRI2Grid_192_by_192_NN.mat')).grid_mapping; |
| right_transmat = load(fullfile(mask_path, 'Right_fMRI2Grid_192_by_192_NN.mat')).grid_mapping; |
|
|
| |
| load(data_full_path) |
|
|
| |
| fmri_data1 = Priors.FC; |
| assert(size(fmri_data1,1)==59412) |
| |
| [LeftSurfData, RightSurfData] = FormatData(fmri_data1,cifti_type,left_transmat,right_transmat,randpermutation,sampleinterval,img_size); |
| |
| SaveData(LeftSurfData, RightSurfData,h5file_path) |
|
|
| |
| |
| function [LeftSurfData, RightSurfData] = FormatData(fmri_data,cifti_type,left_transmat,right_transmat,randpermutation,sampleinterval,img_size) |
| if strcmp(cifti_type, 'dconn') |
| fmri_data(1:size(fmri_data,1)+1:end) = 0; |
| end |
|
|
| if randpermutation |
| idx = randperm(size(fmri_data, 2)); |
| idx = idx(1:sampleinterval:size(fmri_data,2)); |
| else |
| idx = 1:sampleinterval:size(fmri_data,2); |
| end |
|
|
| left_data = fmri_data(1:29696, idx); |
| right_data = fmri_data(29697:59412, idx); |
| disp(['Loading data the size of the left hemisphere is ', num2str(size(left_data)), '; the size of the right hemisphere is ', num2str(size(right_data))]); |
|
|
| |
| LeftSurfData = reshape(left_transmat * left_data, img_size, img_size, 1,[]); |
| RightSurfData = reshape(right_transmat * right_data, img_size, img_size,1, []); |
|
|
| disp(size(LeftSurfData)); |
| disp(size(RightSurfData)); |
| disp('here in format data'); |
| end |
|
|
| |
| function SaveData(LeftSurfData, RightSurfData,file_path) |
| disp(size(LeftSurfData)); |
| disp(['saving to ' file_path]); |
| if isfile(file_path) |
| disp('Output Data Exists. Append Data To The End'); |
| fileInfo = h5info(file_path,'/LeftData'); |
| currentSize = fileInfo.Dataspace.Size(4); |
| else |
| disp('Output Data Does Not Exist. Creating New Data'); |
| currentSize = 0; |
| h5create(file_path, '/LeftData', [size(LeftSurfData,[1,2,3]),Inf], 'Datatype', 'single','ChunkSize',[size(LeftSurfData,[1,2,3]),1]); |
| h5create(file_path, '/RightData', [size(RightSurfData,[1,2,3]),Inf], 'Datatype', 'single','ChunkSize',[size(RightSurfData,[1,2,3]),1]); |
| end |
| |
| N = size(LeftSurfData,4); |
| startIndex = [1,1,1,currentSize+1]; |
| chunkSize = [size(RightSurfData,[1,2,3]),N]; |
| |
| h5write(file_path, '/LeftData', single(LeftSurfData),startIndex,chunkSize); |
| h5write(file_path, '/RightData', single(RightSurfData),startIndex,chunkSize); |
|
|
| disp('here in save_data'); |
| end |
|
|
|
|