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

Issue #114: Update mechanism to handle unrouted features. #115

Merged
merged 2 commits into from
Feb 12, 2025
Merged
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
30 changes: 13 additions & 17 deletions mapmaker/routing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ def pairwise(iterable):
from mapmaker.properties import PropertiesStore
from mapmaker.properties.pathways import Path

#===============================================================================

NOT_LATERAL_NODES = [
'UBERON:0001896',
'UBERON:0000988',
'UBERON:0001891'
]

#=============================================================

Expand Down Expand Up @@ -758,7 +751,7 @@ def __feature_properties_from_node(self, connectivity_node: AnatomicalNode) -> d

elif matched is not None:
properties['name'] = matched[0].name
features = set(f for f in matched[1] if f.id is not None)
features = set(f for f in matched[1] if f.id is not None and not f.get_property('unrouted', False))
if len(features):
properties['type'] = 'feature'
properties['features'] = features
Expand Down Expand Up @@ -967,7 +960,7 @@ def add_route_edges_from_graph(G, used_nodes):
# else connect to one closest no_segment point and neighbour feature.
features = (
neighbour_dict['features']
if len(neighbour_dict['features']) <= 2 and all(item not in {neighbour_dict['node'][0], *neighbour_dict['node'][1]} for item in NOT_LATERAL_NODES)
if len(neighbour_dict['features']) <= 2
else sorted(neighbour_dict['features'], key=lambda f: f.id)[:1]
)
for feature in features:
Expand Down Expand Up @@ -1204,14 +1197,18 @@ def get_node_feature(node_dict, neighbour_features, used_features) -> Feature:
one_feature_terminals = {
n: min([
features[0].geometry.centroid.distance(nf.geometry.centroid)
for neighbour in connectivity_graph.neighbors(n)
for nf in (
connectivity_graph.nodes[neighbour].get("features", set()) |
{self.__flatmap.get_feature(f_id) for f_id in connectivity_graph.nodes[neighbour].get("used", set())}
)
for nf in nfs
])
for n, n_dict in connectivity_graph.nodes(data=True)
if connectivity_graph.degree(n) == 1 and len(features := list(n_dict.get("features", []))) == 1
if connectivity_graph.degree(n) == 1
and len(features := list(n_dict.get("features", []))) == 1
and len(nfs:= [
nf for neighbour in connectivity_graph.neighbors(n)
for nf in (
connectivity_graph.nodes[neighbour].get("features", set()) |
{self.__flatmap.get_feature(f_id) for f_id in connectivity_graph.nodes[neighbour].get("used", set())}
)
]) > 0
}
one_feature_terminals = dict(sorted(one_feature_terminals.items(), key=lambda item: item[1]))
two_feature_terminals = [
Expand Down Expand Up @@ -1274,7 +1271,7 @@ def add_paths_to_neighbours(node, node_dict):
else used_features.get(node, set())
if connectivity_graph.degree(node) > 1 and len(used_features.get(node, set())) in [1, 2]
else set(node_dict['features'])
if connectivity_graph.degree(node) == 1 and all(item not in {node_dict['node'][0], *node_dict['node'][1]} for item in NOT_LATERAL_NODES)
if connectivity_graph.degree(node) == 1
else [get_node_feature(node_dict, neighbour_features, used_features)]
)
for node_feature in node_features:
Expand Down Expand Up @@ -1302,7 +1299,6 @@ def add_paths_to_neighbours(node, node_dict):
neighbour_features = (
neighbour_dict.get('features', [])
if len(neighbour_dict.get('features', [])) <= 2 and degree == 1 and len(node_features) == 1
and all(item not in {neighbour_dict['node'][0], *neighbour_dict['node'][1]} for item in NOT_LATERAL_NODES)
else [get_node_feature(neighbour_dict, [node_feature], used_features)]
if len(neighbour_terminal_laterals) > 0 and len(used_features.get(neighbour, set())) == 0
else [get_node_feature(neighbour_dict, [node_feature], used_features)]
Expand Down
Loading