Metadata-Version: 2.5
Name: lumicall
Version: 0.1.1
Summary: Calibrated calls for qualitative chemiluminescent plate immunoassays
Author-email: Maciej Kochanowski <maciej.kochanowski@piwet.pulawy.pl>
License-Expression: MIT
License-File: LICENSE
Keywords: ELISA,chemiluminescence,conformal p-value,cut-off,food safety,immunoassay,prediction limit
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
Requires-Python: >=3.10
Requires-Dist: numpy>=1.23
Requires-Dist: pandas>=1.5
Requires-Dist: scipy>=1.9
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Provides-Extra: xlsx
Requires-Dist: openpyxl>=3.1; extra == 'xlsx'
Description-Content-Type: text/markdown

# lumicall

[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.24666552.svg)](https://doi.org/10.5281/zenodo.24666552)

Calibrated calls for qualitative chemiluminescent plate immunoassays.

**Online version: <https://maciejkochanowski.github.io/lumicall/>** runs the same code in the browser (via Pyodide);
plate data are not uploaded anywhere.

`lumicall` reads a 96-well plate of relative light units (RLU), checks run acceptance,
and gives every sample a p-value and a call (detected, not detected, retest) whose
per-sample false-positive rate is set by the user. It reports the run's own limit
of detection in concentration units, and it always shows the result of the
conventional rule (mean + 3 SD of negatives) alongside, so that changed calls are visible.

The default configuration is the *Anisakis simplex* chemiluminescent sandwich ELISA
(CL-S-ELISA) protocol: Luminoskan reads, controls Blank, Neg, P10 and P1 in A1 to D2,
samples S1 to S44 in horizontal duplicate pairs, limit of detection 0.5 ng/mL
(Kochanowski et al. 2020, *Pathogens* 9:777). Any layout can be supplied as a table.

## Why

A common cut-off is the arithmetic mean + 3 SD of analyte-free samples, which is meant to
give 0.135% false positives. It does not when RLU of negatives are right-skewed or few,
as `validation/coverage.py` shows (expected per-sample false-positive rate for a new negative):

| Negatives | SD of ln RLU | n | mean + 3 SD | Frey 95% on raw RLU | lumicall, alpha 1% |
| --- | --- | --- | --- | --- | --- |
| lognormal | 0.30 | 5 | 4.69% | 7.50% | 0.94% |
| lognormal | 0.30 | 30 | 1.45% | 6.80% | 0.98% |
| lognormal | 0.60 | 30 | 2.61% | 7.44% | 0.99% |

The full table, including negatives that are normal on the raw scale, is in
`validation/coverage_results.md`.

## Install

```
pip install lumicall            # once released; until then: pip install .
pip install "lumicall[xlsx]"    # to read .xlsx exports
```

Python 3.10 or later; depends on numpy, scipy and pandas.

## Quick start

```
lumicall example --out demo
lumicall reference demo/example_negatives.txt --out demo/reference.json
lumicall run demo/example_plate.tsv --reference demo/reference.json --out demo/report
```

The example data are synthetic (the same as in the protocol's online calculator).
`run` writes `samples.csv`, `controls.csv`, `summary.json` and a self-contained
`report.html`. The exit code is 0 for an accepted run, 2 for a rejected run and 1 for an error.

The report prints on A4 (or saves as PDF from the browser). Its first page identifies the run
(plate file with its SHA-256, reference set with its SHA-256 fingerprint, software version and
settings), gives the run verdict with any failed checks, and lists every sample in plate order
with its p-values, call and the result of the mean + 3 SD rule, followed by signature fields.
Figure 1 places each sample and control against the reference negatives, the decision cut-off,
the retest zone and the mean + 3 SD rule. An appendix shows the decision rule, a normal
quantile plot of the reference negatives and the calculation of the run limit of detection.

From Python:

```python
from lumicall import analyse_run, anisakis_cl_elisa, read_negatives, read_plate, Settings

ref = read_negatives("negatives.csv").get(None)
res = analyse_run(read_plate("plate.xlsx"), anisakis_cl_elisa(), ref, Settings(alpha=0.01))
print(res.run_ok, res.cutoff, res.samples[["sample_id", "p_model", "call"]])
```

## Inputs

**Plate.** A grid with rows labelled A to H and twelve values each, in CSV, TSV, TXT
or XLSX, as exported by SkanIt or Gen5 or pasted from a spreadsheet; decimal commas are
accepted. If a file holds several grids (for example two reads), `--block` selects one.
A long table with columns `well` and `rlu` is also accepted.

**Reference negatives.** Analyte-free samples of the same matrix, processed and read as
routine samples. Either a table with one or more columns whose names start with `rlu`
(replicate wells) and optional `sample_id` and `matrix` columns, or one value per line.
A file with several matrices gives one reference per matrix; choose with `--matrix`.

**Layout.** `anisakis` (default) or a table with columns `well`, `role`
(`blank`, `neg`, `p10`, `p1`, `sample`), `sample_id` and optional `matrix`.
Sample names can be supplied in plate order with `--ids`.

## Method

Each sample is summarised by y, the mean of ln(RLU) over its wells. For n reference
negatives with mean m and SD s of y, a new negative sample satisfies, if y is normal,

```
(y - m) / (s * sqrt(1 + 1/n))  ~  t with n - 1 degrees of freedom
```

The model p-value is the upper tail of this t distribution; it is exactly uniform for a
new negative, for any n of 3 or more. A sample is called detected when p <= alpha, which is
the same as comparing its geometric mean with the cut-off
exp(m + t[1 - alpha, n - 1] * s * sqrt(1 + 1/n)), the prediction limit of Frey et al. (1998)
on the log scale.

The conformal p-value (1 + number of reference values >= y) / (n + 1) is valid without any
distributional assumption but cannot fall below 1/(n + 1). When it can reach alpha
(n >= 1/alpha - 1), the report flags samples on which it disagrees with the model.

A sample is a retest when its wells fall on both sides of the cut-off, when a detected
sample has a duplicate CV above 15%, or when its summary lies within 1.96 standard errors
of the cut-off. The standard error uses the within-pair SD of ln(RLU), estimated robustly
from the plate's duplicates (1.4826 * median |ln a - ln b| / sqrt 2) or set from a precision
study with `--repeatability-cv`. Benjamini-Hochberg q-values are reported for screening
use. The expected number of false positives on a plate is at most alpha times the number
of samples.

Run acceptance follows the protocol: blank and negative-matrix control below the cut-off
in both wells, P10 above the cut-off with duplicate CV <= 15%, and P1 above the cut-off as
a sensitivity check. The run limit of detection is the concentration whose expected signal
equals the cut-off, from the net signals of P1 (= LOD) and P10 (= 10 x LOD) above the
negative-matrix control, assumed linear on log-log scales; a run whose limit exceeds the
validated LOD is flagged.

## Validation

- `tests/` (31 tests): the Frey multiplier for n = 3 (3.372); the model p-value equals
  alpha at the cut-off; simulated calibration of the model p-value for n = 3, 5, 10, 30 and
  validity of the conformal p-value under heavy-tailed data; Benjamini-Hochberg against
  `scipy.stats.false_discovery_control`; recovery of the run LOD on noise-free plates with
  log-log slopes 1.0 and 0.8; reproduction of the protocol calculator on its example plate
  (cut-off 39.6 RLU; 8 detected, 34 not detected, 2 retest); plate, layout and CLI input, including semicolon-separated files with decimal commas.
- `validation/coverage.py`: the per-sample false-positive rate of the rules above under
  lognormal negatives and under negatives that are normal on the raw scale. lumicall holds
  alpha under lognormal negatives and is conservative when negatives are normal on the raw
  scale (for example 0.35% at alpha 1% with CV 0.15 and n = 30).

Note on run acceptance: the negative-matrix control is itself a negative sample, so it
occasionally exceeds the cut-off in a valid run. In simulation (SD of ln RLU 0.15 between
samples, well CV 3%), that check rejected 1.3% of valid runs with lumicall at alpha 1% and
1.1% with the mean + 3 SD cut-off.

## Limitations of version 0.1

- Readings at or below the reader floor (censored values) are refused in the reference.
- One reference per matrix; information is not yet shared between matrices or runs.
- Optical crosstalk between wells is not modelled.
- The SkanIt and Gen5 readers are tested on grid exports, not yet on files from every
  software version.

Planned: censoring at the reader floor and saturation, a reference model shared across
matrices and runs with the P10 control as a covariate, pooled conformal p-values, a
crosstalk check from a calibration plate, and a POD curve with LOD95 in the validation report.

## Citation

If you use lumicall, cite the software, doi:10.5281/zenodo.24666552 (all versions; version 0.1.0 is
doi:10.5281/zenodo.24666553, see `CITATION.cff`) and, for the default assay,
Kochanowski M, et al. (2020) *Pathogens* 9(10):777, doi:10.3390/pathogens9100777.

Frey A, Di Canzio J, Zurakowski D (1998) A statistically defined endpoint titer
determination method for immunoassays. *J Immunol Methods* 221:35-41.

## Licence

MIT. Copyright (c) 2026 Maciej Kochanowski, National Veterinary Research Institute,
Puławy, Poland.
