-
Notifications
You must be signed in to change notification settings - Fork 0
/
findgoodexampletraces_Armin.m
207 lines (138 loc) · 7.65 KB
/
findgoodexampletraces_Armin.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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
% get trial #s where that trial and the subsequent 7 trials are varied and
% potentially good for example Ca traces =)
clear all
close all
% --------- enter reqs -----------------------------
% animal_name = 'MMM009'
% exp_date = '2019-03-12'
% exp_series ='2';
animal_name = 'ALK078'
exp_ID = '23'
smooth_factor = 50;
desired_contrasts = [1, 0.5, -0.25];
trial_seq_n = 5; %must be equal to or more tha number of desired contrasts
% --------------------------------------------------
sample_rate = 12000; % photoM recording sampling rate
downsampleScale = 10; % factor downsampling the Ca responses
scale = sample_rate/downsampleScale; % for use in plotting
load('MiceExpInfoPhotoM') % load beh data databse
[animal_ID, chan_order] =Salvatore_Get_chan_order(animal_name); %get animal ID
%path2Beh= ['\\zubjects.cortexlab.net\Subjects\',animal_name,'\',exp_date,'\',exp_series]; addpath (genpath(path2Beh)) %add path to beh
%path2photoM= ['\\zubjects.cortexlab.net\Subjects\',animal_name,'\',exp_date,'\photoM']; addpath (genpath(path2photoM)) %add path to photom
path2data = ['\\zubjects.cortexlab.net\Subjects\',animal_name];
addpath(genpath(path2data))
[SessionList] = getSessionList_photoM(animal_name, exp_ID);
for iSession = SessionList
if isfield (MiceExpInfo.mice(animal_ID).session(iSession), 'Chan4') % if mouse is bi hem
if MiceExpInfo.mice(animal_ID).session(iSession).Chan2(1) == 'L'
chan_ori = 'LR';
elseif MiceExpInfo.mice(animal_ID).session(iSession).Chan2(1) == 'R'
chan_ori = 'RL';
end
else
chan_ori = 1; %if mouse is uni hem
end
exp_date = MiceExpInfo.mice(animal_ID).session(iSession).Blockname(1:10);
exp_series = MiceExpInfo.mice(animal_ID).session(iSession).Blockname(12);
% extract aligned wheel trace :
[WheelTime,WheelMove] = Salvatore_AlignWheelPhotoM(animal_name, exp_date, exp_series);
TrialTimingData = MiceExpInfo.mice(animal_ID).session(iSession).TrialTimingData; %load trial timing data
%desired_contrasts =unique(TrialTimingData(:,2))';
Stimz=unique(TrialTimingData(:,2))'; % stims for that session
photoMFileName=MiceExpInfo.mice(animal_ID).session(iSession).Neuronfile(1:end-4);% load photoM data
load(photoMFileName);
% TimeStamps=photoMdata.Time_s_; % get time stamps
TimeStamps = photoMdata.Time_s_;
ds_TimeStamps = downsample(TimeStamps, 10);
trials2return = [];
for i = 1: length(TrialTimingData)-trial_seq_n+1
match = 0;
tempTrialz = unique(TrialTimingData(i:i+(trial_seq_n-1), 2)); %trials to test
for contrast = 1: length(tempTrialz)
if max(ismember(desired_contrasts, tempTrialz(contrast))) % is this trial's contrast in the desired contrasts list ?
match = match + 1;
end
end
if match == length(desired_contrasts)
trials2return = [trials2return;i];
end
end
trials2return %#ok<NOPTS>
trials2return(trials2return==1)=[];
%% figs each have 4 example traces
for ihem = 1:numel(chan_ori)
itrial = 0;
if ihem == 1
DeltaFoverF = photoMdata.AnalogIn_2_dF_F0; % get DF/F trace data
sm_ds_DeltaFoverF = smooth(downsample(DeltaFoverF,10),smooth_factor);
brain_region = MiceExpInfo.mice(animal_ID).session(iSession).Chan2(end-2:end);
elseif ihem == 2
DeltaFoverF = [];
DeltaFoverF = photoMdata.AnalogIn_4_dF_F0; % get DF/F trace data
sm_ds_DeltaFoverF = smooth(downsample(DeltaFoverF,10),smooth_factor);
brain_region = MiceExpInfo.mice(animal_ID).session(iSession).Chan4(end-2:end);
end
for ifig = 1:ceil(length(trials2return)/4) % loop thru figs
figure
for iplot = 1:4 % loop thru subplots
itrial = itrial +1;
if itrial > length(trials2return)
continue
end
subplot(4, 1, iplot)
start_s = floor(TrialTimingData(trials2return(itrial), 12)) - 1;
end_s = ceil(TrialTimingData(trials2return(itrial)+trial_seq_n-1, 14)) + 1;
% plot(ds_TimeStamps,sm_ds_DeltaFoverF,'color', [0.25 0.25 0.25]) %plot df/f between start -> end time
ymax = 1.9 * max(sm_ds_DeltaFoverF(scale*start_s:scale*end_s));
ymin = 0.4 * min(sm_ds_DeltaFoverF(scale*start_s:scale*end_s));
hold on
WheelStart= find(floor(100*WheelTime)/100==start_s,1);
WheelEnd = find(floor(100*WheelTime)/100==end_s,1);
% WheelMove(WheelMove<1)=0;
% plot(WheelTime(WheelStart:WheelEnd),smooth(WheelMove(WheelStart:WheelEnd),8)-1,'color',[0.8 0 0.8])
% % plot(WheelTime,WheelMove,'b')
% ax = gca;
% ymin = ax.YLim(1); ymax = ax.YLim(2);
yyaxis left
ymin=ymin-3;
ylim([ymin ymax])
xlim([start_s end_s])
xticks([start_s:5:end_s])
xticklabels([start_s:5:end_s])
ax = gca;
if iplot == 4 || itrial == length(trials2return)
xlabel ('Time (s)')
ylabel ('{\Delta} F / F')
end
if numel(chan_ori)==2 && iplot==1
text(TrialTimingData(trials2return(itrial),12)-4, 1.4*ymax, [chan_ori(ihem), ' HEM', animal_name], 'FontWeight', 'bold')
end
for ievent = trials2return(itrial):trials2return(itrial)+trial_seq_n-1
h=rectangle(ax, 'Position',[TrialTimingData(ievent,13) ymin (TrialTimingData(ievent,14)-TrialTimingData(ievent,13)) ymax+abs(ymin)], ...
'EdgeColor',[144/255 186/255 212/255 0.2], 'FaceColor', [144/255 186/255 212/255 0.2]); % trial in progress light blue rectangle
text(TrialTimingData(ievent,13), 1.2*ymax, num2str(TrialTimingData(ievent, 2)), 'FontWeight', 'bold')
line([TrialTimingData(ievent,12) TrialTimingData(ievent,12)], [ymin ymax], 'Color', [74/255 127/255 189/255], 'LineStyle', '--', 'LineWidth', 1.5);
line([TrialTimingData(ievent,13) TrialTimingData(ievent,13)], [ymin ymax], 'Color', [74/255 127/255 189/255], 'LineWidth', 1.5); % stim line
rl = line([TrialTimingData(ievent,14) TrialTimingData(ievent,14)], [ymin ymax], 'LineWidth', 1.5); %rwd line
if TrialTimingData(ievent,9)==1
rl.Color = [47/255 189/255 28/255];
else
rl.Color = [189/255 89/255 28/255];
end
end
plot(ds_TimeStamps,sm_ds_DeltaFoverF,'LineWidth', 1.2, 'color', [0.25 0.25 0.25]) %plot df/f
yyaxis right
plot(WheelTime(WheelStart:WheelEnd),smooth(WheelMove(WheelStart:WheelEnd),8)-1, 'LineWidth', 1.2, 'color',[0.8 0 0.8])
ylabel('Wheel position')
% plot(WheelTime,WheelMove,'b')
hold on
end
cd(['\\zserver.cortexlab.net\Lab\Share\Lak\Morgane\', brain_region, ' Traces\autosave2'])
figname=num2str(ifig);
if exist([animal_name,'_',exp_date,'_',exp_series,'_fig',figname,'.fig'], 'file') > 1
figname = num2str( exist([animal_name,'_',exp_date,'_',exp_series,'_fig',figname,'.fig'], 'file')+1);
end
savefig([animal_name,'_',exp_date,'_',exp_series,'_fig',num2str(figname)])
end
end
end