-
Notifications
You must be signed in to change notification settings - Fork 0
/
dfs_positionvariance.m
146 lines (135 loc) · 7.22 KB
/
dfs_positionvariance.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
%% Neurofeedback: variance in tracked position while at center ports
% control and manipulation cohorts
animals = {'jaq','roquefort','despereaux','montague','remy','gus','bernard','fievel'};
epochfilter{1} = ['isequal($cond_phase,''plateau'') & isequal($environment,''goal'') ']; %cond rats
epochfilter{2} = ['$ripthresh==0 & (isequal($environment,''goal'')) & $forageassist==0 ']; % for control rats
% resultant excludeperiods will define times when velocity is high
timefilter{1} = {'ag_get2dstate', '($immobility == 1)','immobility_velocity',4,'immobility_buffer',0};
iterator = 'epochbehaveanal';
f = createfilter('animal',animals,'epochs',epochfilter,'excludetime', timefilter, 'iterator', iterator);
f = setfilterfunction(f, 'dfa_positionvariance', {'pos','trials'});
f = runfilter(f);
animcol = [123 159 242; 66 89 195; 33 42 165; 6 1 140; 254 123 123; 255 82 82; 255 0 0; 168 1 0; 148 148 148; 115 115 115; 82 82 82; 49 49 49]./255; %ctrlcols
%% Plot mean x and y std during pre-reward
clearvars -except f animals animcol
for a = 1:length(animals)
if a<=4
when=2;
rwdata = arrayfun(@(x) x.rw',f(a).output{when},'UniformOutput',0); % stack data from all trials
rwdata = vertcat(rwdata{:});
type = cellfun(@(x) x.type,rwdata);
meanvel_rip{a} = cellfun(@(x) x.meanvel,rwdata(type>=1));
meanvel_wait{a} = meanvel_rip{a};
stdvel_rip{a} = cellfun(@(x) x.stdvel,rwdata(type>=1));
stdvel_wait{a} = stdvel_rip{a};
std_x_rip{a} = cellfun(@(x) x.std_x,rwdata(type>=1));
std_x_wait{a} = std_x_rip{a};
std_y_rip{a} = cellfun(@(x) x.std_y,rwdata(type>=1));
std_y_wait{a} = std_y_rip{a};
labels_rip{a} = [zeros(length(meanvel_rip{a}),1),a+zeros(length(meanvel_rip{a}),1)];
labels_wait{a} = labels_rip{a};
else
when=1;
rwdata = arrayfun(@(x) x.rw',f(a).output{when},'UniformOutput',0); % stack data from all trials
rwdata = vertcat(rwdata{:});
type = cellfun(@(x) x.type,rwdata);
meanvel_rip{a} = cellfun(@(x) x.meanvel,rwdata(type==1));
meanvel_wait{a} = cellfun(@(x) x.meanvel,rwdata(type==2));
stdvel_rip{a} = cellfun(@(x) x.stdvel,rwdata(type==1));
stdvel_wait{a} = cellfun(@(x) x.stdvel,rwdata(type==2));
std_x_rip{a} = cellfun(@(x) x.std_x,rwdata(type==1));
std_x_wait{a} = cellfun(@(x) x.std_x,rwdata(type==2));
std_y_rip{a} = cellfun(@(x) x.std_y,rwdata(type==1));
std_y_wait{a} = cellfun(@(x) x.std_y,rwdata(type==2));
labels_rip{a} = [ones(length(meanvel_rip{a}),1),a+zeros(length(meanvel_rip{a}),1)];
labels_wait{a} = [ones(length(meanvel_wait{a}),1),a+zeros(length(meanvel_wait{a}),1)];
end
end
figure;
subplot(2,2,1); hold on
allrat_lmeplot(meanvel_rip,meanvel_wait,labels_rip,labels_wait,'spacer',[2 10])
ylabel('Vel (cm/s)');title('meanvel pre-rew'); ylim([0 4]);
subplot(2,2,2); hold on
allrat_lmeplot(stdvel_rip,stdvel_wait,labels_rip,labels_wait,'spacer',[2 10])
ylabel('std vel (cm/s)');title('std vel pre-rew'); ylim([0 4]);
subplot(2,2,3); hold on
allrat_lmeplot(std_x_rip,std_x_wait,labels_rip,labels_wait,'spacer',[1 10])
ylabel('Std of pos (cm)');title('Std of x pos (front to back)'); xlim([.5 9.5]); ylim([0 2]);
subplot(2,2,4); hold on
allrat_lmeplot(std_y_rip,std_y_wait,labels_rip,labels_wait,'spacer',[1 10])
ylabel('Std of pos (cm)');title('Std of Y pos (side to side)'); xlim([.5 9.5]); ylim([0 2]);
%% plot velocity traces aligned to start
clearvars -except f animals animcol
figure;
for a = 1:length(animals)
if a<=4
when=2;
rwdata = arrayfun(@(x) x.rw',f(a).output{when},'UniformOutput',0); % stack data from all trials
rwdata = vertcat(rwdata{:});
type = cellfun(@(x) x.type,rwdata);
veltrace_rip{a} = cellfun(@(x) x.veltrace,rwdata(type>=1),'un',0);
eval(['ax',num2str(a),'=subplot(12,1,',num2str(a),');']); hold on;
cellfun(@(x) plot(x,'b'),veltrace_rip{a}(1:10));
xlim([0 500]); ylim([0 15]);
else a>4
when=1;
rwdata = arrayfun(@(x) x.rw',f(a).output{when},'UniformOutput',0); % stack data from all trials
rwdata = vertcat(rwdata{:});
type = cellfun(@(x) x.type,rwdata);
veltrace_rip{a} = cellfun(@(x) x.veltrace,rwdata(type==1),'un',0);
eval(['ax',num2str(a),'=subplot(12,1,',num2str(a),');']); hold on;
cellfun(@(x) plot(x,'r'),veltrace_rip{a}(1:10)); xlim([0 500]); ylim([0 15]);
veltrace_wait{a} = cellfun(@(x) x.veltrace,rwdata(type==2),'un',0);
eval(['ax',num2str(a+4),'=subplot(12,1,',num2str(a+4),');']); hold on;
cellfun(@(x) plot(x,'k'),veltrace_wait{a}(1:10)); xlim([0 500]); ylim([0 15]);
end
end
linkaxes([ax1,ax2,ax3,ax4,ax5,ax6,ax7,ax8,ax9,ax10,ax11,ax12],'xy')
%% Plot mean x and y std during post-reward
clearvars -except f animals animcol
for a = 1:length(animals)
if a<=4
when=2;
rwdata = arrayfun(@(x) x.postrw',f(a).output{when},'UniformOutput',0); % stack data from all trials
rwdata = vertcat(rwdata{:});
type = cellfun(@(x) x.type,rwdata);
meanvel_rip{a} = cellfun(@(x) x.meanvel,rwdata(type>=1));
meanvel_wait{a} = meanvel_rip{a};
stdvel_rip{a} = cellfun(@(x) x.stdvel,rwdata(type>=1));
stdvel_wait{a} = stdvel_rip{a};
std_x_rip{a} = cellfun(@(x) x.std_x,rwdata(type>=1));
std_x_wait{a} = std_x_rip{a};
std_y_rip{a} = cellfun(@(x) x.std_y,rwdata(type>=1));
std_y_wait{a} = std_y_rip{a};
labels_rip{a} = [zeros(length(meanvel_rip{a}),1),a+zeros(length(meanvel_rip{a}),1)];
labels_wait{a} = labels_rip{a};
else
when=1;
rwdata = arrayfun(@(x) x.postrw',f(a).output{when},'UniformOutput',0); % stack data from all trials
rwdata = vertcat(rwdata{:});
type = cellfun(@(x) x.type,rwdata);
meanvel_rip{a} = cellfun(@(x) x.meanvel,rwdata(type==1));
meanvel_wait{a} = cellfun(@(x) x.meanvel,rwdata(type==2));
stdvel_rip{a} = cellfun(@(x) x.stdvel,rwdata(type==1));
stdvel_wait{a} = cellfun(@(x) x.stdvel,rwdata(type==2));
std_x_rip{a} = cellfun(@(x) x.std_x,rwdata(type==1));
std_x_wait{a} = cellfun(@(x) x.std_x,rwdata(type==2));
std_y_rip{a} = cellfun(@(x) x.std_y,rwdata(type==1));
std_y_wait{a} = cellfun(@(x) x.std_y,rwdata(type==2));
labels_rip{a} = [ones(length(meanvel_rip{a}),1),a+zeros(length(meanvel_rip{a}),1)];
labels_wait{a} = [ones(length(meanvel_wait{a}),1),a+zeros(length(meanvel_wait{a}),1)];
end
end
figure;
subplot(2,2,1); hold on
allrat_lmeplot(meanvel_rip,meanvel_wait,labels_rip,labels_wait,'spacer',[2 10])
ylabel('Vel (cm/s)');title('meanvel post-rew'); ylim([0 4]);
subplot(2,2,2); hold on
allrat_lmeplot(stdvel_rip,stdvel_wait,labels_rip,labels_wait,'spacer',[2 10])
ylabel('std vel (cm/s)');title('std vel post-rew'); ylim([0 4]);
subplot(2,2,3); hold on
allrat_lmeplot(std_x_rip,std_x_wait,labels_rip,labels_wait,'spacer',[1 10])
ylabel('Std of pos (cm)');title('Std of x pos (front to back)'); xlim([.5 9.5]); ylim([0 2]);
subplot(2,2,4); hold on
allrat_lmeplot(std_y_rip,std_y_wait,labels_rip,labels_wait,'spacer',[1 10])
ylabel('Std of pos (cm)');title('Std of Y pos (side to side)'); xlim([.5 9.5]); ylim([0 2]);