0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015 global dataroot spm_path subject_ids use_model_proto sinfo
0016 global SCAN_OFFSET
0017 global REGRESS_MOTION_CORRECTION_PARAMS ADD_LINEAR_TREND_REGRESS ADD_RT_REGRESS
0018
0019 nsub = length(subject_ids);
0020
0021 subj_nsess = length(sinfo(1).cond_order);
0022
0023 disp('Getting subject file info for models')
0024 for isub = 1:nsub
0025 for isess = 1:subj_nsess
0026 sessions(isub).images{isess} = spm_get('Files', ...
0027 sprintf('%s/%s/epi/run%d/', dataroot, char(subject_ids(isub)), isess), ...
0028 sprintf('sn%s*.img', char(subject_ids(isub))) ...
0029 );
0030 end
0031 end
0032
0033 prime_long_model_protos;
0034
0035 model_init = model_prototype(use_model_proto);
0036 conditions_init = conditions_prototype(use_model_proto);
0037
0038 if REGRESS_MOTION_CORRECTION_PARAMS | ADD_LINEAR_TREND_REGRESS
0039 regressors_init = regressors_prototype(use_model_proto);
0040 end
0041
0042 ncond_idxs = 0;
0043 nregress_idxs = 0;
0044
0045 clear regressors
0046
0047 disp('Getting subject specific model parameters')
0048 for isub = 1:nsub
0049 model(isub) = model_init;
0050
0051 model(isub).files = sessions(isub).images;
0052
0053
0054 ttinfo_fname = fullfile(dataroot, char(subject_ids(isub)), sprintf('%s_ttinfo.mat', char(subject_ids(isub))));
0055 sot = prime_SOTs(ttinfo_fname, use_model_proto);
0056
0057 for isess = 1:model(isub).nsess
0058 ncond_idxs = ncond_idxs + 1;
0059 sub_conds(isess) = ncond_idxs;
0060
0061
0062 conditions(ncond_idxs) = conditions_init;
0063 conditions(ncond_idxs).onsets = sot{isess};
0064
0065
0066
0067
0068
0069
0070
0071 ncond = length(sot{isess});
0072 empty_cond = [];
0073 for icond = 1:ncond
0074 if isempty(sot{isess}{icond})
0075 empty_cond(end+1) = icond;
0076 end
0077 end
0078
0079
0080
0081
0082
0083 if empty_cond
0084 conditions(ncond_idxs).names(empty_cond) = [];
0085 conditions(ncond_idxs).onsets(empty_cond) = [];
0086 conditions(ncond_idxs).types(empty_cond) = [];
0087 conditions(ncond_idxs).bf_ev(empty_cond) = [];
0088 conditions(ncond_idxs).bf_ep(empty_cond) = [];
0089 conditions(ncond_idxs).durations{1}(empty_cond) = [];
0090 end
0091
0092 sub_nconds(isess) = length(conditions(ncond_idxs).names);
0093
0094 if REGRESS_MOTION_CORRECTION_PARAMS | ADD_LINEAR_TREND_REGRESS
0095 nregress_idxs = nregress_idxs + 1;
0096 regressors(nregress_idxs) = regressors_init;
0097 nregress_sess = 0;
0098 end
0099
0100
0101 if REGRESS_MOTION_CORRECTION_PARAMS
0102
0103
0104 fname = spm_get('Files',sprintf('%s/%s/epi/run%d/', dataroot, char(subject_ids(isub)), isess),sprintf('realignment_params_%s*i%04d.txt', char(subject_ids(isub)),SCAN_OFFSET+1));
0105 vals = load(fname);
0106 ncol = size(vals,2);
0107 regressors(nregress_idxs).values(1:sinfo(isub).nvol(isess)-SCAN_OFFSET,nregress_sess+1:nregress_sess+ncol) = load(fname);
0108 nregress_sess = nregress_sess + ncol;
0109 end
0110
0111 if ADD_LINEAR_TREND_REGRESS
0112 vals = 0:sinfo(isub).nvol(isess)-SCAN_OFFSET-1;
0113 vals = vals'/max(vals);
0114 regressors(nregress_idxs).values(1:sinfo(isub).nvol(isess)-SCAN_OFFSET,nregress_sess+1) = vals;
0115 nregress_sess = nregress_sess + 1;
0116 end
0117
0118 if ADD_RT_REGRESS
0119
0120 a_info=load(ttinfo_fname);
0121
0122 nb = length(a_info.rt.raw)/model(isub).nsess;
0123 a_start = (isess-1)*nb+1; a_stop = isess*nb;
0124
0125 a_idx_rcr = find(a_info.good_idx.rcr >= a_start & a_info.good_idx.rcr <= a_stop);
0126 a_rcr = a_info.good_idx.rcr(a_idx_rcr);
0127 a_help = a_info.rt.raw(a_rcr);
0128 a_when = round(sot{isess}{4});
0129 vals(a_when) = a_help; clear a_help a_when
0130
0131 a_idx_ucr = find(a_info.good_idx.ucr >= a_start & a_info.good_idx.ucr <= a_stop);
0132 a_ucr = a_info.good_idx.ucr(a_idx_ucr);
0133 a_help = a_info.rt.raw(a_ucr);
0134 a_when = round(sot{isess}{6});
0135 vals(a_when) = a_help;clear a_help a_when
0136
0137 a_idx_rdr = find(a_info.good_idx.rdr >= a_start & a_info.good_idx.rdr <= a_stop);
0138 a_rdr = a_info.good_idx.rdr(a_idx_rdr);
0139 a_help = a_info.rt.raw(a_rdr);
0140 a_when = round(sot{isess}{5});
0141 vals(a_when) = a_help;clear a_help a_when
0142
0143 a_idx_udr = find(a_info.good_idx.udr >= a_start & a_info.good_idx.udr <= a_stop);
0144 a_udr = a_info.good_idx.udr(a_idx_udr);
0145 a_help = a_info.rt.raw(a_udr);
0146 a_when = round(sot{isess}{7});
0147 vals(a_when) = a_help;clear a_help a_when
0148
0149
0150 a_nan = isnan(vals); a_wo = find(a_nan > 0);
0151 for ai=1:length(a_wo)
0152 vals(a_wo(ai,1)) = 0;
0153 end
0154
0155 regressors(nregress_idxs).values(1:sinfo(isub).nvol(isess)-SCAN_OFFSET,nregress_sess+1) = vals;
0156 nregress_sess = nregress_sess + 1;
0157 end
0158
0159 sub_regress(isess) = nregress_idxs;
0160 sub_nregress(isess) = length(regressors(nregress_idxs).names);
0161 end
0162
0163
0164 model(isub).conditions = sub_conds;
0165 model(isub).conditions_nb = sub_nconds;
0166
0167
0168 model(isub).regressors = sub_regress;
0169 model(isub).regressors_nb = sub_nregress;
0170
0171
0172 model(isub).nscans = sinfo(isub).nvol - SCAN_OFFSET;
0173
0174 end
0175