Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MRG] Add ability to modify cell-cell connectivity #276

Merged
merged 65 commits into from Mar 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
9f7ea59
Create documentation outline of intended functionality
ntolley Mar 4, 2021
6703492
Modify calls to _connectcell_types to accept gid ranges
ntolley Mar 5, 2021
2e08cbc
WIP: _connect_celltypes() accepts gid ranges, need to fix drives
ntolley Mar 5, 2021
60bbb34
WIP: Modify drive connectivity calls (error causing discrepancy with …
ntolley Mar 5, 2021
ac574b4
Create dict structure to store connectivity info
ntolley Mar 5, 2021
c4903ad
Clean up definition of cell-cell connections, allow passing lists of …
ntolley Mar 5, 2021
e624fde
Update test_network to use new _connect_celltypes() calls
ntolley Mar 5, 2021
6253af9
Flake8
ntolley Mar 5, 2021
ab9f06a
_connect_celltypes() accepts connectivity lists, add helper function …
ntolley Mar 6, 2021
e47a3de
Modify test_network to work with connectivity list
ntolley Mar 6, 2021
0a5ae49
Doc typo
ntolley Mar 6, 2021
d3b5923
Change connectivity list elements to dict
ntolley Mar 7, 2021
eb5ad70
Add connectivity list attribute to network class
ntolley Mar 7, 2021
cf75998
Move connectivity list update code to _attach_drive()
ntolley Mar 8, 2021
2c48d11
WIP: Fix discrepancy with network instantiation
ntolley Mar 9, 2021
341b7df
WIP: Try moving drives
ntolley Mar 9, 2021
32a3c28
WIP
ntolley Mar 9, 2021
4c836d8
Final fix, discrepancy due to not copying dictionary
ntolley Mar 9, 2021
1d30829
Update test_network with connectivity_list as Network attribute
ntolley Mar 9, 2021
e495ad3
Flake 8
ntolley Mar 9, 2021
82250f0
WIP: Add functions to edit connectivity_list with basic unit tests
ntolley Mar 9, 2021
93779da
Add tests for net.add_connection() and net.clear_connectivity()
ntolley Mar 9, 2021
6aab8a6
MAINT: simplify default connectivity
jasmainak Mar 10, 2021
e597090
Simplify arguments of connectivity dict
ntolley Mar 12, 2021
4eeb7bb
DOC: Update add_connection docstring
ntolley Mar 12, 2021
9e8ef89
Fix error in docstring
ntolley Mar 12, 2021
e3759a1
Remove unused function
ntolley Mar 12, 2021
92f07d2
WIP: Start example for connectivity API
ntolley Mar 12, 2021
7640f2b
Remove unused function
ntolley Mar 12, 2021
cca514f
Finish first draft of connectivity example
ntolley Mar 14, 2021
8660f66
Fix example title
ntolley Mar 14, 2021
bee215e
Modify add_connection() to accept args instead of dict
ntolley Mar 15, 2021
0eecd13
Modify connectivity example with updated API
ntolley Mar 15, 2021
0eae6e5
Update tests with add_connection() API
ntolley Mar 15, 2021
2d3bd0f
flake8
ntolley Mar 15, 2021
0f12a08
misc fixes
ntolley Mar 15, 2021
863ff42
MAINT: slightly more compact
jasmainak Mar 16, 2021
39d88dc
MAINT: remove old example
jasmainak Mar 16, 2021
b2f61d4
Add dipole comparison to example
ntolley Mar 18, 2021
7f69474
Rebase fix
ntolley Mar 18, 2021
022da7a
Aesthetics ;)
ntolley Mar 18, 2021
08109a3
DOC: improve explanations
ntolley Mar 18, 2021
d6b19ff
DOC: minor fixes
ntolley Mar 18, 2021
77443b8
Flake8 fixes
ntolley Mar 20, 2021
e0cf756
Incorporate add_connection() into default connectivity function
ntolley Mar 20, 2021
0081ef5
Change net.connectivity_list to net.connectivity, remove unused varia…
ntolley Mar 20, 2021
4c2421c
Add tests for loc and receptor arguments
ntolley Mar 20, 2021
ea6e440
Fix example variables
ntolley Mar 20, 2021
2072bf4
Make delay and threshold attibutes of the Network class
ntolley Mar 21, 2021
1d156ff
Remove threshold and delay from example add_connection() call
ntolley Mar 21, 2021
921e6c5
Implement externals.mne test functions for parameter checks, allow pa…
ntolley Mar 21, 2021
8afaed7
Add tests for list of target_gids
ntolley Mar 21, 2021
810f34b
minor fix
ntolley Mar 21, 2021
bf38f5f
Fix connectivity filtering in example
ntolley Mar 21, 2021
3bdf281
Add back delay parameter to add_connection() to fix discrepancy
ntolley Mar 24, 2021
778492f
Update tests and examples with delay parameter
ntolley Mar 24, 2021
f588aa5
Flake 8
ntolley Mar 24, 2021
b21451e
Update whats_new.rst
ntolley Mar 24, 2021
c97936d
Add edge case check for l2 pyramidal inhibitory synapses, update docs
ntolley Mar 25, 2021
defa84b
Add test to make sure netconn object is made from add_connection
ntolley Mar 25, 2021
6b3e62b
Remove hard coded edge case check
ntolley Mar 25, 2021
2c9e89d
Simplify example
ntolley Mar 25, 2021
7181073
Minor doc edits, add test for netconn object
ntolley Mar 25, 2021
174e809
Fix example error
ntolley Mar 25, 2021
e498da3
Allow range to be passed for target_gid
ntolley Mar 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions doc/whats_new.rst
Expand Up @@ -7,6 +7,22 @@ What's new?

.. currentmodule:: hnn_core

.. _0.2:

Current
-------

Changelog
~~~~~~~~~
- Store all connectivity information under :attr:`~hnn_core.Network.connectivity` before building the network, by `Nick Tolley`_ in `#276 <https://github.com/jonescompneurolab/hnn-core/pull/276>`_

Bug
~~~

API
~~~
- New API for defining cell-cell connections. Custom connections can be added with :func:`~hnn_core.Network.add_connection`, by `Nick Tolley`_ in `#276 <https://github.com/jonescompneurolab/hnn-core/pull/276>`_

.. _0.1:

0.1
Expand Down
96 changes: 96 additions & 0 deletions examples/plot_connectivity.py
@@ -0,0 +1,96 @@
"""
=====================
07. Plot Connectivity
=====================

This example demonstrates how to modify the network connectivity.
"""

# Author: Nick Tolley <nicholas_tolley@brown.edu>

import os.path as op

###############################################################################
# Let us import ``hnn_core``.

import hnn_core
from hnn_core import read_params, Network, simulate_dipole

hnn_core_root = op.dirname(hnn_core.__file__)

###############################################################################
# Then we read the parameters file
params_fname = op.join(hnn_core_root, 'param', 'default.json')
params = read_params(params_fname)

###############################################################################
# To explore how to modify network connectivity, we will start with simulating
# the evoked response from the
# :ref:`evoked example <sphx_glr_auto_examples_plot_simulate_evoked.py>`, and
# explore how it changes with new connections. We first instantiate the
# network. (Note: Setting ``add_drives_from_params=True`` loads a set of
# predefined drives without the drives API shown previously).
net = Network(params, add_drives_from_params=True)

###############################################################################
# Instantiating the network comes with a predefined set of connections that
# reflect the canonical neocortical microcircuit. ``net.connectivity``
# is a list of dictionaries which detail every cell-cell, and drive-cell
# connection.
print(len(net.connectivity))
print(net.connectivity[0])
print(net.connectivity[-1])

###############################################################################
# Data recorded during simulations are stored under
# :class:`~hnn_core.Cell_Response`. To test multiple network structures, we can
# create a copy of the original network. The copied network is then simulated.
net_erp = net.copy()
dpl_erp = simulate_dipole(net_erp, n_trials=1)
net_erp.cell_response.plot_spikes_raster()

###############################################################################
# We can modify the connectivity list to test the effect of different
# connectivity patterns. For example, we can remove all layer 2 inhibitory
# connections.
new_connectivity = [conn for conn in net.connectivity
if conn['src_type'] != 'L2_basket']
net.connectivity = new_connectivity

net_remove = net.copy()
dpl_remove = simulate_dipole(net_remove, n_trials=1)
net_remove.cell_response.plot_spikes_raster()

###############################################################################
# That's a lot of spiking! Since basket cells are inhibitory, removing these
# connections increases network wide excitability. We can additionally add
# new connections using ``net.add_connection()``. Let's try connecting a
# single layer 2 basket cell, to every layer 2 pyramidal cell. We can utilize
# ``net.gid_ranges`` to help
# find the gids of interest.
print(net.gid_ranges)
src_gid = net.gid_ranges['L2_basket'][0]
target_gids = net.gid_ranges['L2_pyramidal']
location, receptor = 'soma', 'gabaa'
weight, delay, lamtha = 1.0, 1.0, 70
net.add_connection(src_gid, target_gids, location, receptor,
delay, weight, lamtha)

net_add = net.copy()
dpl_add = simulate_dipole(net_add, n_trials=1)
net_add.cell_response.plot_spikes_raster()

###############################################################################
# Adding more inhibitory connections did not completely restore the normal
# spiking. L2 basket and pyramidal cells rhythymically fire in the gamma
# range (30-80 Hz). As a final step, we can see how this change in spiking
# activity impacts the aggregate current dipole.
import matplotlib.pyplot as plt
from hnn_core.viz import plot_dipole
fig, axes = plt.subplots(2, 1, sharex=True, figsize=(6, 6),
constrained_layout=True)
dpls = [dpl_erp[0], dpl_remove[0], dpl_add[0]]
plot_dipole(dpls, ax=axes[0], layer='agg', show=False)
axes[0].legend(['Normal', 'No L2 Basket', 'Single L2 Basket'])
net_erp.cell_response.plot_spikes_hist(
ax=axes[1], spike_types=['evprox', 'evdist'])
2 changes: 1 addition & 1 deletion examples/plot_firing_pattern.py
Expand Up @@ -84,7 +84,7 @@
###############################################################################
# Here, we explain more details about the data structures and how they can
# be used to better interpret the data. The cell IDs (gids) uniquely define
# neurons in the network and are stored in the :class:`~hnn_core.Network`
# neurons in the network and are stored in the :class:`~hnn_core.Network`
# object as a dictionary
gid_ranges = net.gid_ranges
print(net.gid_ranges)
Expand Down