4040from ..settings import settings
4141from ..utils import get_metadata , json_metadata , json_map_metadata
4242
43+ from .knowledge import query_knowledge
44+
4345#===============================================================================
4446"""
4547If 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}' )
262275async 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