Evaluation
Core evaluation orchestration for the DNA segmentation benchmark.
The public entry point benchmark_from_arrays() (built on the internal
per-sequence _benchmark_gt_vs_pred_single()) compares ground-truth
nucleotide-level annotations with predictions and dispatches to the per-metric
modules:
INDEL —
indel_metricsREGION_DISCOVERY / BOUNDARY_EXACTNESS —
section_metricsNUCLEOTIDE_CLASSIFICATION — local confusion counts
PHASE_DRIFT —
frame_shiftSTRUCTURAL_COHERENCE —
chain_comparison,structure,splice_sitesDIAGNOSTIC_DEPTH —
structural_summary
The state-transition diagnostics (transition_failures /
false_transitions) are opt-in via EvalMetrics.STATE_TRANSITIONS. They
remain in the default metric set (_DEFAULT_METRICS) so the transition-matrix
plots that frame every other metric still render by default; pass an explicit
metrics list without STATE_TRANSITIONS to skip the pass. Every metric
group is opt-in via metrics.
Input preprocessing (intron inference, mask splitting) lives in
preprocessing; cross-sequence accumulation and reduction live in
accumulators. All functions accept a LabelConfig that maps
integer tokens to names and declares semantic roles (background, coding, …).
- class gene_calling_benchmark.eval.evaluate_predictors.StreamingBenchmark(label_config, metrics=None, infer_introns=False)[source]
Bases:
objectIncrementally aggregate per-sequence benchmarks without materialising them.
Wraps a single
BenchmarkAccumulator. Feed paired GT/pred arrays one at a time withadd()— each array is reduced to a per-sequence fragment, accumulated, and may then be discarded by the caller — and callresult()once to obtain the aggregated summary. This lets callers build label arrays lazily (one transcript pair at a time) instead of holding every array in memory at once.benchmark_from_arrays()(aggregate mode) is implemented on top of this class, so streaming and list-based aggregation return identical numbers for the same sequence of pairs.- Parameters:
label_config (LabelConfig)
metrics (list[EvalMetrics] | None)
infer_introns (bool)
- add(gt_labels, pred_labels, mask_labels=None)[source]
Accumulate one GT/pred pair (same per-sequence path as the list API).
Atomic: all fragments for the sequence are computed before any is committed, so a mid-sequence failure leaves the accumulator untouched (nothing partially added) and can be safely isolated by the caller.
- gene_calling_benchmark.eval.evaluate_predictors.benchmark_from_arrays(gt_labels, pred_labels, label_config, metrics=None, return_individual_results=False, mask_labels=None, infer_introns=False)[source]
Benchmark paired GT/prediction label-array lists (the array entry point).
Runs the internal per-sequence
_benchmark_gt_vs_pred_single()over each pair and, by default, aggregates the fragments into precision/recall and distribution statistics.Per-sequence isolation: a pair that raises during evaluation is logged and skipped so a single pathological sequence never aborts the whole batch — important when the benchmark runs inside a training loop. In aggregate mode the failing pair is simply omitted; in
return_individual_resultsmode its slot isNone(indices stay aligned with the inputs).- Parameters:
gt_labels (
list[ndarray]) – Equally-sized lists of 1-D integer token arrays.pred_labels (
list[ndarray]) – Equally-sized lists of 1-D integer token arrays.label_config (
LabelConfig) – Token-to-name mapping and semantic roles.metrics (
list[EvalMetrics] |None) – Metric groups to compute. Defaults to_DEFAULT_METRICS(REGION_DISCOVERY,BOUNDARY_EXACTNESS,NUCLEOTIDE_CLASSIFICATION,STATE_TRANSITIONS).return_individual_results (
bool) – IfTrue, return per-sequence results as a list instead of aggregating.mask_labels (
list[ndarray] |None) – Optional boolean masks (True = exclude). Must match length of GT.infer_introns (
bool) – IfTrue, background gaps between adjacent coding segments are relabelled as introns before each sequence is evaluated.
- Returns:
Aggregated (default) or per-sequence results. In
return_individual_resultsmode the list may containNonefor any sequence whose evaluation failed.- Return type: