-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathfig5.py
More file actions
184 lines (159 loc) · 10.2 KB
/
fig5.py
File metadata and controls
184 lines (159 loc) · 10.2 KB
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
import sys
import numpy as np
from matplotlib import pyplot as plt
from matplotlib import cm
from matplotlib.colors import ListedColormap, LinearSegmentedColormap
import os
import utils
def load_fig5_dat(root):
dat = {}
pretrain = np.load(os.path.join(root, r'beh\Unsupervised_pretraining_behavior\Beh_pretrain_on_nat_image.npy'), allow_pickle=1).item()
control = np.load(os.path.join(root, r'beh\Unsupervised_pretraining_behavior\Beh_no_pretrain.npy'), allow_pickle=1).item()
grating = np.load(os.path.join(root, r'beh\Unsupervised_pretraining_behavior\Beh_pretrain_on_grat_image.npy'), allow_pickle=1).item()
dat['nat_d1'] = utils.pretrain_exp_lick_raster(pretrain['CBL08_2023_05_09_1_day1'])
dat['nat_d4'] = utils.pretrain_exp_lick_raster(pretrain['CBL08_2023_05_12_1_day4'])
dat['ctl_d1'] = utils.pretrain_exp_lick_raster(control['SL3_2023_06_13_1_day1'])
dat['ctl_d4'] = utils.pretrain_exp_lick_raster(control['SL3_2023_06_16_1_day4'])
dat['grat_d1'] = utils.pretrain_exp_lick_raster(grating['LZ08_2024_05_21_1_day1'])
dat['grat_d4'] = utils.pretrain_exp_lick_raster(grating['LZ08_2024_05_24_1_day4'])
dat['natPerf'], dat['nat_ntr'] = utils.get_lick_response_in_zone(pretrain)
dat['gratPerf'], dat['grat_ntr'] = utils.get_lick_response_in_zone(grating)
dat['ctlPerf'], dat['ctl_ntr'] = utils.get_lick_response_in_zone(control)
dat['nat_FL'] = utils.get_first_lick_distribution(pretrain)
dat['grat_FL'] = utils.get_first_lick_distribution(grating)
dat['ctl_FL'] = utils.get_first_lick_distribution(control)
return dat
def plot_fig5(dat, root):
fig = plt.figure(figsize=(7, 7*7/10.5), dpi=500)
plt.rcParams["font.family"] = "arial"
plt.rcParams["font.size"] = 5
ax_text = fig.add_axes([0,0.07,1,0.75])
utils.fmt(ax_text, xlm=[0,1], ylm=[0,1], boxoff=0)
ax_text.plot([0.46, 0.8],[0.19,0.19],'k-',lw=0.5)
ax_text.set_facecolor('None')
ax_text.axis('off')
x, y, dx, dy, w, h =0.37, 0.66, 0.105, 0, 0.076, 0.105
# example pretraining on naturalistic images mouse
ax0 = [fig.add_axes([x ,y, w, h]), fig.add_axes([x+dx, y, w, h])]
lick_raster(ax0, dat['nat_d1'])
x = 0.62
ax1 = [fig.add_axes([x ,y, w, h]), fig.add_axes([x+dx, y, w, h])]
lick_raster(ax1, dat['nat_d4'])
# example pretraining on gratings mouse
x, y = 0.37,0.475
ax2 = [fig.add_axes([x ,y, w, h]), fig.add_axes([x+dx, y, w, h])]
lick_raster(ax2, dat['grat_d1'])
x = 0.62
ax3 = [fig.add_axes([x ,y, w, h]), fig.add_axes([x+dx, y, w, h])]
lick_raster(ax3, dat['grat_d4'])
# no pretraining mouse
x, y = 0.37,0.29
ax4 = [fig.add_axes([x ,y, w, h]), fig.add_axes([x+dx, y, w, h])]
lick_raster(ax4, dat['ctl_d1'])
x = 0.62
ax5 = [fig.add_axes([x ,y, w, h]), fig.add_axes([x+dx, y, w, h])]
lick_raster(ax5, dat['ctl_d4'])
# lick performance
x,y, dx,dy, w,h =0.87,0.29, 0,0.177, 0.12,0.135
ax_perf0 = fig.add_axes([x, y+2*dy, w, h])
pretrain_beh_plot(ax_perf0, dat['natPerf'],isxn=0)
ax_perf0.text(0.5, 1.05, 'VR$_{n}$ pretraining mice', transform=ax_perf0.transAxes, horizontalalignment='center')
ax_perf1 = fig.add_axes([x,y+dy,w,h])
pretrain_beh_plot(ax_perf1, dat['gratPerf'],isxn=0)
ax_perf1.text(0.5, 1.05, 'VR$_{g}$ pretraining mice', transform=ax_perf1.transAxes, horizontalalignment='center')
ax_perf2 = fig.add_axes([x,y,w,h])
pretrain_beh_plot(ax_perf2, dat['ctlPerf'],isxn=0)
ax_perf2.text(0.5, 1.05, 'no pretraining mice', transform=ax_perf2.transAxes, horizontalalignment='center')
################## lick diff. 5 days ######################
x,y, dx,dy, w,h =0.03,0.07, 0,0.15, 0.29,0.33
ax_diff_5days = fig.add_axes([x, y, w, h])
pretrain_diff_beh_plot(ax_diff_5days, [dat['ctlPerf'], dat['gratPerf'], dat['natPerf']], isxn=0, ms=1)
################## first-lick distributions ######################
x,y, dx,dy, w,h =0.37,0.07, 0.09,0, 0.075,0.125
FL_ax = [fig.add_axes([x+i*dx, y, w, h]) for i in range(5)]
FL_dist_plot(FL_ax, [dat['ctl_FL'], dat['grat_FL'], dat['nat_FL']])
################# trials per day ##########################
x,y, dx,dy, w,h =0.87,0.07, 0.08,0, 0.12,0.145
tr_ax = fig.add_axes([x,y,w,h])
number_of_trials(tr_ax, dat)
ax_text.text(0.36, 1, r"$\bf{a}$ Licks in day 1 of active reward", fontsize=5.5)
ax_text.text(.61, 1, r"$\bf{b}$ Licks in day 4 of active reward", fontsize=5.5)
ax_text.text(.84, 1, r"$\bf{c}$ Learning performance", fontsize=5.5)
ax_text.text(0, .46, r"$\bf{d}$ Performance summary", fontsize=5.5)
ax_text.text(.34, .21, r"$\bf{e}$ Distribution of first-licks", fontsize=5.5)
ax_text.text(.84, .21, r"$\bf{f}$ Number of trials per session", fontsize=5.5)
ax_text.text(.405, .96, r"VR$_{n}$ pretraining (mouse 1)", fontsize=5.5)
ax_text.text(.415, .71, r"VR$_{g}$ pretraining (mouse 1)", fontsize=5.5)
ax_text.text(.415, .46, r"no pretraining (mouse 1)", fontsize=5.5)
ax_text.text(.66, .96, r"VR$_{n}$ pretraining (mouse 1)", fontsize=5.5)
ax_text.text(.67, .71, r"VR$_{g}$ pretraining (mouse 1)", fontsize=5.5)
ax_text.text(.66, .46, r"no pretraining (mouse 1)", fontsize=5.5)
ax_text.text(.6, .205, r"active reward", fontsize=5.5)
def lick_raster(ax, dat):
ax[0].scatter(dat['LickPos'][1][0], dat['LickPos'][1][1], marker='.', s=2, color='k', edgecolor='None')
ax[0].scatter(dat['firstLick'][1][0], dat['firstLick'][1][1], marker='.', s=6, color='brown', edgecolor='None')
ax[0].fill_betweenx([-1, dat['ntrials'][1]], 40, 60, color='k', alpha=0.15, edgecolor=None)
ax[1].scatter(dat['LickPos'][0][0], dat['LickPos'][0][1], marker='.', s=2, color='k', edgecolor='None')
ax[1].scatter(dat['firstLick'][0][0], dat['firstLick'][0][1], marker='.', s=6, color='brown', edgecolor='None')
ax[1].fill_betweenx([-1, dat['ntrials'][0]], 20, 40,color='b', alpha=0.2, edgecolor=None)
ax[1].fill_betweenx([-1, dat['ntrials'][0]], 40, 60, color='k', alpha=0.15, edgecolor=None)
utils.fmt(ax[0], title='non-reward', xtick=[[0, 20, 40, 60], [0, 2, 4, 6]], xlm=[0, 60],
ytick=[[0, dat['ntrials'][1]]], ylm=[0, dat['ntrials'][1]], y_invert=1, tpad=0, xlabel='position (m)')
utils.fmt(ax[1], title='reward', xtick=[[0, 20, 40, 60], [0, 2, 4, 6]], xlm=[0, 60],
ytick=[[0, dat['ntrials'][0]]], ylm=[0, dat['ntrials'][0]], y_invert=1, tpad=0)
def pretrain_beh_plot(ax, beh, isxn=0, ms=1):
"""This is for behavior mice only"""
u, sem = beh.mean(0), beh.std(0, ddof=1)/np.sqrt(beh.shape[0])
ax.plot(np.zeros(beh.shape[0]), beh[:, 0, 0].T, 'b.', ls='None', markersize=ms)
ax.plot(np.arange(4)+1, beh[:, 1:, 0].T, 'b-', lw=0.5, markersize=ms, alpha=0.3)
ax.plot(np.zeros(beh.shape[0]), beh[:, 0, 1].T, 'r.', ls='None', markersize=ms)
ax.plot(np.arange(4)+1, beh[:, 1:, 1].T, 'r-', lw=0.5, markersize=ms, alpha=0.3)
ax.errorbar(0, u[0, 0], yerr=sem[0, 0], color='b', marker='_', ms=4)
ax.errorbar(0, u[0, 1], yerr=sem[0, 1], color='r', marker='_', ms=4)
ax.errorbar(np.arange(4)+1, u[1:, 0], yerr=sem[1:, 0], color='b', marker='.', ms=2, lw=1)
ax.errorbar(np.arange(4)+1, u[1:, 1], yerr=sem[1:, 1], color='r', marker='.', ms=2, lw=1)
if isxn:
xt = [np.arange(5), ['passive\nreward', 1, 2, 3, 4]]
xn = 'day'
else:
xt = [np.arange(5), [None]*5]
xn = ''
utils.fmt(ax, ytick=[[0, 0.5, 1], [0, 50, 100]], xtick=xt, xlabel=xn, xlm=[-0.5, 4.2], ylm=[0, 1.02], ylabel='lick response (% trials)')
def pretrain_diff_beh_plot(ax, beh, isxn=0, ms=1):
"""This is for behavior mice only"""
xoff = [-0.2, 0, 0.2]
lgs = ['no pretraining', "VR$_{g}$ pretraining", "VR$_{n}$ pretraining"]
for i,icol in enumerate(['k', '0.5', [0.46, 0, 0.23]]):
ax.scatter(np.tile(np.arange(5), (beh[i].shape[0], 1)) + xoff[i], -np.diff(beh[i]), color=icol, edgecolor='None', alpha=0.3, s=15)
u, sem = -np.diff(beh[i]).mean(0), np.std(-np.diff(beh[i]), 0, ddof=1)/np.sqrt(beh[i].shape[0])
ax.errorbar(np.arange(5) + xoff[i], u[:, 0], yerr=sem[:, 0], color=icol, marker='_', ms=5, lw=1, linestyle='None')
ax.text(1, 0.15 - i*0.05, lgs[i], color=icol, horizontalalignment='right', transform=ax.transAxes)
xt = [np.arange(5), ['passive\nreward', 1, 2, 3, 4]]
xn = 'day'
utils.fmt(ax, ytick=[[0, 0.5, 1], [0, 50, 100]], xtick=xt, xlabel=xn, xlm=[-0.5, 4.3], ylm=[-0.05, 1.02], ylabel='$\Delta$ lick response (% trials, reward - non-reward)')
def FL_dist_plot(ax, beh):
"""This is for distribution of first licking of behavior only mice"""
tns = ['passive reward', 'day1', 'day2', 'day3', 'day4']
for i,icol in enumerate(['k', '0.5', [0.46, 0, 0.23]]):
u,sem = np.mean(beh[i], 0), np.std(beh[i], 0, ddof=1)/np.sqrt(beh[i].shape[0])
for j in range(5):
if i==0:
ax[j].fill_betweenx([0, 1], 20, 40,color='b', alpha=0.2, edgecolor=None)
ax[j].plot(np.arange(40), u[j], color=icol, lw=0.7)
ax[j].fill_between(np.arange(40), u[j]-sem[j], u[j]+sem[j], color=icol, alpha=0.5, edgecolor='None')
if j==0:
xn = 'position (m)'
yn = 'first-lick probability (%)'
else:
xn, yn = '', ''
tn = tns[j] if i==2 else ''
utils.fmt(ax[j], ytick=[[0, 0.1], [0, 10]], xtick=[[0, 20, 40], [0, 2, 4]], xlabel=xn, xlm=[0, 40], ylm=[0, 0.12], ylabel=yn, title=tn, tpad=0)
def number_of_trials(ax, dat):
N = [dat['ctl_ntr'], dat['grat_ntr'], dat['nat_ntr']]
lgs = ['no pretraining', "VR$_{g}$ pretraining", "VR$_{n}$ pretraining"]
for i,icol in enumerate(['k', '0.5', [0.46, 0, 0.23]]):
u, sem = np.mean(N[i], 0), np.std(N[i], 0, ddof=1)/np.sqrt(N[i].shape[0])
ax.errorbar(0, u[0], yerr=sem[0], marker='_', ms=3, color=icol, linewidth=0.5)
ax.errorbar(np.arange(4)+1, u[1:], yerr=sem[1:], marker='.', ms=3, color=icol, linewidth=0.5)
ax.text(1, 0.25 - i*0.1, lgs[i], color=icol, horizontalalignment='right', transform=ax.transAxes)
utils.fmt(ax, ytick=[[0, 100, 200]], xtick=[np.arange(5), ['passive\nreward', 1, 2, 3, 4]], xlabel='day', xlm=[-0.5, 4.2], ylm=[0, 220], ylabel='# trials')