Home > fmri > utils > convert_format_v2.m

convert_format_v2

PURPOSE ^

convert_format(sinfo, inpath, outpath, scan_offset);

SYNOPSIS ^

function convert_format_v2(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_v2(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   subpath = fullfile(outpath, subj_root);
0068     check_dir(subpath);
0069 
0070     % Figure out the number of sessions we have for this subject
0071     nsess = length(s.sessinfo);
0072     
0073     for isess = 1:nsess
0074         sessinfo = s.sessinfo(isess);
0075         
0076         if ~sessinfo.use_session
0077             continue
0078         end
0079         
0080         sesspath = fullfile(subpath, sessinfo.id);
0081         
0082         % Figure out how many series we need to convert
0083     series = sessinfo.series_mappings;
0084     nseries= size(series,1);
0085         
0086         num_epi = 0;  % counter for total number of epi runs we have converted
0087         nexams = sessinfo.nexams;
0088  
0089         for mapping_idx = 1:nseries
0090             % Figure out type of series we are converting
0091             series_type = series{mapping_idx,2};
0092             
0093             % If we are dealing with more than one exam, figure out what the exam
0094             % directory is
0095             if nexams > 1
0096                 exam_idx = series(mapping_idx,3);
0097             else
0098                 exam_idx = 1;
0099             end
0100             
0101             exam_root = sprintf('%05d', sessinfo.exam_ids(exam_idx));
0102             exampath = fullfile(sesspath, exam_root);
0103     
0104             srcdir = fullfile(exampath, char(series(mapping_idx,1)));
0105 
0106       % Make sure the directory whose data we want to convert exists
0107       if ~exist(srcdir)
0108                 fprintf('Could not locate input directory: %s (skipping ...)\n', srcdir);
0109                 continue
0110             end
0111             
0112             switch series_type
0113                 case {'epi','epi1','epi2','epi3','epi4','epi_12','epi_34'}
0114                     epidir = fullfile(sesspath, series_type);
0115                     check_dir(epidir)
0116                     
0117                     % Check for number of EPI runs
0118                     % Check to see if there is condition order information in the series
0119                     % mappings
0120                     % In version 2 this has been moved to column 4 (epi_runcol)
0121                     epi_runcol = 4;
0122                     if size(series,2) == epi_runcol
0123                         nruns = length(series{mapping_idx, epi_runcol});
0124                         multi_epi_series = 1;
0125                     else
0126                         nruns = length(sessinfo.cond_order);
0127                         multi_epi_series = 0;
0128                     end
0129                     
0130                     for irun = 1:nruns
0131                         num_epi = num_epi+1;
0132                         
0133                         outdir = fullfile(epidir, sprintf('run%d', num_epi));
0134                         
0135                         % Check to make sure that output directory exists
0136                         check_dir(outdir)
0137                         
0138                         nvol = sessinfo.nvol(num_epi);
0139           
0140                         if multi_epi_series
0141                             % 12/4/01 This code still needs to be tested before it should be
0142                             % fully trusted
0143                             [dummy, vol_idx] = intersect(1:length(sessinfo.cond_order), ...
0144                                 series{mapping_idx,epi_runcol}(1:irun));
0145                             run_offset = sum(sessinfo.nvol(vol_idx)) - sessinfo.nvol(vol_idx(irun));
0146                         else
0147                             run_offset = sum(sessinfo.nvol(1:num_epi))-sessinfo.nvol(num_epi);
0148                         end
0149 
0150                         start_num = run_offset+2+scan_offset; % 2 = increment 1 for
0151                         % template, 1 to get to first image
0152 
0153                         outstub = fullfile(outdir, sprintf('%s_%s_r%d',sessinfo.id, char(series(mapping_idx,1)), num_epi));
0154                         status = GE_convertADW(srcdir, outstub, start_num, nvol-scan_offset);
0155           
0156                         if status
0157                             disp(sprintf('Error in converting run %d, series %s, exam %s', irun, char(series(mapping_idx,1)), exam_root))
0158                             % Decrement run indicator so that next run writes into the
0159                             % location of the bad run.  Also, delete the incorrect
0160                             % directory.
0161                             % This functionality might be
0162                             % assuming too much about how errors are to be handled and
0163                             % might have to be removed in future versions
0164                             unix(['rmdir ' outdir]);
0165                             num_epi = num_epi - 1;
0166                             break
0167                         end
0168                     end % for irun
0169                     
0170                 otherwise            % e.g. {'hires','coplanar', 'coplanar2'}
0171                     outdir = fullfile(sesspath, series_type);
0172                     check_dir(outdir)
0173                     
0174                     outstub = fullfile(outdir, [subj_root '_' char(series(mapping_idx,1))]);
0175                     disp(sprintf('Source: %s; Destination: %s', srcdir, outdir))
0176                     
0177                     switch series_type
0178                         case {'hires_T2_PD'}
0179                             GE_convertT2PD(srcdir,outstub);
0180                         otherwise
0181                             GE_convertVolume(srcdir,1,outstub);
0182                     end
0183             end % switch % series_type
0184     end  % for mapping_idx = 1:nseries
0185   end % for isess = 1:nsess
0186 end % for isub = 1:nsub

Generated on Sun 19-May-2019 04:00:51 by m2html © 2003