Home > fmri > utils > batch_shuffle_check.m

batch_shuffle_check

PURPOSE ^

batch_shuffle_check(dataroot, sinfo)

SYNOPSIS ^

function data = batch_shuffle_check(dataroot, sinfo, outfstub, epidir)

DESCRIPTION ^

 batch_shuffle_check(dataroot, sinfo)

 Performs slice-shuffle checking for all subjects specified in sinfo.

 For each functional run, the script goes through all volumes slice by slice
 and creates a color image in which the columns represent time and the rows
 represent slices. The color of each slice at each time point relects the
 summed image intensity for that slice.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function data = batch_shuffle_check(dataroot, sinfo, outfstub, epidir)
0002 % batch_shuffle_check(dataroot, sinfo)
0003 %
0004 % Performs slice-shuffle checking for all subjects specified in sinfo.
0005 %
0006 % For each functional run, the script goes through all volumes slice by slice
0007 % and creates a color image in which the columns represent time and the rows
0008 % represent slices. The color of each slice at each time point relects the
0009 % summed image intensity for that slice.
0010 
0011 % Input:
0012 %   dataroot -- directory in which all subject directories live
0013 
0014 %   sinfo -- a structure array in which each element contains information about
0015 %            the subject. Required fields are:
0016 %     .id -- the subject string, e.g. 'sub01', which is the name of the
0017 %            directory in which the subject's data live.
0018 %     .use_runs -- a list of EPI runs to analyze
0019 %
0020 %   outfstub -- the root name of the file into which the images will be
0021 %               written.  Assuming that ps2pdf works, a PDF file is created
0022 %               that contains the data for all subjects.
0023 %
0024 %   epidir -- the name of the subdirectory within subject directories that the
0025 %             data exist in.  Default is 'epi'.  It is assumed that individual
0026 %             run directories are called run? where ? is the run number.
0027 %
0028 % Output:
0029 %   data -- the actual data
0030 
0031 % 09/27/03 Petr Janata
0032 
0033 if nargin < 4
0034   epidir = 'epi';
0035 end
0036 
0037 if nargin < 3
0038   outfstub = 'shuffle_check';
0039 end
0040 
0041 PRINT_TO_FILE = 1;
0042 
0043 proc_sub = 1:length(sinfo);
0044 nsub = length(proc_sub);
0045 
0046 for isub = 1:nsub
0047   sub_idx = proc_sub(isub);
0048   
0049   runs = sinfo(sub_idx).use_runs;
0050   nruns = length(runs);
0051 
0052   figure(1), clf
0053   
0054   for irun = 1:nruns
0055     run_idx = runs(irun);
0056     epi_dir = fullfile(dataroot,sinfo(sub_idx).id,epidir,sprintf('run%d', run_idx));
0057     P = spm_get('Files',epi_dir,'*.img');
0058     nvol = length(P);
0059   
0060     % Get the number of slices from the first volume
0061     V = spm_vol(deblank(P(1,:)));
0062     nslice = V.dim(3);
0063     
0064     data{sub_idx,irun} = zeros(nslice,nvol);
0065     for ivol = 1:nvol
0066       fprintf('Subject: %s, Run %d, Vol %d\n', sinfo(sub_idx).id,run_idx, ivol)
0067       V = spm_vol(deblank(P(ivol,:)));
0068       for islice = 1:nslice
0069     tmp = spm_slice_vol(V,spm_matrix([0 0 islice]),V.dim(1:2),0);
0070     data{sub_idx,irun}(islice,ivol) = sum(tmp(:));
0071       end % for islice=
0072     end % for ivol=
0073     
0074     subplot(nruns,1,irun);
0075     imagesc(data{sub_idx,irun})
0076     set(gca,'xtick',[0:10:nvol],'xticklabel','')
0077     
0078     tick_locs = get(gca,'xtick');
0079     use_ticks = 1:5:length(tick_locs);
0080     for itick = 1:length(use_ticks)
0081       tick_val = tick_locs(use_ticks(itick));
0082       text(tick_val,nslice+1,num2str(tick_val),'rotation',-90)
0083     end
0084     
0085     grid
0086     title(sprintf('Subject: %s, Run %d', sinfo(sub_idx).id,run_idx))
0087     
0088   end % for irun=
0089 
0090   if PRINT_TO_FILE
0091     if isub ~= 1
0092       append_str = '-append';
0093     else
0094       append_str = '';
0095     end
0096     print('-dpsc',append_str,sprintf('%s.ps',outfstub))
0097   end
0098 end % for isub =
0099 
0100 if PRINT_TO_FILE
0101   unix_str = sprintf('ps2pdf %s.ps %s.pdf', outfstub,outfstub);
0102   unix(unix_str);
0103 end

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003