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

Upload New File

parent 265b11dd
No related branches found
No related tags found
No related merge requests found
%% Script for coregistration of EPI to Structural/Template/MNI
% using this code we get are the followings:
% 1-
% 2-
% 3-
% --> BE CAREFUL : this code only reads "prepared" data. You need to have
% the data downloaded on your computer in the prepared format:
%..../prepared
% --> sub-008
% --> ses-evening
% --> MRI
% --> 005-b1map_sag_p2
% --> 007-cmrr_mbep2d_p3_mb2_1.4iso_VolCheck
% --> ...
% --> LM
% --> Physio
% --> ses-morning
% --> MRI
% --> 005-b1map_sag_p2
% --> 007-cmrr_mbep2d_p3_mb2_1.4iso_VolCheck
% --> ...
% --> LM
% --> Physio
% --> ses-struct
% --> MRI
% --> 005-b1map_sag_p2
% --> 007-cmrr_mbep2d_p3_mb2_1.4iso_VolCheck
% --> ...
% --> LM
% --> Physio
% --> sub-009
% Written by R. Sharifpour
% Cyclotron Research Centre, University of Liege, Belgium
% 20th November 2022
%%
function Coregistration(task,overwrite)
% default values
if nargin < 2
overwrite = 0;
end
if nargin < 1
warning('Task [1,2,3] must be specified as first input');
return;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% paths
% load file 'your_paths.txt' which contains:
% 1. path to the data
% 2. path to SPM
% 3. path to template
% 4. path to bash scripts
% 5. path to ANTs
% 6. path to edf toolbox
% 7% path to synthstrip
paths_txt = fileread('/home/islay/Documents/HILIGHT_CODES/MRI_processing/Functional_Preproc/Prepared/your_paths.txt') ; % better to use an absolute path
% split data by new lines
% the data is structured as follows:
% path to your data (example):
% corresponding path, for example: /mnt/data/Prepared
paths_txt = char(strsplit(paths_txt, '\n')) ;
% create a struct to store the paths we are interested in
paths = [];
paths.data = (strtrim(paths_txt(2,:)));
paths.spm = (strtrim(paths_txt(4,:)));
paths.template = (strtrim(paths_txt(6,:)));
paths.bash = (strtrim(paths_txt(8,:)));
paths.ANTs = (strtrim(paths_txt(10,:)));
paths.synthstrip = (strtrim(paths_txt(14,:)));
% add SPM path to matlab's search path
addpath(paths.spm)
% go to the path where the data is stored
addpath(pwd)
% go to the path where the data is stored
cd(paths.data);
% select directories of subjects for analyses
% directory has to be 'sub-0ID'
[all_subs_dir] = spm_select(Inf,'dir','Select subject directory');
%for each subject, select the session/sessions to be analyzed
all_subs_ses = [];
for ii=1:size(all_subs_dir,1)
cd (all_subs_dir(ii,:))
sub_ses = spm_select(Inf,'dir','Select subject directory');
all_subs_ses =[all_subs_ses; sub_ses];
end
all_subs_ses = string(all_subs_ses);
% extract subject ID subject session/sessions name: sub-ID/ses-
split_subs_dir = split(paths.data,filesep);
subjects_folder = char(split_subs_dir(end));
subs_info = extractAfter(all_subs_ses,[subjects_folder '/']);
T = dir(fullfile(paths.data,'HILIGHT_participants.xlsx')) ;
T = readtable(char([paths.data '/' T.name])) ;
fprintf('\n path initialization done \n')
for isub = 1:size(subs_info,1)
cd(paths.data);
subject_info = char(subs_info(isub));
subject_ID = subject_info(5:7);
switch subject_info(13)
case 'm'
subject_session = 'M';
case 'e'
subject_session = 'E';
end
entry_table = ['HILIGHT_', subject_ID '_' subject_session] ;
index = strcmp(T.subject_Ids, entry_table) ;
patient_data = T(index,:) ;
fprintf('Looking for processed functional folder (TASK : NBACK)')
% go to where all subjects' data have been saved
prep_folder = dir(char([paths.data])) ;
% look for the subject that's beeing processed
for iFile = 1:numel(prep_folder)
if(strncmpi(prep_folder(iFile).name,['sub-', subject_ID],7))
sub_folder = fullfile(char([paths.data]), prep_folder(iFile).name); % .../Prepared/sub-...
end
end
mri_folder = dir(char([sub_folder subject_info(8:end) '/MRI'])) ; % .../Prepared/sub-.../ses-.../MRI
for ii = 1:numel(mri_folder)
if (endsWith(mri_folder(ii).name,'output_preprocessing'))
switch(task)
case 1
outputfolder = fullfile(char([mri_folder(ii).folder '/output_preprocessing/nback']));
case 2
outputfolder = fullfile(char([mri_folder(ii).folder '/output_preprocessing/oddball']));
case 3
outputfolder = fullfile(char([mri_folder(ii).folder '/output_preprocessing/emo']));
otherwise
warning('Unexpected task type. No preprocessing done. Please enter a valid task type : 1 (nback), 2 (oddball) or 3 (emotional).')
end
end
end
if ~isempty(dir(outputfolder)) && overwrite == false
message = ['Output already exists and "overwrite" set to false. No preprocessing conducted for sub-', subject_ID] ;
disp(message)
continue
end
%%
% Coregistration of meanuf to the Structural,template and MNI spaces
input1= paths.ANTs;
input2= outputfolder ;
input3= [sub_folder '/ses-struct/MRI/output_preprocessing/mp2rage_UNI'];
input4= paths.template;
PathToScript= [paths.bash '/Coreg.sh']; %Corg_DCM.sh
cmdStr=[PathToScript ' ' input1 ' ' input2 ' ' input3 ' ' input4];
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