0001 function stimulusDataStruct = ensemble_get_stiminfo(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 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
0036 stimIDCol = strmatch('stimulus_id',indata.vars,'exact');
0037 stimIDCol = unique( stimIDCol(~isnan(stimIDCol)) );
0038
0039
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
0052 stimMeta = mysql_extract_metadata('table','stimulus', ...
0053 'stimulus_id',stimIDList, ...
0054 'conn_id', conn_id);
0055
0056
0057
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
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
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
0078
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