HPOTerm

HPOTerm instances contain all relevant information about a single HPO term. They are part of an Ontology and contain links to parental and offspring HPOTerm s.

HPOTerm

class pyhpo.term.HPOTerm(**kwargs)[source]

An HPOTerm instance can be build solely by itself, without knowledge of the actual Ontology. This is not recommended because it would miss all ontology features, such as parents, children, associated genes and diseaases etc.

An HPOTerm instance should always be derived from the pyhpo.Ontology

Parameters:
  • id (str) –

  • name (str) –

  • index (int) –

  • comment (str) –

  • definition (str) –

  • synonym (List[str]) –

  • xref (List[str]) –

  • alt_id (List[str]) –

  • is_obsolete (bool) –

  • replaced_by (str | None) –

  • consider (List[str]) –

  • parents (Set[HPOTerm]) –

  • children (Set[HPOTerm]) –

  • genes (Set[GeneSingleton]) –

  • omim_diseases (Set[OmimDisease]) –

  • omim_excluded_diseases (Set[OmimDisease]) –

  • orpha_diseases (Set[OrphaDisease]) –

  • orpha_excluded_diseases (Set[OrphaDisease]) –

  • decipher_diseases (Set[DecipherDisease]) –

  • decipher_excluded_diseases (Set[DecipherDisease]) –

  • information_content (InformationContent) –

Attributes

HPOTerm.id: str

The HPO identifier, e.g. HP:0000118

HPOTerm.name: str

The name of the HPO term, e.g. Abnormal axial skeleton morphology

HPOTerm.information_content: InformationContent

The InformationContent of the HPO term. Multiple kinds of IC are automatically calculated, others can be manually calculated.

HPOTerm.comment: str

The comment from the OBO source file

HPOTerm.definition: str

The definition from the OBO source file

HPOTerm.synonym: List[str]

A list of synonymous names for the term

HPOTerm.parents: Set[HPOTerm]

A set of all direct parent terms

HPOTerm.children: Set[HPOTerm]

A set of all direct child terms

HPOTerm.genes: Set[GeneSingleton]

A set of all associated genes. Associated genes are inversely inherited from child terms as well

HPOTerm.omim_diseases: Set[OmimDisease]

A set of all associated Omim diseases. Associated diseases are inversely inherited from child terms as well

HPOTerm.orpha_diseases: Set[OrphaDisease]

A set of all associated Orpha diseases. Associated diseases are inversely inherited from child terms as well

HPOTerm.decipher_diseases: Set[DecipherDisease]

A set of all associated Decipher diseases. Associated diseases are inversely inherited from child terms as well

parent_of

HPOTerm.parent_of(other)[source]

Checks if self is a direct or indirect parent of other.

Parameters:

other (HPOTerm) – HPOTerm to check for lineage dependency

Returns:

Is the HPOTerm a direct or indirect parent of another HPOTerms

Return type:

bool

child_of

HPOTerm.child_of(other)[source]

Checks if self is a direct or indirect child of other.

Parameters:

other (HPOTerm) – HPOTerm to check for lineage dependency

Returns:

Is the HPOTerm a direct or indirect child of another HPOTerms

Return type:

bool

parent_ids

HPOTerm.parent_ids()[source]
Return type:

List[int]

common_ancestors

HPOTerm.common_ancestors(other)[source]

Identifies all common ancestors of two HPO terms

Parameters:

other (HPOTerm) – Target HPO term for path finding

Returns:

Set of common ancestor HPOTerms

Return type:

set

count_parents

HPOTerm.count_parents()[source]

Calculates total number of ancestral HPO Terms

Returns:

The number of all ancestral HPO Terms

Return type:

int

longest_path_to_root

HPOTerm.longest_path_to_root()[source]

Calculates the longest path to root

Returns:

Maximum number of nodes until the root HPOTerm

Return type:

int

shortest_path_to_root

HPOTerm.shortest_path_to_root()[source]

Calculates the shortest path to root

Returns:

Minimum number of nodes until the root HPOTerm

Return type:

int

shortest_path_to_parent

HPOTerm.shortest_path_to_parent(other)[source]

Calculates the shortest path to another HPO Term

Parameters:

other (HPOTerm) – parent HPOTerm instance

Return type:

Tuple[int, Tuple[HPOTerm, ...]]

Returns:

  • int – Minimum number of nodes until the specified HPOTerm

    (float(β€˜inf’) if other is not a parent.)

  • tuple – Tuple of all HPOTerm instances on the path

    (None if other is not a parent)

longest_path_to_bottom

HPOTerm.longest_path_to_bottom(level=0)[source]

Calculates how far the most distant child is apart

Parameters:

level (int) – Offset level to indicate for calculation Default: 0

Returns:

Number of steps to most distant child

Return type:

int

path_to_other

HPOTerm.path_to_other(other)[source]

Identifies the shortest connection between two HPO terms

Parameters:

other (HPOTerm) – Target HPO term for path finding

Return type:

Tuple[int, Tuple[HPOTerm, ...], int, int]

Returns:

  • int – Length of path

  • tuple – Tuple of HPOTerms in the path

  • int – Number of steps from term-1 to the common parent

  • int – Number of steps from term-2 to the common parent

similarity_score

HPOTerm.similarity_score(other, kind=None, method=None)[source]

Calculate the similarity between this and another HPO-Term It uses pyhpo.similarity.base._Similarity underneath

Parameters:
Raises:
  • RuntimeError – The specified method does not exist

  • NotImplementedError – This error can only occur with custom Similarity-Score methods that do not have a similarity method defined.

  • AttributeError – The information content for kind does not exist

Return type:

float

toJSON

HPOTerm.toJSON(verbose=False)[source]

Creates a JSON-like object of the HPOTerm

Parameters:

verbose (bool, default False) – Include extra properties

Returns:

A dictionary with the main properties of the HPOTerm

Return type:

dict

Example:

>>> terms[2].toJSON()
{
    'name': 'Abnormality of body height',
    'id': 'HP:0000002',
    'int': 2
}

>>> terms[2].toJSON(verbose=True)
{
    'name': 'Abnormality of body height',
    'synonym': ['Abnormality of body height'],
    'comment': None,
    'def': '"Deviation from the norm of height with respect [...]',
    'xref': ['UMLS:C4025901'],
    'is_a': ['HP:0001507 ! Growth abnormality'],
    'id': 'HP:0000002',
    'int': 2
}

InformationContent

class pyhpo.term.InformationContent(**data)[source]

InformationContent contains automatically calculated IC based on direct/indirect associations with genes, omim, orpha and decipher. IC instances are created automatically and accessed through pyhpo.term.HPOTerm instances.

Users can also register and calculate custom IC scores via pyhpo.term.InformationContent.set_custom().

Parameters:
  • gene (float) –

  • omim (float) –

  • orpha (float) –

  • decipher (float) –

  • custom (Dict[str, float]) –

Default attributes

InformationContent.gene: float
InformationContent.omim: float
InformationContent.orpha: float
InformationContent.decipher: float

set_custom

InformationContent.set_custom(key, value)[source]

Set the IC of a custom score

Parameters:
  • key (str) – The name of the information-content metric

  • value (float) – The actual information content

Return type:

None

Example:

for term in Ontology:
    # For some reason, you want to base the information content
    # on the depths of the Term in the ontology
    term.setcustom('depth',  term.shortest_path_to_root())

# and now calculate similarity of two sets
my_similarity = term_set_1.similarity(term_set_2, kind='depth')