#!/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/#from__future__importannotationsfromtypingimportGenerator,NamedTupleimportcollectionsimportpandasaspdimportpypath.share.curlascurlimportpypath.resources.urlsasurlsimportpypath.inputs.commonasinputs_common_notavail=lambdax:Noneifx=='Not Available'elsex_synonyms=lambdax:(tuple(sorted(y.strip()foryinx.split('|')))ifxelse())
[docs]defadrecs_drug_identifiers(return_df:bool=False,)->list[tuple]|pd.DataFrame:""" Drug identifiers from the AdReCS database. IUPAC name, synonyms, DrugBank, MeSH, KEGG and TDD IDs of drugs. http://www.bio-add.org/ADReCS/index.jsp Args: return_df: Return a pandas data frame. Returns: List of tuples or data frame of drug identifiers. """return_adrecs_base(url_key='drug_information',record=AdrecsDrug,cell_range='A1:H2527',synonym_idx=[2],return_df=return_df,)
[docs]defadrecs_adr_ontology(return_df:bool=False)->list[AdrecsTerm]|pd.DataFrame:""" Adverse drug reaction (ADR) ontology from the AdReCS database. Args: return_df: Return a pandas data frame. Returns: List of tuples or data frame of adverse drug reaction terms. """return_adrecs_base(url_key='terminology',record=AdrecsTerm,cell_range='A1:E13856',synonym_idx=[3],return_df=return_df,)
[docs]defadrecs_drug_adr(return_df:bool=False,)->Generator[AdrecsDrugAdr]|pd.DataFrame:""" Drug-ADR pairs from the AdReCS database. Args: return_df: Return a pandas data frame. Returns: List of tuples or data frame of drug-ADR pairs. """result=_adrecs_drug_adr()returnpd.DataFrame(result)ifreturn_dfelseresult
[docs]defadrecs_hierarchy()->set[AdrecsChildParent]:""" Child-parent relationships between AdReCS ontology terms. Return: Set of tuples representing child-parent relationship. Both the child and parent terms present with their numeric class and BADD identifiers. """adr_ontology=adrecs_adr_ontology()child_adrs={record.adrecs_class:record.baddforrecordinadr_ontology}result=set()forfieldinadr_ontology:if'.'notinfield.adrecs_class:continueparent_adrecs=field.adrecs_class.rsplit('.',1)[0]result.add(AdrecsChildParent(child=AdrecsAdr(adr_class=field.adrecs_class,badd=field.badd,),parent=AdrecsAdr(adr_class=parent_adrecs,badd=child_adrs.get(parent_adrecs),),))returnresult