liveBook · Manning

Gene

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

Gene is a book-specific array-based representation of a nucleotide sequence as an ordered collection of codons.

A gene is an ordered array of codons. Each codon contains three nucleotides, and each nucleotide is one of A, C, G, or T. section 2.1

A Swift representation builds the model in small layers:

  • Represent a nucleotide with an enum whose cases are A, C, G, and T. section 2.1
  • Represent a codon as a tuple of three Nucleotide values. section 2.1
  • Define Gene as an array of codons, preserving their sequence order. section 2.1
  • Add Comparable behavior to Nucleotide so codons and genes can support ordered searches. section 2.1

Converting a sequence into a gene

Given a nucleotide string, stringToGene() reads three characters at a time, converts them into a codon, and appends that codon to a Gene. If fewer than three nucleotides remain, it ignores the incomplete ending. A resulting gene can then be searched linearly or sorted before binary search. 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.

Use the diagram to keep the representation hierarchy visible: nucleotide, codon, then gene. section 2.1

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

How deep it goes
Defines nucleotides, codons, array conversion, ordering, and searches without developing broader biological semantics.
Examples
Uses a nucleotide string, stringToGene(), an ACG codon, and linear or binary containment searches.
What you can do after
Build it from scratch as Swift enums, tuples, arrays, and a parser for codon sequences.
How it connects
Connects nucleotides and codons to DNA search, and genes to chromosomes in genetic algorithms.

Also explained in

Compare how 5 books explain gene →

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.