123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289 |
- parent_path = "F:\Projects\CBIrep_Imaging\subjects";
- cd (parent_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\")
- %%
- px = dir('sub*');
- master = zeros(300,5);
- noPhysio = zeros(300);
- tick = 1;
- tack = 1;
- %%
- % level of subjects
- for i = 50:length(px)
- cd (parent_path)
- subject = px(i).name;
- cd (subject)
- cd ("MRI")
- tx = dir("tp*");
-
- % level of timepoints
- for k = 1:length(tx)
- cd (fullfile(parent_path,subject,"MRI"))
- time = tx(k).name;
- cd (time)
- % check for missing physiodata in dataset
- % % if exist("physio","dir")==7
- % % cd ("physio\")
- % % kx = dir;
- % % if length(kx)<3
- % % noPhysio(tack,1) = strcat(subject,"_",time);
- % % tack = tack+1;
- % % end
- % % else
- % % noPhysio(tack,1) = strcat(subject,"_",time);
- % % tack = tack+1;
- % % 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;
- %%
-
-
-
- % % % get DVARS
- % % V1 = load_untouch_nii(fMRI_fullfile);
- % % V2 = V1.img;
- % % X0 = size(V2,1); Y0 = size(V2,2); Z0 = size(V2,3); T0 = size(V2,4);
- % % I0 = prod([X0,Y0,Z0]);
- % % Y = reshape(V2,[I0,T0]); clear V2 V1;
- % % [DVARS,DVARS_Stat]=DVARSCalc(Y,'scale',1/100,'TransPower',1/3,'RDVARS','verbose',1);
- % % [V,DSE_Stat]=DSEvars(Y,'scale',1/100);
- % % % fMRIDiag_plot(V,DVARS_Stat)
- % % % saveas(gcf,strcat(fmri_name(1:end-7),'_',"DVARS_plot.png"))
- % % % pause(2)
- % % % close all
- % %
- % % bad_points = find(DVARS_Stat.pvals<0.001);
- % % bad_points (bad_points<5)=[];
- % % bad_points = bad_points-4;
- % % perc_bad = length(bad_points)/1.05;
- % % disp("amount of bad points: ")
- % % disp(num2str(perc_bad))
- % % disp("%")
- % %
- % % bad_points_list{tick,1} = fmri_name;
- % % bad_points_list{tick,2} = bad_points;
- % % bad_points_list{tick,4} = mean(DSE_Stat.DeltapDvar(6:end));
- % % bad_points_list{tick,5} = mean(DSE_Stat.DeltapSvar(6:end));
- % % bad_points_list{tick,6} = bad_points;
- % %
- % %
- % % % getFD
- % % cd (fullfile(parent_path,subject,"MRI",time,"fMRI/"))
- % % if exist("txtRegrPython","dir")
- % % cd txtRegrPython\
- % % txtRegr_files = dir("*mcf*");
- % % if size(txtRegr_files,1)>1
- % % txtRegr = txtRegr_files(floor(length(txtRegr_files)/2)).name;
- % % txtRegr_table = readtable(txtRegr);
- % % if ~isempty(txtRegr_table)
- % % Regression_parameters = txtRegr_table(:,5:10);
- % % MP = cell2mat(table2cell(Regression_parameters));
- % % FD_measures = calculateFD(MP, .5, 0.5);
- % % FD = FD_measures.FD_outliers_ind;
- % % else
- % % FD = [];
- % % end
- % % else
- % % FD = [];
- % % end
- % % else
- % % FD = [];
- % % end
- % %
- % % bad_points_list{tick,3} = FD;
- % spm_dir = "F:\Projects\CBIrep_Imaging\scripts\toolbox\spm12";
- % out_dir = pwd;
- % functional4D_fn = char(gunzip(fMRI_fullfile));
- % functional4D_fn = fullfile(fmri_orig.folder,functional4D_fn);
- % structural_fn = char(gunzip(struct_fullfile));
- % structural_fn = fullfile(struct_orig.folder,structural_fn);
- % fwhm = 0.3;
- % calculateQCmeasures(functional4D_fn, structural_fn, fwhm, spm_dir, out_dir, subject)
-
- end
- end
- end
-
- % %
- % % % level of individual datasets
- % % for m = 1:length(tix)
- % % cd (fullfile(parent_path,trial,time))
- % % dataset = tix(m).name;
- % %
- % % % find corresponding Physio dataset
- % % physioID = find(~cellfun('isempty',regexp({phx.name},dataset,'once')));
- % % if ~isempty(physioID)
- % % physiofolder = fullfile(Physio_path,phx(physioID).name);
- % % master {tick,5} = "y";
- % % else
- % % noPhysio{tack} = dataset;
- % % tack = tack +1;
- % % master {tick,5} = "n";
- % % end
- % %
- % % sjx = strfind(dataset,'_');
- % % subject = dataset(sjx(2)+3:sjx(3)-1);
- % %
- % % master {tick,1} = subject;
- % % master {tick,2} = num2str(length(tx));
- % % master {tick,3} = dataset;
- % % master {tick,4} = subject;
- % %
- % % disp(strcat("running dataset:",dataset));
- % % cd(dataset)
- % %
- % % % copy data to BIDS
- % % folder_from = pwd;
- % % folder_to = fullfile(BIDS_path,strcat("sub-",subject),"MRI",time);
- % %
- % % if ~exist("folder_to","dir")
- % % mkdir(folder_to)
- % % end
- % % % copy MRI data
- % % % copyfile(folder_from,folder_to)
- % % tick = tick +1;
- % %
- % % % copy physio data
- % % if exist("physiofolder","var")
- % % physio_to = fullfile(folder_to,"physio",phx(physioID).name);
- % % if ~exist(physio_to,"dir")
- % % mkdir(physio_to)
- % % end
- % % % copyfile(physiofolder,physio_to);
- % % end
- % % end
- % %
- % %
- % % end
- % %
- % % end
|