Skip to content
Snippets Groups Projects
Commit 17a60c94 authored by Vandewalle Gilles's avatar Vandewalle Gilles
Browse files

Upload New File

parent 42e3d16c
No related branches found
No related tags found
No related merge requests found
%% This script does the 1st level analysis of fMRI data in the native space.
% % Task = 1 (nback) ; 2 (oddball) ; 3 (emotional)
% mod = 0 >> no parametric modulation
% mod = 1 >> light intensity parametric modulation
% mod = 2 >> linear time parametric modulation
% mod = 3 >> pupil size parametric modulation
% mod = 4 >> RT parametric modulation
% pupille = 0 >> no continuous pupil regressor
% pupille = 1 >> continuous pupil regressor
% Overwrite = "true" or "false"
% Make sure you've preprocessed both the structral and functional data first,
% because the main scripts for 1st level analysis
% will look for the output computed by the structural and functional preprocessing scripts.
% Therefore, this code will look for required files in the
% .../output_preprocessing/mp2rage_UNI & task folder.
% Written by R.Sharifpour
% Cyclotron Research Centre, University of Liege, Belgium
% 23th November 2022
%%
function nback_1stlevel_v07(subs_info,paths,mod,pupille,overwrite)
for id = 1:length(subs_info)
%this part of the code search for the preprocessed functional files (nback task) of the
%current subject being processed
subject_info = char(subs_info(id));
subject_ID = subject_info(5:7);
message = ['processing functional images of subject: sub-', subject_ID '/' subject_info(9:end)] ;
disp(message)
% if ~exist(fullfile(char([paths.data '/sub-' subject_ID '/' subject_info(9:end)])))
% message = ['(1) No data found for sub-', subject_ID '/' subject_info(9:end)] ;
% disp(message)
% continue
% end
fprintf('Looking for preprocessed functional files (TASK : NBACK)')
nback_folder = char([paths.data '/' char(subs_info(id)) '/MRI' '/output_preprocessing' '/nback']) ;
%We extracted the name of the .nii files but since the input in the
%batch need the entire path to the nifti files, we will change the
%content of the cell containing the names of the files to add the
%entire path before the name
list_folder = nback_folder ;
preprocessed_nifti = dir(fullfile(list_folder, 'sBET*')) ;
preprocessed_nifti = {preprocessed_nifti.name} ;
[r c] = size(preprocessed_nifti) ;
%We save the entire path to the nifti files (fith the files names)
for i = 1:c
preprocessed_nifti{i} = char([list_folder '/' preprocessed_nifti{i}]) ;
end
%Here, we reshape the cell into a format readable by spm. The input is
%put in a single 1x1 cell containing #volume x 1 cells.
preprocessed_nifti = preprocessed_nifti' ;
%preprocessed_nifti = {preprocessed_nifti} ;
fprintf('\n Preprocessed functional data found \n ')
%We will find for the "onsets_task_HILIGHT_ID" and the
%"REGRESSOR_nback_HILIGHT_ID_..." files created respectively with the
%"task_LM.m" codes and the "Merge_reg.m" code + creates output dir
output = char([paths.data '/' char(subs_info(id)) '/MRI' '/output_1stlevel_TASK-5LightConditions_RESTLight_LightOnOff']) ;%we save that path to create an output folder
if mod == 0
onsets_nback = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'onsets_nback_nomod_TASK-4LightDark_RESTLight_LightOnOff_HILIGHT_*')) ;
output_nback = char([output '/nback_nomod']) ;
end
onset_nback = char([onsets_nback.folder '/' onsets_nback.name]) ;
if pupille == 0
pupil_nback = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'REGRESSOR_Motion_Physio_noPUPIL_nback_HILIGHT_*')) ;
output_nback = char(strcat(output_nback,'_NoPUPIL')) ;
elseif pupille == 1
pupil_nback = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'REGRESSOR_Motion_Physio_PUPIL_nback_HILIGHT_*')) ;
output_nback = char(strcat(output_nback,'_PUPIL')) ;
end
pupil_nback = char([pupil_nback.folder '/' pupil_nback.name]) ;
if exist(output_nback)
rmdir(output_nback,'s')
end
if ~exist(output)
mkdir(output)
mkdir(output_nback)
elseif ~exist(output_nback)
mkdir(output_nback)
end
if ~isempty(dir(output_nback)) && overwrite == false
message = ['Output already exists and "overwrite" set to false. No 1st-level Analysis conducted for sub-', subject_ID] ;
disp(message)
continue
end
%%
% %set up batch
if mod==0
clear matlabbatch
spm_jobman('initcfg') ;
matlabbatch{1}.spm.stats.fmri_spec.dir = {output_nback};
matlabbatch{1}.spm.stats.fmri_spec.timing.units = 'scans';
matlabbatch{1}.spm.stats.fmri_spec.timing.RT = 2.34;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t = 16;
matlabbatch{1}.spm.stats.fmri_spec.timing.fmri_t0 = 8;
%%
matlabbatch{1}.spm.stats.fmri_spec.sess.scans = preprocessed_nifti ;
%%
matlabbatch{1}.spm.stats.fmri_spec.sess.cond = struct('name', {}, 'onset', {}, 'duration', {}, 'tmod', {}, 'pmod', {}, 'orth', {});
matlabbatch{1}.spm.stats.fmri_spec.sess.multi = {onset_nback} ;
matlabbatch{1}.spm.stats.fmri_spec.sess.regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess.multi_reg = {pupil_nback};
matlabbatch{1}.spm.stats.fmri_spec.sess.hpf = 512;
matlabbatch{1}.spm.stats.fmri_spec.fact = struct('name', {}, 'levels', {});
matlabbatch{1}.spm.stats.fmri_spec.bases.hrf.derivs = [0 0];
matlabbatch{1}.spm.stats.fmri_spec.volt = 1;
matlabbatch{1}.spm.stats.fmri_spec.global = 'None';
matlabbatch{1}.spm.stats.fmri_spec.mthresh = -inf;
matlabbatch{1}.spm.stats.fmri_spec.mask = {''};
matlabbatch{1}.spm.stats.fmri_spec.cvi = 'AR(1)';
matlabbatch{2}.spm.stats.fmri_est.spmmat(1) = cfg_dep('fMRI model specification: SPM.mat File', substruct('.','val', '{}',{1}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
matlabbatch{2}.spm.stats.fmri_est.write_residuals = 0;
matlabbatch{2}.spm.stats.fmri_est.method.Classical = 1;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%creation of contrasts
matlabbatch{3}.spm.stats.con.spmmat(1) = cfg_dep('Model estimation: SPM.mat File', substruct('.','val', '{}',{2}, '.','val', '{}',{1}, '.','val', '{}',{1}), substruct('.','spmmat'));
matlabbatch{3}.spm.stats.con.consess{1}.tcon.name = 'N0B1';
matlabbatch{3}.spm.stats.con.consess{1}.tcon.weights = [1];
matlabbatch{3}.spm.stats.con.consess{1}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{2}.tcon.name = 'N0B2';
matlabbatch{3}.spm.stats.con.consess{2}.tcon.weights = [0 1];
matlabbatch{3}.spm.stats.con.consess{2}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{3}.tcon.name = 'N0B3';
matlabbatch{3}.spm.stats.con.consess{3}.tcon.weights = [0 0 1];
matlabbatch{3}.spm.stats.con.consess{3}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{4}.tcon.name = 'N0O';
matlabbatch{3}.spm.stats.con.consess{4}.tcon.weights = [0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{4}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{5}.tcon.name = 'N0D';
matlabbatch{3}.spm.stats.con.consess{5}.tcon.weights = [0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{5}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{6}.tcon.name = 'N2B1';
matlabbatch{3}.spm.stats.con.consess{6}.tcon.weights = [0 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{6}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{7}.tcon.name = 'N2B2';
matlabbatch{3}.spm.stats.con.consess{7}.tcon.weights = [0 0 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{7}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{8}.tcon.name = 'N2B3';
matlabbatch{3}.spm.stats.con.consess{8}.tcon.weights = [0 0 0 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{8}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{9}.tcon.name = 'N2O';
matlabbatch{3}.spm.stats.con.consess{9}.tcon.weights = [0 0 0 0 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{9}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{10}.tcon.name = 'N2D';
matlabbatch{3}.spm.stats.con.consess{10}.tcon.weights = [0 0 0 0 0 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{10}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{11}.tcon.name = 'N0(B3-B1)';
matlabbatch{3}.spm.stats.con.consess{11}.tcon.weights = [-1 0 1];
matlabbatch{3}.spm.stats.con.consess{11}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{12}.tcon.name = 'N0(B3-B2)';
matlabbatch{3}.spm.stats.con.consess{12}.tcon.weights = [0 -1 1];
matlabbatch{3}.spm.stats.con.consess{12}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{13}.tcon.name = 'N0(B2-B1)';
matlabbatch{3}.spm.stats.con.consess{13}.tcon.weights = [-1 1];
matlabbatch{3}.spm.stats.con.consess{13}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{14}.tcon.name = 'N0(B3-O)';
matlabbatch{3}.spm.stats.con.consess{14}.tcon.weights = [0 0 1 -1];
matlabbatch{3}.spm.stats.con.consess{14}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{15}.tcon.name = 'N0(B2-O)';
matlabbatch{3}.spm.stats.con.consess{15}.tcon.weights = [0 1 0 -1];
matlabbatch{3}.spm.stats.con.consess{15}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{16}.tcon.name = 'N0(B1-O)';
matlabbatch{3}.spm.stats.con.consess{16}.tcon.weights = [1 0 0 -1];
matlabbatch{3}.spm.stats.con.consess{16}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{17}.tcon.name = 'N2(B3-B1)';
matlabbatch{3}.spm.stats.con.consess{17}.tcon.weights = [0 0 0 0 0 -1 0 1];
matlabbatch{3}.spm.stats.con.consess{17}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{18}.tcon.name = 'N2(B3-B2)';
matlabbatch{3}.spm.stats.con.consess{18}.tcon.weights = [0 0 0 0 0 0 -1 1];
matlabbatch{3}.spm.stats.con.consess{18}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{19}.tcon.name = 'N2(B2-B1)';
matlabbatch{3}.spm.stats.con.consess{19}.tcon.weights = [0 0 0 0 0 -1 1];
matlabbatch{3}.spm.stats.con.consess{19}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{20}.tcon.name = 'N2(B3-O)';
matlabbatch{3}.spm.stats.con.consess{20}.tcon.weights = [0 0 0 0 0 0 0 1 -1];
matlabbatch{3}.spm.stats.con.consess{20}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{21}.tcon.name = 'N2(B2-O)';
matlabbatch{3}.spm.stats.con.consess{21}.tcon.weights = [0 0 0 0 0 0 1 0 -1];
matlabbatch{3}.spm.stats.con.consess{21}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{22}.tcon.name = 'N2(B1-O)';
matlabbatch{3}.spm.stats.con.consess{22}.tcon.weights = [0 0 0 0 0 1 0 0 -1];
matlabbatch{3}.spm.stats.con.consess{22}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{23}.tcon.name = '(N2-N0)B1';
matlabbatch{3}.spm.stats.con.consess{23}.tcon.weights = [-1 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{23}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{24}.tcon.name = '(N2-N0)B2';
matlabbatch{3}.spm.stats.con.consess{24}.tcon.weights = [0 -1 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{24}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{25}.tcon.name = '(N2-N0)B3';
matlabbatch{3}.spm.stats.con.consess{25}.tcon.weights = [0 0 -1 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{25}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{26}.tcon.name = '(N2-N0)O';
matlabbatch{3}.spm.stats.con.consess{26}.tcon.weights = [0 0 0 -1 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{26}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{27}.tcon.name = '(N2-N0)D';
matlabbatch{3}.spm.stats.con.consess{27}.tcon.weights = [0 0 0 0 -1 0 0 0 0 1];
matlabbatch{3}.spm.stats.con.consess{27}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{28}.tcon.name = '(N2-N0)B3-(N2-N0)B1';
matlabbatch{3}.spm.stats.con.consess{28}.tcon.weights = [1 0 -1 0 0 -1 0 1];
matlabbatch{3}.spm.stats.con.consess{28}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{29}.tcon.name = '(N2-N0)B3-(N2-N0)B2';
matlabbatch{3}.spm.stats.con.consess{29}.tcon.weights = [0 1 -1 0 0 0 -1 1];
matlabbatch{3}.spm.stats.con.consess{29}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{30}.tcon.name = '(N2-N0)B2-(N2-N0)B1';
matlabbatch{3}.spm.stats.con.consess{30}.tcon.weights = [1 -1 0 0 0 -1 1 0];
matlabbatch{3}.spm.stats.con.consess{30}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{31}.tcon.name = '(N2-N0)B3-(N2-N0)O';
matlabbatch{3}.spm.stats.con.consess{31}.tcon.weights = [0 0 -1 1 0 0 0 1 -1];
matlabbatch{3}.spm.stats.con.consess{31}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{32}.tcon.name = '(N2-N0)B2-(N2-N0)O';
matlabbatch{3}.spm.stats.con.consess{32}.tcon.weights = [0 -1 0 1 0 0 1 0 -1];
matlabbatch{3}.spm.stats.con.consess{32}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{33}.tcon.name = '(N2-N0)B1-(N2-N0)O';
matlabbatch{3}.spm.stats.con.consess{33}.tcon.weights = [-1 0 0 1 0 1 0 0 -1];
matlabbatch{3}.spm.stats.con.consess{33}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{34}.tcon.name = 'N2';
matlabbatch{3}.spm.stats.con.consess{34}.tcon.weights = [0 0 0 0 0 1 1 1 1 1];
matlabbatch{3}.spm.stats.con.consess{34}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{35}.tcon.name = 'N0';
matlabbatch{3}.spm.stats.con.consess{35}.tcon.weights = [1 1 1 1 1];
matlabbatch{3}.spm.stats.con.consess{35}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
matlabbatch{3}.spm.stats.con.consess{36}.tcon.name = 'N2-N0';
matlabbatch{3}.spm.stats.con.consess{36}.tcon.weights = [-1 -1 -1 -1 -1 1 1 1 1 1];
matlabbatch{3}.spm.stats.con.consess{36}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
if pupille==1
matlabbatch{3}.spm.stats.con.consess{37}.tcon.name = 'pupil_reg' ;
matlabbatch{3}.spm.stats.con.consess{37}.tcon.weights = [zeros(1,16) 1];
matlabbatch{3}.spm.stats.con.consess{37}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spm_jobman('run', matlabbatch) % run batch
end
%%
% Coregistration of statistical maps to the template ans MNI spaces.
input1= paths.ANTs ;
input2= char([paths.data '/' char(subs_info(id)) '/MRI' '/output_preprocessing' '/nback']) ;
input3= char([paths.data '/sub-' subject_ID '/ses-struct/MRI/output_preprocessing/mp2rage_UNI']);
input4= paths.template;
input5= output_nback ;
PathToScript= [paths.bash '/Coreg_Stat.sh'];
cmdStr=[PathToScript ' ' input1 ' ' input2 ' ' input3 ' ' input4 ' ' input5];
system(cmdStr)
end
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment