Documentation ¶
Overview ¶
Package typo implements the game of typogenetics as described in Gödel, Escher Bach: an Eternal Golden Braid by Douglas Hofstadter.
Example (Book) ¶
e := Enzyme{Rpu, Inc, Cop, Mvr, Mvl, Swi, Lpu, Int} s := "TAGATCCAGTCCATCGA" first, last := e.Fold() pref := e.Preference() fmt.Printf("Folding:\n First:%s Last:%s\n\nPrefers:%q\n\n", first, last, pref) var pos []int for i, b := range Strand(s) { if b == pref { pos = append(pos, i) } } fmt.Printf("%d possible start positions: %d\n\n", len(pos), pos) for _, p := range pos { var buf bytes.Buffer fmt.Printf("Start at %d:\n\n", p) // As stated in the game rules, the strand // being operated on is consumed by the enzyme // so this example creates a new Strand from // a string constant for each start position. products := e.OperateOn(NewComplex(Strand(s)), p, &buf).Products() fmt.Printf("%s\nProducts:%q\n\n", &buf, products) }
Output: Folding: First:west Last:north Prefers:'G' 3 possible start positions: [2 8 15] Start at 2: Rpu 2 G "TAGATCCAGTCCATCGA" "·················" Inc 3 A "TAGATCCAGTCCATCGA" "·················" Cop 4 C "TAGACTCCAGTCCATCGA" "··················" Mvr 4 C "TAGACTCCAGTCCATCGA" "·············G····" Mvl 5 T "TAGACTCCAGTCCATCGA" "············AG····" Swi 4 C "TAGACTCCAGTCCATCGA" "············AG····" Lpu 13 G "············AG····" "TAGACTCCAGTCCATCGA" Int 12 A "············AG····" "TAGACTCCAGTCCATCGA" done 13 T "············ATG····" "TAGACATCCAGTCCATCGA" Products:["ATG" "TAGACATCCAGTCCATCGA"] Start at 8: Rpu 8 G "TAGATCCAGTCCATCGA" "·················" Inc 12 A "TAGATCCAGTCCATCGA" "·················" Cop 13 C "TAGATCCAGTCCACTCGA" "··················" Mvr 13 C "TAGATCCAGTCCACTCGA" "····G·············" Mvl 14 T "TAGATCCAGTCCACTCGA" "···AG·············" Swi 13 C "TAGATCCAGTCCACTCGA" "···AG·············" Lpu 4 G "···AG·············" "TAGATCCAGTCCACTCGA" Int 3 A "···AG·············" "TAGATCCAGTCCACTCGA" done 4 T "···ATG·············" "TAGATCCAGTCCACATCGA" Products:["ATG" "TAGATCCAGTCCACATCGA"] Start at 15: Rpu 15 G "TAGATCCAGTCCATCGA" "·················" Inc 16 A "TAGATCCAGTCCATCGA" "·················" Cop 17 C "TAGATCCAGTCCATCGAC" "··················" Mvr 17 C "TAGATCCAGTCCATCGAC" "G·················" off 18 - "TAGATCCAGTCCATCGAC" "G·················" Products:["TAGATCCAGTCCATCGAC" "G"]
Example (Quine) ¶
seed := "CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG" pool := []Strand{Strand(seed)} fmt.Printf("%s: 1\n", seed) for n := 0; n < 5; n++ { var daughters []Strand for _, s := range pool { m := s.Enzymes() c := NewComplex(s) for _, e := range m { pref := e.Preference() for i, b := range c[0] { if b == pref { c = e.OperateOn(c, i, nil) break } } } daughters = append(daughters, c.Products()...) } pool = daughters gen := make(map[string]int) for _, s := range pool { gen[string(s)]++ } for s, count := range gen { fmt.Printf("%s: %d\n", s, count) } }
Output: CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG: 1 CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG: 2 CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG: 4 CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG: 8 CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG: 16 CGTTCCTCTCTCTCTATAGAGAGAGAGGAACG: 32
Index ¶
Examples ¶
Constants ¶
const ( Left = iota - 1 Straight Right )
Variables ¶
var ( // Complement describes how bases pair. Complement = [255]func() byte{'A': T, 'C': G, 'G': C, 'T': A} // Code is the pseudo-codon to amino acid lookup. Code = [16]AminoAcid{ Non, Cut, Del, Swi, Mvr, Mvl, Cop, Off, Ina, Inc, Ing, Int, Rpy, Rpu, Lpy, Lpu, } // Inserts specifies what base or pseudobase // is inserted by insert and cut amino acids. Inserts = [16]func() byte{ Cut: null, Ina: A, Inc: C, Ing: G, Int: T, } // Moves specifies the direction the search amino // acids move. Moves = [16]int{ Rpy: Right, Rpu: Right, Lpy: Left, Lpu: Left, } // Matches specifies the matching criteria of // search amino acids. Matches = [16]func(byte) bool{ Rpy: IsPyrimidine, Rpu: IsPurine, Lpy: IsPyrimidine, Lpu: IsPurine, } // Kinks specifies the folding characteristics // of each amino acid. Kinks = [16]Kink{ Cut: Straight, Del: Straight, Swi: Right, Mvr: Straight, Mvl: Straight, Cop: Right, Off: Left, Ina: Straight, Inc: Right, Ing: Right, Int: Left, Rpy: Right, Rpu: Left, Lpy: Left, Lpu: Left, } // Preference specifies the binding preference of // each folding direction. Preference = [4]func() byte{ East: A, North: C, South: G, West: T, } )
Functions ¶
Types ¶
type AminoAcid ¶
type AminoAcid byte
AminoAcid represents a typogenetics amino acid.
const ( Non AminoAcid = iota Cut // cut strand(s) Del // delete a base from strand Swi // switch enzyme to other strand Mvr // move one unit to the right Mvl // move one unit to the left Cop // turn on Copy mode Off // turn off Copy mode Ina // insert A to the right of this unit Inc // insert C to the right of this unit Ing // insert G to the right of this unit Int // insert T to the right of this unit Rpy // search for the nearest pyrimidine to the right Rpu // search for the nearest purine to the right Lpy // search for the nearest pyrimidine to the left Lpu // search for the nearest purine to the left )
type Direction ¶
type Direction int8
Direction represent the tertiary structure direction of a typogenetics enzyme.
type Enzyme ¶
type Enzyme []AminoAcid
Enzyme is implements a typogenetics enzyme.
func (Enzyme) OperateOn ¶
OperateOn performs the enzymatic activity of the receiver on the given typogenetics complex starting from the specified position of the first strand of the complex according to rules of typogenetics on pp504-513 of GEB and returns the resulting product complex. If debug is not nil, the sequence of operations and the intermediate results are written into the buffer. OperateOn will panic if the receiver includes an unknown amino acid or the Non amino acid.
func (Enzyme) Preference ¶
Preference returns the base preference of the receiver.