Zac Gross

Code & More

Encoding Data in DNA With Go

| Comments

As a recent programming exercise I wrote a golang library that allows encoding/decoding arbitrary data in DNA segments.

The encoding algorithm is based on the method described in this Nature paper: http://www.nature.com/nature/journal/v494/n7435/full/nature11875.html . Pseudo code and details can be found here: http://www.nature.com/nature/journal/vaop/ncurrent/extref/nature11875-s2.pdf

Usage Example:

Encoding
1
2
3
   str := "some string to encode in DNA"
  dna := dna.Encode(str)
  fmt.Println("Result: ", dna)

The resulting string is a valid DNA sequence.

Sequences can be decoded back to human readable text the same way:

Decoding
1
2
3
   dna := "ATAGTATATCGACTAGTACAGCGTAGCATCTCGCAGCGAGATACGCTGCTACGCAGCATGCTGTGAGTATCGATGACGAGTGACTCTGTACAGTACGTACGATACGTACGTACGTCGTATAGTCGTACGTACGTACGTACGTACGTACGTACTGTACAGAGTCACTCGTCATCGATACTCACAGCATGCTGCGTAGCAGCGTATCTCGCTGCGAGATGATACGTACGTACGAGC"
  str := dna.Decode(dna)
  fmt.Println("Result",str)

Source on github: https://github.com/zacg/dna

Comments