# Counts per million per gene and sample, version 1.1.0

ngs-expression-cpm\@1.1.0: this version's equations with their symbols, each constant's value, their sources and whether each was read, a worked example where the record holds one, its level and what it was checked against, the number of cases, and what was not checked. This version's record is not rewritten; a correction is added under Changes.

## What this page can and cannot show

**Level: Checked against a reference; Agrees with rnanorm 2.2.0 and exact rationals; arithmetic on the counts and library sizes given. Reference kind: our own exact-arithmetic script and a hand-worked case.**

Not fully recorded, and not independently reviewed. Items marked "Not recorded" are missing from this project's records for the version named. Apart from any worked example shown, the cases and their values are not printed, so a reader cannot re-run these checks. No independent scientist has yet reviewed these methods or checks.

[Every version of this method](https://www.drybench.com/methods/m/ngs-expression-cpm) · [Every method](https://www.drybench.com/methods/m) · [What the levels mean](https://www.drybench.com/methods/levels)

## Version 1.1.0

**Level: Checked against a reference; Agrees with rnanorm 2.2.0 and exact rationals; arithmetic on the counts and library sizes given. Reference kind: our own exact-arithmetic script and a hand-worked case.** `ngs-expression-cpm@1.1.0`

Built, not hosted. Generated from a snapshot of the library's records taken on 2026-11-25, as committed on 2026-11-25. A later snapshot replaces this one, so these records and this page can change.

**Verification statement:** CPM checked against rnanorm 2.2.0 on random column-total cases and exactly against rationals in a script of our own, hand-worked; arithmetic on the counts and library sizes given

CPM = count x 10^6 / N for each gene in each sample, with N the column total over the supplied genes or a library size the caller states; a sample with N = 0 is withheld.

- **How results are reported:** none: full double precision, unrounded; each CPM is within a few ulps of the exact value on the counts given (one product, one quotient, and a compensated column total), where it is a normal double; a sample whose CPM would exceed the largest double is withheld (cpm-above-double, S128)
- **Uncertainty:** Exact arithmetic on the supplied counts; counting noise is not propagated.
- **Reference, as its record states it:** rnanorm 2.2.0's CPM on random column-total cases (the outside comparison), with exact rational arithmetic in a script of our own
- **Level confirmed by this project's ruling of** 14 November 2026

[What this page can and cannot show](#what-this-page-can-and-cannot-show)

### What was checked

69 cases in 2 files, linked by this exact version.

Run through the tool at build against our own exact-arithmetic script and a hand-worked case: 32 agree within the tolerance the file states, 37 refuse as the case expects, 0 differ, 0 were not run.

- **File 1, 41 cases**
  - **Where the expected values came from:** our own exact-arithmetic script and a hand-worked case
  - **Recorded on:** 2026-11-14
  - **Reference:** second implementation (Python 3.13), 2026-11-14; licence BSD-3-Clause
  - **Tolerance as the file states it:** CPM relative 1e-15 (zero exact); library sizes, texts, statuses, codes and withheld rules exact

- **File 2, 28 cases**
  - **Where the expected values came from:** our own exact-arithmetic script and a hand-worked case
  - **Recorded on:** 2026-11-14
  - **Reference:** CPython standard library (fractions), 3.13.18; licence PSF-2.0
  - **Tolerance as the file states it:** CPM relative 1e-15 (zero exact); library sizes, texts, statuses, codes and withheld rules exact

Apart from the worked example, the cases and their values are not printed here. This shows agreement with this project's recorded cases. It does not show that a method suits your work, and it is not a qualification.

### What was not checked

Whether the supplied genes are the whole library; log-CPM and prior counts (not offered).

### Definition or model

A closed form: the result follows from the inputs by the equations alone.

### Equations

**Equation 1**

```equation
N_j = sum over the supplied genes g of c_gj (column-total), or N_j as stated (stated-library-size): this project's ruling
the column total is a compensated (Neumaier) sum in input order, exact for read counts and within about one ulp for estimated counts
inputs are read as the exact value of their shortest decimal, and the range and whole-number tests are decided on that value
CPM is in double precision
order of checks: the kit's checks of each argument in schema order (a bare array where { values, unit } is expected is UNIT_REQUIRED, an object with no unit is MISSING_UNIT, a count above 1e10 or below 0 and a length above 10 Mb or not above 0 are OUT_OF_RANGE), then DUPLICATE_NAME (genes, then samples), then MATRIX_ABOVE_CAP, then per sample in order VALUES_MISALIGNED and, for read counts, NOT_AN_INTEGER, then the measure's argument checks (with cpm: MISSING_ARGUMENT without libraryBasis, then CONFLICTING_ARGUMENT for lengthBasis, then for lengths, then per sample MISSING_ARGUMENT or CONFLICTING_ARGUMENT for librarySize)
```

| Symbol | Meaning and unit |
| --- | --- |
| N\_j | library size of sample j |
| c\_gj | count of gene g in sample j |

Ruling of this project: 11 November 2026, section "2. Reasoning (rulings)". Not yet published; its effect is stated on this page. A choice this project made, not a value from the literature.

**Equation 2**

```equation
CPM_gj = c_gj x 10^6 / N_j
```

| Symbol | Meaning and unit |
| --- | --- |
| CPM\_gj | counts per million, countsPerMillion |

Ruling of this project: 11 November 2026, section "2. Reasoning (rulings)". Not yet published; its effect is stated on this page. A choice this project made, not a value from the literature.

### Conventions

What each mode computes:

- `measure = cpm`: counts per million: each count times one million over its sample's library size
- `libraryBasis = column-total`: the library size is the sum of the sample's supplied counts
- `libraryBasis = stated-library-size`: the library size is the one the caller states for each sample

### Constants

Constants: none used.

### Worked example

Worked example: one case of ngs-expression-cpm\@1.1.0, from its inputs through each step to the answer. Values are written as a person writes them; the working carries more digits, so your own figure may differ in the last digit shown.

**Inputs**

- measure = cpm
- countKind = read-counts
- libraryBasis = column-total
- genes\[0\] = geneA
- genes\[1\] = geneB
- genes\[2\] = geneC
- samples\[0\].id = s1
- samples\[0\].counts.values\[0\] = 10
- samples\[0\].counts.values\[1\] = 30
- samples\[0\].counts.values\[2\] = 60
- samples\[0\].counts.unit = 1

**Steps**

1. N = 100, from samples\[0\].counts; by equation 1; gives result.samples\[0\].librarySize.
2. cA = 100000 countsPerMillion, from samples\[0\].counts, N; by equation 2; gives result.samples\[0\].expression.values\[0\].

The working, as the case writes it:

```equation
s1: N = 100
CPM = 100000, 300000, 600000
```

**Answer**

- `result.samples[0].librarySize` = **100**
- `result.samples[0].expression.values[0]` = **100000 countsPerMillion**

Where these values came from: our own exact-arithmetic script and a hand-worked case; Worked by hand by Drybench on 11 November 2026 (ruling 7). This is not an independent check.

At build the tool returned this answer within the tolerance the file states: CPM relative 1e-15 (zero exact); library sizes, texts, statuses, codes and withheld rules exact.

Who worked this case: not recorded.

### What it refuses, and its input ranges

- `VALUES_MISALIGNED` (invalid input): a sample's counts, or a length vector, does not have one value per gene
- `MATRIX_ABOVE_CAP` (invalid input): the counts and lengths together are more numeric cells than the tool's cap; a smaller gene subset changes the results

### Changes

#### 2026-11-14-ngs-expression-cpm\@1.1.0-1

2026-11-14 · [`ngs-expression-cpm@1.1.0`](https://www.drybench.com/methods/m/ngs-expression-cpm) · Corrections to our methods

- **What was wrong:** A stated library size far below the counts (for example 1e-300 with a count of 1e10) made a count per million exceed the largest double, and the tool failed instead of replying. Estimated counts' column totals were plain sums.
- **Affected:** Version 1.0.0 of the assistant tool ngs\_expression\_normalise with measure cpm: stated library sizes some 290 orders of magnitude below any real one got no reply; column totals of fractional estimated counts could differ from the exact sum in the last digits. No served number on a realistic input was wrong.
- **What changed:** In 1.1.0 such a sample is withheld under the rule cpm-above-double, with its reason, and the column total is a compensated sum.
- **How it was found:** The CSO's review of the raising run, 14 November 2026 (S128), from the code; reproduced by the builder.
- **Cases added:** stored reference values re-records the retired -1 at 1.1.0 with cpm-above-double and three random cases checked against rnanorm 2.2.0.

## Tools that use it

- [`ngs_expression_normalise`](https://www.drybench.com/methods/tools/ngs-expression-normalise)

## Cite this version

Counts per million per gene and sample. Drybench; ngs-expression-cpm\@1.1.0; [https://www.drybench.com/methods/m/ngs-expression-cpm/1.1.0](https://www.drybench.com/methods/m/ngs-expression-cpm/1.1.0) (accessed \[date\]).
