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

Add has_no_back_tracking function #1113

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)]
Loading