123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308 |
- BIDS_path = "F:\Projects\StrokePT_tDCS_rsfmri\subjects";
- cd (BIDS_path)
- addpath("..\scripts\toolbox\DVARS-master\")
- addpath("..\scripts\toolbox\DVARS-master\Nifti_Util\")
- addpath("..\scripts")
- addpath("..\scripts\toolbox\spm12")
- addpath("..\scripts\toolbox\fMRI-Quality-Checker-master")
- addpath("..\scripts\toolbox\spm12\matlabbatch")
- addpath("..\scripts\toolbox\nifti_utils-master\")
- %% Preps
- % px = dir('sub*');
- timeX = {'tpA','tpB','tpC','tpD'};
- % master = zeros300,5};
- % noPhysio = zeros(300);
- master_tag = {'subject','group','timepoint','dataset','physio','volumes','bad_volumes','meanDeltaDvar'};
- tick = 1;
- tack = 1;
- % Check for registration quality (user input)?
- quali = "on";
- %% level1: group folders
- cd (BIDS_path)
- gx = dir('sub*');
- for g = 21:length(gx)
- subject = gx(g).name;
- cd (fullfile(gx(g).folder,gx(g).name))
- %% level2: timepoints
- tx = dir('ses*');
- for t = 1:length(tx)
- time = tx(t).name;
- cd (fullfile(tx(t).folder,tx(t).name))
-
- folder_to = pwd;
- %%
-
- % a) get structural
- if exist(fullfile(folder_to,"anat/"))==7 && exist (fullfile(folder_to,"func/"))==7
- cd (fullfile(folder_to,"anat/"))
- struct_orig = dir("*.1.nii.gz");
- struct_name = struct_orig(length(struct_orig)).name;
- struct_fullfile = fullfile(struct_orig(length(struct_orig)).folder,struct_orig(length(struct_orig)).name);
-
- struct_reg = dir("*BiasBet_AnnorsfMRI.nii.gz");
- if ~isempty(struct_reg)
- structReg_fullfile = fullfile(struct_reg.folder,struct_reg.name);
-
- struct_BET = dir("*BiasBet.nii.gz");
- structBET_fullfile = fullfile(struct_BET.folder,struct_BET.name);
- end
- % copyfile(struct_fullfile,fullfile(folder_to,"anat/",strcat(struct_name(1:end-7),'_T2w.nii.gz')))
- struct_orig = dir("*_T2w.nii.gz");
- struct_name = struct_orig(length(struct_orig)).name;
- struct_fullfile = fullfile(struct_orig(length(struct_orig)).folder,struct_orig(length(struct_orig)).name);
-
- % b) get fMRI
- cd (fullfile(folder_to,"func/"))
- fmri_orig = dir("*.1.nii.gz");
- clear ('fx_rep')
- for jx = 1:length(fmri_orig)
- fx_scan = niftiinfo(fmri_orig(jx).name);
- fx_rep(jx) = fx_scan.ImageSize(4);
- end
- fx_id = find(fx_rep>100);
- fx = length(fx_id);
- fMRI_fullfile = fullfile(fmri_orig(fx_id(1)).folder,fmri_orig(fx_id(1)).name);
- fMRI_file = fmri_orig(fx_id(1));
- fMRI_name = fMRI_file.name;
- % copyfile(fMRI_fullfile,fullfile(fMRI_file.folder,strcat(fMRI_name(1:end-7),'_bold.nii.gz')))
- info = niftiinfo(fMRI_fullfile);
- master{tick,6} = info.ImageSize(4);
- fmri_smooth = dir("*SmoothBet.nii.gz");
- if ~isempty(fmri_smooth)
- fmriSmooth_fullfile = fullfile(fmri_smooth.folder,fmri_smooth.name);
- end
- % c) get Regression File
- cd (fullfile(folder_to,"func/"))
- ABAreg_orig = dir("*SmoothBet_AnnoSplit_rsfMRI.nii.gz");
- if ~isempty(ABAreg_orig)
- ABAreg_fullfile = fullfile(ABAreg_orig.folder,ABAreg_orig.name);
- end
- if exist("regr","dir")
- cd regr\
- SFRGR_orig = dir("*_SFRGR.nii.gz");
- if ~isempty(SFRGR_orig)
- SFRGR_fullfile = fullfile(SFRGR_orig.folder,SFRGR_orig.name);
- else
- SFRGR_fullfile = [];
- end
- end
- %% plot raw images to check registration
- if ~exist("quali",'var')
- quali = "off"
- end
- if quali == "on"
- fMRI_imag = niftiread(fmriSmooth_fullfile);
- fMRI_imag = imrotate(fMRI_imag,-90);
-
- if ~isempty(ABAreg_orig)
- fMRI_Reg = niftiread(ABAreg_fullfile);
- fMRI_Reg = imrotate(fMRI_Reg,-90);
- else
- fMRI_Reg = zeros(96,96,16);
- end
- T2raw = niftiread(structBET_fullfile);
- T2raw = imrotate(T2raw,-90);
- if ~isempty(struct_reg)
- T2Reg = niftiread(structReg_fullfile);
- T2Reg = imrotate(T2Reg,-90);
- else
- T2Reg = zeros(256,256,28);
- end
-
- Loc = [8 10];
- Loc2 = [4 6];
- figure('units','normalized','outerposition',[0 0 1 1])
- for ix = 1:2
- % Raw T2w
- subplot(2,4,1+(4*(ix-1)))
- imagesc(fMRI_imag(:,:,Loc2(ix)))
- subplot(2,4,2+(4*(ix-1)))
- imagesc(fMRI_Reg(:,:,Loc2(ix)))
- % % subplot(2,4,1+(4*(ix-1)))
- % % imagesc(T2raw(:,:,floor(Loc(ix)/16*48)))
- colormap("hot")
- % % % T2 ARA Reg
- % % subplot(2,4,2+(4*(ix-1)))
- % % imagesc(T2Reg(:,:,floor(Loc(ix)/16*48)))
- % % % colormap("hot")
- % Raw fMRI
- subplot(2,4,3+(4*(ix-1)))
- imagesc(fMRI_imag(:,:,Loc(ix)))
- % colormap("gray")
- % fMRI ARA Reg
- subplot(2,4,4+(4*(ix-1)))
- imagesc(fMRI_Reg(:,:,Loc(ix)))
- % colormap("hot")
- end
- title(strcat(subject,'-',time))
- pause
- close
- %% user input to evaluate quality
- RegQuali{tick,1}=subject;
- RegQuali{tick,2}=time;
-
- % get input of image quality
- checkT2 = input("is T2 ok? Y/N [Y]");
- if isempty(checkT2)
- checkT2 = "Y";
- else
- checkT2 = "N";
- end
- RegQuali{tick,3} = checkT2;
-
- checkfMRI = input("is fMRI ok? Y/N [Y]");
- if isempty(checkfMRI)
- checkfMRI = "Y";
- else
- checkfMRI = "N";
- end
- disp('')
- RegQuali{tick,4} = checkfMRI;
- end
- %%
- tick=tick +1;
- end
-
- end
- end
- % % % a) get structural
- % % if exist(fullfile(parent_path,subject,"MRI",time,"T2w/"))==7 && exist (fullfile(parent_path,subject,"MRI",time,"fMRI/"))==7
- % % cd (fullfile(parent_path,subject,"MRI",time,"T2w/"))
- % % struct_orig = dir("*.1.nii.gz");
- % % struct_name = struct_orig(length(struct_orig)).name;
- % % struct_fullfile = fullfile(struct_orig(length(struct_orig)).folder,struct_orig(length(struct_orig)).name);
- % %
- % % struct_reg = dir("*BiasBet_AnnorsfMRI.nii.gz");
- % % if ~isempty(struct_reg)
- % % structReg_fullfile = fullfile(struct_reg.folder,struct_reg.name);
- % % end
- % % struct_BET = dir("*BiasBet.nii.gz");
- % % structBET_fullfile = fullfile(struct_BET.folder,struct_BET.name);
- % %
- % %
- % % % b) get fMRI
- % % cd (fullfile(parent_path,subject,"MRI",time,"fMRI/"))
- % % fmri_orig = dir("*.1.nii.gz");
- % % fmri_name = fmri_orig(length(fmri_orig)).name;
- % % fMRI_fullfile = fullfile(fmri_orig(length(fmri_orig)).folder,fmri_orig(length(fmri_orig)).name);
- % % fmri_smooth = dir("*SmoothBet.nii.gz");
- % % fmriSmooth_fullfile = fullfile(fmri_smooth.folder,fmri_smooth.name);
- % %
- % % if ~exist("analyses","dir")
- % % mkdir("analyses")
- % % end
- % % cd ("analyses")
- % %
- % % % c) get Regression File
- % % cd (fullfile(parent_path,subject,"MRI",time,"fMRI/"))
- % % ABAreg_orig = dir("*SmoothBet_AnnoSplit_rsfMRI.nii.gz");
- % % if ~isempty(ABAreg_orig)
- % % ABAreg_fullfile = fullfile(ABAreg_orig.folder,ABAreg_orig.name);
- % % end
- % % cd regr\
- % % SFRGR_orig = dir("*_SFRGR.nii.gz");
- % % if ~isempty(SFRGR_orig)
- % % SFRGR_fullfile = fullfile(SFRGR_orig.folder,SFRGR_orig.name);
- % % else
- % % SFRGR_fullfile = [];
- % % end
- % % % plot raw images to check registration
- % %
- % %
- % % fMRI_imag = niftiread(fmriSmooth_fullfile);
- % % fMRI_imag = imrotate(fMRI_imag,-90);
- % %
- % % if ~isempty(ABAreg_orig)
- % % fMRI_Reg = niftiread(ABAreg_fullfile);
- % % fMRI_Reg = imrotate(fMRI_Reg,-90);
- % % else
- % % fMRI_Reg = zeros(96,96,16);
- % % end
- % %
- % % T2raw = niftiread(structBET_fullfile);
- % % T2raw = imrotate(T2raw,-90);
- % % if ~isempty(struct_reg)
- % % T2Reg = niftiread(structReg_fullfile);
- % % T2Reg = imrotate(T2Reg,-90);
- % % else
- % % T2Reg = zeros(256,256,28);
- % % end
- % %
- % % Loc = [8 13];
- % % %%
- % % figure('units','normalized','outerposition',[0 0 1 1])
- % % for ix = 1:2
- % % % Raw T2w
- % % subplot(2,4,1+(4*(ix-1)))
- % % imagesc(T2raw(:,:,floor(Loc(ix)/16*28)))
- % % colormap("hot")
- % % % T2 ARA Reg
- % % subplot(2,4,2+(4*(ix-1)))
- % % imagesc(T2Reg(:,:,floor(Loc(ix)/16*28)))
- % % % colormap("hot")
- % % % Raw fMRI
- % % subplot(2,4,3+(4*(ix-1)))
- % % imagesc(fMRI_imag(:,:,Loc(ix)))
- % % % colormap("gray")
- % % % fMRI ARA Reg
- % % subplot(2,4,4+(4*(ix-1)))
- % % imagesc(fMRI_Reg(:,:,Loc(ix)))
- % % % colormap("hot")
- % % end
- % % title(strcat(subject,'-',time))
- % % pause
- % % close
- % % %%
- % % RegQuali{tick,1}=subject;
- % % RegQuali{tick,2}=time;
- % %
- % % % get input of image quality
- % % checkT2 = input("is T2 ok? Y/N [Y]");
- % % if isempty(checkT2)
- % % checkT2 = "Y";
- % % else
- % % checkT2 = "N";
- % % end
- % % RegQuali{tick,3} = checkT2;
- % %
- % % checkfMRI = input("is fMRI ok? Y/N [Y]");
- % % if isempty(checkfMRI)
- % % checkfMRI = "Y";
- % % else
- % % checkfMRI = "N";
- % % end
- % % disp('')
- % % RegQuali{tick,4} = checkfMRI;
- % %
- % % tick = tick + 1;
- %
- % xlswrite('Reg_Quali.xls',RegQuali)
|