Skip to content

Nucleotides and residues

Open this tutorial as a notebook

The NUC enum represents the full IUPAC encoding of DNA and RNA. Each constant carries the properties you would otherwise have to look up: molecular weights, complements, and ambiguity codes.

%use biokotlin
import biokotlin.seq.*

// Importing the enum constants lets you write `A` instead of `NUC.A`. Do this
// only when you are not also working with amino acids, whose single-letter
// names overlap.
import biokotlin.seq.NUC.*

The molecular weight of adenine as a DNA nucleotide:

A.dnaWeight
331.2218

And its complement:

A.dnaComplement
T

Because NUC is an ordinary Kotlin enum, the whole standard collections framework applies. Here every nucleotide code is listed by weight.

NUC.values().asSequence()
    .sortedBy { it.rnaWeight }
    .forEach { println("$it weighs ${it.dnaWeight}") }
GAP weighs -1.0
C weighs 307.1971
Y weighs 314.7028
T weighs 322.2085
U weighs 322.2085
H weighs 320.2091333333333
M weighs 319.20944999999995
W weighs 326.71515
B weighs 325.54226666666665
X weighs 326.96214999999995
N weighs 326.96214999999995
S weighs 327.20915
K weighs 334.71485
V weighs 328.54669999999993
D weighs 333.5505
A weighs 331.2218
R weighs 339.2215
G weighs 347.2212