nirs4all.data.repetition_detection module

Repetition (biological replicate) group detection.

Heuristics for recovering “which measurements belong to the same biological sample” from dataset metadata columns or sample-id naming conventions.

These previously lived in the nirs4all-studio HTTP layer; they are NIRS data semantics and belong to the library (the studio’s 2026-06-05 tech-debt closeout flagged the boundary violation).

Two entry points:

  • auto_detect_repetition_column() — pick the metadata column that most plausibly identifies biological samples (bio_sample, sample_group, …), skipping partition/fold bookkeeping and repeat-index columns.

  • detect_repetition_groups() — group sample ids into biological samples using an explicit regex or a ladder of common naming conventions (name_rep1, name_2, name-A, name (1)).

class nirs4all.data.repetition_detection.RepetitionGroups(groups: dict[str, list[int]]=<factory>, pattern: str | None = None, n_repeated: int = 0)[source]

Bases: object

Result of sample-id based repetition detection.

Variables:
  • groups (dict[str, list[int]]) – Mapping of biological-sample id to member sample indices.

  • pattern (str | None) – The regex that produced the grouping (None when no convention matched at least one repeated group).

  • n_repeated (int) – Number of biological samples with >= 2 measurements.

groups: dict[str, list[int]]
property has_repetitions: bool

Whether any biological sample has more than one measurement.

n_repeated: int = 0
pattern: str | None = None