0001 function [panas] = extract_panas(expt, sub_list, resp_table, conn_id)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 global SQL_HOST
0014
0015 if nargin < 2
0016 sub_list = {};
0017 end
0018
0019 try conn_id(1);
0020 catch
0021 mysql_make_conn;
0022 conn_id = 0;
0023 end
0024
0025
0026 [form_info{1:2}] = mysql(conn_id,'select form_id, form_name from form');
0027 form_id = form_info{1}(strmatch('PANAS Survey',form_info{2},'exact'));
0028
0029
0030
0031
0032 quest_id = mysql(conn_id,sprintf('select question_id from form_x_question where form_id=%d',form_id));
0033
0034
0035
0036 [panas.adj, sq_id] = mysql(conn_id,sprintf('select heading, subquestion from question_x_data_format where question_id=%d and subquestion>1', quest_id));
0037
0038
0039
0040 extract_vars = {'subject_id', 'form_order', 'subquestion', 'response_enum'};
0041 sql_str = sprintf(['select %s from %s where question_id=%d and subquestion>1'], ...
0042 cell2str(extract_vars,','), resp_table, quest_id);
0043 [panas_resp{1:length(extract_vars)}] = mysql(conn_id,sql_str);
0044
0045 form_col = strmatch('form_order',extract_vars,'exact');
0046 sq_col = strmatch('subquestion',extract_vars,'exact');
0047 resp_col = strmatch('response_enum',extract_vars,'exact');
0048
0049
0050 iter_ids = unique(panas_resp{form_col});
0051 niter = length(iter_ids);
0052
0053
0054 if isempty(sub_list)
0055 sub_list = unique(panas_resp{1});
0056 end
0057
0058 nsub_proc = length(sub_list);
0059 panas.subids = sub_list;
0060 panas.data = zeros(nsub_proc,length(sq_id),niter)+NaN;
0061
0062 for iiter = 1:niter
0063 iter_mask = panas_resp{form_col} == iter_ids(iiter);
0064 for isub = 1:nsub_proc
0065
0066 sub_mask = ...
0067 ismember(panas_resp{strmatch('subject_id',extract_vars,'exact')},sub_list{isub});
0068
0069
0070 curr_idxs = find(iter_mask&sub_mask);
0071 panas.data(isub,panas_resp{sq_col}(curr_idxs)-1,iiter) = log2(panas_resp{resp_col}(curr_idxs));
0072
0073 end
0074 end
0075
0076 if ~conn_id
0077 mysql(conn_id,'close')
0078 end
0079 return