#!/usr/bin/env python# -*- coding: utf-8 -*-## This file is part of the `pypath` python module## Copyright 2014-2023# EMBL, EMBL-EBI, Uniklinik RWTH Aachen, Heidelberg University## Authors: see the file `README.rst`# Contact: Dénes Türei (turei.denes@gmail.com)## Distributed under the GPLv3 License.# See accompanying file LICENSE.txt or copy at# https://www.gnu.org/licenses/gpl-3.0.html## Website: https://pypath.omnipathdb.org/#fromtypingimportAnyimportpypath.share.commonascommonfrompypath.inputs.hmdbimport_logXMLNS='{http://www.hmdb.ca}'SIMPLE_FIELDS={'accession','name','version',}ARRAY_FIELDS={('secondary_accessions','accession'),('synonyms','synonym'),}PATHWAYS=('pathways',('pathway','findall'),{'name','smpdb_id','kegg_map_id'},)def_ref_chunk(container:str='references')->tuple:return(container,('reference','findall'),'pubmed_id',None,)
defprocess(self,record)->tuple[tuple[Any]]:value=((record,),)name=common.to_tuple(self.name)fordinself.d:ifd=='@':value=tuple(v[0]ifisinstance(v[0],(list,tuple))elsevforvinvalue)elifd=='*'orisinstance(d,tuple):ifd=='*':d=tuple(sorted(value[0][0].keys()))iflen(value[0][0])>1:_log('List of dicts content encountered.')value=value[0][0]value=tuple((value.get(k),)forkind)name=tuple(f'{n}__{k}'forninnameforkind)elifisinstance(d,str):value=tuple(tuple(v.get(d)forvinvv)forvvinvalue)returnname,valuedef__str__(self):returnself.name