0001 function turnDistribution = RadialMazeTurns(data,mode)
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 global RAT DAY TRIAL CONF GROUP ARM;
0035
0036 if nargin < 2,
0037 mode = 'preferred';
0038 else
0039 mode = lower(mode);
0040 end
0041
0042 nTrials = 3;
0043 nArms = 8;
0044 turnAngles = (-3:4)'*45;
0045 armAngles = mod(360-(2:9)'*45,360)-180;
0046
0047
0048 RAT = 1;
0049 DAY = 2;
0050 TRIAL = 3;
0051 CONF = 4;
0052 GROUP = 5;
0053 ARM = 6;
0054 arms = data(:,ARM);
0055 trials = data(:,TRIAL);
0056 rats = data(:,RAT);
0057 configurations = data(:,CONF);
0058 days = data(:,DAY);
0059 groups = data(:,GROUP);
0060
0061 if nargin < 1,
0062 error('Incorrect number of parameters (type ''help <a href="matlab:help RadialMazeTurns">RadialMazeTurns</a>'' for details).');
0063 end
0064
0065
0066
0067 turns = diff(data(:,ARM));
0068
0069 turns = mod(4-turns,8);
0070 turns(turns==0) = 8;
0071 turns = [0;turns];
0072
0073
0074
0075
0076 change_rat = diff(data(:,RAT)) ~= 0;
0077 change_configuration = diff(data(:,CONF)) ~= 0;
0078 change_day = diff(data(:,DAY)) ~= 0;
0079 change_trial = diff(data(:,TRIAL)) ~= 0;
0080 change = change_rat|change_configuration|change_day|change_trial;
0081 change = [true;change];
0082 valid = ~change;
0083
0084
0085 maxVisits = 5;
0086
0087
0088 nBlocks = 3;
0089 blocks = Bin(days,nBlocks);
0090
0091
0092 newTrial = [change;false];
0093 nVisits = diff([1;find(newTrial)]);
0094 visits = ones(size(change));
0095 visits(newTrial) = -nVisits+1;
0096 visits = cumsum(visits);
0097
0098 P = [];
0099 nGroups = max(groups);
0100 for group = 1:nGroups,
0101
0102 ratsInThisGroup = unique(rats(groups==group));
0103
0104 nRats = length(ratsInThisGroup);
0105 for r = 1:nRats,
0106 thisRat = rats==ratsInThisGroup(r);
0107 fig = figure('position',[1285 52 1272 890]);
0108 c1 = uicontainer('position',[0 0 1 0.85]);
0109 c2 = uicontainer('position',[0 0.85 1 0.08]);
0110 c3 = uicontainer('position',[0 0.93 1 0.07]);
0111
0112 nConfigurations = max(configurations);
0113 for configuration = 1:nConfigurations,
0114
0115 thisConfiguration = configurations==configuration;
0116
0117 for block = 1:nBlocks+1,
0118
0119 thisBlock = blocks==min([block nBlocks]);
0120
0121
0122 nVisitsInEachArm = hist(arms(thisRat&thisConfiguration&visits==1),1:8);
0123 [~,preferredArm] = max(nVisitsInEachArm);
0124
0125
0126 T = turns(valid&thisRat&thisConfiguration&thisBlock);
0127 N = visits(valid&thisRat&thisConfiguration&thisBlock)-1;
0128 if block == nBlocks+1,
0129 if strcmp(mode,'preferred'),
0130
0131 a = arms([valid(2:end,1);logical(1)]&thisRat&thisConfiguration&thisBlock);
0132 i = length(N);
0133 while i > 1,
0134 n = N(i);
0135 if a(i-n+1) ~= preferredArm,
0136 T(i-n+1:i)=[];
0137 N(i-n+1:i)=[];
0138 a(i-n+1:i)=[];
0139 end
0140 i = i - n;
0141 end
0142 elseif strcmp(mode,'non-preferred'),
0143
0144 a = arms([valid(2:end,1);logical(1)]&thisRat&thisConfiguration&thisBlock);
0145 i = length(N);
0146 while i > 1,
0147 n = N(i);
0148 if a(i-n+1) == preferredArm,
0149 T(i-n+1:i)=[];
0150 N(i-n+1:i)=[];
0151 a(i-n+1:i)=[];
0152 end
0153 i = i - n;
0154 end
0155 else
0156
0157 i = length(N);
0158 while i > 1,
0159 n = N(i);
0160 if n > maxVisits-1,
0161 T(i-n+1:i)=[];
0162 N(i-n+1:i)=[];
0163 end
0164 i = i - n;
0165 end
0166 end
0167 if length(T) < 2, continue; end
0168 end
0169 turnDistribution = Accumulate([T N],1,[8 max(N)]);
0170 nTurns = size(turnDistribution,2);
0171
0172
0173 A = arms(thisRat&thisConfiguration&thisBlock);
0174 V = visits(thisRat&thisConfiguration&thisBlock);
0175 if block == nBlocks+1,
0176 if strcmp(mode,'preferred'),
0177
0178 i = length(V);
0179 a = arms([valid(1,2:end);logical(1)]&thisRat&thisConfiguration&thisBlock);
0180 while i > 1,
0181 n = V(i);
0182 if a(i-n+1) ~= preferredArm,
0183 V(i-n+1:i)=[];
0184 A(i-n+1:i)=[];
0185 a(i-n+1:i)=[];
0186 end
0187 i = i - n;
0188 end
0189 elseif strcmp(mode,'non-preferred'),
0190
0191 a = arms([valid(2:end,1);logical(1)]&thisRat&thisConfiguration&thisBlock);
0192 i = length(N);
0193 while i > 1,
0194 n = N(i);
0195 if a(i-n+1) == preferredArm,
0196 V(i-n+1:i)=[];
0197 A(i-n+1:i)=[];
0198 a(i-n+1:i)=[];
0199 end
0200 i = i - n;
0201 end
0202 else
0203
0204 i = length(V);
0205 while i > 1,
0206 n = V(i);
0207 if n > maxVisits,
0208 V(i-n+1:i)=[];
0209 A(i-n+1:i)=[];
0210 end
0211 i = i - n;
0212 end
0213 end
0214 end
0215 armDistribution = Accumulate([A V],1,[8 max(V)]);
0216 nVisits = size(armDistribution,2);
0217 for i = 1:nVisits,
0218 subplot(1,nVisits*(nBlocks+1),i+(block-1)*nVisits,'parent',c3);hold on;
0219
0220 m = 1.5*max(armDistribution(:,i));
0221 tt = 0:0.01:2*pi;
0222 fill(m*cos(tt),m*sin(tt),'w');
0223
0224 h = rose(armAngles(A(V==i))*pi/180,(0:22.5:360)*pi/180);
0225 set(h,'color','k');
0226 xlim([-1 1]*m);
0227 ylim([-1 1]*m);
0228 axis square;axis off;
0229 end
0230
0231
0232 for i = 1:nTurns,
0233 subplot(1,nTurns*(nBlocks+1),i+(block-1)*nTurns,'parent',c2);hold on;
0234
0235 m = 1.5*max(turnDistribution(:,i));
0236 tt = 0:0.01:2*pi;
0237 fill(m*cos(tt),m*sin(tt),'w');
0238
0239 h = rose(turnAngles(T(N==i))*pi/180,(0:22.5:360)*pi/180);
0240
0241
0242
0243
0244 p = circ_rtest(turnAngles(T(N==i))*pi/180);
0245 if p < 0.05, set(h,'color','r'); end
0246 if block == nBlocks+1,
0247 P = [P;p i group];
0248 end
0249 xlim([-1 1]*m);
0250 ylim([-1 1]*m);
0251 axis square;axis off;
0252 end
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264 subplot(2,4,block,'parent',c1);
0265 colormap(jet(6));
0266 image(1:size(turnDistribution,2),(-3:4)*45,turnDistribution+1);
0267 caxis([0 6]);set(gca,'ydir','normal','ytick',(-3:4)*45);
0268
0269
0270 subplot(2,4,block,'parent',c1);
0271 hold on;
0272 start = [find(N==1);length(N)+1];
0273 for i = 1:length(start)-1,
0274 k = start(i):start(i+1)-1;
0275 plot(N(k),turnAngles(T(k))+rand(length(k),1)*15,'w','LineWidth',2);
0276 end
0277
0278
0279 subplot(2,4,4+block,'parent',c1);
0280 hold on;
0281 start = [find(N==1);length(N)+1];
0282 for i = 1:length(start)-1,
0283 x = turnAngles(T(start(i):start(i+1)-2));
0284 y = turnAngles(T(start(i)+1:start(i+1)-1));
0285 plot(x+rand(length(x),1)*15,y+rand(length(x),1)*15,'k.-','LineWidth',1,'MarkerSize',12);
0286 end
0287
0288
0289 subplot(2,4,4+block,'parent',c1);xlim([-155 200]);ylim([-155 200]);
0290 set(gca,'xtick',turnAngles,'ytick',turnAngles);
0291 end
0292 end
0293 xlabel(['Group ' int2str(group) ' - Rat ' int2str(ratsInThisGroup(r)) ' [' mode ']']);
0294 end
0295 end
0296
0297 figure;hold on;
0298 colors = 'rbkgmy';
0299 for group = 1:nGroups,
0300 p = P(P(:,3)==group,:);
0301 plot((p(:,3)-1)*10+p(:,2),p(:,1),colors(group),'marker','.','markersize',16,'linestyle','none');
0302 end
0303 xlim([0 nGroups*10]);
0304 PlotHVLines(0.05,'h',':');