Skip to content

Commit

Permalink
allow for morphologies without soma (#900)
Browse files Browse the repository at this point in the history
  • Loading branch information
asanin-epfl authored May 3, 2021
1 parent 318b90f commit 401fa5c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 6 deletions.
6 changes: 4 additions & 2 deletions neurom/check/neuron_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
from neurom.check.morphtree import get_flat_neurites
from neurom.core.neuron import Section, iter_neurites, iter_sections, iter_segments
from neurom.core.dataformat import COLS
from neurom.exceptions import NeuroMError
from neurom.features import neuritefunc as _nf
from neurom.morphmath import section_length, segment_length

Expand Down Expand Up @@ -67,8 +68,7 @@ def has_apical_dendrite(neuron, min_number=1, treefun=_read_neurite_type):
Arguments:
neuron(Neuron): The neuron object to test
min_number: minimum number of apical dendrites required
treefun: Optional function to calculate the tree type of neuron's
neurites
treefun: Optional function to calculate the tree type of neuron's neurites
Returns:
CheckResult with result
Expand Down Expand Up @@ -279,6 +279,8 @@ def has_no_dangling_branch(neuron):
Returns:
CheckResult with a list of all first segments of dangling neurites
"""
if len(neuron.soma.points) == 0:
raise NeuroMError('Can\'t check for dangling neurites if there is no soma')
soma_center = neuron.soma.points[:, COLS.XYZ].mean(axis=0)
recentered_soma = neuron.soma.points[:, COLS.XYZ] - soma_center
radius = np.linalg.norm(recentered_soma, axis=1)
Expand Down
4 changes: 3 additions & 1 deletion neurom/core/neuron.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@ def __init__(self, filename, name=None):
name (str): a option neuron name
"""
try:
morphio.set_ignored_warning([morphio.Warning.wrong_root_point], True)
morphio.set_ignored_warning([morphio.Warning.wrong_root_point,
morphio.Warning.no_soma_found,
morphio.Warning.zero_diameter], True)
morphio.set_raise_warnings(True)
super().__init__(filename)
finally:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
install_requires=[
'click>=7.0',
'matplotlib>=3.2.1',
'morphio>=3.0.2',
'morphio>=3.1.1',
'numpy>=1.8.0',
'pandas>=1.0.5',
'pyyaml>=3.10',
Expand Down
8 changes: 8 additions & 0 deletions tests/check/test_neuron_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
from neurom.check import neuron_checks as nrn_chk
from neurom.core.dataformat import COLS
from neurom.core.types import dendrite_filter
from neurom.exceptions import NeuroMError
import pytest
from numpy.testing import assert_array_equal

DATA_PATH = Path(__file__).parent.parent / 'data'
Expand Down Expand Up @@ -403,6 +405,12 @@ def test_has_no_dangling_branch():
assert res.status


def test_dangling_branch_no_soma():
with pytest.raises(NeuroMError, match='Can\'t check for dangling neurites if there is no soma'):
nrn = load_neuron(SWC_PATH / 'Single_apical_no_soma.swc')
nrn_chk.has_no_dangling_branch(nrn)


def test__bool__():
c = check.CheckResult(status=True)
assert c.__nonzero__()
Expand Down
10 changes: 9 additions & 1 deletion tests/check/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,15 @@ def test_single_axon_neuron():


def test_single_apical_no_soma():
_run_test(SWC_PATH / 'Single_apical_no_soma.swc', dict([('ALL', False)]))
expected = {'ALL': False,
'Has all nonzero neurite radii': True,
'Has all nonzero section lengths': True,
'Has all nonzero segment lengths': False,
'Has apical dendrite': True,
'Has axon': False,
'Has basal dendrite': False,
'Has nonzero soma radius': False}
_run_test(SWC_PATH / 'Single_apical_no_soma.swc', expected)


def test_directory_input():
Expand Down
2 changes: 1 addition & 1 deletion tests/io/test_swc_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def test_repeated_id():


def test_neurite_followed_by_soma():
with pytest.raises(MorphioError, match='Warning: found a disconnected neurite'):
with pytest.raises(MorphioError, match='Found a soma point with a neurite as parent'):
load_neuron(SWC_PATH / 'soma_with_neurite_parent.swc')


Expand Down

0 comments on commit 401fa5c

Please sign in to comment.