Package: pyhpo
PyHPOA Python library to work with, analyze, filter and inspect theHuman Phenotype OntologyVisit thePyHPO Documentationfor a more detailed overview of all the functionality.Main features👫 Identify patient cohorts based on clinical features👨‍👧‍👦 Cluster patients or other clinical information for GWAS🩻→🧬 Phenotype to Genotype studies🍎🍊 HPO similarity analysis🕸️ Graph based analysis of phenotypes, genes and diseasesPyHPOallows working on individual termsHPOTerm, a set of termsHPOSetand the fullOntology.The library is helpful for discovery of novel gene-disease associations and GWAS data analysis studies. At the same time, it can be used for oragnize clinical information of patients in research or diagnostic settings.Internally the ontology is represented as a branched linked list, every term contains pointers to its parent and child terms. This allows fast tree traversal functionality.It provides an interface to createPandas Dataframefrom its data, allowing integration in already existing data anlysis tools.HintCheck outhpo3(Documentation) for an alternative implementation.hpo3has the exact same functionality, but is much faster 🚀 and supports multithreading for even faster large data processing.Getting startedThe easiest way to installPyHPOis via pippipinstallpyhpoThis will install a base version ofPyHPOthat offers most functionality.NoteSome features of PyHPO requirepandasandscipy. The standard installation via pip will not include pandas or scipy and PyHPO will work just fine. (You will get a warning on the initial import though).Without installingpandas, you won’t be able to export the Ontology as aDataframe, everything else will work fine.Without installingscipy, you won’t be able to use thestatsmodule, especially the enrichment calculations.If you want to do enrichment analysis, you must also installscipy.pipinstall'pyhpo[scipy]'If you want to work withPyHPOusingpandasdataframes, you can install thepandasdependencypipinstall'pyhpo[pandas]'Or simply install both together:# Include all dependenciespipinstall'pyhpo[all]'Usage exampleBasic use casesSome examples for basic functionality of PyHPOHow similar are the phenotypes of two patientsfrompyhpoimportOntologyfrompyhpo.setimportHPOSet# initilize the Ontology ()_=Ontology()# Declare the clinical information of the patientspatient_1=HPOSet.from_queries(['HP:0002943','HP:0008458','HP:0100884','HP:0002944','HP:0002751'])patient_2=HPOSet.from_queries(['HP:0002650','HP:0010674','HP:0000925','HP:0009121'])# and compare their similaritypatient_1.similarity(patient_2)#> 0.7594183905785477How close are two HPO termsfrompyhpoimportOntology# initilize the Ontology ()_=Ontology()term_1=Ontology.get_hpo_object('Scoliosis')term_2=Ontology.get_hpo_object('Abnormal axial skeleton morphology')path=term_1.path_to_other(term_2)fortinpath[1]:print(t)"""
HP:0002650 | Scoliosis
HP:0010674 | Abnormality of the curvature of the vertebral column
HP:0000925 | Abnormality of the vertebral column
HP:0009121 | Abnormal axial skeleton morphology
"""HPOTermAnHPOTermcontains various metadata about the term, as well as pointers to its parents and children terms. You can access its information-content, calculate similarity scores to other terms, find the shortest or longes connection between two terms. List all associated genes or diseases, etc.Examples:Basic functionalities of an HPO-TermfrompyhpoimportOntology# initilize the Ontology ()_=Ontology()# Retrieve a term e.g. via its HPO-IDterm=Ontology.get_hpo_object('Scoliosis')print(term)#> HP:0002650 | Scoliosis# Get information content from Term <--> Omim associationsterm.information_content['omim']#> 2.39# Show how many genes are associated to the term# (Note that this includes indirect associations, associations# from children terms to genes.)len(term.genes)#> 947# Show how many Omim Diseases are associated to the term# (Note that this includes indirect associations, associations# from children terms to diseases.)len(term.omim_diseases)#> 730# Get a list of all parent termsforpinterm.parents:print(p)#> HP:0010674 | Abnormality of the curvature of the vertebral column# Get a list of all children termsforpinterm.children:print(p)"""
HP:0002943 | Thoracic scoliosis
HP:0008458 | Progressive congenital scoliosis
HP:0100884 | Compensatory scoliosis
HP:0002944 | Thoracolumbar scoliosis
HP:0002751 | Kyphoscoliosis
"""(This script is complete, it should run “as is”)Some additional functionality, working with more than one termfrompyhpoimportOntology_=Ontology()term=Ontology.get_hpo_object('Scoliosis')# Let's get a second term, this time using it HPO-IDterm_2=Ontology.get_hpo_object('HP:0009121')print(term_2)#> HP:0009121 | Abnormal axial skeleton morphology# Check if the Scoliosis is a direct or indirect child# of Abnormal axial skeleton morphologyterm.child_of(term_2)#> True# or vice versaterm_2.parent_of(term)#> True# show all nodes between two term:path=term.path_to_other(term_2)fortinpath[1]:print(t)"""
HP:0002650 | Scoliosis
HP:0010674 | Abnormality of the curvature of the vertebral column
HP:0000925 | Abnormality of the vertebral column
HP:0009121 | Abnormal axial skeleton morphology
"""print(f'Steps from Term 1 to Term 2:{path[0]}')#> Steps from Term 1 to Term 2: 3# Calculate the similarity between two termsterm.similarity_score(term_2)#> 0.442(This script is complete, it should run “as is”)OntologyTheOntologycontains all HPO terms, their connections to each other and associations to genes and diseases.
It provides some helper functions forHPOTermsearch functionalityExamplesfrompyhpoimportOntology,HPOSet# initilize the Ontology (this must be done only once)_=Ontology()# Get a term based on its nameterm=Ontology.get_hpo_object('Scoliosis')print(term)#> HP:0002650 | Scoliosis# ...or based on HPO-IDterm=Ontology.get_hpo_object('HP:0002650')print(term)#> HP:0002650 | Scoliosis# ...or based on its indexterm=Ontology.get_hpo_object(2650)print(term)#> HP:0002650 | Scoliosis# shortcut to retrieve a term based on its indexterm=Ontology[2650]print(term)#> HP:0002650 | Scoliosis# Search for termforterminOntology.search('olios'):print(term)"""
HP:0002211 | White forelock
HP:0002290 | Poliosis
HP:0002650 | Scoliosis
HP:0002751 | Kyphoscoliosis
HP:0002943 | Thoracic scoliosis
HP:0002944 | Thoracolumbar scoliosis
HP:0003423 | Thoracolumbar kyphoscoliosis
HP:0004619 | Lumbar kyphoscoliosis
HP:0004626 | Lumbar scoliosis
HP:0005659 | Thoracic kyphoscoliosis
HP:0008453 | Congenital kyphoscoliosis
HP:0008458 | Progressive congenital scoliosis
HP:0100884 | Compensatory scoliosis
"""(This script is complete, it should run “as is”)The Ontology is a Singleton and should only be initiated once.
It can be reused across several modules, e.g:main.pyfrompyhpoimportOntology,HPOSetimportmodule2# initilize the Ontology_=Ontology()if__name__=='__main__':module2.find_term('Compensatory scoliosis')module2.pyfrompyhpoimportOntologydeffind_term(term):returnOntology.get_hpo_object(term)HPOSetAnHPOSetis a collection ofHPOTermand can be used to represent e.g. a patient’s clinical information. It provides APIs for filtering, comparisons to otherHPOSetand term/gene/disease enrichments.Examples:frompyhpoimportOntology,HPOSet# initilize the Ontology_=Ontology()# create HPOSets, corresponding to# e.g. the clinical information of a patient# You can initiate an HPOSet using either# - HPO-ID: 'HP:0002943'# - HPO-Name: 'Scoliosis'# - HPO-ID (int): 2943ci_1=HPOSet.from_queries(['HP:0002943','HP:0008458','HP:0100884','HP:0002944','HP:0002751'])ci_2=HPOSet.from_queries(['HP:0002650','HP:0010674','HP:0000925','HP:0009121'])# Compare the similarityci_1.similarity(ci_2)#> 0.7593552670152157# Remove all non-leave nodes from a setci_leaf=ci_2.child_nodes()len(ci_2)#> 4len(ci_leaf)#> 1ci_2#> HPOSet.from_serialized("925+2650+9121+10674")ci_leaf#> HPOSet.from_serialized("2650")# Check the information content of an HPOSetci_1.information_content()"""
{
    'mean': 6.571224974009769,
    'total': 32.856124870048845,
    'max': 8.97979449089521,
    'all': [5.98406221734122, 8.286647310335265, 8.97979449089521, 5.5458072864100645, 4.059813565067086]
}
"""(This script is complete, it should run “as is”)Get genes enriched in anHPOSetExamples:frompyhpoimportOntology,HPOSetfrompyhpo.statsimportEnrichmentModel# initilize the Ontology_=Ontology()ci=HPOSet.from_queries(['HP:0002943','HP:0008458','HP:0100884','HP:0002944','HP:0002751'])gene_model=EnrichmentModel('gene')genes=gene_model.enrichment(method='hypergeom',hposet=ci)print(genes[0]['item'])#> PAPSS2(This script is complete, it should run “as is”)For a more detailed description of how to use PyHPO, visit thePyHPO Documentation.ContributingYes, please do so. We appreciate any help, suggestions for improvement or other feedback. Just create a pull-request or open an issue.LicensePyHPO is released under theMIT license.PyHPO is using the Human Phenotype Ontology. Find out more athttp://www.human-phenotype-ontology.orgSebastian Köhler, Leigh Carmody, Nicole Vasilevsky, Julius O B Jacobsen, et al. Expansion of the Human Phenotype Ontology (HPO) knowledge base and resources. Nucleic Acids Research. (2018) doi: 10.1093/nar/gky1105