Value Objects¶
Value Objects are immutable objects that represent domain concepts without identity. Equality is based on their attributes, not on a unique identifier.
KO (KEGG Orthology)¶
KO dataclass ¶
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__ ¶
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
__str__ ¶
__repr__ ¶
Returns debug representation of KO.
Returns:
| Type | Description |
|---|---|
str | Representation in format "KO('KXXXXX')". |
__hash__ ¶
Allows using KO as dictionary key or in sets.
Returns:
| Type | Description |
|---|---|
int | Hash of the ID. |
SampleId¶
SampleId dataclass ¶
Value Object for sample identifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value | str | Sample identifier name (cannot be empty) | required |
Raises:
| Type | Description |
|---|---|
ValueError | If value is empty or contains only spaces |
Notes
This object is immutable ensuring identifier consistency throughout the application lifecycle.
Functions¶
__post_init__ ¶
Validates the identifier after initialization.
Raises:
| Type | Description |
|---|---|
ValueError | If value is empty or None. |
Source code in src/domain/value_objects/sample_id.py
__str__ ¶
Returns string representation of Sample ID.
Returns:
| Type | Description |
|---|---|
str | The identifier value. |
__repr__ ¶
Returns debug representation of Sample ID.
Returns:
| Type | Description |
|---|---|
str | Representation in format "SampleId('value')". |
__hash__ ¶
Allows using SampleId as dictionary key.
Returns:
| Type | Description |
|---|---|
int | Hash of the value. |
Pathway¶
Pathway dataclass ¶
Value Object for KEGG metabolic pathway.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id | str | Pathway identifier (e.g., 'map00010') | required |
name | str | Descriptive pathway name (e.g., 'Glycolysis / Gluconeogenesis') | required |
Raises:
| Type | Description |
|---|---|
ValueError | If ID or name are empty |
Notes
Pathways are immutable and uniquely identified by ID.
Functions¶
__post_init__ ¶
Validates pathway fields.
Raises:
| Type | Description |
|---|---|
ValueError | If ID or name are invalid. |
Source code in src/domain/value_objects/pathway.py
__str__ ¶
__repr__ ¶
Returns debug representation of pathway.
Returns:
| Type | Description |
|---|---|
str | Representation in format "Pathway('id', 'name')". |
Compound¶
Compound dataclass ¶
Value Object for chemical compound.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cpd | str | Compound identifier code (e.g., 'C00001') | required |
name | str | Compound name (e.g., 'H2O', 'Water') | required |
smiles | Optional[str] | SMILES notation of the compound | None |
chebi | Optional[str] | ChEBI identifier | None |
Raises:
| Type | Description |
|---|---|
ValueError | If cpd or name are empty |
Notes
Compounds are uniquely identified by cpd code. SMILES and ChEBI are optional for data enrichment.
Functions¶
__post_init__ ¶
Validates required compound fields.
Raises:
| Type | Description |
|---|---|
ValueError | If cpd or name are invalid. |
Source code in src/domain/value_objects/compound.py
__str__ ¶
__repr__ ¶
Returns debug representation of compound.
Returns:
| Type | Description |
|---|---|
str | Representation with cpd and name. |
__hash__ ¶
has_structure ¶
Checks if compound has structural information (SMILES).
Returns:
| Type | Description |
|---|---|
bool | True if SMILES is defined. |
has_chebi ¶
Checks if compound has ChEBI reference.
Returns:
| Type | Description |
|---|---|
bool | True if ChEBI is defined. |
Related Documentation¶
- Domain Entities - Business objects with identity
- Domain Services - Business logic operations
Value Object Principles¶
According to Domain-Driven Design (DDD):
- Immutability: Once created, cannot be changed
- Equality by Value: Two value objects are equal if all attributes match
- No Identity: Don't have a unique identifier
- Validation: Business rules enforced at construction time