-
Notifications
You must be signed in to change notification settings - Fork 0
/
NEU422_HW2_analysis.m
124 lines (113 loc) · 3.42 KB
/
NEU422_HW2_analysis.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
%NEU422_HW2_analysis
%% sequence model
N = 50;
A = eye(N);
A = A(randperm(N),:);
imagesc(A)
observeNetworkActivity(A);
sigma = 0.3;
AA = A+randn(N,N)*sigma;
AA(AA>1) = 1;
AA(AA<0) = 0;
observeNetworkActivity(A);
learnWeights;
%% Neural dynamics in data
load('/Users/Macintosh/Desktop/fiete_sim-master/k55_20160613_RSM.mat')
%% Behavioral correlation
window = 110;
acs = 20;
lefturn = [];
righturn = [];
for tr = 1:size(trials,1)
thistrial = trials(tr);
if thistrial.goodQuality==1 && thistrial.mainTrial==1
pos = thistrial.fArmEntry;
%at the arm entry point, we can check the position or velocity, and
%sort with choice or types of trials
if thistrial.choice=='L' %thistrial.trialType=='L' %
lefturn = [lefturn; data.velocity(pos-window:pos+acs)];
%lefturn = [lefturn; data.position(pos-window:pos+acs)];
end
if thistrial.choice=='R' %thistrial.trialType=='R' %
righturn = [righturn; data.velocity(pos-window:pos+acs)];
%righturn = [righturn; data.position(pos-window:pos+acs)];
end
end
end
dt = mean(diff(data.time));
plot(-window*dt:dt:acs*dt,lefturn','r')
hold on
plot(-window*dt:dt:acs*dt,righturn','b')
xlabel('time to arm entry')
ylabel('velocity')
%% Task/choice-modulated transients
window = 110;
acs = 20;
temp = [];
index = 0;
for tr = 1:size(trials,1)
thistrial = trials(tr);
if thistrial.goodQuality==1 && thistrial.mainTrial==1
if thistrial.correctChoice==1 %choice-specific
pos = thistrial.fCueEntry; %task structure
temp = [temp; data.DFF(pos-window:pos+acs,:)'];
index = index+1;
end
end
end
%%%temp is trials*neurons X time
temp = reshape(temp, index,size(temp,1)/index,size(temp,2));
%%%now Raster is tiral X neurons X time
Raster = squeeze(nanmean(temp,1));
dt = mean(diff(data.time));
imagesc(-window*dt:dt:acs*dt,1:size(Raster,1),Raster)
xlabel('time to arm entry')
ylabel('cell ID')
%% find specific cells
prefcell = [];
criteria = 5;
for nn = 1:size(data.DFF,2)
tempL = []; tempR = [];
for tr = 1:size(trials,1)
thistrial = trials(tr);
if thistrial.goodQuality==1 && thistrial.mainTrial==1
pos = thistrial.fMemEntry;
if thistrial.choice=='L'; tempL = [tempL; nanmean(data.DFF(pos-window:pos+acs,nn))]; end;
if thistrial.choice=='R'; tempR = [tempR; nanmean(data.DFF(pos-window:pos+acs,nn))]; end;
end
end
%if nanmean(tempL)/nanvar(tempL) > criteria*nanmean(tempR)/nanvar(tempR)
% prefcell = [prefcell nn];
%end
prefcell = [prefcell nanmean(tempL)/(nanmean(tempL)+nanmean(tempR))];
end
%% plotting
cellid = 198; %260
trialss= [];
for tr = 1:size(trials,1)
thistrial = trials(tr);
if thistrial.goodQuality==1 && thistrial.mainTrial==1
%if thistrial.correctChoice==1 %choice-specific
if thistrial.choice=='L'
pos = thistrial.fMemEntry; %task structure
trialss = [trialss; data.DFF(pos-window:pos+acs,cellid)'];
end
end
end
imagesc(-window*dt:dt:acs*dt,1:size(trialss,1),trialss)
xlabel('trials')
ylabel('dF/F')
figure();
plot(-window*dt:dt:acs*dt,nanmean(trialss,1))
xlabel('trials')
ylabel('dF/F')
%% Neural sequences
selected = find(prefcell>0.5);
[a,b] = max(Raster(selected,:)');
[aa,bb] = sort(b);
imagesc(Raster(selected(bb),:))
%%%z-scoring
temp = Raster(selected(bb),:);
temp = temp./var(temp');
imagesc(temp)
%% ...lower-dimension structure