Home > database > ensemble_export_stims.m

ensemble_export_stims

PURPOSE ^

Copies stimuli that are registered in the Ensemble database to a folder

SYNOPSIS ^

function stim_st = ensemble_export_stims(data_st,params)

DESCRIPTION ^

 Copies stimuli that are registered in the Ensemble database to a folder

 Stimuli to be exported can be specified either in stimulus_id variable in
 data_st or can be harvested from a response table associated with the
 experiment specified in params.experiment_name

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function stim_st = ensemble_export_stims(data_st,params)
0002 % Copies stimuli that are registered in the Ensemble database to a folder
0003 %
0004 % Stimuli to be exported can be specified either in stimulus_id variable in
0005 % data_st or can be harvested from a response table associated with the
0006 % experiment specified in params.experiment_name
0007 %
0008 
0009 % 23Feb2013 Petr Janata
0010 % 10Sep2013 PJ - adapted to handle multiple experiment names simultaneously
0011 
0012 % Establish a connection to the database
0013 params.mysql.conn_id = mysql_make_conn(mysql_login(params));
0014 conn_id = params.mysql.conn_id;
0015 
0016 % Determine whether stimuli are specified in data_st or whether we need to
0017 % retrieve them via the response table
0018 if ~isempty(data_st) && ismember(data_st.vars,'stimulus_id')
0019   cols = set_var_col_const(data_st.vars);
0020   stimids = unique(data_st.data{cols.stimulus_id});
0021 else
0022   srchFlds = {'expname','experiment_name','experiment_title'};
0023   expNameMask = isfield(params.ensemble,srchFlds);
0024   if ~any(expNameMask)
0025     error('Cannot locate experiment name in params structure');
0026   else
0027     experiment_names = params.ensemble.(srchFlds{find(expNameMask,1,'first')});
0028   end
0029 
0030   if ~iscell(experiment_names)
0031     experiment_names = {experiment_names};
0032   end
0033   
0034   nexp = length(experiment_names);
0035   stimids = [];
0036   for iexp = 1:nexp
0037     experiment_title = experiment_names{iexp};
0038     
0039     % Get the experiment_id
0040     mysql_str = sprintf(['SELECT experiment_id, response_table FROM experiment WHERE ' ...
0041       'experiment_title = "%s";'], experiment_title);
0042     [expID, respTable] = mysql(conn_id, mysql_str);
0043     
0044     % Retrieve unique stims associated with this response table and this
0045     % experiment I
0046     mysql_str = sprintf(['SELECT DISTINCT stimulus_id FROM %s ' ...
0047       'WHERE experiment_id = %d AND stimulus_id IS NOT NULL;'], respTable{1}, expID);
0048     stimids = union(stimids, mysql(conn_id, mysql_str));
0049   end % for iexp
0050 end
0051 
0052 % Now retrieve stimulus location info
0053 fprintf('Retrieving information for %d stimuli\n', length(stimids));
0054 stim_st = ensemble_get_stiminfo(struct('vars','stimulus_id','data',{{stimids}}),params);
0055 scols = set_var_col_const(stim_st.vars);
0056 
0057 % Now call the stim processing wrapper
0058 params.funcName = 'ensemble_copy_stimulus';
0059 params.funcParams.stimroot = params.ensemble.stimroot;
0060 params.funcParams.outpath = params.paths.stimpath;
0061 
0062 stim_st = stim_st.data{scols.stimulus_metadata};
0063 fprintf('Processing stimuli with function: %s\n', params.funcName);
0064 ensemble_processStims(stim_st,params);
0065 
0066 return
0067 end

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