CpG methylation beta-value and M-value from signals, or converted between them
genome_methylation_level
Gives each CpG's beta-value and M-value from methylated and unmethylated signals, or converts between them.
- Runs
- On the server
- Level
- Checked against a reference: Du et al.'s printed Eq. 3 pairs (the outside comparison, reproduced exactly), with a 60-digit decimal script of our own
What it is
Returns the beta-value and M-value of each CpG from methylated and unmethylated signals, or converts one to the other. Use when turning array intensities or bisulfite read counts into methylation levels, or moving levels between the beta and M scales. Not for sequencing depth from a read count: use `ngs_coverage_depth`. Not for differential methylation or calling a site methylated, which no library tool does. from, signalKind and both offsets are required; offsets are never assumed, and the beta-M conversion ignores them.
Field: Sequencing and genomics.
What it does
You give
from(required): signals, beta or m-value: what you are sending. Required.signalKind: With signals, required: intensities (array) or read-counts (bisulfite reads, whole numbers). Optional.methylated: With signals: the methylated signal per site. Optional.unmethylated: With signals: the unmethylated signal per site, in the same order. Optional.betaOffset: With signals, required: the offset added to beta's denominator, at least 0 (Illumina's statement is 100); never assumed. Must be at least 0 and at most 1000000000000. Optional.mOffset: With signals, required: the offset added to both signals for M, at least 0 (Du et al. state 1); never assumed. Must be at least 0 and at most 1000000000000. Optional.
and 3 more, listed below
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.
- Du et al.'s beta-value and M-value arithmetic on the signals or values you supply, with the offsets you state; nothing is defaulted.
- Negative signals are set to zero and reported.
- Probe type, dye bias, normalisation and detection p-values are outside it; for read counts, so are bisulfite conversion efficiency and sampling uncertainty at low depth; a saturated array intensity cannot be detected here.
- An offset sized for array intensities (Illumina states 100) pulls beta-values from low read counts toward zero.
- Converting between beta and M by Eq.
- 3 ignores the offsets, so it does not reproduce the M-value computed from signals when an offset is above zero.
- No site is called methylated or unmethylated and no threshold is applied; this is not a test for differential methylation.
- 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
- both signals are zero after negatives are set to zero and the beta offset is zero, so beta is zero over zero.
- a signal is zero after negatives are set to zero and the M offset is zero, so M is infinite.
- a beta-value of zero or one has no finite M-value.
- a beta-value, from signals or from an M-value, would be a non-zero number below the smallest normal double, which a double holds only to reduced precision; a beta that rounds to zero is returned as zero.
Every input, with its units9 inputs
from(required): signals, beta or m-value: what you are sending. Required.signalKind: With signals, required: intensities (array) or read-counts (bisulfite reads, whole numbers). Optional.methylated: With signals: the methylated signal per site. Optional.unmethylated: With signals: the unmethylated signal per site, in the same order. Optional.betaOffset: With signals, required: the offset added to beta's denominator, at least 0 (Illumina's statement is 100); never assumed. Must be at least 0 and at most 1000000000000. Optional.mOffset: With signals, required: the offset added to both signals for M, at least 0 (Du et al. state 1); never assumed. Must be at least 0 and at most 1000000000000. Optional.betaValue: With beta: beta-values, each from 0 to 1; 0 and 1 have no M. Optional.mValue: With m-value: M-values in log2(1). Optional.ids: Optional ids, one per site, echoed. Optional.
Every refusal, with its code6 refusals
| Code | When |
|---|---|
BETA_UNDEFINED | both signals are zero after negatives are set to zero and the beta offset is zero, so beta is zero over zero. |
M_UNDEFINED | a signal is zero after negatives are set to zero and the M offset is zero, so M is infinite. |
BETA_AT_BOUND | a beta-value of zero or one has no finite M-value. |
BETA_BELOW_DOUBLE_RANGE | a beta-value, from signals or from an M-value, would be a non-zero number below the smallest normal double, which a double holds only to reduced precision; a beta that rounds to zero is returned as zero. |
VALUES_MISALIGNED | the methylated and unmethylated vectors, or the ids, are not one per site. |
MATRIX_ABOVE_CAP | the values sent are more numeric cells than the tool's cap. |
The calculation
The method's equations, constants and worked example.
Equation 1
beta = max(meth, 0) / (max(unmeth, 0) + max(meth, 0) + alpha_beta): Du et al.'s Eq. 1, with negatives "reset to 0" as the source states
the source quotes Illumina's default offset ("by default, α = 100"), and requiring the caller to state it is this project's ruling
read counts as signals are the record's extension (the source treats array intensities)
inputs are read as the exact value of their shortest decimal
signals are at most 1e15 and offsets at most 1e12 (the kit's OUT_OF_RANGE above, tested on that value)
order of checks: the kit's checks of each argument, then CONFLICTING_ARGUMENT for an argument the chosen from does not use, then MISSING_ARGUMENT (signalKind, the signals, betaOffset, mOffset, in that order), then MATRIX_ABOVE_CAP (methylated and unmethylated together above 6,000 values), then VALUES_MISALIGNED, then the ids (VALUES_MISALIGNED, DUPLICATE_NAME), then for read counts NOT_AN_INTEGER (a negative read count included), then per site in order BETA_UNDEFINED, M_UNDEFINED and BETA_BELOW_DOUBLE_RANGE (RAISE-X5)
setToZero positions count from 0
| Symbol | Meaning |
|---|---|
beta | beta-value |
meth | methylated signal |
unmeth | unmethylated signal |
alpha_beta | the caller's beta offset |
Source 1.
Equation 2
M = log2((max(meth, 0) + alpha_M) / (max(unmeth, 0) + alpha_M)): Du et al.'s Eq. 2, whose offset the source gives "by default, α = 1"
requiring it to be stated is this project's ruling
| Symbol | Meaning |
|---|---|
M | M-value, log2(1) |
alpha_M | the caller's M offset |
Source 1.
Equation 3
beta = 2^M / (2^M + 1), offsets ignored
| Symbol | Meaning |
|---|---|
beta | beta-value |
M | M-value, log2(1) |
Source 1.
Equation 4
M = log2(beta / (1 - beta)), offsets ignored: computed on the exact value of beta's shortest decimal (SGB-1), b/(1 - b) as a fraction, then log1p of b/(1 - b) - 1 over ln 2 where the ratio is within a factor of 2 of 1, else log2 of its nearest double
so Du et al.'s 0.8 gives exactly 2, and 0.9999999999999999 gives log2(9999999999999999), about 53.15, where the double's 1 - beta would give 53
BETA_AT_BOUND is decided on that decimal, so a typed 0.99999999999999999, which JSON reads as 1, is refused
| Symbol | Meaning |
|---|---|
M | M-value, log2(1) |
beta | beta-value |
Source 1.
Conventions
- from = signals: beta and M from methylated and unmethylated signals, by Eq. 1 and 2 with the stated offsets
- from = beta: M from beta-values by Eq. 3, which ignores offsets
- from = m-value: beta from M-values by Eq. 3, which ignores offsets
A definition, not a model: the equation states what the quantity means. A different convention gives a different number.
Worked example
Worked example: one case of genome-methylation-level@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
- from = signals
- signalKind = intensities
- methylated.values[0] = 3000
- methylated.unit = 1
- unmethylated.values[0] = 1000
- unmethylated.unit = 1
- betaOffset = 100
- mOffset = 1
Steps
- b = 0.73170732, from methylated, unmethylated, betaOffset; by equation 1; gives result.betaValue.values[0].
- m = 1.5840013 log2(1), from methylated, unmethylated, mOffset; by equation 2; gives result.mValue.values[0].
The working, as the case writes it:
[0] beta = 3000/(1000+3000+100) = 0.7317073170731707317073170731707317073171
M = log2((3000+1)/(1000+1)) = 1.584001344762294793309824886573047887911
Answer
result.betaValue.values[0] = 0.73170732
result.mValue.values[0] = 1.5840013 log2(1)
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 3). This is not an independent check.
At build the tool returned this answer within the tolerance the file states: beta-values relative 1e-14 (zero exact); M-values absolute 1e-14 in log2; counts, positions, texts, statuses and codes exact.
Sources
Du P, Zhang X, Huang C-C, Jafari N, Kibbe WA, Hou L, Lin SM (2010), Comparison of Beta-value and M-value methods for quantifying methylation levels by microarray analysis, BMC Bioinformatics 11:587, doi 10.1186/1471-2105-11-587
Used for: Beta-value and M-value of a CpG, and the conversion between them. At: equation Eq. 1 to 3, section Results: Eq. 1 and 2 under "Definition of Beta-value and M-value"; Eq. 3 under "Relationship between Beta-value and M-value".
Read in full, 11 November 2026
How it is checked
- Level
Checked against a reference.
- Checked against
Our own exact-arithmetic script and a hand-worked case; the source's own worked example, CPython standard library (decimal), 3.13.18.
- Cases
No case set is linked to this version.
- Not checked
Probe type, dye bias, normalisation and detection p-values; saturated intensities; any default offset of a package.
Changes to its methods1 change
- 14 November 2026, genome-methylation-level@2.0.0: In 2.0.0, M keeps full relative precision near zero (log1p) and elsewhere (one division); M from beta is taken on the exact decimal, so Du et al.'s 0.8 gives exactly 2; beta from M is within two ulps of the exact value everywhere (a series above M of 30), and the statement names the three forms, says that beta is in the open interval and that a returned one or zero is rounding. The bounds are measured by stored reference values. A beta-value that would be a non-zero subnormal is refused as BETA_BELOW_DOUBLE_RANGE (a served subnormal beta-value becomes a refusal; RAISE-X5).