Update
This commit is contained in:
60
go/protein-translation/README.md
Normal file
60
go/protein-translation/README.md
Normal file
@@ -0,0 +1,60 @@
|
||||
# Protein Translation
|
||||
|
||||
Write a program that will translate RNA sequences into proteins.
|
||||
|
||||
Lets write a program that will translate RNA sequences into proteins. [general ref](http://en.wikipedia.org/wiki/Translation_(biology)
|
||||
|
||||
RNA can be broken into three nucleotide sequences called codons, and then translated to a polypeptide like so:
|
||||
|
||||
RNA: `"AUGUUUUCU"` => translates to
|
||||
|
||||
Codons: `"AUG", "UUU", "UCU"`
|
||||
=> which become a polypeptide with the following sequence =>
|
||||
|
||||
Protein: `"Methionine", "Phenylalanine", "Serine"`
|
||||
|
||||
There are 64 codons which in turn correspond to 20 amino acids; however, all of the codon sequences and resulting amino acids are not important in this exercise. If it works for one codon, the program should work for all of them.
|
||||
However, feel free to expand the list in the test suite to include them all.
|
||||
|
||||
There are also four terminating codons (also known as 'STOP' codons); if any of these codons are encountered (by the ribosome), all translation ends and the protein is terminated.
|
||||
|
||||
All subsequent codons after are ignored, like this:
|
||||
|
||||
RNA: `"AUGUUUUCUUAAAUG"` =>
|
||||
|
||||
Codons: `"AUG", "UUU", "UCU", "UAG", "AUG"` =>
|
||||
|
||||
Protein: `"Methionine", "Phenylalanine", "Serine"`
|
||||
|
||||
Note the stop codon terminates the translation and the final methionine is not translated into the protein sequence.
|
||||
|
||||
Below are the codons and resulting Amino Acids needed for the exercise.
|
||||
|
||||
Codon | Protein
|
||||
:--- | :---
|
||||
AUG | Methionine
|
||||
UUU, UUC | Phenylalanine
|
||||
UUA, UUG | Leucine
|
||||
UCU, UCC, UCA, UCG | Serine
|
||||
UAU, UAC | Tyrosine
|
||||
UGU, UGC | Cysteine
|
||||
UGG | Tryptophan
|
||||
UAA, UAG, UGA | STOP
|
||||
|
||||
To run the tests simply run the command `go test` in the exercise directory.
|
||||
|
||||
If the test suite contains benchmarks, you can run these with the `-bench`
|
||||
flag:
|
||||
|
||||
go test -bench .
|
||||
|
||||
For more detailed info about the Go track see the [help
|
||||
page](http://exercism.io/languages/go).
|
||||
|
||||
## Source
|
||||
|
||||
Tyler Long
|
||||
|
||||
## Submitting Incomplete Problems
|
||||
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|
||||
|
62
go/protein-translation/protein.go
Normal file
62
go/protein-translation/protein.go
Normal file
@@ -0,0 +1,62 @@
|
||||
package protein
|
||||
|
||||
const testVersion = 1
|
||||
|
||||
func FromRNA(inp string) []string {
|
||||
var ret []string
|
||||
for i := 0; i < len(inp); i = i + 3 {
|
||||
cdn := FromCodon(inp[i : i+3])
|
||||
if cdn == "STOP" {
|
||||
break
|
||||
}
|
||||
ret = append(ret, cdn)
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
||||
func FromCodon(inp string) string {
|
||||
switch inp {
|
||||
case "AUG":
|
||||
return "Methionine"
|
||||
case "UUU":
|
||||
return "Phenylalanine"
|
||||
case "UUC":
|
||||
return "Phenylalanine"
|
||||
case "UUA":
|
||||
return "Leucine"
|
||||
case "UUG":
|
||||
return "Leucine"
|
||||
case "UCU":
|
||||
return "Serine"
|
||||
case "UCC":
|
||||
return "Serine"
|
||||
case "UCA":
|
||||
return "Serine"
|
||||
case "UCG":
|
||||
return "Serine"
|
||||
case "UAU":
|
||||
return "Tyrosine"
|
||||
case "UAC":
|
||||
return "Tyrosine"
|
||||
case "UGU":
|
||||
return "Cysteine"
|
||||
case "UGC":
|
||||
return "Cysteine"
|
||||
case "UGG":
|
||||
return "Tryptophan"
|
||||
}
|
||||
return "STOP"
|
||||
}
|
||||
|
||||
/*
|
||||
Codon | Protein
|
||||
:--- | :---
|
||||
AUG | Methionine
|
||||
UUU, UUC | Phenylalanine
|
||||
UUA, UUG | Leucine
|
||||
UCU, UCC, UCA, UCG | Serine
|
||||
UAU, UAC | Tyrosine
|
||||
UGU, UGC | Cysteine
|
||||
UGG | Tryptophan
|
||||
UAA, UAG, UGA | STOP
|
||||
*/
|
69
go/protein-translation/protein_translation_test.go
Normal file
69
go/protein-translation/protein_translation_test.go
Normal file
@@ -0,0 +1,69 @@
|
||||
package protein
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const targetTestVersion = 1
|
||||
|
||||
type codonCase struct {
|
||||
input string
|
||||
expected string
|
||||
}
|
||||
|
||||
var codonTestCases = []codonCase{
|
||||
{"AUG", "Methionine"},
|
||||
{"UUU", "Phenylalanine"},
|
||||
{"UUC", "Phenylalanine"},
|
||||
{"UUA", "Leucine"},
|
||||
{"UUG", "Leucine"},
|
||||
{"UCU", "Serine"},
|
||||
{"UCC", "Serine"},
|
||||
{"UCA", "Serine"},
|
||||
{"UCG", "Serine"},
|
||||
{"UAU", "Tyrosine"},
|
||||
{"UAC", "Tyrosine"},
|
||||
{"UGU", "Cysteine"},
|
||||
{"UGC", "Cysteine"},
|
||||
{"UGG", "Tryptophan"},
|
||||
{"UAA", "STOP"},
|
||||
{"UAG", "STOP"},
|
||||
{"UGA", "STOP"},
|
||||
}
|
||||
|
||||
type rnaCase struct {
|
||||
input string
|
||||
expected []string
|
||||
}
|
||||
|
||||
var proteinTestCases = []rnaCase{
|
||||
{"AUGUUUUCUUAAAUG", []string{"Methionine", "Phenylalanine", "Serine"}},
|
||||
{"AUGUUUUGG", []string{"Methionine", "Phenylalanine", "Tryptophan"}},
|
||||
{"AUGUUUUAA", []string{"Methionine", "Phenylalanine"}},
|
||||
{"UGGUGUUAUUAAUGGUUU", []string{"Tryptophan", "Cysteine", "Tyrosine"}},
|
||||
}
|
||||
|
||||
func TestCodon(t *testing.T) {
|
||||
for _, test := range codonTestCases {
|
||||
actual := FromCodon(test.input)
|
||||
if actual != test.expected {
|
||||
t.Errorf("Protein Translation test [%s], expected [%s], actual [%s]", test.input, test.expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestProtein(t *testing.T) {
|
||||
for _, test := range proteinTestCases {
|
||||
actual := FromRNA(test.input)
|
||||
if !reflect.DeepEqual(actual, test.expected) {
|
||||
t.Errorf("Protein Translation test [%s], expected %q, actual %q", test.input, test.expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestTestVersion(t *testing.T) {
|
||||
if testVersion != targetTestVersion {
|
||||
t.Errorf("Found testVersion = %v, want %v.", testVersion, targetTestVersion)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user