0001 function sessData = ensemble_session_trial_info_without_trial_id(indata,params)
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 if ~isfield(params,'verbose'), params.verbose=0; end
0040
0041
0042
0043
0044
0045 if(isfield(params,'numPracticeTrials'))
0046 practiceTrialIdxs = 1:params.numPracticeTrials;
0047 else
0048 practiceTrialIdxs = [];
0049 end
0050
0051
0052
0053
0054
0055 if(isfield(params,'num_practice_trials_database_only'))
0056 databasePracticeTrialIdxs = 1:params.num_practice_trials_database_only;
0057 else
0058 databasePracticeTrialIdxs = [];
0059 end
0060
0061 dataStructCrit.name = 'session_info';
0062 sessIdx = ensemble_find_analysis_struct(indata,dataStructCrit);
0063 sessData = indata{sessIdx};
0064 sessData.name = 'session_x_trial_info';
0065 sessData.type = 'session_x_trial_info';
0066 sessData.vars{end+1} = 'trial_info';
0067 sessCols = set_var_col_const(sessData.vars);
0068
0069 dataStructCrit.name = 'response_data';
0070 respIdx = ensemble_find_analysis_struct(indata,dataStructCrit);
0071 respData = indata{respIdx};
0072 respCols = set_var_col_const(respData.vars);
0073
0074
0075 sessionIDs = sessData.data{sessCols.session_id};
0076 subjectIDs = sessData.data{sessCols.subject_id};
0077
0078 sessData.data{sessCols.trial_info} = cell(length(sessionIDs),1);
0079 tinfoStack = cell(length(sessionIDs),1);
0080 for sessIdx = 1:length(sessionIDs)
0081
0082 session_id = sessionIDs(sessIdx);
0083 subject_id = subjectIDs{sessIdx};
0084
0085 message(['Sorting trial info for session # ' num2str(sessIdx) ...
0086 ', ID ' subject_id ...
0087 ', Ensemble session # ' num2str(session_id)],...
0088 params.verbose);
0089
0090 cfilt = [];
0091 cfilt.include.all.session_id = session_id;
0092 respThisSess = ensemble_filter(respData,cfilt);
0093
0094 trialInfoStruct = ensemble_init_data_struct;
0095 trialInfoStruct.name='trial info';
0096 trialInfoStruct.type='trial info';
0097 trialInfoStruct.vars={'response_order' 'stimulus_id'};
0098
0099
0100
0101
0102
0103
0104 trialInfoVector = [respThisSess.data{respCols.response_order} ...
0105 respThisSess.data{respCols.stimulus_id}];
0106
0107 trialdiffIdx = [ 1 diff(trialInfoVector(:,1))'];
0108 trialInfoVector(trialdiffIdx == 0,:) = [];
0109 trialInfoVector( isnan(trialInfoVector(:,2)),: ) = [];
0110
0111
0112 if ~isempty(databasePracticeTrialIdxs)
0113 trialInfoVector(databasePracticeTrialIdxs,:) = [];
0114 end
0115
0116 trialInfoCols = set_var_col_const(trialInfoStruct.vars);
0117 trialInfoStruct.data{trialInfoCols.response_order}=trialInfoVector(:,1);
0118 trialInfoStruct.data{trialInfoCols.stimulus_id}=trialInfoVector(:,2);
0119
0120
0121
0122
0123 if isfield(params,'parse_audio_stims') && ~isempty(params.parse_audio_stims)
0124
0125 parseAudioParams = params.parse_audio_stims;
0126 parseAudioParams.mysql = params.mysql;
0127 parseAudioParams.filename = ...
0128 replaceFilenameTags(parseAudioParams.filename,struct('subject_id',subject_id,'session_id',session_id));
0129
0130
0131
0132
0133
0134
0135 if(isfield(params,'ignoreMatchedEventForSub'))
0136
0137 [hasEventExclusions,ignoreCellIdx] = ismember(subject_id,params.ignoreMatchedEventForSub{1});
0138 if(ignoreCellIdx ~= 0)
0139 parseAudioParams.ignoreEventIdxs = ...
0140 params.ignoreMatchedEventForSub{2}{ignoreCellIdx};
0141
0142
0143
0144
0145
0146 usePracticeTrialIdxs = setdiff(practiceTrialIdxs,parseAudioParams.ignoreEventIdxs);
0147
0148 end
0149 end
0150
0151 if(isfield(params,'ignoreParsedStimAudioForSub'))
0152 [hasStimAudioExclusions,ignoreCellIdx] = ...
0153 ismember(subject_id,params.ignoreParsedStimAudioForSub{1});
0154
0155 if(ignoreCellIdx ~= 0)
0156 parseAudioParams.ignoreParsedAudioIdxs = params.ignoreParsedStimAudioForSub{2}{ignoreCellIdx};
0157 end
0158 end
0159
0160 trialInfoStruct = parse_audio_clips(trialInfoStruct,parseAudioParams);
0161 if isempty(trialInfoStruct)
0162 warning('no audio data for %s',subject_id);
0163 continue
0164 end
0165 end
0166
0167 if isfield(params,'parse_midi_resps') && ~isempty(params.parse_midi_resps)
0168
0169 parseMidiRespsParams = params.parse_midi_resps;
0170 parseMidiRespsParams.filename = replaceFilenameTags(parseMidiRespsParams.filename,struct('subject_id',subject_id,'session_id',session_id));
0171 trialInfoStruct = parse_midi_slider_response(trialInfoStruct,parseMidiRespsParams);
0172
0173 end
0174
0175
0176 allTrialIdxs = 1:length(trialInfoStruct.data{1});
0177 trialIdxsToKeep = setdiff(allTrialIdxs,practiceTrialIdxs);
0178 for iCol = 1:length(trialInfoStruct.data)
0179 trialInfoStruct.data{iCol} = trialInfoStruct.data{iCol}(trialIdxsToKeep);
0180 end
0181
0182 tinfoStack{sessIdx} = trialInfoStruct;
0183
0184 end
0185 sessData.data{sessCols.trial_info} = tinfoStack;
0186
0187 function message(messageString,verbose)
0188
0189 if(verbose > 0)
0190 disp(sprintf(messageString));
0191 end
0192
0193 return
0194
0195
0196 function filename = replaceFilenameTags(filename,replaceStrings)
0197
0198 filename = strrep(filename,'<subject_id>',replaceStrings.subject_id);
0199 filename = strrep(filename,'<session_id>',num2str(replaceStrings.session_id));
0200
0201 return