Graph

class Graph(*, id: str | None = None, meta: ~bioontologies.obograph.Meta | None = None, nodes: list[~bioontologies.obograph.Node] = <factory>, edges: list[~bioontologies.obograph.Edge] = <factory>, equivalentNodesSets: list[~typing.Any] = <factory>, logicalDefinitionAxioms: list[~typing.Any] = <factory>, domainRangeAxioms: list[~typing.Any] = <factory>, propertyChainAxioms: list[~typing.Any] = <factory>, prefix: str | None = None, standardized: bool = False)[source]

Bases: BaseModel, StandardizeMixin

A graph corresponds to an ontology.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Attributes Summary

default_namespace

Get the version of the ontology.

description

Get the license of the ontology.

license

Get the license of the ontology.

model_config

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

roots

Get the ontology root terms.

title

Get the title of the ontology.

version

Get the version of the ontology.

version_iri

Get the version of the ontology.

Methods Summary

get_alternative_ids()

Get a mapping of primary identifiers to secondary identifiers.

get_curie_to_name()

Get a mapping from CURIEs to names.

get_edges_df(*[, require_labels])

Get all triples as a dataframe.

get_incoming_xrefs(prefix)

Get incoming xrefs.

get_networkx()

Get a networkx multi-directional graph.

get_nodes_df([sep])

Get a nodes dataframe appropriate for serialization.

get_sssom_df()

Get a SSSOM dataframe of mappings.

get_xrefs()

Get all database cross-references from the ontology.

nodes_from(prefix)

Iterate non-deprecated nodes whose identifiers start with the given prefix.

standardize([keep_invalid, use_tqdm, nodes, ...])

Standardize the OBO graph.

Attributes Documentation

default_namespace

Get the version of the ontology.

description

Get the license of the ontology.

license

Get the license of the ontology.

model_config: ClassVar[ConfigDict] = {}

Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].

roots

Get the ontology root terms.

title

Get the title of the ontology.

version

Get the version of the ontology.

version_iri

Get the version of the ontology.

Methods Documentation

get_alternative_ids() Mapping[str, list[str]][source]

Get a mapping of primary identifiers to secondary identifiers.

get_curie_to_name() Mapping[str, str][source]

Get a mapping from CURIEs to names.

get_edges_df(*, require_labels: bool = False) DataFrame[source]

Get all triples as a dataframe.

get_incoming_xrefs(prefix: str) Mapping[str, str][source]

Get incoming xrefs.

Parameters:

prefix – An external prefix.

Returns:

A dictionary of external local unique identifiers to local unique identifiers in this ontology

get_networkx()[source]

Get a networkx multi-directional graph.

get_nodes_df(sep: str = ';') DataFrame[source]

Get a nodes dataframe appropriate for serialization.

get_sssom_df() DataFrame[source]

Get a SSSOM dataframe of mappings.

get_xrefs() list[tuple[Reference, Reference, Reference]][source]

Get all database cross-references from the ontology.

nodes_from(prefix: str) Iterable[Node][source]

Iterate non-deprecated nodes whose identifiers start with the given prefix.

standardize(keep_invalid: bool = False, use_tqdm: bool = True, nodes: bool = True, edges: bool = True, tqdm_kwargs: Mapping[str, Any] | None = None, prefix: str | None = None) Self[source]

Standardize the OBO graph.

Parameters:
  • keep_invalid – Should CURIEs/IRIs that aren’t handled by the Bioregistry be kept? Defaults to false.

  • use_tqdm – Should a progress bar be used?

  • tqdm_kwargs – Arguments to pass to tqdm if used

  • prefix – The prefix this graph came from (used for logging purposes)

  • nodes – Should nodes be standardized?

  • edges – Should edges be standardized?

Returns:

This OBO graph, modified in place as follows:

  1. Convert IRIs to CURIEs (in many places) using bioregistry

  2. Add alternative identifiers to Node objects