Metadata-Version: 2.5
Name: lumicall
Version: 0.3.0
Summary: Calibrated calls for qualitative plate immunoassays (chemiluminescent or colorimetric, direct, sandwich or competitive)
Author-email: Maciej Kochanowski <maciej.kochanowski@piwet.pulawy.pl>
License-Expression: MIT
License-File: LICENSE
Keywords: ELISA,absorbance,chemiluminescence,competitive ELISA,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 plate immunoassays: chemiluminescent or colorimetric,
direct, sandwich or competitive.

**Online version, no installation and no Python needed: <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 readings (relative light units, optical density or any
other signal), 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. With a reference of at least 1/alpha - 1
negatives (99 at alpha 1%) that rate holds whatever the distribution of the negatives; with
fewer it rests on the negatives being log-normal. 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). Other assays use the `duplicates` or
`singles` template or any layout table, with the settings described under
[Other assays](#other-assays).

## 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`.

Real negatives are not always log-normal either. In 627 negative sera measured with two
SARS-CoV-2 IgG ELISAs (KEMIS data, `validation/kemis.py`), the log-normal rule at alpha 1%
gave 1.8% false positives on one assay (95% interval 1.1% to 2.6% with 30 reference
negatives) and 1.0% on the other. Adapting the shape to a small reference (Box-Cox) did not
fix this. A reference of 99 or more negatives does: calls then use the distribution-free
p-value, and the rate was 0.95% to 1.01% on both assays.

## Install

```
pip install lumicall
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"]])
```

## Other assays

Three settings adapt lumicall to an assay other than the default protocol:

```
lumicall run plate.csv --reference negatives.txt --layout duplicates --scale linear --direction lower --unit OD
```

- `--layout`: `anisakis` (default), `duplicates` (blank, negative and positive control in A1 to
  C2, then 45 samples in horizontal pairs from D1, filled down each column pair), `singles`
  (the same controls in A1 to C1, then 93 samples from D1) or a layout table (see Inputs).
- `--scale`: `log` (default) for readings above 0, such as RLU; `linear` for readings that
  can be 0 or negative, such as blank-corrected absorbance. On the linear scale each sample is
  summarised by the arithmetic mean of its wells and the t model works on the readings
  themselves (the prediction limit of Frey et al. 1998 in its original form). The conformal
  rule depends only on ranks and is the same on both scales.
- `--direction`: `higher` (default) when a higher signal means detection (direct and sandwich
  assays); `lower` for competitive and inhibition assays, in which a sample is detected
  when its signal falls below the cut-off and the conventional rule is mean - 3 SD.
- `--unit` sets the signal label in the report (RLU by default).

Run acceptance uses the controls present in the layout, and every control is optional:
the reagent blank (direct and sandwich assays only, because in a competitive assay it reads
on the detected side) and the negative control must not be detected; a positive control
(`pos`, or `p10` at 10 x LOD) must be detected, with a duplicate CV of at most `--cv-max`.
A positive control at the LOD (`p1`) is reported as a sensitivity check, and the run limit of
detection is estimated only when the layout has the negative, P1 and P10 controls. A layout
without controls gives calls without a run acceptance check. The online version offers the
same choices in its Assay section.

## 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` (or `od`, `signal`, `value`) 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`,
`od`, `signal` or `value` (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.** A template (`anisakis`, the default; `duplicates`; `singles`) or a table with
columns `well`, `role` (`blank`, `neg`, `pos`, `p10`, `p1` or `sample`; `negative`, `nc`,
`positive` and `pc` are also accepted), `sample_id` and optional `matrix`. Every control is optional.
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. With `--scale linear`, y is the arithmetic mean of the wells and the cut-off
is m + t[1 - alpha, n - 1] * s * sqrt(1 + 1/n); with `--direction lower` the sign of y is
reversed, so the cut-off becomes a lower limit.

The conformal p-value (1 + number of reference values >= y) / (n + 1) is valid without any
distributional assumption, provided reference and routine negatives come from the same
population, but cannot fall below 1/(n + 1).

**Which p-value decides.** When the conformal p-value can reach alpha (n >= 1/alpha - 1,
that is 99 negatives at alpha 1% and 19 at alpha 5%), calls use it: the false-positive rate
is then at most alpha for any distribution of the negatives, and the cut-off is a value of
the reference set (the largest one when n + 1 < 2/alpha). With fewer negatives no rule can
promise this without a distributional assumption, so calls use the t model above, whose
rate is alpha only if ln(RLU) of negatives is normal. The report, `summary.json` and the
command line name the rule used, and with the distribution-free rule the report notes the
samples the model would call differently. Benjamini-Hochberg q-values use the p-value that
decides.

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/` (43 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 t model under
  lognormal negatives and under negatives that are normal on the raw scale. It 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).
- `validation/kemis.py` (results in `validation/kemis_results.md`): 627 negative and 347
  positive sera, two SARS-CoV-2 IgG ELISAs, reference sets drawn at random. At alpha 1%:
  - t model (fewer than 99 negatives): 1.8% false positives on the KWTRP assay for n = 5,
    10 and 30, 0.7% to 1.0% on the InBios assay. The share of KWTRP negatives above the
    normal 99th percentile was 1.75% (exact 95% CI 0.88% to 3.12%).
  - Two Box-Cox rules, specified in advance as candidate fixes for small references, failed
    the criterion set before they were run (1.4% to 2.1% on one assay or the other).
  - Distribution-free rule (n = 99 and 199): 0.95% to 1.01% on both assays. Sensitivity was
    1.1 to 1.6 points lower than with the t model, except InBios at n = 99 (6.6 points),
    where the cut-off is the single highest negative.
  - At alpha 0.135% (the level mean + 3 SD aims at) the t model gave 0.08% to 0.41%;
    a distribution-free rule would need 740 negatives.

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

- With fewer than 1/alpha - 1 reference negatives the false-positive rate rests on ln(RLU)
  of negatives being normal; on one of the two KEMIS assays it was 1.8% at alpha 1%. More
  reference negatives are the remedy: 99 at alpha 1%, better 199, so that the cut-off does
  not rest on the single highest negative.
- No rule protects against a reference from a different population than the routine
  samples. In KEMIS, a reference from one cohort applied to another gave up to 16.6% false
  positives at alpha 1% with the t model (n = 30) and 1.34% with the distribution-free
  rule (n = 99).
- On the log scale, readings at or below 0 are refused in the reference; the linear scale
  accepts them. Censoring at the reader floor is not modelled.
- 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.2.0 is
doi:10.5281/zenodo.24667766, version 0.1.1 is doi:10.5281/zenodo.24667115, 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.
