Skip to content

KEGG Orthology

kegg_orthology

KEGG Orthology Value Object

Represents an immutable KEGG Orthology (KO) identifier.

Classes

KO dataclass

KO(id: str)

Immutable Value Object for KEGG Orthology.

Parameters:

Name Type Description Default
id str

KO identifier in format 'KXXXXX' where X are digits Example: 'K00001', 'K12345'

required

Raises:

Type Description
ValueError

If ID does not start with 'K' or does not have exactly 6 characters

Notes

This object is immutable (frozen=True) ensuring that once created it cannot be modified, respecting the DDD Value Object principle.

Functions
__post_init__
__post_init__()

Validates KO ID format after initialization.

Raises:

Type Description
ValueError

If ID is invalid (does not start with 'K' or length != 6).

Source code in src/domain/value_objects/kegg_orthology.py
def __post_init__(self):
    """
    Validates KO ID format after initialization.

    Raises
    ------
    ValueError
        If ID is invalid (does not start with 'K' or length != 6).
    """
    if not self.id:
        logger.warning("KO validation failed: Empty ID")
        raise ValueError("KO ID cannot be empty")

    if not self.id.startswith("K"):
        logger.warning(
            "KO validation failed: Invalid prefix", extra={"ko_id": self.id}
        )
        raise ValueError(f"Invalid KO ID: {self.id}. Must start with 'K'")

    if len(self.id) != 6:
        logger.warning(
            "KO validation failed: Invalid length",
            extra={"ko_id": self.id, "length": len(self.id)},
        )
        raise ValueError(
            f"Invalid KO ID: {self.id}. Must have exactly 6 characters"
        )

    # Verifica se os 5 últimos caracteres são dígitos
    if not self.id[1:].isdigit():
        logger.warning(
            "KO validation failed: Non-numeric suffix", extra={"ko_id": self.id}
        )
        raise ValueError(
            f"Invalid KO ID: {self.id}. Last 5 characters must be digits"
        )

    logger.debug("KO created successfully", extra={"ko_id": self.id})
__str__
__str__() -> str

Returns string representation of KO.

Returns:

Type Description
str

The KO ID.

Source code in src/domain/value_objects/kegg_orthology.py
def __str__(self) -> str:
    """
    Returns string representation of KO.

    Returns
    -------
    str
        The KO ID.
    """
    return self.id
__repr__
__repr__() -> str

Returns debug representation of KO.

Returns:

Type Description
str

Representation in format "KO('KXXXXX')".

Source code in src/domain/value_objects/kegg_orthology.py
def __repr__(self) -> str:
    """
    Returns debug representation of KO.

    Returns
    -------
    str
        Representation in format "KO('KXXXXX')".
    """
    return f"KO('{self.id}')"
__hash__
__hash__() -> int

Allows using KO as dictionary key or in sets.

Returns:

Type Description
int

Hash of the ID.

Source code in src/domain/value_objects/kegg_orthology.py
def __hash__(self) -> int:
    """
    Allows using KO as dictionary key or in sets.

    Returns
    -------
    int
        Hash of the ID.
    """
    return hash(self.id)

Functions