Skip to main content

A Python package to work with the HPO Ontology

Project description

A Python library to work with, analyze, filter and inspect the Human Phenotype Ontology

Visit the PyHPO Documentation for 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 diseases

PyHPO allows working on individual terms HPOTerm, a set of terms HPOSet and the full Ontology.

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 create Pandas Dataframe from its data, allowing integration in already existing data anlysis tools.

Examples

How similar are the phenotypes of two patients

from pyhpo import Ontology
from pyhpo.set import HPOSet

# initilize the Ontology ()
_ = Ontology()

# Declare the clinical information of the patients
patient_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 similarity
patient_1.similarity(patient_2)
#> 0.7594183905785477

How close are two HPO terms

from pyhpo import Ontology

# 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)
for t in path[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
"""

Getting started

The easiest way to install PyHPO is via pip

pip install pyhpo

or, you can additionally install optional packages for extra functionality

# Include pandas during install
pip install pyhpo[pandas]

# Include scipy
pip install pyhpo[scipy]

# Include all dependencies
pip install pyhpo[all]

Usage example

HPOTerm

An HPOTerm contains 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-Term

from pyhpo import Ontology

# initilize the Ontology ()
_ = Ontology()

# Retrieve a term e.g. via its HPO-ID
term = Ontology.get_hpo_object('Scoliosis')

print(term)
#> HP:0002650 | Scoliosis

# Get information content from Term <--> Omim associations
term.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 terms
for p in term.parents:
    print(p)
#> HP:0010674 | Abnormality of the curvature of the vertebral column

# Get a list of all children terms
for p in term.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 term

from pyhpo import Ontology
_ = Ontology()
term = Ontology.get_hpo_object('Scoliosis')

# Let's get a second term, this time using it HPO-ID
term_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 morphology

term.child_of(term_2)
#> True

# or vice versa
term_2.parent_of(term)
#> True

# show all nodes between two term:
path = term.path_to_other(term_2)
for t in path[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 terms
term.similarity_score(term_2)
#> 0.442

(This script is complete, it should run “as is”)

Ontology

The Ontology contains all HPO terms, their connections to each other and associations to genes and diseases. It provides some helper functions for HPOTerm search functionality

Examples

from pyhpo import Ontology, HPOSet

# initilize the Ontology (this must be done only once)
_ = Ontology()

# Get a term based on its name
term = Ontology.get_hpo_object('Scoliosis')
print(term)
#> HP:0002650 | Scoliosis

# ...or based on HPO-ID
term = Ontology.get_hpo_object('HP:0002650')
print(term)
#> HP:0002650 | Scoliosis

# ...or based on its index
term = Ontology.get_hpo_object(2650)
print(term)
#> HP:0002650 | Scoliosis

# shortcut to retrieve a term based on its index
term = Ontology[2650]
print(term)
#> HP:0002650 | Scoliosis

# Search for term
for term in Ontology.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.py

from pyhpo import Ontology, HPOSet

import module2

# initilize the Ontology
_ = Ontology()

if __name__ == '__main__':
    module2.find_term('Compensatory scoliosis')

module2.py

from pyhpo import Ontology

def find_term(term):
    return Ontology.get_hpo_object(term)

HPOSet

An HPOSet is a collection of HPOTerm and can be used to represent e.g. a patient’s clinical information. It provides APIs for filtering, comparisons to other HPOSet and term/gene/disease enrichments.

Examples:

from pyhpo import Ontology, 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): 2943

ci_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 similarity
ci_1.similarity(ci_2)
#> 0.7593552670152157

# Remove all non-leave nodes from a set
ci_leaf = ci_2.child_nodes()
len(ci_2)
#> 4
len(ci_leaf)
#> 1
ci_2
#> HPOSet.from_serialized("925+2650+9121+10674")
ci_leaf
#> HPOSet.from_serialized("2650")

# Check the information content of an HPOSet
ci_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 an HPOSet

Examples:

from pyhpo import Ontology, HPOSet
from pyhpo.stats import EnrichmentModel

# 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 the PyHPO Documentation.

Contributing

Yes, please do so. We appreciate any help, suggestions for improvement or other feedback. Just create a pull-request or open an issue.

License

PyHPO is released under the MIT license.

PyHPO is using the Human Phenotype Ontology. Find out more at http://www.human-phenotype-ontology.org

Sebastian 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyhpo-3.2.0.tar.gz (13.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyhpo-3.2.0-py3-none-any.whl (13.7 MB view details)

Uploaded Python 3

File details

Details for the file pyhpo-3.2.0.tar.gz.

File metadata

  • Download URL: pyhpo-3.2.0.tar.gz
  • Upload date:
  • Size: 13.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pyhpo-3.2.0.tar.gz
Algorithm Hash digest
SHA256 be655ba99c2d8f8a097f300051b9c86f90ce60bb067bb46521b7bc71540568a4
MD5 5f547f579c50b44ece1fb40f4d59696d
BLAKE2b-256 e14d8749119c75a86161ee4b90b4ea497699aca111983eecdcb5061bb245fb89

See more details on using hashes here.

File details

Details for the file pyhpo-3.2.0-py3-none-any.whl.

File metadata

  • Download URL: pyhpo-3.2.0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.17

File hashes

Hashes for pyhpo-3.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b88a140e99db7c3adea5dd9a6171409f6cdc9cee4f702dfb677ba1988b6712e6
MD5 0a137cf81fe69f42b57c30f344749f3b
BLAKE2b-256 f16c6fa17cb58075ba00832da4b9f070eaf743c57b79b649701d63309147896f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page