From 79219df32e9474ee6f6f1a675328b4f2a0cfcb5b Mon Sep 17 00:00:00 2001 From: Adrien Berchet Date: Fri, 12 Apr 2024 17:22:27 +0200 Subject: [PATCH] Add has_no_back_tracking function --- neurom/check/morphology_checks.py | 8 +++++++- tests/check/test_morphology_checks.py | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/neurom/check/morphology_checks.py b/neurom/check/morphology_checks.py index db1a2bdd..4c3b960e 100644 --- a/neurom/check/morphology_checks.py +++ b/neurom/check/morphology_checks.py @@ -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 @@ -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) diff --git a/tests/check/test_morphology_checks.py b/tests/check/test_morphology_checks.py index 0322f0fd..4a92ae98 100644 --- a/tests/check/test_morphology_checks.py +++ b/tests/check/test_morphology_checks.py @@ -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)]