0001 function [subject] = freesurfer_read_subject(subjectPath,filetype)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056 ver = '$Revision: 1.3 $ $Date: 2005/08/14 21:22:42 $';
0057 fprintf('FREESURFER_READ_SUBJECT [v %s]\n',ver(11:15));
0058
0059 if ~exist('subjectPath','var'),
0060 error('no subjectPath specified');
0061 end
0062 if isempty(subjectPath),
0063 error('empty subjectPath specified');
0064 end
0065 if exist(subjectPath) ~= 7,
0066 error('subjectPath specified is not a directory');
0067 end
0068
0069 surfPath = fullfile(subjectPath,'surf','');
0070 labelPath = fullfile(subjectPath,'label','');
0071 mriPath = fullfile(subjectPath,'mri','');
0072 xfmPath = fullfile(mriPath,'transforms','');
0073 brainPath = fullfile(subjectPath,'bem','');
0074
0075
0076
0077
0078 if ~exist('filetype','var'),
0079 filetype = 'all';
0080 end
0081 if isempty(filetype),
0082 filetype = 'all';
0083 end
0084
0085 filetype = lower(filetype);
0086 if strmatch('all',filetype),
0087 filetype = {'brain','orig','smoothwm','white','pial','inflated','curv','thickness','aparc','xfm'};
0088 end
0089
0090 for f = filetype,
0091 f = f{:};
0092 switch f,
0093
0094 case {'brain'},
0095
0096
0097 file.brain = fullfile(brainPath,'brain.tri');
0098 if exist(file.brain) == 2,
0099 [brain.vertices, brain.faces] = freesurfer_read_tri(file.brain);
0100 subject.brain = brain;
0101 else
0102 msg = sprintf('file does not exist: %s',file.brain);
0103 warning(msg);
0104 end
0105
0106 case {'orig'},
0107
0108
0109 file.lh.orig = fullfile(surfPath,'lh.orig');
0110 if exist(file.lh.orig) == 2,
0111 [lh.orig.vertices, lh.orig.faces] = freesurfer_read_surf(file.lh.orig);
0112 else
0113 msg = sprintf('file does not exist: %s',file.lh.orig);
0114 warning(msg);
0115 end
0116
0117 file.rh.orig = fullfile(surfPath,'rh.orig');
0118 if exist(file.rh.orig) == 2,
0119 [rh.orig.vertices, rh.orig.faces] = freesurfer_read_surf(file.rh.orig);
0120 else
0121 msg = sprintf('file does not exist: %s',file.rh.orig);
0122 warning(msg);
0123 end
0124
0125 case {'smoothwm'},
0126
0127
0128 file.lh.smoothwm = fullfile(surfPath,'lh.smoothwm');
0129 if exist(file.lh.smoothwm) == 2,
0130 [lh.smoothwm.vertices, lh.smoothwm.faces] = freesurfer_read_surf(file.lh.smoothwm);
0131 else
0132 msg = sprintf('file does not exist: %s',file.lh.smoothwm);
0133 warning(msg);
0134 end
0135
0136 file.rh.smoothwm = fullfile(surfPath,'rh.smoothwm');
0137 if exist(file.rh.smoothwm) == 2,
0138 [rh.smoothwm.vertices, rh.smoothwm.faces] = freesurfer_read_surf(file.rh.smoothwm);
0139 else
0140 msg = sprintf('file does not exist: %s',file.rh.smoothwm);
0141 warning(msg);
0142 end
0143
0144 case {'white'},
0145
0146
0147 file.lh.white = fullfile(surfPath,'lh.white');
0148 if exist(file.lh.white) == 2,
0149 [lh.white.vertices, lh.white.faces] = freesurfer_read_surf(file.lh.white);
0150 else
0151 msg = sprintf('file does not exist: %s',file.lh.white);
0152 warning(msg);
0153 end
0154
0155 file.rh.white = fullfile(surfPath,'rh.white');
0156 if exist(file.rh.white) == 2,
0157 [rh.white.vertices, rh.white.faces] = freesurfer_read_surf(file.rh.white);
0158 else
0159 msg = sprintf('file does not exist: %s',file.rh.white);
0160 warning(msg);
0161 end
0162
0163 case {'pial'},
0164
0165
0166 file.lh.pial = fullfile(surfPath,'lh.pial');
0167 if exist(file.lh.pial) == 2,
0168 [lh.pial.vertices, lh.pial.faces] = freesurfer_read_surf(file.lh.pial);
0169 else
0170 msg = sprintf('file does not exist: %s',file.lh.pial);
0171 warning(msg);
0172 end
0173
0174 file.rh.pial = fullfile(surfPath,'rh.pial');
0175 if exist(file.rh.pial) == 2,
0176 [rh.pial.vertices, rh.pial.faces] = freesurfer_read_surf(file.rh.pial);
0177 else
0178 msg = sprintf('file does not exist: %s',file.rh.pial);
0179 warning(msg);
0180 end
0181
0182 case {'inflated'},
0183
0184
0185 file.lh.inflated = fullfile(surfPath,'lh.inflated');
0186 if exist(file.lh.inflated) == 2,
0187 [lh.inflated.vertices, lh.inflated.faces] = freesurfer_read_surf(file.lh.inflated);
0188 else
0189 msg = sprintf('file does not exist: %s',file.lh.inflated);
0190 warning(msg);
0191 end
0192
0193 file.rh.inflated = fullfile(surfPath,'rh.inflated');
0194 if exist(file.rh.inflated) == 2,
0195 [rh.inflated.vertices, rh.inflated.faces] = freesurfer_read_surf(file.rh.inflated);
0196 else
0197 msg = sprintf('file does not exist: %s',file.rh.inflated);
0198 warning(msg);
0199 end
0200
0201 case {'curv'},
0202
0203
0204 file.lh.curv = fullfile(surfPath,'lh.curv');
0205 if exist(file.lh.curv) == 2,
0206 lh.curv = freesurfer_read_curv(file.lh.curv);
0207 else
0208 msg = sprintf('file does not exist: %s',file.lh.curv);
0209 warning(msg);
0210 end
0211
0212 file.rh.curv = fullfile(surfPath,'rh.curv');
0213 if exist(file.rh.curv) == 2,
0214 rh.curv = freesurfer_read_curv(file.rh.curv);
0215 else
0216 msg = sprintf('file does not exist: %s',file.rh.curv);
0217 warning(msg);
0218 end
0219
0220 case {'thickness'},
0221
0222
0223 file.lh.thickness = fullfile(surfPath,'lh.thickness');
0224 if exist(file.lh.thickness) == 2,
0225 lh.thickness = freesurfer_read_thickness(file.lh.thickness);
0226 else
0227 msg = sprintf('file does not exist: %s',file.lh.thickness);
0228 warning(msg);
0229 end
0230
0231 file.rh.thickness = fullfile(surfPath,'rh.thickness');
0232 if exist(file.rh.thickness) == 2,
0233 rh.thickness = freesurfer_read_thickness(file.rh.thickness);
0234 else
0235 msg = sprintf('file does not exist: %s',file.rh.thickness);
0236 warning(msg);
0237 end
0238
0239 case {'aparc'},
0240
0241
0242 file.lh.aparc = fullfile(labelPath,'lh.aparc.annot');
0243 if exist(file.lh.aparc) == 2,
0244 lh.aparc = freesurfer_read_annotation(file.lh.aparc);
0245 else
0246 msg = sprintf('file does not exist: %s',file.lh.aparc);
0247 warning(msg);
0248 end
0249
0250 file.rh.aparc = fullfile(labelPath,'rh.aparc.annot');
0251 if exist(file.rh.aparc) == 2,
0252 rh.aparc = freesurfer_read_annotation(file.rh.aparc);
0253 else
0254 msg = sprintf('file does not exist: %s',file.rh.aparc);
0255 warning(msg);
0256 end
0257
0258 case {'xfm'},
0259
0260
0261 file.xfm = fullfile(xfmPath,'talairach.xfm');
0262 if exist(file.xfm) == 2,
0263 subject.TalairachXFM = freesurfer_read_talxfm(file.xfm);
0264 else
0265 msg = sprintf('file does not exist: %s',file.xfm);
0266 warning(msg);
0267 end
0268 end
0269 end
0270
0271 subject.file = file;
0272 subject.lh = lh;
0273 subject.rh = rh;
0274
0275 return