0001 function [data,vars] = stim_ids_from_resp_tbl(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 data{1} = nan(0);
0027 vars = {'stimulus__stimulus_id'};
0028
0029
0030 if isfield(params,'mysql')
0031 m = params.mysql;
0032 elseif isfield(params,'ensemble')
0033 m = params.ensemble;
0034 else
0035 warning('no database connection info provided, assuming ensemble_main');
0036 m = struct();
0037 end
0038
0039 if ~isfield(m,'conn_id') || mysql(m.conn_id,'status')
0040 if ~all(isfield(m,{'host','database','user','passwd'}))
0041 error('%s: No valid connection or insufficient information to establish one', mfilename);
0042 else
0043 m.conn_id = 6;
0044 mysql_make_conn(m);
0045 tmp_conn_id = 1;
0046 end
0047 else
0048 tmp_conn_id = 0;
0049 end
0050
0051
0052 if ~isfield(params,'stim_ids_from_resp_tbl') || ...
0053 ~isfield(params.stim_ids_from_resp_tbl,'tables') || ...
0054 ~isstruct(params.stim_ids_from_resp_tbl.tables) || ...
0055 ~isfield(params.stim_ids_from_resp_tbl.tables,'name')
0056 error('required parameters not found\n');
0057 else
0058 t = params.stim_ids_from_resp_tbl.tables;
0059 end
0060
0061
0062 for i = 1:length(t)
0063
0064
0065 tbl = t(i).name;
0066 tdata = ensemble_init_data_struct();
0067 tbl_desc = mysql_describe_table(tbl,m.conn_id);
0068 tdata.vars = transpose(tbl_desc.flds);
0069 tcol = set_var_col_const(tdata.vars);
0070
0071 mysql_str = sprintf('SELECT %s FROM %s WHERE stimulus_id IS NOT NULL',...
0072 cell2str(tdata.vars,', '),tbl);
0073
0074 [tdata.data{1:length(tdata.vars)}] = mysql(m.conn_id, mysql_str);
0075
0076
0077 if isfield(t(i),'filt') && isstruct(t(i).filt)
0078 tdata = ensemble_filter(tdata,t(i).filt);
0079 end
0080
0081
0082 b = unique(tdata.data{tcol.stimulus_id});
0083 data{1} = union(b,data{1});
0084 end
0085
0086 if tmp_conn_id
0087 mysql(m.conn_id,'close');
0088 m.conn_id = [];
0089 end