Home > FMAToolbox > Analyses > SurveyPhasePrecession.m

SurveyPhasePrecession

PURPOSE ^

SurveyPhasePrecession - Compute and plot phase precession plots for all subsessions.

SYNOPSIS ^

function [data,stats] = SurveyPhasePrecession(group,clusters,channel,subsessions,varargin)

DESCRIPTION ^

SurveyPhasePrecession - Compute and plot phase precession plots for all subsessions.

  USAGE

    [data,stats] = SurveyPhasePrecession(group,clusters,channel,subsessions,<options>)

    group          electrode group (e.g. tetrode ID)
    clusters       list of cluster IDs
    channel        channel ID for LFP
    subsessions    optional list of subsession numbers
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'linearize'   linearization function name or handle
     'minv'        minimum instantaneous velocity (default = 0)
     'pixel'       size of the video pixel in cm (no default value)
     'track'       'linear' or 'circular' (default = 'linear')
     'show'        set to 'off' to compute but not plot data (default = 'on')
     'figures'     for each cluster, group all plots on one single figure
                   ('single') or create one figure per subsession ('multiple',
                   default)
     'slopes'      search start value for slopes (default = 0) for each
                   subsession
    =========================================================================

  OUTPUT

    The outputs are the same as for <a href="matlab:help PhasePrecession">PhasePrecession</a>.

  CUSTOM DEFAULTS

    Poperties 'linearize', 'pixel' and 'minv' can have custom default values
    (type 'help <a href="matlab:help CustomDefaults">CustomDefaults</a>' for details).

  SEE

    See also PhasePrecession, PlotPhasePrecession.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [data,stats] = SurveyPhasePrecession(group,clusters,channel,subsessions,varargin)
0002 
0003 %SurveyPhasePrecession - Compute and plot phase precession plots for all subsessions.
0004 %
0005 %  USAGE
0006 %
0007 %    [data,stats] = SurveyPhasePrecession(group,clusters,channel,subsessions,<options>)
0008 %
0009 %    group          electrode group (e.g. tetrode ID)
0010 %    clusters       list of cluster IDs
0011 %    channel        channel ID for LFP
0012 %    subsessions    optional list of subsession numbers
0013 %    <options>      optional list of property-value pairs (see table below)
0014 %
0015 %    =========================================================================
0016 %     Properties    Values
0017 %    -------------------------------------------------------------------------
0018 %     'linearize'   linearization function name or handle
0019 %     'minv'        minimum instantaneous velocity (default = 0)
0020 %     'pixel'       size of the video pixel in cm (no default value)
0021 %     'track'       'linear' or 'circular' (default = 'linear')
0022 %     'show'        set to 'off' to compute but not plot data (default = 'on')
0023 %     'figures'     for each cluster, group all plots on one single figure
0024 %                   ('single') or create one figure per subsession ('multiple',
0025 %                   default)
0026 %     'slopes'      search start value for slopes (default = 0) for each
0027 %                   subsession
0028 %    =========================================================================
0029 %
0030 %  OUTPUT
0031 %
0032 %    The outputs are the same as for <a href="matlab:help PhasePrecession">PhasePrecession</a>.
0033 %
0034 %  CUSTOM DEFAULTS
0035 %
0036 %    Poperties 'linearize', 'pixel' and 'minv' can have custom default values
0037 %    (type 'help <a href="matlab:help CustomDefaults">CustomDefaults</a>' for details).
0038 %
0039 %  SEE
0040 %
0041 %    See also PhasePrecession, PlotPhasePrecession.
0042 
0043 % Copyright (C) 2009-2013 by Anne Cei, Michaƫl Zugaro
0044 %
0045 % This program is free software; you can redistribute it and/or modify
0046 % it under the terms of the GNU General Public License as published by
0047 % the Free Software Foundation; either version 3 of the License, or
0048 % (at your option) any later version.
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 % Default values
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 % Unit list
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 % Parse options
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 % Customizable defaults (if not already set)
0127 linearize = GetCustomDefaults(linearize,'linearize','');
0128 pixel = GetCustomDefaults(pixel,'pixel','');
0129 minv = GetCustomDefaults(minv,'minv','');
0130 
0131 % Do we need to compute phases or can we restore them from a previous run?
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 % Get and linearize positions,
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 % Get events
0158 start = GetEvents('beginning of .*');
0159 stop = GetEvents('end of .*');
0160 
0161 % Sessions
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 % Figure information
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     % Loop through units
0190     for c = 1:length(clusters),
0191         % Get spikes for this cluster
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         % Loop through subsessions
0199         for i = 1:nSubsessions,
0200             subsession = subsessions(i);
0201             % Restrict data to this subsession
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     %  f=gcf;figureList = [figureList figure];PlotXY(subsessionX);figure(f);
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                 % Title
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

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005