A nucleotide is one of four DNA symbols: A, C, G, or T. Three nucleotides form a codon, and multiple codons form a gene. section 2.1
For DNA search, model a nucleotide as a Swift enum with four cases and Comparable conformance. Comparing raw Character values supplies an ordering for codons and genes. section 2.1
Use the nucleotide representation to build larger DNA structures:
- Define Codon as a tuple of three Nucleotides. section 2.1
- Define Gene as an array of Codons. section 2.1
- Convert a DNA string into codons in groups of three, skipping a final incomplete group. section 2.1
- Encode A, C, G, and T as 00, 01, 10, and 11 when compact storage matters. section 1.2
Searching a gene
Convert a sequence such as ACGTGGCTCTCTAACGTACGTACGTACGGGGTTTATATATACCCTAGGACTCCCTTT into a Gene, then search for the codon (.A, .C, .G). Linear search scans codons sequentially; binary search requires a sorted gene. section 2.1
Compressed storage
A sequence such as ATGAATGCC can be stored as a two-bit-per-nucleotide bit string and decompressed back to its original letters. section 1.2
Figure 2.1. A nucleotide is represented by one of the letters A, C, G, and T. A codon is composed of three nucleotides, and a gene is composed of multiple codons.
Use the diagram to connect individual nucleotides with codons and genes. section 2.1
