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_current('small')
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 "standard multipatch" experiment types in order to exclude other experiment types as well as filter for "mouse" as the species.
# 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(
experiment_type='standard multipatch',
species='mouse',
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)))
# we now have all synapses loaded into one dataframe:
pairs.head()
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, 15e-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="synapse."+field, data=pairs, ax=ax[i], palette='pastel', width=0.8, linewidth=1)
sns.swarmplot(x="post_class", y="synapse."+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="synapse."+x_field,
y="synapse."+y_field,
hue="post_class",
size="synapse.psp_amplitude",
data=pairs,
ax=ax,
)
ax.legend(loc="upper right", bbox_to_anchor=(1.5, 1))