bkbit.utils.generate_bkbit_id module

Module for generating unique BKBit object IDs using SHA-256 hashing.

bkbit.utils.generate_bkbit_id.NON_IDENTIFYING_ATTRIBUTES = frozenset({'broad_match', 'close_match', 'exact_match', 'mapping_relation', 'narrow_match', 'related_match'})

the SKOS ontology mappings.

The id is a content hash, so whatever is hashed becomes part of what makes an entity that entity. Two consequences follow:

  1. Changing a hashed attribute renumbers the entity, then everything that refers to it, recursively. In a cell taxonomy one abbreviation feeds CellTypeTaxon.has_abbreviation, which feeds the taxon’s own id, which feeds has_parent on its children – so recording a new ontology mapping on an abbreviation would renumber most of the tree.

  2. Two sources recording different mappings for the same entity produce two different nodes, so the mappings never meet. Keeping them out lets the descriptions merge onto one node.

The SKOS mapping properties are links between concepts in different schemes – assertions about an entity rather than part of what it is – and they are open-ended: more get discovered over time.

xref is deliberately not listed. For some classes it is the only attribute that tells two entities apart: a GenomeAssembly’s accession lives only in its NCBIAssembly: xref, so the GenBank (GCA_) and RefSeq (GCF_) assemblies of one genome, which share a name and version, would otherwise get the same id.

Type:

Attributes deliberately kept out of the identity hash

bkbit.utils.generate_bkbit_id.generate_object_id(attributes: dict)[source]

Generate a unique object ID based on the provided attributes.

Attributes named in NON_IDENTIFYING_ATTRIBUTES are ignored, so recording a new ontology mapping for an entity does not change its id. Cross references (xref) are still hashed.

Parameters:

attributes (dict) – A dictionary containing the attributes of the object.

Returns:

The generated object ID.

Return type:

str