From 3bbe21ccde141850df2eeef8140640f94d09af4a Mon Sep 17 00:00:00 2001 From: Eleftherios Zisis Date: Wed, 29 May 2024 15:22:34 +0200 Subject: [PATCH 1/3] Allow fork AcDs --- neurom/core/morphology.py | 6 ++++-- tests/test_mixed.py | 24 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/neurom/core/morphology.py b/neurom/core/morphology.py index 1431eda6..1d10f992 100644 --- a/neurom/core/morphology.py +++ b/neurom/core/morphology.py @@ -454,8 +454,10 @@ def subtree_types(self): subtree_types = [next(it).to_morphio().type] for section in it: - if section.type != section.parent.type: - subtree_types.append(NeuriteType(section.to_morphio().type)) + # A subtree can start from a single branch or as a fork of the same type from a parent + # with different type. + if section.type != section.parent.type and section.type != subtree_types[-1]: + subtree_types.append(section.to_morphio().type) return subtree_types diff --git a/tests/test_mixed.py b/tests/test_mixed.py index b3bed778..92d5660a 100644 --- a/tests/test_mixed.py +++ b/tests/test_mixed.py @@ -1140,3 +1140,27 @@ def test_sholl_frequency_pop(mixed_morph): 2, 0, ] + + +def test_axon_fork_as_axon_carrying_dendrite(): + """Test that a axon subtree starting as a fork is considered an AcD. + """ + m = neurom.load_morphology( + """ + 1 1 0 0 0 0.5 -1 + 2 3 0 1 0 0.1 1 + 3 3 1 2 0 0.1 2 + 4 2 1 4 0 0.1 3 + 5 2 1 4 1 0.1 4 + 6 2 1 4 -1 0.1 4 + 7 2 2 3 0 0.1 3 + 8 2 2 4 0 0.1 7 + 9 2 3 3 0 0.1 7 + 10 2 3 3 1 0.1 9 + 11 2 3 3 -1 0.1 9 + """, + reader="swc", + process_subtrees=True, + ) + neurite = m.neurites[0] + assert neurite.type is NeuriteType.axon_carrying_dendrite From 6996eebd87f1c21fcade0fa77c95d3f02e90acae Mon Sep 17 00:00:00 2001 From: Eleftherios Zisis Date: Thu, 30 May 2024 10:48:00 +0200 Subject: [PATCH 2/3] Fix lint --- neurom/core/morphology.py | 2 +- tests/test_mixed.py | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/neurom/core/morphology.py b/neurom/core/morphology.py index 1d10f992..b3a22611 100644 --- a/neurom/core/morphology.py +++ b/neurom/core/morphology.py @@ -456,7 +456,7 @@ def subtree_types(self): for section in it: # A subtree can start from a single branch or as a fork of the same type from a parent # with different type. - if section.type != section.parent.type and section.type != subtree_types[-1]: + if section.type not in {section.parent.type, subtree_types[-1]}: subtree_types.append(section.to_morphio().type) return subtree_types diff --git a/tests/test_mixed.py b/tests/test_mixed.py index 92d5660a..d06177ec 100644 --- a/tests/test_mixed.py +++ b/tests/test_mixed.py @@ -1143,8 +1143,7 @@ def test_sholl_frequency_pop(mixed_morph): def test_axon_fork_as_axon_carrying_dendrite(): - """Test that a axon subtree starting as a fork is considered an AcD. - """ + """Test that a axon subtree starting as a fork is considered an AcD.""" m = neurom.load_morphology( """ 1 1 0 0 0 0.5 -1 From 700ed2881e2ba90b46e4f6c6e083104c487435b7 Mon Sep 17 00:00:00 2001 From: Eleftherios Zisis Date: Thu, 30 May 2024 10:58:19 +0200 Subject: [PATCH 3/3] Use a tuple --- neurom/core/morphology.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/neurom/core/morphology.py b/neurom/core/morphology.py index b3a22611..6852aeef 100644 --- a/neurom/core/morphology.py +++ b/neurom/core/morphology.py @@ -456,7 +456,7 @@ def subtree_types(self): for section in it: # A subtree can start from a single branch or as a fork of the same type from a parent # with different type. - if section.type not in {section.parent.type, subtree_types[-1]}: + if section.type not in (section.parent.type, subtree_types[-1]): subtree_types.append(section.to_morphio().type) return subtree_types