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

Upload New File

parent 6046db44
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
% for LM v05
function emo_1stlevel_v05(subs_info,paths,mod,pupille,overwrite)
for id = 1:length(subs_info)
%this part of the code search for the preprocessed functional files (emo 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: ' char(subs_info(id))] ;
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 : emo)')
emo_folder = char([paths.data '/' char(subs_info(id)) '/MRI' '/output_preprocessing' '/emo']) ;
%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 = emo_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_emo_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_5Con_Sept']) ;%we save that path to create an output folder
if mod == 0
onsets_emo = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'onsets_emo_nomod_Mel_6Con_*')) ;
output_emo = char([output '/emo_nomod']) ;
elseif mod == 1
onsets_emo = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'onsets_emo_lightmod_Mel_Dark_*')) ;
output_emo = char([output '/emo_lightmod']) ;
elseif mod == 2
onsets_emo = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'onsets_emo_timemod_Mel_HILIGHT_*')) ;
output_emo = char([output '/emo_timemod']) ;
elseif mod == 3
onsets_emo = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'onsets_emo_pupilmod_Mel_HILIGHT_*')) ;
output_emo = char([output '/emo_pupilmod']) ;
end
onset_emo = char([onsets_emo.folder '/' onsets_emo.name]) ;
if pupille == 0
pupil_emo = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'REGRESSOR_Motion_Physio_noPUPIL_emo_HILIGHT_*')) ;
output_emo = char(strcat(output_emo,'_NoPUPIL')) ;
elseif pupille == 1
pupil_emo = dir(fullfile(char([paths.data '/' char(subs_info(id)) '/LM/']), 'REGRESSOR_Motion_Physio_PUPIL_emo_HILIGHT_*')) ;
output_emo = char(strcat(output_emo,'_PUPIL')) ;
end
pupil_emo = char([pupil_emo.folder '/' pupil_emo.name]) ;
if ~exist(output)
mkdir(output)
mkdir(output_emo)
elseif ~exist(output_emo)
mkdir(output_emo)
end
if ~isempty(dir(output_emo)) && 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 %nomod
clear matlabbatch
spm_jobman('initcfg') ;
matlabbatch{1}.spm.stats.fmri_spec.dir = {output_emo};
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_emo} ;
matlabbatch{1}.spm.stats.fmri_spec.sess.regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess.multi_reg = {pupil_emo};
matlabbatch{1}.spm.stats.fmri_spec.sess.hpf = 256;
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 = 'Emo_B1';
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 = 'Emo_B2';
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 = 'Emo_B3';
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 = 'Emo_O';
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 = 'Emo_D';
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 = 'Neut_B1';
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 = 'Neut_B2';
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 = 'Neut_B3';
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 = 'Neut_O';
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 = 'Neut_D';
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 = 'Emo_B1-Neut_B1';
% matlabbatch{3}.spm.stats.con.consess{11}.tcon.weights = [1 0 0 0 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 = 'Emo_B1-Neut_B2';
% matlabbatch{3}.spm.stats.con.consess{12}.tcon.weights = [1 0 0 0 0 0 -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 = 'Emo_B1-Neut_B3';
% matlabbatch{3}.spm.stats.con.consess{13}.tcon.weights = [1 0 0 0 0 0 0 -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 = 'Emo_B1-Neut_O';
% matlabbatch{3}.spm.stats.con.consess{14}.tcon.weights = [1 0 0 0 0 0 0 0 -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 = 'Emo_B1-Neut_D';
% matlabbatch{3}.spm.stats.con.consess{15}.tcon.weights = [1 0 0 0 0 0 0 0 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 = 'Emo_B2-Neut_B1';
% matlabbatch{3}.spm.stats.con.consess{16}.tcon.weights = [0 1 0 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 = 'Emo_B2-Neut_B2';
% matlabbatch{3}.spm.stats.con.consess{17}.tcon.weights = [0 1 0 0 0 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 = 'Emo_B2-Neut_B3';
% matlabbatch{3}.spm.stats.con.consess{18}.tcon.weights = [0 1 0 0 0 0 0 -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 = 'Emo_B2-Neut_O';
% matlabbatch{3}.spm.stats.con.consess{19}.tcon.weights = [0 1 0 0 0 0 0 0 -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 = 'Emo_B2-Neut_D';
% matlabbatch{3}.spm.stats.con.consess{20}.tcon.weights = [0 1 0 0 0 0 0 0 0 -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 = 'Emo_B3-Neut_B1';
% matlabbatch{3}.spm.stats.con.consess{21}.tcon.weights = [0 0 1 0 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 = 'Emo_B3-Neut_B2';
% matlabbatch{3}.spm.stats.con.consess{22}.tcon.weights = [0 0 1 0 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 = 'Emo_B3-Neut_B3';
% matlabbatch{3}.spm.stats.con.consess{23}.tcon.weights = [0 0 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 = 'Emo_B3-Neut_O';
% matlabbatch{3}.spm.stats.con.consess{24}.tcon.weights = [0 0 1 0 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 = 'Emo_B3-Neut_D';
% matlabbatch{3}.spm.stats.con.consess{25}.tcon.weights = [0 0 1 0 0 0 0 0 0 -1];
% matlabbatch{3}.spm.stats.con.consess{25}.tcon.sessrep = 'none';
% matlabbatch{3}.spm.stats.con.delete = 1;
if pupille==1
matlabbatch{3}.spm.stats.con.consess{26}.tcon.name = 'pupil_reg' ;
matlabbatch{3}.spm.stats.con.consess{26}.tcon.weights = [zeros(1,14) 1];
matlabbatch{3}.spm.stats.con.consess{26}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
spm_jobman('run', matlabbatch) % run batch
elseif mod==1 % Lightmod
clear matlabbatch
spm_jobman('initcfg') ;
matlabbatch{1}.spm.stats.fmri_spec.dir = {output_emo};
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_emo} ;
matlabbatch{1}.spm.stats.fmri_spec.sess.regress = struct('name', {}, 'val', {});
matlabbatch{1}.spm.stats.fmri_spec.sess.multi_reg = {pupil_emo};
matlabbatch{1}.spm.stats.fmri_spec.sess.hpf = 256;
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 = 'Emo';
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 = 'Neut';
matlabbatch{3}.spm.stats.con.consess{2}.tcon.weights = [0 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 = 'Emo_M';
matlabbatch{3}.spm.stats.con.consess{3}.tcon.weights = [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 = 'Neut_M';
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 = 'Emo-Neut';
matlabbatch{3}.spm.stats.con.consess{5}.tcon.weights = [1 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 = 'Emo_M-Neut_M';
matlabbatch{3}.spm.stats.con.consess{6}.tcon.weights = [0 1 0 -1];
matlabbatch{3}.spm.stats.con.consess{6}.tcon.sessrep = 'none';
matlabbatch{3}.spm.stats.con.delete = 1;
if pupille==1
matlabbatch{3}.spm.stats.con.consess{7}.tcon.name = 'pupil_reg' ;
matlabbatch{3}.spm.stats.con.consess{7}.tcon.weights = [zeros(1,14) 1];
matlabbatch{3}.spm.stats.con.consess{7}.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' '/emo']) ;
input3= char([paths.data '/sub-' subject_ID '/ses-struct/MRI/output_preprocessing/mp2rage_UNI']);
input4= paths.template;
input5= output_emo ;
PathToScript= [paths.bash '/Coreg_Stat.sh'];
cmdStr=[PathToScript ' ' input1 ' ' input2 ' ' input3 ' ' input4 ' ' input5];
system(cmdStr)
end
end
\ No newline at end of file
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