Skip to content

Commit

Permalink
IntEnum for treenode-connector relationships
Browse files Browse the repository at this point in the history
  • Loading branch information
clbarnes committed Jul 6, 2023
1 parent 20659c2 commit 299ad2b
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
3 changes: 3 additions & 0 deletions docs/source/whats_new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ repository.
* - dev
- ongoing
- - dropped support for Python 3.7
- :class:`navis.NodeConnectorRelation` is an :class:`enum.IntEnum`
encoding relationships between (tree)nodes and connector nodes,
used in neurons' connector tables.
* - 1.4.0
- 21/12/22
- - BREAKING: ``navis.flow_centrality`` was renamed to :func:`navis.synapse_flow_centrality`
Expand Down
5 changes: 3 additions & 2 deletions navis/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# GNU General Public License for more details.

from .volumes import Volume
from .base import Neuron, BaseNeuron
from .base import Neuron, BaseNeuron, NodeConnectorRelation
from .skeleton import TreeNeuron
from .mesh import MeshNeuron
from .dotprop import Dotprops
Expand All @@ -25,4 +25,5 @@
NeuronObject = Union[NeuronList, TreeNeuron, BaseNeuron, MeshNeuron]

__all__ = ['Volume', 'Neuron', 'BaseNeuron', 'TreeNeuron', 'MeshNeuron',
'Dotprops', 'VoxelNeuron', 'NeuronList', 'make_dotprops']
'Dotprops', 'VoxelNeuron', 'NeuronList', 'make_dotprops',
'NodeConnectorRelation']
28 changes: 26 additions & 2 deletions navis/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# GNU General Public License for more details.

import copy
from enum import IntEnum
import hashlib
import numbers
import pint
Expand Down Expand Up @@ -45,6 +46,27 @@
pint.Quantity([])


class NodeConnectorRelation(IntEnum):
"""An integer describing a (tree)node-connector relationship.
i.e. "the (tree)node is <NodeConnectorType> the connector node"
Based on the `CATMAID link types`_.
A node PRESYNAPTIC_TO a connector is an output site.
A node POSTSYNAPTIC_TO a connector is an input site.
.. _`CATMAID link types`: https://github.com/catmaid/CATMAID/blob/2964e04e6e9772aff5d305e72c1b878030fe0e25/django/applications/catmaid/control/link.py#L16
"""
PRESYNAPTIC_TO = 0
POSTSYNAPTIC_TO = 1
ABUTTING = 2
GAPJUNCTION_WITH = 3
TIGHTJUNCTION_WITH = 4
DESMOSOME_WITH = 5
ATTACHMENT_TO = 6
CLOSE_TO = 7


def Neuron(x: Union[nx.DiGraph, str, pd.DataFrame, 'TreeNeuron', 'MeshNeuron'],
**metadata):
"""Constructor for Neuron objects. Depending on the input, either a
Expand Down Expand Up @@ -421,7 +443,8 @@ def presynapses(self):
raise ValueError('No connector table found.')
# Make an educated guess what presynapses are
types = self.connectors['type'].unique()
pre = [t for t in types if 'pre' in str(t) or t in [0, "0"]]
pre_int = NodeConnectorRelation.PRESYNAPTIC_TO.value
pre = [t for t in types if 'pre' in str(t) or t in [pre_int, str(pre_int)]]

if len(pre) == 0:
logger.debug(f'Unable to find presynapses in types: {types}')
Expand All @@ -442,7 +465,8 @@ def postsynapses(self):
raise ValueError('No connector table found.')
# Make an educated guess what presynapses are
types = self.connectors['type'].unique()
post = [t for t in types if 'post' in str(t) or t in [1, "1"]]
post_int = NodeConnectorRelation.POSTSYNAPTIC_TO.value
post = [t for t in types if 'post' in str(t) or t in [post_int, str(post_int)]]

if len(post) == 0:
logger.debug(f'Unable to find postsynapses in types: {types}')
Expand Down

0 comments on commit 299ad2b

Please sign in to comment.