Home > database > ensemble_get_stiminfo.m

ensemble_get_stiminfo

PURPOSE ^

Obtains stimulus and attribute meta data for stim IDs in the response table.

SYNOPSIS ^

function stimulusDataStruct = ensemble_get_stiminfo(indata,params)

DESCRIPTION ^

 Obtains stimulus and attribute meta data for stim IDs in the response table.

 ensemble_get_stiminfo({respDataStruct,stimids},params)

 The first input argument can be either
 respDataStruct - the response table data structure containing stim IDs to retrieve meta data
 stimids - vector of stimulus IDs to obtain information on

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function stimulusDataStruct = ensemble_get_stiminfo(indata,params)
0002 % Obtains stimulus and attribute meta data for stim IDs in the response table.
0003 %
0004 % ensemble_get_stiminfo({respDataStruct,stimids},params)
0005 %
0006 % The first input argument can be either
0007 % respDataStruct - the response table data structure containing stim IDs to retrieve meta data
0008 % stimids - vector of stimulus IDs to obtain information on
0009 %
0010 %
0011 
0012 % 9 Feb, 2007 - First Version, Stefan Tomic
0013 % 15 Mar, 2007 - Edited function to conform to ensemble data structures, S.T.
0014 % 05/18/07 PJ - Added conn_id support
0015 % 8/13/07 ST - minor fix to make vars a row cell array instead of
0016 %              column cell array
0017 % 10/07/08 PJ - enabled passing in of stimids to make this function more useful
0018 % 09/30/09 ST - Added code to deal with missing attribute data (simply set
0019 %               attributeMeta to empty struct)
0020 % 25Jan2013 PJ - Fixed handling of mysql and ensemble fields
0021   
0022 % Handle database and connection defaults
0023 
0024 if isfield(params,'mysql')
0025   dbinfofld = 'mysql';
0026 elseif isfield(params,'ensemble')
0027   dbinfofld = 'ensemble';
0028 else
0029   error('Must provide database information in params.mysql');
0030 end
0031 
0032 conn_id = params.(dbinfofld).conn_id;
0033   
0034 if isstruct(indata)
0035   %obtain a list of unique stimulus IDs that are in the response table
0036   stimIDCol = strmatch('stimulus_id',indata.vars,'exact');
0037   stimIDCol = unique( stimIDCol(~isnan(stimIDCol)) );
0038 
0039   %throw an error if no stimulus IDs were provided
0040   if(isempty(stimIDCol))
0041     error(['Cannot get stimulus information. Stimulus IDs not provided' ...
0042       ' from response data']);
0043   end
0044 
0045   stimIDAll = indata.data{stimIDCol};
0046   stimIDList = unique(stimIDAll(~isnan(stimIDAll)));
0047 else
0048   stimIDList = unique(indata);
0049 end
0050 
0051 % Extract the stimulus data
0052 stimMeta = mysql_extract_metadata('table','stimulus', ...
0053     'stimulus_id',stimIDList, ...
0054     'conn_id', conn_id);
0055 
0056 %add the stimulus_id field to attribute structures, so that we can
0057 %separate the attribute meta info from the stimulus meta info
0058 for iStim = 1:length(stimMeta)
0059     for iAttribute = 1:length(stimMeta(iStim).attribute)
0060       stimMeta(iStim).attribute(iAttribute).stimulus_id = stimMeta(iStim).stimulus_id;
0061     end
0062 end
0063 
0064 %separate the stimulus and attribute meta info
0065 attributeMeta = [stimMeta.attribute];
0066 if(~isempty(attributeMeta))
0067   attributeMeta = orderfields(attributeMeta,{'stimulus_id','attribute_id','name','class','attribute_value_double','attribute_value_text'});
0068 else
0069   %if there is no attribute metadata, just setting this to an empty struct
0070   attributeMeta = struct('stimulus_id',[],'attribute_id',[],'name',[],'class',[],'attribute_value_double',[],'attribute_value_text',[]);
0071 end
0072 stimMeta = rmfield(stimMeta,'attribute');
0073 
0074 att2DCells = squeeze(struct2cell(attributeMeta))';
0075 stim2DCells = squeeze(struct2cell(stimMeta))';
0076 
0077 %reorganize the 2D cells to cell column data, and set type and vars
0078 %fields
0079 stimMetaCells = ensemble_init_data_struct;
0080 stimMetaCells.name = 'stimulus_metadata';
0081 stimMetaCells.type = 'stimulus_metadata';
0082 for iStimCol = 1:size(stim2DCells,2)
0083   if isnumeric(stim2DCells{1,iStimCol})
0084     columnData = [stim2DCells{:,iStimCol}]';
0085   else
0086     columnData = {stim2DCells{:,iStimCol}}';
0087   end
0088   stimMetaCells.data(:,iStimCol) = {columnData};
0089 end
0090 stimMetaCells.vars = fieldnames(stimMeta)';
0091 
0092 attMetaCells = ensemble_init_data_struct;
0093 attMetaCells.name = 'stimulus_x_attribute_metadata';
0094 attMetaCells.type = 'stimulus_x_attribute_metadata';
0095 for iAttCol = 1:size(att2DCells,2)  
0096   if isnumeric(att2DCells{1,iAttCol})
0097     columnData = [att2DCells{:,iAttCol}]';
0098   else
0099     columnData = {att2DCells{:,iAttCol}}';
0100   end
0101   attMetaCells.data(:,iAttCol) = {columnData};
0102 end
0103 attMetaCells.vars = fieldnames(attributeMeta)';
0104 
0105 stimulusDataStruct = ensemble_init_data_struct;
0106 stimulusDataStruct.vars = {'stimulus_metadata', ...
0107             'stimulus_x_attribute_metadata'};
0108 stimulusDataStruct.data = {stimMetaCells, attMetaCells};
0109 
0110 if(exist('tmp_conn_id','var'))
0111   mysql(conn_id,'close');
0112 end

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