0001 function [data,stats] = SurveyPhasePrecession(group,clusters,channel,subsessions,varargin)
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
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050 if nargin < 3,
0051 error('Incorrect number of parameters (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0052 end
0053
0054
0055 if nargin < 4 || ~isivector(subsessions),
0056 if nargin >= 4, varargin = {subsessions,varargin{:}}; end
0057 subsessions = [];
0058 end
0059 figs = 'multiple';
0060 minv = 0;
0061 track = 'linear';
0062 linearize = '';
0063 show = 'on';
0064 slopes = [];
0065 nBins = 200;
0066
0067
0068 if clusters == -1,
0069 units = GetUnits(group);
0070 clusters = units(:,2);
0071 end
0072
0073 if mod(length(varargin),2) ~= 0,
0074 error('Incorrect number of parameters (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0075 end
0076
0077
0078 for i = 1:2:length(varargin),
0079 if ~ischar(varargin{i}),
0080 error(['Parameter ' num2str(i+1) ' is not a property (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).']);
0081 end
0082 switch(lower(varargin{i})),
0083 case 'linearize',
0084 linearize = lower(varargin{i+1});
0085 if isa(linearize,'function_handle'),
0086 linearize = func2str(linearize);
0087 end
0088 if ~ischar(linearize) || isempty(which(linearize)),
0089 error('Incorrect value for property ''linearize'' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0090 end
0091 case 'minv',
0092 minv = varargin{i+1};
0093 if ~isdscalar(minv,'>=0'),
0094 error('Incorrect value for property ''minv'' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0095 end
0096 case 'pixel',
0097 pixel = varargin{i+1};
0098 if ~isdscalar(pixel,'>0'),
0099 error('Incorrect value for property ''pixel'' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0100 end
0101 case 'figures',
0102 figs = lower(varargin{i+1});
0103 if ~isastring(figs,'single','multiple'),
0104 error('Incorrect value for property ''figs'' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0105 end
0106 case 'track',
0107 track = lower(varargin{i+1});
0108 if ~isastring(track,'linear','circular'),
0109 error('Incorrect value for property ''track'' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0110 end
0111 case 'slopes',
0112 slopes = varargin{i+1};
0113 if ~isdvector(slopes),
0114 error('Incorrect value for property ''slopes'' (type ''help <a href="matlab:help CircularRegression">PhasePrecession</a>'' for details).');
0115 end
0116 case 'show',
0117 show = varargin{i+1};
0118 if ~isastring(show,'on','off'),
0119 error('Incorrect value for property ''show'' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).');
0120 end
0121 otherwise,
0122 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help SurveyPhasePrecession">SurveyPhasePrecession</a>'' for details).']);
0123 end
0124 end
0125
0126
0127 linearize = GetCustomDefaults(linearize,'linearize','');
0128 pixel = GetCustomDefaults(pixel,'pixel','');
0129 minv = GetCustomDefaults(minv,'minv','');
0130
0131
0132 phase = Recall('phase',channel);
0133 if isempty(phase);
0134 lfp = GetLFP(channel);
0135 fil = FilterLFP(lfp,'passband','theta');
0136 phase = Phase(fil);
0137 Store(phase,'phase',channel);
0138 end
0139
0140
0141 positions = GetPositions;
0142 if isempty(linearize),
0143 warning('No linearization function provided - using position abscissae (ignoring ordinates).');
0144 x = positions(:,1:2);
0145 else
0146 x = feval(linearize,positions);
0147 end
0148 if minv ~= 0,
0149 if isempty(pixel),
0150 error(['Missing pixel size for minimum velocity (type ''help <a href="matlab:help SurveyFiringMaps">SurveyPhasePrecession</a>'' for details).']);
0151 end
0152 v = LinearVelocity(GetPositions('coordinates','real','pixel',pixel),30);
0153 [~,in] = Threshold(v,'>',minv,'min',10,'max',1);
0154 x = x(in,:);
0155 end
0156
0157
0158 start = GetEvents('beginning of .*');
0159 stop = GetEvents('end of .*');
0160
0161
0162 if isempty(subsessions),
0163 subsessions = 1:length(start);
0164 end
0165 nSubsessions = length(subsessions);
0166 if isempty(slopes),
0167 slopes = zeros(size(subsessions));
0168 elseif length(slopes) ~= length(subsessions),
0169 error('Slopes and subsessions do not have the same length (type ''help <a href="matlab:help CircularRegression">PhasePrecession</a>'' for details).');
0170 end
0171
0172
0173 if strcmp(show,'on'),
0174 titles = GetEventTypes('beginning of .*');
0175 n = floor(sqrt(nSubsessions));
0176 m = ceil(nSubsessions/n);
0177 if strcmp(figs,'single'),
0178 titleWidth = floor(130/nSubsessions);
0179 else
0180 titleWidth = 130;
0181 end
0182 figureList = [];
0183 status = Hide('status');
0184 Hide('on');
0185 end
0186
0187 try
0188 k = 0;
0189
0190 for c = 1:length(clusters),
0191
0192 cluster = clusters(c);
0193 spikes = GetSpikes([group cluster]);
0194 if strcmp(show,'on') && strcmp(figs,'single'),
0195 figureList = [figureList figure];
0196 end
0197
0198
0199 for i = 1:nSubsessions,
0200 subsession = subsessions(i);
0201
0202 subsessionSpikes = Restrict(spikes,[start(subsession) stop(subsession)]);
0203 if size(subsessionSpikes,1) < 50,
0204 continue;
0205 end
0206 subsessionX = Restrict(x,[start(subsession) stop(subsession)]);
0207 if isempty(subsessionX), continue; end
0208
0209
0210 subsessionPhase = Restrict(phase,[start(subsession) stop(subsession)]);
0211 [d,st] = PhasePrecession(subsessionX,subsessionSpikes,subsessionPhase,'slope',slopes(i));
0212 st.unit = [group cluster];
0213 st.subsession = i;
0214 st.channel = channel;
0215 k = k + 1;
0216 data(k) = d;
0217 stats(k) = st;
0218 if strcmp(show,'on'),
0219 if strcmp(figs,'single'),
0220 p = Subpanel(n,m,i);
0221 else
0222 figureList = [figureList figure];
0223 p = Subpanel(1,1,1);
0224 end
0225
0226 name = [titles{subsession}(14:end) ' (' int2str(group) '-' int2str(cluster) ')'];
0227 SplitTitle(p,name,titleWidth);
0228 PlotPhasePrecession(d,st,'parent',p,'track',track);
0229 end
0230 end
0231 end
0232 catch err
0233 if strcmp(show,'on'),
0234 Hide(status);
0235 Hide(figureList,status);
0236 end
0237 err.rethrow;
0238 end
0239
0240 if strcmp(show,'on'),
0241 Hide(status);
0242 Hide(figureList,status);
0243 end