Home > fmri > utils > convert_format.m

convert_format

PURPOSE ^

convert_format(sinfo, inpath, outpath, scan_offset);

SYNOPSIS ^

function convert_format(sinfo, inpath, outpath, scan_offset)

DESCRIPTION ^

  convert_format(sinfo, inpath, outpath, scan_offset);

  Converts from GE format to Analyze format

  sinfo is the subject info structure.  See one of the get_*_sinfo.m files for format.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function convert_format(sinfo, inpath, outpath, scan_offset) 
0002 %  convert_format(sinfo, inpath, outpath, scan_offset);
0003 %
0004 %  Converts from GE format to Analyze format
0005 %
0006 %  sinfo is the subject info structure.  See one of the get_*_sinfo.m files for format.
0007 %
0008 
0009 % 06/28/00 PJ Modified to accommodate new GE_convert calling structure.
0010 %             NOTE: Incompatible with xcult and schubert scripts
0011 %
0012 % 02/12/01 PJ -- implemented volume tossing during conversion step.  The
0013 %                "starting volume" for each run will be incremented by the
0014 %                number of volumes specified in scan_offset (default = 0)
0015 %
0016 % 02/19/01 PJ -- run number assignments for functional runs increment.  This
0017 %                prevents writing of EPI data collected in different series
0018 %                into the same run numbers.
0019 %
0020 % 04/27/01 PJ Added ability to handle EPI runs distributed across multiple
0021 %             series in a single exam. To take advantage of this specification,
0022 %             the epi run numbers associated with a series must be specified in
0023 %             a 3rd column of cells in the series_mapping field of the subject
0024 %             information structure.  Otherwise, the cond_order field is used
0025 %             and assumes that all EPI runs in an exam were collected under a
0026 %             single series.
0027 % 04/27/01 PJ EPI series with single and multiple runs are now handled the same way.
0028 %
0029 % 04/29/01 PJ fixed indexing problem when grabbing number of volumes for a
0030 %             run. Needed to refer to cond_order field.
0031 % 12/04/01 PJ It turns out the s.num_vol already contains the number of volumes
0032 %             per run ordered by run (this is set in the get_exp_sinfo.m
0033 %             files), so there is no need to refer to cond_order.
0034 %
0035 % 09/04/03 PJ Added handling of double echo acquisitions in which T2 and PD
0036 %             images are interleaved
0037 %
0038 % 08/30/04 PJ Allowed skipping of directories for which there are no data
0039 
0040 nsub = length(sinfo);
0041 
0042 if nargin < 2
0043   inpath = './';
0044   outpath = './';
0045 elseif nargin < 3
0046   outpath = './';
0047 end
0048 
0049 if nargin < 4
0050   scan_offset = 0;
0051 end
0052 
0053 if isempty(outpath)
0054   outpath = './';
0055 end
0056 
0057 if isempty(inpath)
0058   inpath = './';
0059 end
0060 
0061 for isub = 1:nsub
0062   
0063   s = sinfo(isub);
0064   subj_root = s.id;
0065   
0066   % specify root output directory and make sure it exists
0067   outroot = fullfile(outpath, subj_root);
0068 
0069   if ~exist(outroot,'dir')
0070     disp(sprintf('Creating directory: %s', outroot))
0071     unix(['mkdir ' outroot]);
0072   end
0073 
0074   num_epi = 0;
0075   for iexam = 1:s.nexams
0076 
0077     exam_root = sprintf('%05d', s.exam_nums(iexam));
0078     datapath = fullfile(inpath, subj_root, exam_root);
0079     
0080     series=s.series_mappings{iexam};
0081     nseries= size(series,1);
0082 
0083     for mapping_idx = 1:nseries
0084       indir = fullfile(datapath, char(series(mapping_idx,1)));
0085 
0086       % Make sure the directory whose data we want to convert exists
0087       if ~exist(indir)
0088     fprintf('Could not locate input directory: %s (skipping ...)\n', indir);
0089       else
0090     switch char(series(mapping_idx,2))
0091       case {'epi','epi1','epi2','epi3','epi4','epi_12','epi_34'}
0092         epidir = fullfile(outroot, char(series(mapping_idx,2)));
0093 
0094         % Check to make sure that output directory exists
0095         if ~exist(epidir,'dir')
0096           disp(sprintf('Creating directory: %s', epidir))
0097           unix(['mkdir ' epidir]);
0098         end
0099         
0100         % Check for number of EPI runs
0101         % Check to see if there is condition order information in the series
0102         % mappings
0103         if size(series,2) == 3
0104           nruns = length(series{mapping_idx,3});
0105           multi_epi_series = 1;
0106         else
0107           nruns = length(s.cond_order);
0108           multi_epi_series = 0;
0109         end
0110         
0111         for irun = 1:nruns
0112           num_epi = num_epi+1;
0113           
0114           outdir = fullfile(epidir, sprintf('run%d', num_epi));
0115 
0116           % Check to make sure that output directory exists
0117           if ~exist(outdir,'dir')
0118         disp(sprintf('Creating directory: %s', outdir))
0119         unix(['mkdir ' outdir]);
0120           end
0121           
0122           if multi_epi_series
0123         %          nvol = s.nvol(series{mapping_idx,3}(irun));
0124         nvol = s.nvol(num_epi);
0125           else
0126         nvol = s.nvol(num_epi);
0127           end
0128           
0129           if multi_epi_series
0130         % 12/4/01 This code still needs to be tested before it should be
0131         % fully trusted
0132         [dummy, vol_idx] = intersect(1:length(s.cond_order), series{mapping_idx,3}(1:irun));
0133         run_offset = sum(s.nvol(vol_idx)) - s.nvol(vol_idx(irun));
0134           else
0135         run_offset = sum(s.nvol(1:num_epi))-s.nvol(num_epi);
0136           end
0137 
0138           start_num = run_offset+2+scan_offset; % 2 = increment 1 for
0139           % template, 1 to get to
0140           % first image
0141 
0142           outstub = fullfile(outdir, sprintf('%s_%s_r%d',subj_root, char(series(mapping_idx,1)), num_epi));
0143           status = GE_convertADW(indir,outstub, start_num, ...
0144           nvol-scan_offset);
0145           if status
0146         disp(sprintf('Error in converting run %d, series %s, exam %s', irun, char(series(mapping_idx,1)), exam_root))
0147         % Decrement run indicator so that next run writes into the
0148         % location of the bad run.  Also, delete the incorrect
0149         % directory.
0150         % This functionality might be
0151         % assuming too much about how errors are to be handled and
0152         % might have to be removed in future versions
0153         unix(['rmdir ' outdir]);
0154         num_epi = num_epi - 1;
0155         break
0156           end
0157         end
0158       otherwise            % e.g. {'hires','coplanar', 'coplanar2'}
0159         outdir = fullfile(outroot, char(series(mapping_idx,2)));
0160 
0161         outstub = fullfile(outdir, [subj_root '_' char(series(mapping_idx,1))]);
0162         disp(sprintf('Source: %s; Destination: %s', indir, outdir))
0163         
0164         % Check to make sure that output directory exists
0165         if ~exist(outdir,'dir')
0166           disp(sprintf('Creating directory: %s', outdir))
0167           unix(['mkdir ' outdir]);
0168         end
0169         switch char(series(mapping_idx,2))
0170           case {'hires_T2_PD'}
0171         GE_convertT2PD(indir,outstub);
0172           otherwise
0173         GE_convertVolume(indir,1,outstub);
0174         end
0175     end % switch
0176       end % if exist(indir)
0177     end  % for mapping_idx = 1:nseries
0178   end % for iexam = 1:s.nexams
0179 end % for isub = 1:nsub

Generated on Wed 20-Mar-2019 04:00:51 by m2html © 2003