liveBook · Manning

Codon

As explained in Classic Computer Science Problems in Swift: Essential techniques for practicing programmers

A codon is a sequence of three nucleotides that specifies an amino acid.

A codon is a sequence of three nucleotides. Each nucleotide is represented by A, C, G, or T, and each codon specifies an amino acid; multiple amino acids can form a protein. section 2.1

In Swift, represent a codon as a three-element tuple and a gene as an array of codons. A parser reads a nucleotide string in groups of three and ignores a final incomplete group. section 2.1

Representing and parsing codons

typealias Codon = (Nucleotide, Nucleotide, Nucleotide) typealias Gene = [Codon] func stringToGene(_ s: String) -> Gene { var gene = Gene() for i in stride(from: 0, to: s.count, by: 3) { guard i + 2 < s.count else { return gene } // Convert the next three characters into a Codon. } return gene } let acg: Codon = (.A, .C, .G) section 2.1

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.

Shows the relationship between a nucleotide, a codon composed of three nucleotides, and a gene composed of multiple codons. section 2.1

How Classic Computer Science Problems in Swift: Essential techniques for practicing programmers covers it

How deep it goes
Defines codons biologically and models them in Swift, stopping short of detailed amino-acid translation.
Examples
Uses A, C, G, and T nucleotides, an ACG codon, and a parsed gene sequence.
What it assumes
Assumes basic Swift types and strings while defining nucleotide, codon, and gene representations directly.
What you can do after
Build it from scratch as a Swift tuple and parse nucleotide strings into arrays of codons.
How it connects
Connects codons with nucleotides, genes, amino acids, proteins, linear search, and binary search.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Classic Computer Science Problems in Swift: Essential techniques for practicing programmers. The section links point to the parts of the book it draws on.