Home > database > ensemble_session_trial_info.m

ensemble_session_trial_info

PURPOSE ^

Extracts the trial and session IDs in order, for each given session.

SYNOPSIS ^

function sessData = ensemble_session_trial_info(indata,params)

DESCRIPTION ^

 Extracts the trial and session IDs in order, for each given session.

 indata is a cell array of two data structures (response_data and
 session_info), as returned from ensemble_load_expinfo

 This function looks at the response table (from ensemble_load_expinfo)
 of an experiment to extract the trial IDs and stimulus IDs for each 
 session, in the order which they were presented. This info is stored 
 in a 'trial info' structure that is tagged to the end of each session 
 in the session structure (also retrieved from ensemble_load_expinfo). Optionally,
 the audio corresponding to each trial can be parsed from a session recording
 (e.g. from digital performer). The time offsets of each trial relative to
 the beginning of the recording are then recorded. This information is then
 used to parse MIDI responses corresponding to each trial (if MIDI data was
 recorded along-side the audio recording.
 

 handles only single stimulus trials for now


 21 March 2007 - S.T.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function sessData = ensemble_session_trial_info(indata,params)
0002 % Extracts the trial and session IDs in order, for each given session.
0003 %
0004 % indata is a cell array of two data structures (response_data and
0005 % session_info), as returned from ensemble_load_expinfo
0006 %
0007 % This function looks at the response table (from ensemble_load_expinfo)
0008 % of an experiment to extract the trial IDs and stimulus IDs for each
0009 % session, in the order which they were presented. This info is stored
0010 % in a 'trial info' structure that is tagged to the end of each session
0011 % in the session structure (also retrieved from ensemble_load_expinfo). Optionally,
0012 % the audio corresponding to each trial can be parsed from a session recording
0013 % (e.g. from digital performer). The time offsets of each trial relative to
0014 % the beginning of the recording are then recorded. This information is then
0015 % used to parse MIDI responses corresponding to each trial (if MIDI data was
0016 % recorded along-side the audio recording.
0017 %
0018 %
0019 % handles only single stimulus trials for now
0020 %
0021 %
0022 % 21 March 2007 - S.T.
0023 
0024 % params.numPracticeTrials parameter is used for removing practice trials from the
0025 % parsed audio/ensemble response set. This is useful if practice
0026 % trials were recorded, but are not desired in the results
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   % get rid of repeated trial ids and stimulus ids
0068   % this is done by taking the diff of the response order
0069   % and zeroing out all the indices where the diff == 0
0070   % also, getting rid of NaNs in the trial id and stim id list
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   %if params.parse_audio was set, then audio parsing will be
0084   %performed. params.parse_audio serves as the param struct for the
0085   %audio parser
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     %if the recorded responses in Ensemble or audio recordings
0094     %don't match, these parameters will ignore either Ensemble
0095     %session info (ignoreMatchedEventForSub) or audio info
0096     %(ignoreParsedStimAudioForSub)during matching
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     %if ensemble practice sessions are missing from database,
0106         %then we might need to revise which practice trials to
0107         %throw out.
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   %throw out the practice trials if this was set
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

Generated on Wed 20-Sep-2023 04:00:50 by m2html © 2003