# Estimated library size in distinct molecules from read-pair duplicate counts

`ngs_library_complexity` · Runs: On the server · Level: Checked against a reference: Picard 3.4.0 run offline and a second implementation in Python by a separate agent of the same model family (mpmath at 100 digits)

Estimates the size of a library in distinct molecules from read-pair duplicate counts.

Research and education software; not medical advice, and not for diagnosis or treatment decisions. It computes from the inputs it receives. It does not check the person's data, design or sample.

[Catalogue](https://www.drybench.com/mcp/catalogue) / [Genomics](https://www.drybench.com/mcp/catalogue/genomics)

[Ask your assistant](https://www.drybench.com/mcp/connect)

```cite
Estimated library size in distinct molecules from read-pair duplicate counts (ngs_library_complexity), Drybench MCP server 1.0.0; ngs-library-complexity@2.0.0 (Checked against a reference); https://www.drybench.com/mcp/tools/ngs-library-complexity
```

## What it is

Returns a library's estimated size in distinct molecules from read-pair duplicate counts, as a Lander-Waterman model. Use when judging, from Picard duplicate metrics (MarkDuplicates or EstimateLibraryComplexity), how many distinct molecules a library holds and how much of it a run has sampled. Not for depth from a read count: use \`ngs\_coverage\_depth\`; not for reads needed for a target depth: use \`ngs\_reads\_required\`. All three counts are required, readPairOpticalDuplicates included (0 when none were detected); refuses when every pair is a duplicate and withholds the estimate when none is.

Field: [Sequencing and genomics](https://www.drybench.com/mcp/catalogue/genomics).

## What it does

**You give**

- `readPairsExamined` (required): Read pairs examined (Picard's READ\_PAIRS\_EXAMINED), at least 1. Must be at least 1.
- `readPairDuplicates` (required): Read pairs marked duplicate, optical included (Picard's READ\_PAIR\_DUPLICATES). Must be at least 0.
- `readPairOpticalDuplicates` (required): Read pairs marked optical duplicate (Picard's READ\_PAIR\_OPTICAL\_DUPLICATES): 0 when optical duplicates were not detected (e.g. READ\_NAME\_REGEX=null); included in readPairDuplicates. Must be at least 0.

No request is recorded for this tool.

**Limits**

- Research arithmetic for planning sequencing libraries and runs and for genomic coordinate bookkeeping; it does arithmetic on the inputs it receives, and does not measure the library, the instrument or the data.
- Estimated library size is a model, not a measurement: it assumes every molecule is equally likely to be read and that reads sample molecules independently (C/X = 1 − exp(−N/X), as in Picard 3.4.0; Lander and Waterman 1988 is cited there and unread).
- No measured prediction error is available.
- If some molecules are read more often than others, as with uneven amplification, the true number of molecules is larger than this estimate.
- The estimate is only as good as the duplicate counts, which depend on the tool and settings that marked them; optical duplicates not flagged as such are counted as library duplicates and lower the estimate.
- Counts are read pairs; single-end counts overstate duplicates at depth.
- No interval is given: with D duplicate pairs used, the count alone carries a relative uncertainty of about 1/√D, so an estimate from a few duplicates is an order of magnitude at best.
- With no duplicates, no size is estimated.
- Every computed number a reply returns, other than an integer or an exact decimal, is rounded once to 12 significant figures: to the nearest, a change of at most 5 × 10⁻¹² of its value, except that a lower bound is rounded down and an upper bound up, a change of less than 1 × 10⁻¹¹; the method computes, and decides any pass or fail, on the unrounded value.

**It will not answer when**

- every pair examined is a duplicate: the counts are inconsistent, since every duplicate set keeps one pair.
- the read pairs are above the method's range, beyond which the counts are not exact in double.

### Every input, with its units

3 inputs

- `readPairsExamined` (required): Read pairs examined (Picard's READ\_PAIRS\_EXAMINED), at least 1. Must be at least 1.
- `readPairDuplicates` (required): Read pairs marked duplicate, optical included (Picard's READ\_PAIR\_DUPLICATES). Must be at least 0.
- `readPairOpticalDuplicates` (required): Read pairs marked optical duplicate (Picard's READ\_PAIR\_OPTICAL\_DUPLICATES): 0 when optical duplicates were not detected (e.g. READ\_NAME\_REGEX=null); included in readPairDuplicates. Must be at least 0.

### Every refusal, with its code

2 refusals

| Code | When |
| --- | --- |
| `ALL_DUPLICATES` | every pair examined is a duplicate: the counts are inconsistent, since every duplicate set keeps one pair. |
| `PAIRS_ABOVE_RANGE` | the read pairs are above the method's range, beyond which the counts are not exact in double. |

## The calculation

The method's equations, constants and worked example.

### [Library size in distinct molecules from read-pair duplicate counts](https://www.drybench.com/methods/m/ngs-library-complexity/2.0.0)

`ngs-library-complexity@2.0.0`

**Equation 1**

```text
C/X = 1 - exp(-N/X)
with d = (N - C)/N from the integers and y = N/X: g(y) = 1 - (1 - e^(-y))/y = d, X = N/y
fraction of the library observed = C/X
```

| Symbol | Meaning |
| --- | --- |
| `X` | distinct molecules in the library |
| `N` | read pairs examined less optical duplicate pairs |
| `C` | read pairs examined less duplicate pairs |
| `d` | duplicate events per pair used |

Source 1.

**Equation 2**

```text
the root y lies in [2d, N/C] (g(y) <= y/2
g(N/C) >= d)
bisection on the natural log of y, starting from lo = ln(2d) and hi = ln(N/C), at most 200 iterations: mid = (lo + hi)/2 in double
if mid equals lo or hi the solve has settled and y = e^mid, else lo = mid when the root lies above e^mid and hi = mid otherwise
the root lies above e^mid when g(e^mid) < d (g increases with y) or, where 2(N - C) > N, when h(e^mid) > c (the same test on the complement, h = 1 - g, c = C/N, 2.0.0)
X = N/y
an unconverged solve is refused with the kit's NO_CONVERGENCE and returns no number
```

| Symbol | Meaning |
| --- | --- |
| `y` | N/X |

Source 1.

**Equation 3**

```text
duplicateFraction = READ_PAIR_DUPLICATES / READ_PAIRS_EXAMINED, optical included (Picard's PERCENT_DUPLICATION on pairs only)
```

| Symbol | Meaning |
| --- | --- |
| `duplicateFraction` | fraction of pairs marked duplicate |

Source 1.

A model of nature: it predicts a measurement and can be wrong for your sample. No prediction error is available.

**Worked example**

Worked example: one case of ngs-library-complexity\@2.0.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**

- readPairsExamined = 10
- readPairDuplicates = 1
- readPairOpticalDuplicates = 0

**Steps**

1. dup = 0.1, from readPairDuplicates, readPairsExamined; by equation 3; gives result.duplicateFraction.
2. d = 0.1, from readPairsExamined, readPairDuplicates, readPairOpticalDuplicates; by equation 1.
3. y = 0.21455574, from d; by equation 2.
4. X = 46.607935, from readPairsExamined, y; by equation 1; gives result.model.estimatedLibrarySize.

The working, as the case writes it:

```text
N = 10, C = 9, d = 0.1
g(y) = 1 - (1 - e^-y)/y = 0.1 at y = 0.21455574
X = 10/y = 46.607935 (worked by hand by the raising builder, 14 November 2026)
```

**Answer**

- result.duplicateFraction = 0.1
- result.model.estimatedLibrarySize = 46.607935

Where these values came from: an outside program, second implementation (Python 3.13) 2026-11-14; the second implementation's run(arguments).

At build the tool returned this answer within the tolerance the file states: relative 1e-12 (exact below 1e-300); Picard agreement asserted by the generator as floor equality where its arithmetic resolves the root; statuses, codes and withheld rules exact.

Who worked this case: not recorded.

## Sources

1. Picard (Broad Institute), stored reference values, the Javadoc of estimateLibrarySize and calculateDerivedFields Used for: Library size in distinct molecules from read-pair duplicate counts. At: equation C/X = 1 - exp(-N/X) (lines 136 to 141); ESTIMATED\_LIBRARY\_SIZE (line 111); PERCENT\_DUPLICATION (line 115). **Read in full, 11 November 2026**

Read by AI-assisted sessions. No person has checked these readings.

## How it is checked

**Level:** Checked against a reference.

**Checked against:** A reference program this project wrote itself, second implementation (Python 3.13), 2026-11-14, mpmath 1.4.1 at 100 digits: bisection on ln y in the record's bracket, rounded once; not an outside program.

**Cases:** No case set is linked to this version.

**Not checked:** Lander and Waterman 1988 itself (cited through Picard); real libraries against UMI-counted molecules; how the upstream tool marks duplicates and optical duplicates; unpaired reads; Picard's ROI projection (out of 1.0.0); Daley and Smith 2013.

No independent scientist has yet reviewed this.

### Changes to its methods

1 change

- [14 November 2026, ngs-library-complexity\@2.0.0](https://www.drybench.com/methods/corrections#2026-11-14-ngs-library-complexity200-1): In 2.0.0, where more than half of the pairs used are duplicate events, the solver compares the fraction of distinct pairs, (1 - e^(-y))/y against C/N, which keeps full relative precision. The size is now within 1e-12 relative (the fixture's tolerance); about 1e-14 measured on the cases run: within 1e-14 on the 54 cases of stored reference values, whose expected values are the second implementation's solve in mpmath at 100 digits, and at most 1.0e-14 on a sweep of N from 2 to 10^15 pairs and C/N from 10^-15 to 1 - 10^-15 against a solve in mpmath at 60 digits, a check of our own made at the fix and not kept in the repository. One published case moved: stored reference values#one-distinct (1,000 pairs, one distinct pair), from 1.000000000000057 to 1.0000000000000002, within its 1e-12 tolerance either way.
