In this notebook we use the Allen Institute synaptic physiology dataset to measure short term plasticity and its 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
import scipy.stats
from aisynphys.database import SynphysDatabase
from aisynphys.cell_class import CellClass, classify_cells, classify_pairs
from aisynphys.connectivity import measure_connectivity, pair_was_probed
First, load up the "small" database from release 1.0 and query all cell pairs
for mouse projects.
# 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')
# Load all synapses associated with mouse V1 projects
pairs = db.pair_query(
project_name=["mouse V1 coarse matrix", "mouse V1 pre-production"],
synapse=True,
).all()
print("loaded %d synapses" % len(pairs))
loaded 1368 synapses
We will pick four simple class defintions for this analysis:
cell_classes = {
'pyr': CellClass(cell_class='ex', name='pyr'),
'pvalb': CellClass(cre_type='pvalb', name='pvalb'),
'sst': CellClass(cre_type='sst', name='sst'),
'vip': CellClass(cre_type='vip', name='vip'),
}
# get a list of all cells in the selected pairs
cells = set([pair.pre_cell for pair in pairs] + [pair.post_cell for pair in pairs])
# Classify each cell. Note that, depending on the class definitions above, a cell could
# belong to multiple classes.
cell_class = {}
for cell in cells:
# which of the classes defined above is this cell a member of?
cell_in_classes = [cls_name for cls_name, cls in cell_classes.items() if cell in cls]
cell_class[cell] = ','.join(cell_in_classes)
Now we build a dataframe with one row per synapse that contains the pre/postsynaptic cell class names as well as a measure of short-term plasticity.
import pandas
# construct a pandas dataframe containing the pre/postsynaptic cell class names
# and a measure of short-term plasticity
pre_class = [cell_class[pair.pre_cell] for pair in pairs]
post_class = [cell_class[pair.post_cell] for pair in pairs]
stp = [None if pair.dynamics is None else pair.dynamics.stp_induction_50hz for pair in pairs]
df = pandas.DataFrame(
zip(pairs, pre_class, post_class, stp),
columns=['pair', 'pre_class', 'post_class', 'stp'])
# select out only cells that are a member of exactly 1 class
mask = df.pre_class.isin(cell_classes) & df.post_class.isin(cell_classes)
df = df[mask]
# select only pairs with a measured stp
df = df.dropna()
df.head()
pair | pre_class | post_class | stp | |
---|---|---|---|---|
2 | <pair 1492460382.776 4 6> | pyr | pyr | -0.084996 |
7 | <pair 1490997794.081 8 2> | sst | vip | 0.367114 |
8 | <pair 1490997794.081 8 7> | sst | vip | 0.323405 |
9 | <pair 1501101571.166 1 5> | pyr | pyr | -0.114559 |
16 | <pair 1484862803.120 1 7> | pvalb | pvalb | -0.347905 |
stp = df.pivot_table('stp', 'pre_class', 'post_class', aggfunc=np.mean)
# sort rows/cols into the expected order
order = list(cell_classes)
stp = stp[order].loc[order]
stp
post_class | pyr | pvalb | sst | vip |
---|---|---|---|---|
pre_class | ||||
pyr | -0.273996 | -0.185856 | 0.165965 | -0.007874 |
pvalb | -0.455301 | -0.365362 | -0.423736 | -0.327010 |
sst | -0.137356 | -0.130458 | -0.147765 | 0.132345 |
vip | -0.008266 | -0.066462 | -0.096198 | -0.128896 |
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
fig,ax = plt.subplots(figsize=(8, 6))
hm = sns.heatmap(stp, cmap='coolwarm', vmin=-0.4, vmax=0.4, square=True, ax=ax,
cbar_kws={"ticks":[-0.3, 0, 0.3], 'label': '<-- depressing facilitating -->'})
fig.suptitle("50 Hz Train-induced STP", fontsize=16)
hm.set_xlabel("postsynaptic", fontsize=14)
hm.set_ylabel("presynaptic", fontsize=14);
hm.figure.axes[-1].yaxis.label.set_size(14)
hm.tick_params(labelsize=12)