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