Skip to content

Commit ac474e5

Browse files
authored
Merge pull request #175 from napakalas/issue-#174
Expose rendered-to-SCKAN node mappings via pathways.
2 parents ec6f451 + 5cda4b1 commit ac474e5

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

mapmaker/properties/pathways.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def __init__(self):
128128
self.__node_phenotypes = dict()
129129
self.__forward_connections = set()
130130
self.__node_nerves = set()
131+
self.__node_mappings = set()
131132

132133
@property
133134
def as_dict(self) -> dict[str, Any] :
@@ -142,7 +143,8 @@ def as_dict(self) -> dict[str, Any] :
142143
'connectivity': list(self.__connectivity),
143144
'node-phenotypes': self.__node_phenotypes,
144145
'forward-connections': list(self.__forward_connections),
145-
'node-nerves': list(self.__node_nerves)
146+
'node-nerves': list(self.__node_nerves),
147+
'node-mappings': list(self.__node_mappings)
146148
}
147149
if len(self.__centrelines):
148150
result['centrelines'] = list(self.__centrelines)
@@ -239,6 +241,17 @@ def extend_node_nerves(self, node_nerves: list[tuple]):
239241
"""
240242
self.__node_nerves.update(node_nerves)
241243

244+
def extend_node_mappings(self, node_mappings: list[tuple]):
245+
"""
246+
Associate rendered node mapping with the path.
247+
248+
Arguments:
249+
----------
250+
node_mappings
251+
Rendered node_mappings
252+
"""
253+
self.__node_mappings.update(node_mappings)
254+
242255
#===============================================================================
243256

244257
class Route:
@@ -359,6 +372,11 @@ def list_to_tuple(obj):
359372
'node_nerves': [
360373
list_to_tuple(n) for n in connectivity_graph.graph.get('nerves', [])
361374
if list_to_tuple(n) in available_nodes
375+
],
376+
'node_mappings': [
377+
# mapping from rendered node to knowledge node
378+
(list_to_tuple(connectivity_graph.nodes[node]['node']), list_to_tuple(node))
379+
for node in connectivity_graph.nodes
362380
]
363381
}
364382
return rendered_data
@@ -382,6 +400,7 @@ def add_connectivity(self, path_id: str, line_geojson_ids: list[int],
382400
resolved_path.extend_node_phenotypes(rendered_data['node_phenotypes'])
383401
resolved_path.extend_forward_connections(rendered_data['forward_connections'])
384402
resolved_path.extend_node_nerves(rendered_data['node_nerves'])
403+
resolved_path.extend_node_mappings(rendered_data['node_mappings'])
385404
if centrelines is not None:
386405
resolved_path.add_centrelines(centrelines)
387406

0 commit comments

Comments
 (0)