In this notebook we use the Allen Institute synaptic physiology dataset to measure the kinetic properties of synaptic connections and the relationship to cell subclass.
For an introduction to the Jupyter Notebook interface interface, try Codeacademy: How To Use Jupyter Notebooks or Jupyter Notebook Quick Start Guide.
import numpy as np
from aisynphys.database import SynphysDatabase
from aisynphys.cell_class import CellClass
# Download and cache the sqlite file for the requested database
# (for available versions, see SynphysDatabase.list_versions)
db = SynphysDatabase.load_version('synphys_r1.0_2019-08-29_small.sqlite')
We are going to compare the strength of excitatory connectivity onto the three inhibitory cell subclassess -- Pvalb, Sst, and Vip.
Begin by defining these subclasses:
post_classes = {
'pvalb': CellClass(cre_type='pvalb'),
'sst': CellClass(cre_type='sst'),
'vip': CellClass(cre_type='vip'),
}
Query the database to get all excitatory synapses with a specific postsynaptic cre type. We also filter here for specific project names "mouse V1 coarse matrix" and "mouse V1 pre production" in order to exclude other experiment types.
# query once for each postsynaptic type, building up a Pandas dataframe
pairs = None
for name, post_class in post_classes.items():
pair_query = db.pair_query(
project_name=["mouse V1 coarse matrix", "mouse V1 pre production"],
post_class=post_class,
synapse=True,
synapse_type='ex',
)
pair_query = pair_query.add_columns(
db.Synapse.latency,
db.Synapse.psc_rise_time,
db.Synapse.psc_decay_tau,
db.Synapse.psp_amplitude,
)
df = pair_query.dataframe()
df['post_class'] = name
if pairs is None:
pairs = df
else:
pairs = pairs.append(df)
print("%s: %d synapses" % (name, len(df)))
pvalb: 90 synapses sst: 71 synapses vip: 24 synapses
# we now have all synapses loaded into one dataframe:
pairs.head()
id | experiment_id | pre_cell_id | post_cell_id | has_synapse | has_electrical | crosstalk_artifact | n_ex_test_spikes | n_in_test_spikes | distance | meta | latency | psc_rise_time | psc_decay_tau | psp_amplitude | post_class | |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | 43122 | 1235 | 7375 | 7370 | True | False | None | 12 | 0 | 0.000058 | None | NaN | NaN | NaN | NaN | pvalb |
1 | 44106 | 1264 | 7546 | 7550 | True | False | None | 484 | 60 | 0.000052 | None | 0.000937 | 0.000547 | 0.001353 | 0.000436 | pvalb |
2 | 44111 | 1264 | 7547 | 7550 | True | False | None | 196 | 60 | 0.000085 | None | NaN | NaN | NaN | NaN | pvalb |
3 | 44116 | 1264 | 7548 | 7550 | True | False | None | 648 | 60 | 0.000110 | None | NaN | NaN | NaN | NaN | pvalb |
4 | 44412 | 1279 | 7617 | 7621 | True | False | None | 480 | 480 | 0.000226 | None | 0.000395 | NaN | NaN | 0.000101 | pvalb |
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
limits = {
'latency': (0.3e-3, 5e-3),
'psc_rise_time': (0.3e-3, 5e-3),
'psc_decay_tau': (0.3e-3, 5e-3),
'psp_amplitude': (10e-6, 5e-3),
}
units = ['ms', 'ms', 'ms', 'mV']
ticks = {
'ms': 0.5e-3 * 2**np.arange(4),
'mV': 20e-6 * 4**np.arange(4),
}
fig,ax = plt.subplots(len(limits), 1, figsize=(8, 2.5 * len(limits)))
for i, (field, lim) in enumerate(limits.items()):
# box and swarm plots
ax[i].set_yscale('log')
ax[i].set_ylim(*lim)
sns.boxplot(x="post_class", y=field, data=pairs, ax=ax[i], palette='pastel', width=0.8, linewidth=1)
sns.swarmplot(x="post_class", y=field, data=pairs, ax=ax[i], size=5, color=(0, 0, 0, 0.5))
# clean up labels / ticks
if i == len(limits)-1:
ax[i].set_xlabel('postsynaptic class', size=14)
else:
ax[i].set_xlabel('')
ax[i].set_ylabel(field.replace('_', ' ') + ' (%s)'%units[i], size=12)
ax[i].set_yticks(ticks[units[i]])
ax[i].set_yticklabels(['%0.2f' % (x*1000) for x in ticks[units[i]]])
ax[i].set_yticklabels([], minor=True)
fig,ax = plt.subplots()
x_field = 'psc_rise_time'
y_field = 'psc_decay_tau'
ax.set_xlim(limits[x_field])
ax.set_ylim(limits[y_field])
ax.set_yscale('log')
ax.set_xscale('log')
sns.scatterplot(x=x_field, y=y_field, hue="post_class", size="psp_amplitude", data=pairs, ax=ax)
ax.legend(loc="upper right", bbox_to_anchor=(1.5, 1))
<matplotlib.legend.Legend at 0x7fd5e0091668>