Skip to content

Commit

Permalink
Add has_no_back_tracking function
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet committed Apr 12, 2024
1 parent 7052c1e commit 79219df
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
8 changes: 7 additions & 1 deletion neurom/check/morphology_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import numpy as np
from neurom import NeuriteType
from neurom.check import CheckResult
from neurom.check.morphtree import get_flat_neurites
from neurom.check.morphtree import get_flat_neurites, back_tracking_segments
from neurom.core.morphology import Section, iter_neurites, iter_sections, iter_segments
from neurom.core.dataformat import COLS
from neurom.exceptions import NeuroMError
Expand Down Expand Up @@ -355,3 +355,9 @@ def has_no_single_children(morph):
"""Check if the morphology has sections with only one child section."""
bad_ids = [section.id for section in iter_sections(morph) if len(section.children) == 1]
return CheckResult(len(bad_ids) == 0, bad_ids)


def has_no_back_tracking(morph):
"""Check if the morphology has sections with back-tracks."""
bad_ids = [i for neurite in iter_neurites(morph) for i in back_tracking_segments(neurite)]
return CheckResult(len(bad_ids) == 0, bad_ids)
26 changes: 26 additions & 0 deletions tests/check/test_morphology_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,3 +458,29 @@ def test_single_children():
result = morphology_checks.has_no_single_children(m)
assert result.status is False
assert result.info == [0]


def test_has_no_back_tracking():
m = load_morphology("""
((CellBody) (-1 0 0 2) (1 0 0 2))
((Dendrite)
(0 0 0 0.4)
(0 1 0 0.3)
(0 2 0 0.28)
(
(0 2 0 0.28)
(1 3 0 0.3)
(2 4 0 0.22)
|
(0 2 0 0.28)
(1 -3 0 0.3)
(2 -4 0 0.24)
(1 -3 0 0.52)
(3 -5 0 0.2)
(4 -6 0 0.2)
))
""", "asc")
result = morphology_checks.has_no_back_tracking(m)
assert result.status is False
assert result.info == [(2, 1, 0), (2, 1, 1)]

0 comments on commit 79219df

Please sign in to comment.