%% (1) RUN THIS BEFORE PLOTTING TO GENERATE ALL THE REQUIRED FILES FOR AAL3 clear % This is the GM mask we built in the preprocessing part. mask_nii = spm_vol('C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_aal3\data\mask.nii'); mask_nii = spm_read_vols(mask_nii); mask_nii = reshape(mask_nii,1,[]); mask_nii = logical(mask_nii); % Change the path accordingly. cd('C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\Atlases_Mikael\warp_atlas\result') % Remember that you first have to have co-registered the swc01 images with the % atlases. Alternatively you can also use the ones we provide here since % the number of subjects is quite large. V1 = spm_vol('raal_AAL3v1_1mm.nii'); aal3 = spm_read_vols(V1); aal3 = reshape(aal3,1,[]); aal3_roi_tbl = tabulate(aal3); aal3_roi_tbl = aal3_roi_tbl(aal3_roi_tbl(:,1)>0,1); load('aal3areanames.mat') % You need to change this to the framework name you have created. framework_to_run = 'C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_aal3\framework\spls_fair20-5_fair_modeA_pub_aal3_new_noAnom_common_bmi\res'; cd(framework_to_run) for i = 1:length(dir('level*')) % number of significant levels % change the cd below to the /model/res of your choice cd(framework_to_run) cd(['level' num2str(i)]) % BE CAREFUL WHEN YOU SWAP THE ORIGINAL WITH THE RESHAPED TO PLOT RESULTS. % YOU SHOULD CHANGE IT BACK TO THE ORIGINAL BEFORE RUNNING THIS AGAIN. % wX model model_name = dir('model*'); model_name = model_name.name; delete original* delete reshaped* copyfile(model_name, ['original_wX_' model_name]) copyfile(model_name, ['reshaped_wX_' model_name]) load(model_name,'wX') wX_image = zeros(1,length(aal3)); for aal3_i = 1:length(aal3_roi_tbl) aal3_roi_id = aal3_roi_tbl(aal3_i); current_roi_vx = (aal3 == aal3_roi_id); wX_image(current_roi_vx) = wX(aal3_i); end wX_image = wX_image(mask_nii); wX = wX_image; save(['reshaped_wX_' model_name],'wX','-append') % corrCell corrCell_name = 'corrCell.mat'; copyfile(corrCell_name, ['original_corrCellX_' corrCell_name]) copyfile(corrCell_name, ['reshaped_corrCellX_' corrCell_name]) load(corrCell_name) corrCellX_image = zeros(1,length(aal3)); for aal3_i = 1:length(aal3_roi_tbl) aal3_roi_id = aal3_roi_tbl(aal3_i); current_roi_vx = (aal3 == aal3_roi_id); corrCellX_image(current_roi_vx) = corrCell{1,1}(aal3_i); end corrCellX_image = corrCellX_image(mask_nii); corrCell{1,1} = corrCellX_image; save(['reshaped_corrCellX_' corrCell_name],'corrCell','-append') end cd(framework_to_run) for i = 1:length(dir('level*')) % number of significant levels % change the cd below to the /model/res of your choice cd(framework_to_run) cd(['level' num2str(i)]) load(['original_wX_' model_name]) load('original_corrCellX_corrCell.mat') clear wX_table_aal3 corrCell_table_aal3 wX_table_aal3.area_name = aal3areanames.name; wX_table_aal3 = struct2table(wX_table_aal3); for aal3_i = 1:height(aal3areanames) kk = find(aal3_roi_tbl == aal3areanames.index(aal3_i)); if isempty(kk) wX_table_aal3.weight(aal3_i) = 0; else wX_table_aal3.weight(aal3_i) = wX(kk); end end wX_table_aal3 = wX_table_aal3(wX_table_aal3.weight~=0,:); wX_table_aal3 = flip(sortrows(wX_table_aal3,'weight')); corrCell_table_aal3.area_name = aal3areanames.name; corrCell_table_aal3 = struct2table(corrCell_table_aal3); for aal3_i = 1:height(aal3areanames) kk = find(aal3_roi_tbl == aal3areanames.index(aal3_i)); if isempty(kk) corrCell_table_aal3.correl(aal3_i) = 0; else corrCell_table_aal3.correl(aal3_i) = corrCell{1,1}(kk); end end corrCell_table_aal3 = corrCell_table_aal3(corrCell_table_aal3.correl~=0,:); corrCell_table_aal3 = flip(sortrows(corrCell_table_aal3,'correl')); delete weightX_table_aal3* delete image_corr_table_aal3* % cd(framework_to_run(1:end-4)) writetable(wX_table_aal3,['weightX_table_aal3_level' num2str(i) '.xlsx']) writetable(corrCell_table_aal3,['image_corr_table_aal3_level' num2str(i) '.xlsx']) end %% (2) Reshape wX and corrCell from AAL3 atlas weights to a normal image for visualisation purposes clear % You need to change this to the framework name you have created. framework_to_run = 'C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_aal3\framework\spls_fair20-5_fair_modeA_pub_aal3_new_noAnom_common_bmi\res'; cd(framework_to_run(1:end-4)) cfg_file = dir('cfg*'); cfg_file = cfg_file.name; load([framework_to_run(1:end-4) '\' cfg_file]) cfg = cfg_defaults(cfg); frworkNow=cfg.dir.frwork; cd(framework_to_run) for l=1:length(dir('level*')) cd(framework_to_run) cd(['level' num2str(l)]) % Change model_* and corrCell to the reshaped ones. model_name = dir('model*'); model_name = model_name.name; copyfile(['reshaped_wX_' model_name],model_name) corrCell_name = 'corrCell.mat'; copyfile(['reshaped_corrCellX_' corrCell_name],corrCell_name) display(['Plot level ' num2str(l)]); reses=dir(fullfile(frworkNow,'res',['level' num2str(l)],'res_*')); load(fullfile(frworkNow,'res',['level' num2str(l)],reses(1).name)); plot_spls_atlas2(l,cfg,1); clear res % Change back the model_* and corrCell to the original (atlas) ones. copyfile(['original_wX_' model_name],model_name) copyfile(['original_corrCellX_' corrCell_name],corrCell_name) end %% (1) RUN THIS BEFORE PLOTTING TO GENERATE ALL THE REQUIRED FILES FOR Schaefer-Buckner-Choi clear % This is the GM mask we built in the preprocessing part. mask_nii = spm_vol('C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_aal3\data\mask.nii'); mask_nii = spm_read_vols(mask_nii); mask_nii = reshape(mask_nii,1,[]); mask_nii = logical(mask_nii); % Change the path accordingly. cd('C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\Atlases_Mikael\warp_atlas\result') % Remember that you first have to have co-registered the swc01 images with the % atlases. Alternatively you can also use the ones we provide here since % the number of subjects is quite large. V1 = spm_vol('Schaefer_Buck_Choi_17Networks_atlas.nii'); schaeferbuckchoi = spm_read_vols(V1); schaeferbuckchoi = reshape(schaeferbuckchoi,1,[]); schaeferbuckchoi_roi_tbl = tabulate(schaeferbuckchoi); schaeferbuckchoi_roi_tbl = schaeferbuckchoi_roi_tbl(schaeferbuckchoi_roi_tbl(:,1)>0,1); load('schaeferbuckchoiareanames.mat') % You need to change this to the framework name you have created. framework_to_run = 'C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_schaeferbuckchoi\framework\spls_fair20-5_fair_modeA_pub_schaeferbuckchoi_noAnom_common_bmi\res'; cd(framework_to_run) for i = 1:length(dir('level*')) % number of significant levels cd(framework_to_run) cd(['level' num2str(i)]) % wX model model_name = dir('model*'); model_name = model_name.name; delete original* delete reshaped* copyfile(model_name, ['original_wX_' model_name]) copyfile(model_name, ['reshaped_wX_' model_name]) load(model_name,'wX') wX_image = zeros(1,length(schaeferbuckchoi)); for schaeferbuckchoi_i = 1:length(schaeferbuckchoi_roi_tbl) schaeferbuckchoi_roi_id = schaeferbuckchoi_roi_tbl(schaeferbuckchoi_i); current_roi_vx = (schaeferbuckchoi == schaeferbuckchoi_roi_id); wX_image(current_roi_vx) = wX(schaeferbuckchoi_i); end wX_image = wX_image(mask_nii); wX = wX_image; save(['reshaped_wX_' model_name],'wX','-append') % corrCell corrCell_name = 'corrCell.mat'; copyfile(corrCell_name, ['original_corrCellX_' corrCell_name]) copyfile(corrCell_name, ['reshaped_corrCellX_' corrCell_name]) load(corrCell_name) corrCellX_image = zeros(1,length(schaeferbuckchoi)); for schaeferbuckchoi_i = 1:length(schaeferbuckchoi_roi_tbl) schaeferbuckchoi_roi_id = schaeferbuckchoi_roi_tbl(schaeferbuckchoi_i); current_roi_vx = (schaeferbuckchoi == schaeferbuckchoi_roi_id); corrCellX_image(current_roi_vx) = corrCell{1,1}(schaeferbuckchoi_i); end corrCellX_image = corrCellX_image(mask_nii); corrCell{1,1} = corrCellX_image; save(['reshaped_corrCellX_' corrCell_name],'corrCell','-append') end cd(framework_to_run) for i = 1:length(dir('level*')) % number of significant levels % change the cd below to the /model/res of your choice cd(framework_to_run) cd(['level' num2str(i)]) load(['original_wX_' model_name]) load('original_corrCellX_corrCell.mat') clear wX_table_schaeferbuckchoi corrCell_table_schaeferbuckchoi wX_table_schaeferbuckchoi.area_name = schaeferbuckchoiareanames.name; wX_table_schaeferbuckchoi = struct2table(wX_table_schaeferbuckchoi); for schaeferbuckchoi_i = 1:height(schaeferbuckchoiareanames) kk = find(schaeferbuckchoi_roi_tbl == schaeferbuckchoiareanames.index(schaeferbuckchoi_i)); if isempty(kk) wX_table_schaeferbuckchoi.weight(schaeferbuckchoi_i) = 0; else wX_table_schaeferbuckchoi.weight(schaeferbuckchoi_i) = wX(kk); end end wX_table_schaeferbuckchoi = wX_table_schaeferbuckchoi(wX_table_schaeferbuckchoi.weight~=0,:); wX_table_schaeferbuckchoi = flip(sortrows(wX_table_schaeferbuckchoi,'weight')); corrCell_table_schaeferbuckchoi.area_name = schaeferbuckchoiareanames.name; corrCell_table_schaeferbuckchoi = struct2table(corrCell_table_schaeferbuckchoi); for schaeferbuckchoi_i = 1:height(schaeferbuckchoiareanames) kk = find(schaeferbuckchoi_roi_tbl == schaeferbuckchoiareanames.index(schaeferbuckchoi_i)); if isempty(kk) corrCell_table_schaeferbuckchoi.correl(schaeferbuckchoi_i) = 0; else corrCell_table_schaeferbuckchoi.correl(schaeferbuckchoi_i) = corrCell{1,1}(kk); end end corrCell_table_schaeferbuckchoi = corrCell_table_schaeferbuckchoi(corrCell_table_schaeferbuckchoi.correl~=0,:); corrCell_table_schaeferbuckchoi = flip(sortrows(corrCell_table_schaeferbuckchoi,'correl')); delete weightX_table_aal3* delete image_corr_table_aal3* cd(framework_to_run(1:end-4)) % cd('C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_schaeferbuckchoi\framework\schaeferbuckchoi_noAnom_common_bmi') writetable(wX_table_schaeferbuckchoi,['weightX_table_schaeferbuckchoi_level' num2str(i) '.xlsx']) writetable(corrCell_table_schaeferbuckchoi,['image_corr_table_schaeferbuckchoi_level' num2str(i) '.xlsx']) end %% (2) Reshape wX and corrCell from Schaefer-Buckner-Choi atlas weights to a normal image for visualisation purposes clear % You need to change this to the framework name you have created. framework_to_run = 'C:\Users\Konstantinos Tsirlis\Dropbox\My Desktop\Mourao - Miranda\ABCD results\abcdAll_noA_schaeferbuckchoi\framework\spls_fair20-5_fair_modeA_pub_schaeferbuckchoi_noAnom_common_bmi\res'; cd(framework_to_run(1:end-4)) cfg_file = dir('cfg*'); cfg_file = cfg_file.name; load([framework_to_run(1:end-4) '\' cfg_file]) cfg = cfg_defaults(cfg); frworkNow=cfg.dir.frwork; cd(framework_to_run) for l=1:length(dir('level*')) cd(framework_to_run) cd(['level' num2str(l)]) % Change model_* and corrCell to the reshaped ones. model_name = dir('model*'); model_name = model_name.name; copyfile(['reshaped_wX_' model_name],model_name) corrCell_name = 'corrCell.mat'; copyfile(['reshaped_corrCellX_' corrCell_name],corrCell_name) display(['Plot level ' num2str(l)]); reses=dir(fullfile(frworkNow,'res',['level' num2str(l)],'res_*')); load(fullfile(frworkNow,'res',['level' num2str(l)],reses(1).name)); plot_spls_atlas2(l,cfg,1); clear res % Change back the model_* and corrCell to the original (atlas) ones. copyfile(['original_wX_' model_name],model_name) copyfile(['original_corrCellX_' corrCell_name],corrCell_name) end