INDRA CoGEx Representation (indra_cogex.representation)

This documentation goes over helper functions and the python objects that represent Neo4j Nodes and Relations.

Representations for nodes and relations to upload to Neo4j.

class Node(db_ns, db_id, labels, data=None)[source]

Representation for a node.

Initialize the node.

Parameters:
  • db_ns (str) – The namespace associated with the node. Uses the INDRA standard.

  • db_id (str) – The identifier within the namespace associated with the node. Uses the INDRA standard.

  • labels (Collection[str]) – A collection of labels for the node.

  • data (Optional[Mapping[str, Any]]) – An optional data dictionary associated with the node.

grounding()[source]

Get the grounded namespace and identifier for this node as a tuple

Return type:

Tuple[str, str]

Returns:

A tuple of the namespace and identifier for the node.

classmethod standardized(*, db_ns, db_id, name=None, labels)[source]

Initialize the node, but first standardize the prefix/identifier/name.

Parameters:
  • db_ns (str) – The namespace associated with the node.

  • db_id (str) – The identifier within the namespace associated with the node.

  • name (Optional[str]) – An optional name for the node.

  • labels (Collection[str]) – A collection of labels for the node.

Return type:

Node

Returns:

A node with standardized prefix/identifier/name.

to_json()[source]

Serialize the node to JSON.

Return type:

Dict[str, Union[Collection[str], Dict[str, Any]]]

Returns:

A JSON representation of the node.

class Relation(source_ns, source_id, target_ns, target_id, rel_type, data=None)[source]

Representation for a relation.

Initialize the relation.

Parameters:
  • source_ns (str) – The namespace associated with the source node.

  • source_id (str) – The identifier within the namespace associated with the source node.

  • target_ns (str) – The namespace associated with the target node.

  • target_id (str) – The identifier within the namespace associated with the target node.

  • rel_type (str) – The type of relation.

  • data (Optional[Mapping[str, Any]]) – An optional data dictionary associated with the relation.

to_json()[source]

Serialize the relation to JSON format.

Return type:

Dict[str, Union[Mapping[str, Any], Dict]]

Returns:

A JSON representation of the relation.

indra_stmts_from_relations(rels, deduplicate=True)[source]

Convert a list of relations to INDRA Statements.

Any relations that aren’t representing an INDRA Statement are skipped.

Parameters:
  • rels (Iterable[Relation]) – A list of Relations.

  • deduplicate (bool) – If True, only unique statements are returned. In some cases e.g., for Complexes, there are multiple relations for one statement and this option can be used to return only one of these redundant statements. Default: True

Return type:

List[Statement]

Returns:

A list of INDRA Statements.

norm_id(db_ns, db_id)[source]

Normalize an identifier.

Parameters:
  • db_ns – The namespace of the identifier.

  • db_id – The identifier.

Return type:

str

Returns:

The normalized identifier.