exercism/go/protein-translation/protein.go

63 lines
1.1 KiB
Go
Raw Normal View History

2016-11-30 03:28:40 +00:00
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
*/