0001 function sessData = ensemble_session_trial_info(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 if(isfield(params,'numPracticeTrials'))
0028 practiceTrialIdxs = 1:params.numPracticeTrials;
0029 else
0030 practiceTrialIdxs = [];
0031 end
0032
0033 dataStructCrit.name = 'session_info';
0034 sessIdx = ensemble_find_analysis_struct(indata,dataStructCrit);
0035 sessData = indata{sessIdx};
0036 sessData.name = 'session_x_trial_info';
0037 sessData.type = 'session_x_trial_info';
0038 sessData.vars{end+1} = 'trial_info';
0039 sessCols = set_var_col_const(sessData.vars);
0040
0041 dataStructCrit.name = 'response_data';
0042 respIdx = ensemble_find_analysis_struct(indata,dataStructCrit);
0043 respData = indata{respIdx};
0044 respCols = set_var_col_const(respData.vars);
0045
0046
0047 sessionIDs = sessData.data{sessCols.session_id};
0048 subjectIDs = sessData.data{sessCols.subject_id};
0049
0050 for sessIdx = 1:length(sessionIDs)
0051
0052 sessInfo.session_id = sessionIDs(sessIdx);
0053 sessInfo.subject_id = subjectIDs{sessIdx};
0054
0055 message(['Sorting trial info for session # ' num2str(sessIdx) ...
0056 ', ID ' num2str(sessInfo.session_id)],params.verbose);
0057
0058
0059 filt.include.all.session_id = sessInfo.session_id;
0060 respThisSess = ensemble_filter(respData,filt);
0061
0062 trialInfoStruct = ensemble_init_data_struct;
0063 trialInfoStruct.name='trial info';
0064 trialInfoStruct.type='trial info';
0065 trialInfoStruct.vars={'trial_id' 'stimulus_id'};
0066
0067
0068
0069
0070
0071 trialInfoVector = [respThisSess.data{respCols.response_order} ...
0072 respThisSess.data{respCols.trial_id} ...
0073 respThisSess.data{respCols.stimulus_id}];
0074
0075 trialdiffIdx = [ 1 diff(trialInfoVector(:,1))'];
0076 trialInfoVector(trialdiffIdx == 0,:) = [];
0077 trialInfoVector( isnan(trialInfoVector(:,2)),: ) = [];
0078
0079 trialInfoCols = set_var_col_const(trialInfoStruct.vars);
0080 trialInfoStruct.data{trialInfoCols.trial_id}=trialInfoVector(:,2);
0081 trialInfoStruct.data{trialInfoCols.stimulus_id}=trialInfoVector(:,3);
0082
0083
0084
0085
0086 if isfield(params,'parse_audio_stims') && ~isempty(params.parse_audio_stims)
0087
0088 parseAudioParams = params.parse_audio_stims;
0089 parseAudioParams.filename = ...
0090 replaceFilenameTags(parseAudioParams.filename,sessInfo);
0091
0092
0093
0094
0095
0096
0097 if(isfield(params,'ignoreMatchedEventForSub'))
0098
0099 [hasEventExclusions,ignoreCellIdx] = ismember(sessInfo.subject_id,params.ignoreMatchedEventForSub{1});
0100 if(ignoreCellIdx ~= 0)
0101 parseAudioParams.ignoreEventIdxs = ...
0102 params.ignoreMatchedEventForSub{2}{ignoreCellIdx};
0103
0104
0105
0106
0107
0108 practiceTrialIdxs = setdiff(practiceTrialIdxs,parseAudioParams.ignoreEventIdxs);
0109
0110 end
0111 end
0112
0113 if(isfield(params,'ignoreParsedStimAudioForSub'))
0114 [hasStimAudioExclusions,ignoreCellIdx] = ...
0115 ismember(sessInfo.subject_id,params.ignoreParsedStimAudioForSub{1});
0116
0117 if(ignoreCellIdx ~= 0)
0118 parseAudioParams.ignoreParsedAudioIdxs = params.ignoreParsedStimAudioForSub{2}{ignoreCellIdx};
0119 end
0120 end
0121
0122 trialInfoStruct = parse_audio_clips(trialInfoStruct,parseAudioParams);
0123
0124 end
0125
0126 if isfield(params,'parse_midi_resps') && ~isempty(params.parse_midi_resps)
0127
0128 parseMidiRespsParams = params.parse_midi_resps;
0129 parseMidiRespsParams.filename = replaceFilenameTags(parseMidiRespsParams.filename,sessInfo);
0130 trialInfoStruct = parse_midi_responses(trialInfoStruct,parseMidiRespsParams);
0131
0132 end
0133
0134
0135 allTrialIdxs = 1:length(trialInfoStruct.data{1});
0136 trialIdxsToKeep = setdiff(allTrialIdxs,practiceTrialIdxs);
0137 for iCol = 1:length(trialInfoStruct.data)
0138 trialInfoStruct.data{iCol} = trialInfoStruct.data{iCol}(trialIdxsToKeep);
0139 end
0140
0141 sessData.data{sessCols.trial_info}(sessIdx,1) = {trialInfoStruct};
0142
0143 end
0144
0145 function message(messageString,verbose)
0146
0147 if(verbose > 0)
0148 disp(sprintf(messageString));
0149 end
0150
0151 return
0152
0153
0154 function filename = replaceFilenameTags(filename,replaceStrings)
0155
0156 filename = strrep(filename,'<subject_id>',replaceStrings.subject_id);
0157 filename = strrep(filename,'<session_id>',num2str(replaceStrings.session_id));
0158
0159 return