Skip to content

Commit 47c1b6d

Browse files
committed
Return additional metadata from /flatmap/MAP_UUID/connectivity/PATH_ID so result is compatible with SCKAN connectivity query.
1 parent 14ddd13 commit 47c1b6d

1 file changed

Lines changed: 28 additions & 3 deletions

File tree

mapserver/server/flatmap.py

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
from ..settings import settings
4141
from ..utils import get_metadata, json_metadata, json_map_metadata
4242

43+
from .knowledge import query_knowledge
44+
4345
#===============================================================================
4446
"""
4547
If a file with this name exists in the map's output directory then the map
@@ -258,6 +260,17 @@ async def flatmap_pathways(map_uuid: str) -> dict:
258260

259261
#===============================================================================
260262

263+
CONNECTIVITY_PROPERTIES = [
264+
'label',
265+
'biologicalSex',
266+
'long-label',
267+
'pathDisconnected',
268+
'phenotypes',
269+
'references',
270+
'source',
271+
'taxons',
272+
]
273+
261274
@get('flatmap/{map_uuid:str}/connectivity/{path_id:path}')
262275
async def flatmap_connectivity(map_uuid: str, path_id: str) -> dict:
263276
path_id = path_id[1:] # Remove leading '/''
@@ -269,13 +282,25 @@ async def flatmap_connectivity(map_uuid: str, path_id: str) -> dict:
269282
if not path_id.startswith('ilxtr:') or path_id not in paths:
270283
raise exceptions.NotFoundException(detail=f'Unknown path: {path_id}')
271284
path = paths[path_id]
272-
return {
273-
'path': path_id,
285+
connectivity = {
286+
'id': path_id,
274287
'connectivity': path.get('connectivity', []),
275288
'axons': path.get('axons', []),
276289
'dendrites': path.get('dendrites', []),
277-
'somas': path.get('somas', [])
290+
'somas': path.get('somas', []),
278291
}
292+
metadata = json_map_metadata(map_uuid, 'metadata')
293+
source = metadata.get('connectivity', {}).get('knowledge-source')
294+
if source is not None:
295+
result = query_knowledge('select knowledge from knowledge where source=? and entity=?', [source, path_id])
296+
if 'error' in result:
297+
connectivity['error'] = result['error']
298+
else:
299+
knowledge = json.loads(result['values'][0][0])
300+
for key in CONNECTIVITY_PROPERTIES:
301+
if key in knowledge:
302+
connectivity[key] = knowledge[key]
303+
return connectivity
279304

280305
#===============================================================================
281306
#===============================================================================

0 commit comments

Comments
 (0)