Generic¶
The foundational layer shared across all IRIS domains. Every domain entity, value object, and repository builds on the abstractions defined here.
Entity Relationship Diagram¶
Overview¶
The module is organized in four files:
| File | Contents |
|---|---|
abstracts.py |
Metadata, AliasSet, SerializableFlag |
entities.py |
NamedEntity — simplest base entity |
objects.py |
Sex, QualityCategory, contact value objects |
repositories.py |
Repository[T] hierarchy + EventPublisher |
Design rules¶
All objects are @define(frozen=True) (attrs). State is never mutated in place;
attrs.evolve() produces a modified copy. This applies uniformly from base
abstractions down to the most specific domain entity.
Metadata¶
A generic key-value container for provenance data — source name, version string,
and an arbitrary data mapping. The mapping is frozen on construction so the
object remains immutable. Use with_data(**kwargs) to add keys or merge(other)
to combine two instances (the other's keys win on collision). Entities that carry
provenance attach a Metadata | None field rather than scattering ad-hoc
string fields.
AliasSet¶
An immutable set of canonical names with an optional alias mapping. Used wherever
a domain concept has multiple valid identifiers — gene symbols (GeneNomenclature
stores an AliasSet of HGNC symbols and aliases), transcript names, disease codes.
resolve(value) returns the canonical name, falling back to the value itself when
no alias entry exists.
SerializableFlag¶
Base class for composite Flag enums that need round-trip serialization to
PostgreSQL TEXT[] or a pipe-separated VARCHAR. Concrete examples:
MendelianInheritance (AD, AR, XLR, XLD…) in the genomics domain. Subclasses
inherit to_list(), to_str(), from_list(), and from_str() without any
additional implementation.
Repository hierarchy¶
Repository[T] get(id) → T | None
├── ReadRepository[T] + find_all() → Sequence[T]
├── WriteRepository[T] + save(T) → T, delete(id)
└── CrudRepository[T] (ReadRepository + WriteRepository)
Genomics repositories are read-only (Repository[T] only) because variant and gene
data come from external reference databases. LIMS, HR, and marketing repositories
use CrudRepository[T] because they manage mutable laboratory records.
Abstracts¶
iris.domain.generic.abstracts
¶
Generic domain abstractions: Metadata container and AliasSet.
Metadata
¶
Generic, extensible metadata container.
Stores arbitrary key-value pairs alongside an optional source and
version label. The data mapping is frozen on construction so
the object remains immutable; use with_data() to produce an updated
copy or merge() to combine two instances (the other's keys win on
collision).
get
¶
require
¶
Return the value for key, raising KeyError if absent.
with_data
¶
merge
¶
Merge two metadata objects (other overrides).
to_dict
¶
Convert to mutable dict (for JSON serialization).
Source code in src/iris/domain/generic/abstracts.py
SerializableFlag
¶
Bases: Flag
Base class for Flag enums with TEXT[] serialization.
Subclasses inherit to_list, to_str, from_list, from_str, and primitives.
All methods work generically via type(self) and cls, so subclasses
don't need to override anything.
Example
to_list
¶
Return active primitive member names for Postgres TEXT[] storage.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
Sorted list of primitive member names. |
Source code in src/iris/domain/generic/abstracts.py
to_str
¶
Return a pipe-separated string for VARCHAR storage.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Pipe-separated primitive member names (e.g. 'AD|AR'). |
from_list
classmethod
¶
Reconstruct from a list of member names.
| PARAMETER | DESCRIPTION |
|---|---|
values
|
List of member names (e.g. ['AD', 'AR']).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SerializableFlag
|
Combined flag instance. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If any value is not a valid member name. |
Source code in src/iris/domain/generic/abstracts.py
from_str
classmethod
¶
Reconstruct from a pipe-separated string.
| PARAMETER | DESCRIPTION |
|---|---|
value
|
Pipe-separated member names (e.g. 'AD|AR').
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
SerializableFlag
|
Combined flag instance. |
| RAISES | DESCRIPTION |
|---|---|
KeyError
|
If any part is not a valid member name. |
Source code in src/iris/domain/generic/abstracts.py
primitives
¶
Return active primitive (non-composite) members.
| RETURNS | DESCRIPTION |
|---|---|
list[Self]
|
List of primitive flag members. |
AliasSet
¶
Immutable set of canonical names with an optional alias mapping.
Canonical names are stored as a frozenset and iterated in sorted
order via ordered. The aliases mapping translates alternative
spellings or identifiers back to their canonical form; resolve()
performs that lookup and falls back to the value itself when no alias
entry exists.
resolve
¶
Return the canonical name for value, resolving aliases as needed.
Always returns the single shared string instance stored for the resolved canonical name, never the caller's input object, and never a separately-constructed object from the aliases mapping — see the note in attrs_post_init for why this matters.
Source code in src/iris/domain/generic/abstracts.py
Entities¶
iris.domain.generic.entities
¶
Base entity class shared across all domains.
NamedEntity
¶
Base entity with a string code identifier and a human-readable name.
All domain aggregates and entities inherit from this class. code is
the stable machine-readable key (e.g. "BRCA1", "P-0042"), while
name is the display label shown in reports and UIs. Both fields are
required and immutable after construction.
Objects¶
iris.domain.generic.objects
¶
Generic value objects shared across domains: contact info, quality scores, and enums.
Sex
¶
Bases: Enum
Biological sex of a person.
QualityCategory
¶
Bases: Enum
High-level technical families of quality metrics used in data measurement and pipelines.
Categories:
-
Accuracy: Closeness of an estimate to a reference or ground truth. • e.g., absolute/relative error, identification error.
-
Precision: Stability of repeated measurements under identical conditions. • e.g., coefficient of variation, replicate concordance.
-
Completeness: Degree to which required data, annotations, or evidence are present. • e.g., missingness rate, coverage breadth.
-
Robustness: Sensitivity of metrics to noise, batch effects, or perturbations. • e.g., noise-tolerance score, batch-stability index.
-
Informational: Amount and richness of supporting contextual or evidential data. • e.g., documentation depth, annotation density.
-
Confidence: Algorithm-derived certainty in a call or estimate. • e.g., posterior probability, likelihood-based quality.
-
Coherence: Internal consistency between related metrics or signals. • e.g., cross-metric concordance, structural agreement.
-
Resolution: Ability to distinguish fine-grained states or values. • e.g., discrimination index, signal-to-resolution ratio.
-
Usability: Degree to which outputs are interpretable and operationally actionable. • e.g., interpretability score, clarity index.
-
Trustworthiness: Evidence of integrity, provenance, and auditability of data. • e.g., source-provenance score, integrity checksum.
These categories align with principles from measurement theory, statistical quality assessment, and data reliability frameworks.
Address
¶
Postal address with optional street, city, state, zip, and country fields.
Only name is required; all location fields are optional to accommodate
partial addresses. Typically embedded in a ContactInfo instance rather
than used standalone.
ContactInfo
¶
Contact details aggregating email, phone, and web contacts for a named entity.
EmailContact
¶
An email address with optional primary, verified, and format-validation flags.
The email value is normalized to lowercase and stripped of whitespace
on construction; an invalid format raises ValueError. At most one
EmailContact per ContactInfo may have is_primary=True.
normalize_email
staticmethod
¶
Normalize and validate the email address.
Source code in src/iris/domain/generic/objects.py
PhoneContact
¶
A phone number with optional primary, verified, country code, and extension fields.
normalize_phone
staticmethod
¶
WebContact
¶
A website URL normalized to https:// with optional primary and verified flags.
normalize_url
staticmethod
¶
Normalize and validate the website URL, adding https:// if needed.
Source code in src/iris/domain/generic/objects.py
QualityScore
¶
A quality measurement with a category, pass/fail status, and optional value.
category classifies the dimension being measured (e.g. completeness,
accuracy). passed is the primary signal; value carries a numeric
score when available and info holds a free-text explanation for
failures or borderline results.
ok
classmethod
¶
Return a passing quality score in the SYSTEM category.
Repositories¶
iris.domain.generic.repositories
¶
Generic repository base classes and EventPublisher port.
EventPublisher
¶
Bases: ABC
Puerto genérico para publicar eventos de dominio.
Los eventos son objetos frozen attrs — se serializan a dict antes de publicar. El adaptador decide cómo y dónde persistirlos.
publish
abstractmethod
¶
Publica un evento de dominio.
| PARAMETER | DESCRIPTION |
|---|---|
event
|
Instancia frozen attrs de un evento de dominio.
Debe tener un campo
TYPE:
|
Repository
¶
Bases: ABC, Generic[T]
Base repository: retrieve a single entity by its string identifier.
ReadRepository
¶
WriteRepository
¶
Bases: Repository[T]
Write repository: persist and remove entities.
CrudRepository
¶
Bases: ReadRepository[T], WriteRepository[T]
Full CRUD repository combining read and write operations.