DSSELECT - select subset of data Limitation: dsSelect currently supports returning value ranges but not non-numeric model components (e.g., mechanism_list modifications). Usage: data=dsSelect(data,'option',value) Inputs: - data: DNSim data structure (see dsSimulate) - options: 'time_limits': in units of data.time {[beg,end]} 'varied': specification of search space subset to retrieve (see NOTE 1) Notes: - NOTE 1: 'varied' can be specified in two ways: - Method 1: a way similar to 'vary' in dsSimulate and dsVary2Modifications. However, instead of indicating values for a variable to take, 'varied' involves the specification of a range of values. Syntax: vary={object, variable, [low,high]; ...}, where low is the lower bound on the range varied and high is the upper bound for the component varied. For instance, if 'gNa' in population 'E' was varied 0:.1:1 by setting 'vary' to {'E','gNa',0:.1:1}, then to select the subset of gNa values between .3 and .5, set 'varied' to {'E','gNa',[.3 .5]}. - Method 2: 'varied' can be specified using the resulting component name stored in data.varied. e.g., {'E_iNa_gNa',[.3 .5]}. - NOTE 2: if 'varied' values are requested and not a two-element array (e.g., [.3 .5]), then return all matching values. Examples: % return simulated data from 20-80ms data=dsSelect(data,'time_limits',[20 80]); % return data sets with gNa set between .3 and .5 data=dsSelect(data,'varied',{'E','gNa',[.3 .5]}); data=dsSelect(data,'time_limits',[20 80],'varied',{'E','gNa',[.3 .5]}); data=dsSelect(data,'roi',{'E_v',[1 4]}); TODO: - Specify subsets to return in terms of ROIs: {'E',1:50;'I',1:10,'F',[]} (exclude F) (default all cells for any pops not specified in ROIs). - Possible format for specifying range_varied: {'E','gNa',[.1 .3]; 'I->E','tauI',[15 25]; 'I','mechanism_list','+iM'} See also: dsSimulate, dsVary2Modifications, dsImport Author: Jason Sherfey, PhD <jssherfey@gmail.com> Copyright (C) 2016 Jason Sherfey, Boston University, USA
0001 function data = dsSelect(data,varargin) 0002 %DSSELECT - select subset of data 0003 % 0004 % Limitation: dsSelect currently supports returning value ranges but not 0005 % non-numeric model components (e.g., mechanism_list modifications). 0006 % 0007 % Usage: 0008 % data=dsSelect(data,'option',value) 0009 % 0010 % Inputs: 0011 % - data: DNSim data structure (see dsSimulate) 0012 % - options: 0013 % 'time_limits': in units of data.time {[beg,end]} 0014 % 'varied': specification of search space subset to retrieve (see NOTE 1) 0015 % 0016 % Notes: 0017 % - NOTE 1: 'varied' can be specified in two ways: 0018 % - Method 1: a way similar to 'vary' in dsSimulate and 0019 % dsVary2Modifications. However, instead of indicating values for a variable to 0020 % take, 'varied' involves the specification of a range of values. Syntax: 0021 % vary={object, variable, [low,high]; ...}, where low is the lower bound on 0022 % the range varied and high is the upper bound for the component varied. For 0023 % instance, if 'gNa' in population 'E' was varied 0:.1:1 by setting 'vary' to 0024 % {'E','gNa',0:.1:1}, then to select the subset of gNa values between .3 and 0025 % .5, set 'varied' to {'E','gNa',[.3 .5]}. 0026 % - Method 2: 'varied' can be specified using the resulting component name 0027 % stored in data.varied. e.g., {'E_iNa_gNa',[.3 .5]}. 0028 % 0029 % - NOTE 2: if 'varied' values are requested and not a two-element array (e.g., 0030 % [.3 .5]), then return all matching values. 0031 % 0032 % Examples: 0033 % % return simulated data from 20-80ms 0034 % data=dsSelect(data,'time_limits',[20 80]); 0035 % % return data sets with gNa set between .3 and .5 0036 % data=dsSelect(data,'varied',{'E','gNa',[.3 .5]}); 0037 % data=dsSelect(data,'time_limits',[20 80],'varied',{'E','gNa',[.3 .5]}); 0038 % data=dsSelect(data,'roi',{'E_v',[1 4]}); 0039 % 0040 % TODO: 0041 % - Specify subsets to return in terms of ROIs: {'E',1:50;'I',1:10,'F',[]} 0042 % (exclude F) (default all cells for any pops not specified in ROIs). 0043 % - Possible format for specifying range_varied: 0044 % {'E','gNa',[.1 .3]; 'I->E','tauI',[15 25]; 'I','mechanism_list','+iM'} 0045 % 0046 % See also: dsSimulate, dsVary2Modifications, dsImport 0047 % 0048 % Author: Jason Sherfey, PhD <jssherfey@gmail.com> 0049 % Copyright (C) 2016 Jason Sherfey, Boston University, USA 0050 0051 % check inputs 0052 data=dsCheckData(data, varargin{:}); 0053 0054 options=dsCheckOptions(varargin,{... 0055 'time_limits',[-inf inf],[],... 0056 'varied',[],[],... 0057 'roi',[],[],... 0058 },false); 0059 0060 % select data sets based on range of varied model components 0061 if ~isempty(options.varied) && isfield(data,'varied') 0062 if size(options.varied,2)==3 0063 % convert into field name (set in dsSimulate:prepare_varied_metadata) 0064 % NOTE: this code is redundant with dsSimulate and dsAnalyze. 0065 % TODO: eliminate redundancy 0066 varied={}; 0067 for i=1:size(options.varied,1) 0068 % prepare valid field name for thing varied: 0069 fld=[options.varied{i,1} '_' options.varied{i,2}]; 0070 % convert arrows and periods to underscores 0071 fld=regexprep(fld,'(->)|(<-)|(-)|(\.)','_'); 0072 % remove brackets and parentheses 0073 fld=regexprep(fld,'[\[\]\(\)\{\}]',''); 0074 varied{end+1,1}=fld; 0075 end 0076 options.varied=cat(2,varied,options.varied(:,3)); 0077 end 0078 if size(options.varied,1)>1 0079 error('at present, a range on only one varied parameter can be specified per call to dsSelect.'); 0080 end 0081 if ~ismember(options.varied{1,1},data(1).varied) 0082 error('varied parameter not found in data.varied'); 0083 end 0084 % collect info on parameters varied in data 0085 varied=data(1).varied; 0086 num_varied=length(varied); % number of model components varied across simulations 0087 num_sims=length(data); 0088 % collect info on parameters varied 0089 param_mat=zeros(num_sims,num_varied); % values for each simulation 0090 for j=1:num_varied 0091 if isnumeric(data(1).(varied{j})) 0092 param_mat(:,j)=[data.(varied{j})]; % sims x varied 0093 else 0094 % TODO: handle sims varying non-numeric model components 0095 % (eg, mechanisms) (also in dsPlot) 0096 end 0097 end 0098 % find element of 'varied' whose range has been requested 0099 desired_param=options.varied{1,1}; 0100 desired_range=options.varied{1,2}; 0101 index=find(ismember(data(1).varied,desired_param)); 0102 % find simulations with varied values in desired range 0103 if length(desired_range)==2 0104 sel=find(param_mat(:,index)>=desired_range(1)¶m_mat(:,index)<=desired_range(2)); 0105 else 0106 sel=find(ismember(param_mat(:,index),desired_range)); 0107 end 0108 % select the desired subset of data sets 0109 data=data(sel); 0110 end 0111 0112 % % recursively call dsSelect if more than one data set 0113 % if length(data)>1 0114 % for i=1:length(data) 0115 % data(i)=dsSelect(data(i)); 0116 % end 0117 % return; 0118 % end 0119 0120 for s=1:length(data) 0121 % select time subset from state variables and monitors 0122 time=data(s).time; 0123 seltime=time>=options.time_limits(1) & time<=options.time_limits(2); 0124 for i=1:length(data(s).labels) 0125 data(s).(data(s).labels{i})=data(s).(data(s).labels{i})(seltime,:); 0126 end 0127 % select cell subset 0128 if iscell(options.roi) 0129 for i=1:size(options.roi,1) 0130 if isfield(data,options.roi{i,1}) 0131 dat=data(s).(options.roi{i,1}); 0132 inds=1:size(dat,2); 0133 borders=options.roi{i,2}; 0134 sel=inds>=borders(1)&inds<=borders(end); 0135 data(s).(options.roi{i,1})=dat(:,sel); 0136 end 0137 end 0138 end 0139 end 0140 0141 % TODO: select subset from time-varying post-processed results 0142 if isfield(data,'results') 0143 % get time vectors: time_(*) with * matching matching names in data.results 0144 % ... 0145 0146 end 0147