Skip to content

Commit

Permalink
Merge pull request #202 from NeuralEnsemble/feat-metrics-handle-cell-…
Browse files Browse the repository at this point in the history
…root

fix(nml): handle cell root as a special case
  • Loading branch information
sanjayankur31 authored Sep 13, 2024
2 parents 77b58d3 + 57522d5 commit f7352ca
Show file tree
Hide file tree
Showing 2 changed files with 75 additions and 47 deletions.
60 changes: 37 additions & 23 deletions neuroml/nml/helper_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -2423,8 +2423,17 @@ def get_segment_location_info(self, seg_id):
- distance from the segment group root segment
"""
soma_id = self.get_morphology_root()
distance_from_soma = self.get_distance(seg_id, source=soma_id)
res = {}
cell_root_id = self.get_morphology_root()
is_cell_root = False
if seg_id == cell_root_id:
is_cell_root = True
if not is_cell_root:
distance_from_soma = self.get_distance(seg_id, source=cell_root_id)
else:
distance_from_soma = 0.0
in_sg = None
sg_segs = None
sg_root = None
Expand All @@ -2449,35 +2458,40 @@ def get_segment_location_info(self, seg_id):
# (a segment with more than one child)
current = seg_id
sg_root = current
parent = list(graph.predecessors(current))[0]
children = list(graph.successors(parent))
while len(children) == 1:
# the root of the segment group may not be at a
# branching point: an unbranched cell branch can consist of
# multiple unbranched segment groups
if in_sg is not None:
if current in sg_segs:
sg_root = current
current = parent
if not is_cell_root:
parent = list(graph.predecessors(current))[0]
children = list(graph.successors(parent))
distance_from_bpt = self.get_distance(seg_id, source=current)
res = {}
res['id'] = seg_id
res['length'] = self.get_segment_length(seg_id)
res['distance_from_cell_root'] = distance_from_soma
res['distance_from_nearest_branching_point'] = distance_from_bpt
while len(children) == 1:
# the root of the segment group may not be at a
# branching point: an unbranched cell branch can consist of
# multiple unbranched segment groups
if in_sg is not None:
if current in sg_segs:
sg_root = current
current = parent
parent = list(graph.predecessors(current))[0]
children = list(graph.successors(parent))
distance_from_bpt = self.get_distance(seg_id, source=current)
else:
distance_from_bpt = 0.0
# at unbranched segment root
if in_sg is not None:
res['in_unbranched_segment_group'] = in_sg.id
res['unbranched_segment_group_root'] = sg_root
distance_from_sg_root = self.get_distance(seg_id, source=sg_root)
res['distance_from_segment_group_root'] = distance_from_sg_root
if not is_cell_root:
distance_from_sg_root = self.get_distance(seg_id, source=sg_root)
res['distance_from_segment_group_root'] = distance_from_sg_root
else:
res['distance_from_segment_group_root'] = 0.0
res['id'] = seg_id
res['length'] = self.get_segment_length(seg_id)
res['distance_from_cell_root'] = distance_from_soma
res['distance_from_nearest_branching_point'] = distance_from_bpt
return res
Expand Down
62 changes: 38 additions & 24 deletions neuroml/nml/nml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
# -*- coding: utf-8 -*-

#
# Generated Thu Sep 12 16:44:57 2024 by generateDS.py version 2.44.1.
# Python 3.11.9 (main, Aug 23 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)]
# Generated Fri Sep 13 14:23:30 2024 by generateDS.py version 2.44.1.
# Python 3.11.10 (main, Sep 9 2024, 00:00:00) [GCC 14.2.1 20240801 (Red Hat 14.2.1-1)]
#
# Command line options:
# ('-o', 'nml.py')
Expand Down Expand Up @@ -49999,8 +49999,17 @@ def get_segment_location_info(self, seg_id):
- distance from the segment group root segment

"""
soma_id = self.get_morphology_root()
distance_from_soma = self.get_distance(seg_id, source=soma_id)
res = {}
cell_root_id = self.get_morphology_root()
is_cell_root = False
if seg_id == cell_root_id:
is_cell_root = True

if not is_cell_root:
distance_from_soma = self.get_distance(seg_id, source=cell_root_id)
else:
distance_from_soma = 0.0

in_sg = None
sg_segs = None
sg_root = None
Expand All @@ -50025,35 +50034,40 @@ def get_segment_location_info(self, seg_id):
# (a segment with more than one child)
current = seg_id
sg_root = current
parent = list(graph.predecessors(current))[0]
children = list(graph.successors(parent))

while len(children) == 1:
# the root of the segment group may not be at a
# branching point: an unbranched cell branch can consist of
# multiple unbranched segment groups
if in_sg is not None:
if current in sg_segs:
sg_root = current

current = parent
if not is_cell_root:
parent = list(graph.predecessors(current))[0]
children = list(graph.successors(parent))

distance_from_bpt = self.get_distance(seg_id, source=current)
while len(children) == 1:
# the root of the segment group may not be at a
# branching point: an unbranched cell branch can consist of
# multiple unbranched segment groups
if in_sg is not None:
if current in sg_segs:
sg_root = current

res = {}
res["id"] = seg_id
res["length"] = self.get_segment_length(seg_id)
res["distance_from_cell_root"] = distance_from_soma
res["distance_from_nearest_branching_point"] = distance_from_bpt
current = parent
parent = list(graph.predecessors(current))[0]
children = list(graph.successors(parent))

distance_from_bpt = self.get_distance(seg_id, source=current)
else:
distance_from_bpt = 0.0

# at unbranched segment root
if in_sg is not None:
res["in_unbranched_segment_group"] = in_sg.id
res["unbranched_segment_group_root"] = sg_root
distance_from_sg_root = self.get_distance(seg_id, source=sg_root)
res["distance_from_segment_group_root"] = distance_from_sg_root
if not is_cell_root:
distance_from_sg_root = self.get_distance(seg_id, source=sg_root)
res["distance_from_segment_group_root"] = distance_from_sg_root
else:
res["distance_from_segment_group_root"] = 0.0

res["id"] = seg_id
res["length"] = self.get_segment_length(seg_id)
res["distance_from_cell_root"] = distance_from_soma
res["distance_from_nearest_branching_point"] = distance_from_bpt

return res

Expand Down

0 comments on commit f7352ca

Please sign in to comment.