From: Xenia H. <sa...@us...> - 2005-08-08 02:08:25
|
Update of /cvsroot/x-batch/x_batch In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4344 Modified Files: x_run_protocol.m Log Message: Save information about processed session ONLY if processing succeeded. Index: x_run_protocol.m =================================================================== RCS file: /cvsroot/x-batch/x_batch/x_run_protocol.m,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** x_run_protocol.m 10 Feb 2005 05:32:04 -0000 1.5 --- x_run_protocol.m 8 Aug 2005 02:08:16 -0000 1.6 *************** *** 1,381 **** ! function varargout = x_run_protocol(varargin) ! % X_RUN_PROTOCOL is a gateway to starting actual batch processing with a chosen protocol. ! % it allows the user to specify file locations for particular subject(s) ! % use the 'new subject' button to create a new subject entry in the database (for Protege database) ! % use 'run' button to start the batch processing session ! global defaults; ! global version_number; ! global global_params; ! global spm_results_dir; ! global display_graphix; ! global log_file_fid; ! constants; ! ! if nargin == 0 % LAUNCH GUI ! SPMid = spm('FnBanner',mfilename, version_number); ! fig = openfig(mfilename,'reuse'); ! % Use system color scheme for figure: ! set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); ! % Generate a structure of handles to pass to callbacks, and store it. ! handles = guihandles(fig); ! guidata(fig, handles); ! if nargout > 0 ! varargout{1} = fig ! end ! version_number = '2.2 - beta'; ! elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK ! try ! [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard ! catch ! disp(lasterr); ! end ! ! end ! ! % -------------------------------------------------------------------- ! function varargout = new_patient_Callback(h, eventdata, handles, varargin) ! % create a new patient in the Protege database. A new patient is only ! % identified by his/her subject id, which MUST be unique ! constants; ! subject_id = spm_input('subject_id', '+1', 's', 'X2003'); ! ids = x_get_instances_ids('Subject', SUBJECT); ! % make sure subject ids are unique ! unique = 0; ! while(~unique) ! check_again = 0; ! for i = 1:size(ids,2) ! if strcmpi(subject_id, ids(i)) ! spm_input(['Subject with the id ' subject_id ' already exists!'], 1,'bd','OK') ! subject_id = spm_input('subject_id', '+1', 's', 'X2003'); ! check_again = 1; ! end; ! end; ! if (~check_again) unique = 1; end; ! end; ! spm_protege_interface('new subject', subject_id); ! closereq; ! ! %########################### ! %TODO: print errors if any ! %########################### ! % -------------------------------------------------------------------- ! function varargout = choose_patient_Callback(h, eventdata, handles, varargin) ! % Stub for Callback of the uicontrol handles.choose. ! global subject_id; ! constants; ! val = get(handles.choose_patient, 'Value'); ! subject_ids = x_get_instances_ids('Subject', SUBJECT); ! subject_id = subject_ids(val); ! ! % -------------------------------------------------------------------- ! function varargout = execute_Callback(h, eventdata, handles, varargin) ! % Stub for Callback of the uicontrol handles.pushbutton12. ! global global_params; ! global spm_results_dir; ! global log_file_fid; ! constants; ! ! num_subj = spm_input('Num subjects', 1, 'e', 1); ! ! for i = 1:num_subj ! subjects(i) = struct('subject_id', [], ... ! 'subject_num', [], ... % this is just to display 'processing subject number X' message ! 'struct_imgs', [], ... % note that I assume that there is essentially ONE struct per subject 'struct_dir', '', ... ! 'weight_image', [], ... ! 'root_dir', [], ... ! 'sessions', []); ! end ! ! for i = 1:num_subj, ! % subjects(i) = struct('subject_id', [], ... ! % 'subject_num', [], ... % this is just to display 'processing subject number X' message ! % 'struct_imgs', [], ... % note that I assume that there is essentially ONE struct per subject 'struct_dir', '', ... ! % 'weight_image', [], ... ! % 'root_dir', [], ... ! % 'sessions', []) %semicolon ! % subjects ! % collect subject-specific info ! % get a subject_id ! ! subject_ids = sort(x_get_instances_ids('Subject', SUBJECT, ['Please choose a subject #' i])); ! subjects(i).subject_id = spm_input(['Please choose subject # ' num2str(i)], '2','m',subject_ids, subject_ids); ! subjects(i).subject_num = i; ! spm_input(['Subject ' num2str(i) ': ' subjects(i).subject_id{1}], 3 ,'d'); ! ! % collect info about the structural images, which are SAME for all ! % sessions ! subjects(i).root_dir = spm_get(-1, '',['Indicate the root directory for this subject']); ! % the normalisation may be performed on either struct or func ! % images. Here, we determine what images it is performed on, so ! % that we do not ask the user unneccessary question ! norm_struct = 0; ! if(~isempty(global_params.normalise_params)) ! norm_struct = global_params.normalise_params.normalise_struct; ! % if global_params.normalise_params.option == 2 ! % global_params.normalise_params.file_to_write_from = spm_get(1, norm_file_extention, ['Parameters to write']); ! % end; ! end; ! if ~(isempty(global_params.coreg_params) & isempty(global_params.segment_params) & ~norm_struct) ! subjects(i).struct_imgs = spm_get(Inf, 'IMAGE', ['Choose the structural image for this subject']); ! end; ! ! if(~isempty(subjects(i).struct_imgs)) ! [dir, name, ext] = fileparts(subjects(i).struct_imgs(1, :)); ! subjects(i).struct_dir = dir; ! end; ! ! % if the images are weighted, ask for weight images ! % TODO: now, are weight images session-specific or ! % patient-specific? Are the 'other' images sessions speciic ! % or subjct-specific ! if (~isempty(global_params.realign_params) & (global_params.realign_params.weight_option)) ! subjects(i).weight_image = spm_get(1, 'IMAGE', 'Weight image for the this session'); ! end; ! ! % collect info about all sessions ! num_sessions = 1; ! if ~isempty(global_params.analysis_params) ! % do a little directory switcheroo to insure against ! % MATLAB path problems ! my_dir = pwd; ! x_batch_dir = fullfile(spm('dir'), 'toolbox', 'x_batch'); ! cd(x_batch_dir); ! nscan = x_deal_SPM_mat('nscan'); ! cd(my_dir); ! num_sessions = length(nscan); ! spm_input([' ' ,num2str(num_sessions), ' sessions are defined in analysis: ', ],'+1','d'); ! else ! num_sessions = spm_input('How many sessions?', '+1', 'e', 1); ! end ! ! for s = 1:num_sessions ! done = 0; ! while ~done ! sessions(s) = struct('func_dir','',... ! 'num_slices', 0, ... ! 'other_dir', '', ... ! 'func_imgs','', ... ! 'other_imgs', '', ... ! 'target_image', '', ... ! 'source_image', '', ... ! 'other_image', '', ... ! 'images', [], ... ! 'results_dir' , '',... ! 'mat_file', '', ... ! 'session_num', ''); ! ! ! % I assume that there WILL be some functional images to process. ! % After all, this IS the utility for FMRI processing .... ! % this, of course, might be reconsidered later - perhaps somebody would ! % only do the norm-struct and segment ... ! sessions(s).session_num = s; ! sessions(s).func_imgs = spm_get(Inf, 'IMAGE', ['Session # ', num2str(s), ' functional images']); ! n_imgs = size(sessions(s).func_imgs,1); ! if ~isempty(global_params.analysis_params) ! while nscan(s) ~= n_imgs ! spm_input(['Number of images (' num2str(n_imgs), ') is different from number specified in analysis (', num2str(nscan(s)), ')'] ,'+1','bd','OK'); ! sessions(s).func_imgs = spm_get(Inf, 'IMAGE', ['Session # ', num2str(s), ' functional images']); ! n_imgs = size(sessions(s).func_imgs,1); ! end ! end ! sessions(s).other_image = [];%spm_get('Files', subjects(i).other_dir, '*img'); ! %subjects(i).other_dir = spm_get(Inf, '*', ['Other images directory']); ! % fill the dir info ! if(~isempty(sessions(s).func_imgs)) ! [dir, name, ext] = fileparts(sessions(s).func_imgs(1, :)); ! sessions(s).func_dir = dir; ! ! end; ! ! % TODO: hmmm - what is THAT? ! %********************* OTHER IMAGES *********************** ! %if ~isempty(subjects(i).other_imgs) ! % [dir, name, ext] = fileparts(subjects(i).other_imgs(1, :)); ! % subjects(i).struct_dir = dir; ! %end; ! ! % the following will just give the user a chance to double-check ! % the inputs, in case they mess up the images or something ... ! % note that the struct directory is SAME for all session ! if(~isempty(subjects(i).struct_dir)) ! spm_input([' Structural images in ' subjects(i).struct_dir ], '+1' ,'d'); ! end; ! if(~isempty(sessions(s).func_dir)) ! spm_input([' Functional images in ' sessions(s).func_dir ], '+1' ,'d'); ! end; ! ! if(~isempty(sessions(s).other_dir)) ! spm_input([' Other images; ' sessions(s).other_dir ], '+1' ,'d'); ! end; ! done = spm_input(['Accept subject ', num2str(i), ' session # ', num2str(s) ] , '+1', 'b','Yes| Redo',[1 , 0]); ! ! % set up the 'results' dir ! if (done) ! % note that this logic for subdir making is based on ! % assumption that a subject may have a structural image ! % and, say, 1-n sessions of functional image. NOT !!!! many ! % sessions of structural images ! results_dir_name = strcat(['results_' ,subjects(i).subject_id{1}, '_sess', num2str(s), '_', global_params.protocol_name]); ! if ~isempty(sessions(s).func_dir) ! mkdir(sessions(s).func_dir, results_dir_name); ! sessions(s).results_dir = strcat([sessions(s).func_dir, filesep, results_dir_name]); ! elseif ~isempty(subjects(i).struct_dir) & ~made_result_dir % only make one structural results directory per subject ! mkdir(sessions(s).struct_dir, results_dir_name); ! sessions(s).results_dir = strcat([sessions(s).struct_dir filesep results_dir_name]); ! made_result_dir = 1; ! end; ! % spm_results_dir = sessions(s).results_dir; ! end; ! ! end; % end while ! end; %end sessions input ! subjects(i).sessions = sessions; ! ! %TODO: get 'other images ! %subjects(i).images = subjects(i).func_imgs; %spm_get('Files', subjects(i).func_dir, '*.img') ; ! spm_protege_interface('save scan', subjects(i)); ! 'about to finish patients input' ! subjects ! end; %end patient's input ! display_graphix = spm_input(['Display graphics (progress bars, windows etc.) while processing?'] ,'+1','bd','Yes|No'); ! ! % create a log file ! str = strcat(['log_', datestr(now, 30), '.txt']); ! d = fullfile(spm('dir'), 'toolbox', 'x_batch', 'logs'); ! % TODO: have the user choose log location? ! if(exist(d) ~= 7) % if the 'logs' directory does not exist ! mkdir(fullfile(spm('dir'), 'toolbox', 'x_batch'), 'logs'); ! end ! str = fullfile(spm('dir'), 'toolbox', 'x_batch', 'logs', str); ! log_file_fid = fopen(str, 'at' ); ! %run the batch job ! for i = 1:num_subj ! fprintf(log_file_fid, strcat(['subject #', num2str(i), '\n\n'])); ! if strcmpi(display_graphix, 'No') ! % compliments of SPM mailing list ! names = {'Graphics', 'Interactive'};%, 'Menu'}; ! for n = 1:length(names) ! f = findobj('tag', names{n}); ! set(f, 'visible', 'off'); ! end; ! %%% ! end; ! try ! x_process_subject(subjects(i)); ! ! catch ! disp(['error processing subject ', subjects(i).subject_id{1}]); ! disp(lasterr); ! fprintf(log_file_fid, strcat(['Error processing subject ', subjects(i).subject_id{1}, ': ', lasterr, '\n'])); ! end ! end ! fclose(log_file_fid); ! spm_input([' DONE ' ] ,'+1','bd','OK'); ! %========================================================================== ! % --- Executes on button press in delete_button. ! function delete_button_Callback(hObject, eventdata, handles) ! % hObject handle to delete_button (see GCBO) ! % eventdata reserved - to be defined in a future version of MATLAB ! % handles structure with handles and user data (see GUIDATA) ! x_subjects_delete; ! ! %========================================================================== ! function x_process_subject(subject) ! % X_PROCESS_SUBJECT executes stages specified in the protocol in correct order ! % then moves the files into separate directories ! global defaults; ! global global_params; ! global subject_id; ! global kb; ! global images; ! global log_file_fid; ! import java.util.*; ! spm_defaults; ! constants; ! ! %TODO: check if there is anything to process ! %if isempty(subject.images) ! % disp('no images to process'); ! % return; ! %end ! ! params_cell = cell(7, 1); ! if(~isempty(global_params.coreg_params)) ! params_cell(global_params.coreg_params.order) = {COREG}; ! end ! if(~isempty(global_params.realign_params)) ! params_cell(global_params.realign_params.order) = {REALIGN}; ! end ! if(~isempty(global_params.normalise_params)) ! params_cell(global_params.normalise_params.order) = {NORMALIZE}; ! end ! if(~isempty(global_params.smooth_params)) ! params_cell(global_params.smooth_params.order) = {SMOOTH}; ! end ! if(~isempty(global_params.slice_timing_params)) ! params_cell(global_params.slice_timing_params.order) = {SLICE_TIME}; ! end ! if(~isempty(global_params.segment_params)) ! params_cell(global_params.segment_params.order) = {SEGMENT}; ! end ! % assumption: analysis is ALWAYS after preprocessing ! if(~isempty(global_params.analysis_params)) ! params_cell(7) = {ANALYSIS}; ! end ! ! %images = subject.images; ! ! % TODO: note that the following will only work with MATLAB 6.5 or higher ! ps_file = spm_get('files', pwd, 'spm2.ps'); ! if ~isempty(ps_file) ! movefile(ps_file, 'spm2_old.ps'); ! end ! ! clear ps_file; ! ! for i = 1:size(params_cell,1) ! if ~isempty(params_cell{i}) ! try ! subject = x_process_stage(params_cell{i}, subject); ! fprintf(log_file_fid, '\n completed successfully \n'); ! catch ! fprintf(log_file_fid, ['failed: ', lasterr, '\n']); ! disp(lasterr); ! end ! end ! end ! %############################################## ! %TODO: Make sure that moving is only accomplished when the processing was more or less successful ! %########################################################################### ! %========================================================================== ! function execute_stage( Tag, subject ) ! global defaults; ! spm_defaults; ! global global_params; ! global images; ! ! %skip stages which are not filled ! if isempty(Tag) ! return; ! end; ! ! % switch on the parameters' type ! switch(char(Tag)) ! case COREG ! subject = x_coreg_batch( subject, global_params.coreg_params ); ! case REALIGN ! subject = x_realign_batch( subject, global_params.realign_params ) ; ! case NORMALIZE ! subject = x_norm_batch( subject, global_params.normalise_params ); ! case SMOOTH ! subject = x_smooth_batch(subject, global_params.smooth_params) ! case SEGMENT ! subject = x_segment_batch(subject, global_params.segment_params); ! case SLICE_TIME ! subject = x_slice_timing_batch(subject, global_params.slice_timing_params ); ! case ANALYSIS ! subject = x_analysis_batch(subject, global_params.analysis_params); ! otherwise ! disp('no such stage. yet') end \ No newline at end of file --- 1,380 ---- ! function varargout = x_run_protocol(varargin) ! % X_RUN_PROTOCOL is a gateway to starting actual batch processing with a chosen protocol. ! % it allows the user to specify file locations for particular subject(s) ! % use the 'new subject' button to create a new subject entry in the database (for Protege database) ! % use 'run' button to start the batch processing session ! global defaults; ! global version_number; ! global global_params; ! global spm_results_dir; ! global display_graphix; ! global log_file_fid; ! constants; ! ! if nargin == 0 % LAUNCH GUI ! SPMid = spm('FnBanner',mfilename, version_number); ! fig = openfig(mfilename,'reuse'); ! % Use system color scheme for figure: ! set(fig,'Color',get(0,'defaultUicontrolBackgroundColor')); ! % Generate a structure of handles to pass to callbacks, and store it. ! handles = guihandles(fig); ! guidata(fig, handles); ! if nargout > 0 ! varargout{1} = fig ! end ! version_number = '2.2 - beta'; ! elseif ischar(varargin{1}) % INVOKE NAMED SUBFUNCTION OR CALLBACK ! try ! [varargout{1:nargout}] = feval(varargin{:}); % FEVAL switchyard ! catch ! disp(lasterr); ! end ! ! end ! ! % -------------------------------------------------------------------- ! function varargout = new_patient_Callback(h, eventdata, handles, varargin) ! % create a new patient in the Protege database. A new patient is only ! % identified by his/her subject id, which MUST be unique ! constants; ! subject_id = spm_input('subject_id', '+1', 's', 'X2003'); ! ids = x_get_instances_ids('Subject', SUBJECT); ! % make sure subject ids are unique ! unique = 0; ! while(~unique) ! check_again = 0; ! for i = 1:size(ids,2) ! if strcmpi(subject_id, ids(i)) ! spm_input(['Subject with the id ' subject_id ' already exists!'], 1,'bd','OK') ! subject_id = spm_input('subject_id', '+1', 's', 'X2003'); ! check_again = 1; ! end; ! end; ! if (~check_again) unique = 1; end; ! end; ! spm_protege_interface('new subject', subject_id); ! closereq; ! ! %########################### ! %TODO: print errors if any ! %########################### ! % -------------------------------------------------------------------- ! function varargout = choose_patient_Callback(h, eventdata, handles, varargin) ! % Stub for Callback of the uicontrol handles.choose. ! global subject_id; ! constants; ! val = get(handles.choose_patient, 'Value'); ! subject_ids = x_get_instances_ids('Subject', SUBJECT); ! subject_id = subject_ids(val); ! ! % -------------------------------------------------------------------- ! function varargout = execute_Callback(h, eventdata, handles, varargin) ! % Stub for Callback of the uicontrol handles.pushbutton12. ! global global_params; ! global spm_results_dir; ! global log_file_fid; ! constants; ! ! num_subj = spm_input('Num subjects', 1, 'e', 1); ! ! for i = 1:num_subj ! subjects(i) = struct('subject_id', [], ... ! 'subject_num', [], ... % this is just to display 'processing subject number X' message ! 'struct_imgs', [], ... % note that I assume that there is essentially ONE struct per subject 'struct_dir', '', ... ! 'weight_image', [], ... ! 'root_dir', [], ... ! 'sessions', []); ! end ! ! for i = 1:num_subj, ! % subjects(i) = struct('subject_id', [], ... ! % 'subject_num', [], ... % this is just to display 'processing subject number X' message ! % 'struct_imgs', [], ... % note that I assume that there is essentially ONE struct per subject 'struct_dir', '', ... ! % 'weight_image', [], ... ! % 'root_dir', [], ... ! % 'sessions', []) %semicolon ! % subjects ! % collect subject-specific info ! % get a subject_id ! ! subject_ids = sort(x_get_instances_ids('Subject', SUBJECT, ['Please choose a subject #' i])); ! subjects(i).subject_id = spm_input(['Please choose subject # ' num2str(i)], '2','m',subject_ids, subject_ids); ! subjects(i).subject_num = i; ! spm_input(['Subject ' num2str(i) ': ' subjects(i).subject_id{1}], 3 ,'d'); ! ! % collect info about the structural images, which are SAME for all ! % sessions ! subjects(i).root_dir = spm_get(-1, '',['Indicate the root directory for this subject']); ! % the normalisation may be performed on either struct or func ! % images. Here, we determine what images it is performed on, so ! % that we do not ask the user unneccessary question ! norm_struct = 0; ! if(~isempty(global_params.normalise_params)) ! norm_struct = global_params.normalise_params.normalise_struct; ! % if global_params.normalise_params.option == 2 ! % global_params.normalise_params.file_to_write_from = spm_get(1, norm_file_extention, ['Parameters to write']); ! % end; ! end; ! if ~(isempty(global_params.coreg_params) & isempty(global_params.segment_params) & ~norm_struct) ! subjects(i).struct_imgs = spm_get(Inf, 'IMAGE', ['Choose the structural image for this subject']); ! end; ! ! if(~isempty(subjects(i).struct_imgs)) ! [dir, name, ext] = fileparts(subjects(i).struct_imgs(1, :)); ! subjects(i).struct_dir = dir; ! end; ! ! % if the images are weighted, ask for weight images ! % TODO: now, are weight images session-specific or ! % patient-specific? Are the 'other' images sessions speciic ! % or subjct-specific ! if (~isempty(global_params.realign_params) & (global_params.realign_params.weight_option)) ! subjects(i).weight_image = spm_get(1, 'IMAGE', 'Weight image for the this session'); ! end; ! ! % collect info about all sessions ! num_sessions = 1; ! if ~isempty(global_params.analysis_params) ! % do a little directory switcheroo to insure against ! % MATLAB path problems ! my_dir = pwd; ! x_batch_dir = fullfile(spm('dir'), 'toolbox', 'x_batch'); ! cd(x_batch_dir); ! nscan = x_deal_SPM_mat('nscan'); ! cd(my_dir); ! num_sessions = length(nscan); ! spm_input([' ' ,num2str(num_sessions), ' sessions are defined in analysis: ', ],'+1','d'); ! else ! num_sessions = spm_input('How many sessions?', '+1', 'e', 1); ! end ! ! for s = 1:num_sessions ! done = 0; ! while ~done ! sessions(s) = struct('func_dir','',... ! 'num_slices', 0, ... ! 'other_dir', '', ... ! 'func_imgs','', ... ! 'other_imgs', '', ... ! 'target_image', '', ... ! 'source_image', '', ... ! 'other_image', '', ... ! 'images', [], ... ! 'results_dir' , '',... ! 'mat_file', '', ... ! 'session_num', ''); ! ! ! % I assume that there WILL be some functional images to process. ! % After all, this IS the utility for FMRI processing .... ! % this, of course, might be reconsidered later - perhaps somebody would ! % only do the norm-struct and segment ... ! sessions(s).session_num = s; ! sessions(s).func_imgs = spm_get(Inf, 'IMAGE', ['Session # ', num2str(s), ' functional images']); ! n_imgs = size(sessions(s).func_imgs,1); ! if ~isempty(global_params.analysis_params) ! while nscan(s) ~= n_imgs ! spm_input(['Number of images (' num2str(n_imgs), ') is different from number specified in analysis (', num2str(nscan(s)), ')'] ,'+1','bd','OK'); ! sessions(s).func_imgs = spm_get(Inf, 'IMAGE', ['Session # ', num2str(s), ' functional images']); ! n_imgs = size(sessions(s).func_imgs,1); ! end ! end ! sessions(s).other_image = [];%spm_get('Files', subjects(i).other_dir, '*img'); ! %subjects(i).other_dir = spm_get(Inf, '*', ['Other images directory']); ! % fill the dir info ! if(~isempty(sessions(s).func_imgs)) ! [dir, name, ext] = fileparts(sessions(s).func_imgs(1, :)); ! sessions(s).func_dir = dir; ! ! end; ! ! % TODO: hmmm - what is THAT? ! %********************* OTHER IMAGES *********************** ! %if ~isempty(subjects(i).other_imgs) ! % [dir, name, ext] = fileparts(subjects(i).other_imgs(1, :)); ! % subjects(i).struct_dir = dir; ! %end; ! ! % the following will just give the user a chance to double-check ! % the inputs, in case they mess up the images or something ... ! % note that the struct directory is SAME for all session ! if(~isempty(subjects(i).struct_dir)) ! spm_input([' Structural images in ' subjects(i).struct_dir ], '+1' ,'d'); ! end; ! if(~isempty(sessions(s).func_dir)) ! spm_input([' Functional images in ' sessions(s).func_dir ], '+1' ,'d'); ! end; ! ! if(~isempty(sessions(s).other_dir)) ! spm_input([' Other images; ' sessions(s).other_dir ], '+1' ,'d'); ! end; ! done = spm_input(['Accept subject ', num2str(i), ' session # ', num2str(s) ] , '+1', 'b','Yes| Redo',[1 , 0]); ! ! % set up the 'results' dir ! if (done) ! % note that this logic for subdir making is based on ! % assumption that a subject may have a structural image ! % and, say, 1-n sessions of functional image. NOT !!!! many ! % sessions of structural images ! results_dir_name = strcat(['results_' ,subjects(i).subject_id{1}, '_sess', num2str(s), '_', global_params.protocol_name]); ! if ~isempty(sessions(s).func_dir) ! mkdir(sessions(s).func_dir, results_dir_name); ! sessions(s).results_dir = strcat([sessions(s).func_dir, filesep, results_dir_name]); ! elseif ~isempty(subjects(i).struct_dir) & ~made_result_dir % only make one structural results directory per subject ! mkdir(sessions(s).struct_dir, results_dir_name); ! sessions(s).results_dir = strcat([sessions(s).struct_dir filesep results_dir_name]); ! made_result_dir = 1; ! end; ! % spm_results_dir = sessions(s).results_dir; ! end; ! ! end; % end while ! end; %end sessions input ! subjects(i).sessions = sessions; ! ! %TODO: get 'other images ! %subjects(i).images = subjects(i).func_imgs; %spm_get('Files', subjects(i).func_dir, '*.img') ; ! %spm_protege_interface('save scan', subjects(i)); ! end; %end patient's input ! display_graphix = spm_input(['Display graphics (progress bars, windows etc.) while processing?'] ,'+1','bd','Yes|No'); ! ! % create a log file ! str = strcat(['log_', datestr(now, 30), '.txt']); ! d = fullfile(spm('dir'), 'toolbox', 'x_batch', 'logs'); ! % TODO: have the user choose log location? ! if(exist(d) ~= 7) % if the 'logs' directory does not exist ! mkdir(fullfile(spm('dir'), 'toolbox', 'x_batch'), 'logs'); ! end ! str = fullfile(spm('dir'), 'toolbox', 'x_batch', 'logs', str); ! log_file_fid = fopen(str, 'at' ); ! %run the batch job ! for i = 1:num_subj ! fprintf(log_file_fid, strcat(['subject #', num2str(i), '\n\n'])); ! if strcmpi(display_graphix, 'No') ! % compliments of SPM mailing list ! names = {'Graphics', 'Interactive'};%, 'Menu'}; ! for n = 1:length(names) ! f = findobj('tag', names{n}); ! set(f, 'visible', 'off'); ! end; ! %%% ! end; ! try ! x_process_subject(subjects(i)); ! spm_protege_interface('save scan', subjects(i)); ! ! catch ! disp(['error processing subject ', subjects(i).subject_id{1}]); ! disp(lasterr); ! fprintf(log_file_fid, strcat(['Error processing subject ', subjects(i).subject_id{1}, ': ', lasterr, '\n'])); ! end ! end ! fclose(log_file_fid); ! spm_input([' DONE ' ] ,'+1','bd','OK'); ! %========================================================================== ! % --- Executes on button press in delete_button. ! function delete_button_Callback(hObject, eventdata, handles) ! % hObject handle to delete_button (see GCBO) ! % eventdata reserved - to be defined in a future version of MATLAB ! % handles structure with handles and user data (see GUIDATA) ! x_subjects_delete; ! ! %========================================================================== ! function x_process_subject(subject) ! % X_PROCESS_SUBJECT executes stages specified in the protocol in correct order ! % then moves the files into separate directories ! global defaults; ! global global_params; ! global subject_id; ! global kb; ! global images; ! global log_file_fid; ! import java.util.*; ! spm_defaults; ! constants; ! ! %TODO: check if there is anything to process ! %if isempty(subject.images) ! % disp('no images to process'); ! % return; ! %end ! ! params_cell = cell(7, 1); ! if(~isempty(global_params.coreg_params)) ! params_cell(global_params.coreg_params.order) = {COREG}; ! end ! if(~isempty(global_params.realign_params)) ! params_cell(global_params.realign_params.order) = {REALIGN}; ! end ! if(~isempty(global_params.normalise_params)) ! params_cell(global_params.normalise_params.order) = {NORMALIZE}; ! end ! if(~isempty(global_params.smooth_params)) ! params_cell(global_params.smooth_params.order) = {SMOOTH}; ! end ! if(~isempty(global_params.slice_timing_params)) ! params_cell(global_params.slice_timing_params.order) = {SLICE_TIME}; ! end ! if(~isempty(global_params.segment_params)) ! params_cell(global_params.segment_params.order) = {SEGMENT}; ! end ! % assumption: analysis is ALWAYS after preprocessing ! if(~isempty(global_params.analysis_params)) ! params_cell(7) = {ANALYSIS}; ! end ! ! %images = subject.images; ! ! % TODO: note that the following will only work with MATLAB 6.5 or higher ! ps_file = spm_get('files', pwd, 'spm2.ps'); ! if ~isempty(ps_file) ! movefile(ps_file, 'spm2_old.ps'); ! end ! ! clear ps_file; ! ! for i = 1:size(params_cell,1) ! if ~isempty(params_cell{i}) ! try ! subject = x_process_stage(params_cell{i}, subject); ! fprintf(log_file_fid, '\n completed successfully \n'); ! catch ! fprintf(log_file_fid, ['failed: ', lasterr, '\n']); ! disp(lasterr); ! end ! end ! end ! %############################################## ! %TODO: Make sure that moving is only accomplished when the processing was more or less successful ! %########################################################################### ! %========================================================================== ! function execute_stage( Tag, subject ) ! global defaults; ! spm_defaults; ! global global_params; ! global images; ! ! %skip stages which are not filled ! if isempty(Tag) ! return; ! end; ! ! % switch on the parameters' type ! switch(char(Tag)) ! case COREG ! subject = x_coreg_batch( subject, global_params.coreg_params ); ! case REALIGN ! subject = x_realign_batch( subject, global_params.realign_params ) ; ! case NORMALIZE ! subject = x_norm_batch( subject, global_params.normalise_params ); ! case SMOOTH ! subject = x_smooth_batch(subject, global_params.smooth_params) ! case SEGMENT ! subject = x_segment_batch(subject, global_params.segment_params); ! case SLICE_TIME ! subject = x_slice_timing_batch(subject, global_params.slice_timing_params ); ! case ANALYSIS ! subject = x_analysis_batch(subject, global_params.analysis_params); ! otherwise ! disp('no such stage. yet') end \ No newline at end of file |