Initial upload
This commit is contained in:
30
go/protein-translation/.exercism/config.json
Normal file
30
go/protein-translation/.exercism/config.json
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"blurb": "Translate RNA sequences into proteins.",
|
||||
"authors": [
|
||||
"Akasurde"
|
||||
],
|
||||
"contributors": [
|
||||
"alebaffa",
|
||||
"bitfield",
|
||||
"ekingery",
|
||||
"ferhatelmas",
|
||||
"hilary",
|
||||
"kytrinyx",
|
||||
"leenipper",
|
||||
"robphoenix",
|
||||
"sebito91",
|
||||
"tleen"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"protein_translation.go"
|
||||
],
|
||||
"test": [
|
||||
"protein_translation_test.go"
|
||||
],
|
||||
"example": [
|
||||
".meta/example.go"
|
||||
]
|
||||
},
|
||||
"source": "Tyler Long"
|
||||
}
|
1
go/protein-translation/.exercism/metadata.json
Normal file
1
go/protein-translation/.exercism/metadata.json
Normal file
@@ -0,0 +1 @@
|
||||
{"track":"go","exercise":"protein-translation","id":"1806e002ad7e45bf87a980c11a1bdac1","url":"https://exercism.org/tracks/go/exercises/protein-translation","handle":"halfdan","is_requester":true,"auto_approve":false}
|
40
go/protein-translation/HELP.md
Normal file
40
go/protein-translation/HELP.md
Normal file
@@ -0,0 +1,40 @@
|
||||
# Help
|
||||
|
||||
## Running the tests
|
||||
|
||||
To run the tests run the command `go test` from within the exercise directory.
|
||||
|
||||
If the test suite contains benchmarks, you can run these with the `--bench` and `--benchmem`
|
||||
flags:
|
||||
|
||||
go test -v --bench . --benchmem
|
||||
|
||||
Keep in mind that each reviewer will run benchmarks on a different machine, with
|
||||
different specs, so the results from these benchmark tests may vary.
|
||||
|
||||
## Submitting your solution
|
||||
|
||||
You can submit your solution using the `exercism submit protein_translation.go` command.
|
||||
This command will upload your solution to the Exercism website and print the solution page's URL.
|
||||
|
||||
It's possible to submit an incomplete solution which allows you to:
|
||||
|
||||
- See how others have completed the exercise
|
||||
- Request help from a mentor
|
||||
|
||||
## Need to get help?
|
||||
|
||||
If you'd like help solving the exercise, check the following pages:
|
||||
|
||||
- The [Go track's documentation](https://exercism.org/docs/tracks/go)
|
||||
- [Exercism's support channel on gitter](https://gitter.im/exercism/support)
|
||||
- The [Frequently Asked Questions](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Should those resources not suffice, you could submit your (incomplete) solution to request mentoring.
|
||||
|
||||
To get help if you're having trouble, you can use one of the following resources:
|
||||
|
||||
- [How to Write Go Code](https://golang.org/doc/code.html)
|
||||
- [Effective Go](https://golang.org/doc/effective_go.html)
|
||||
- [Go Resources](http://golang.org/help)
|
||||
- [StackOverflow](http://stackoverflow.com/questions/tagged/go)
|
70
go/protein-translation/README.md
Normal file
70
go/protein-translation/README.md
Normal file
@@ -0,0 +1,70 @@
|
||||
# Protein Translation
|
||||
|
||||
Welcome to Protein Translation on Exercism's Go Track.
|
||||
If you need help running the tests or submitting your code, check out `HELP.md`.
|
||||
|
||||
## Instructions
|
||||
|
||||
Translate RNA sequences into proteins.
|
||||
|
||||
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 three 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", "UAA", "AUG"` =>
|
||||
|
||||
Protein: `"Methionine", "Phenylalanine", "Serine"`
|
||||
|
||||
Note the stop codon `"UAA"` 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
|
||||
|
||||
Learn more about [protein translation on Wikipedia](http://en.wikipedia.org/wiki/Translation_(biology))
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @Akasurde
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @alebaffa
|
||||
- @bitfield
|
||||
- @ekingery
|
||||
- @ferhatelmas
|
||||
- @hilary
|
||||
- @kytrinyx
|
||||
- @leenipper
|
||||
- @robphoenix
|
||||
- @sebito91
|
||||
- @tleen
|
||||
|
||||
### Based on
|
||||
|
||||
Tyler Long
|
3
go/protein-translation/go.mod
Normal file
3
go/protein-translation/go.mod
Normal file
@@ -0,0 +1,3 @@
|
||||
module protein
|
||||
|
||||
go 1.13
|
9
go/protein-translation/protein_translation.go
Normal file
9
go/protein-translation/protein_translation.go
Normal file
@@ -0,0 +1,9 @@
|
||||
package protein
|
||||
|
||||
func FromRNA(rna string) ([]string, error) {
|
||||
panic("Please implement the FromRNA function")
|
||||
}
|
||||
|
||||
func FromCodon(codon string) (string, error) {
|
||||
panic("Please implement the FromCodon function")
|
||||
}
|
35
go/protein-translation/protein_translation_detailed_test.go
Normal file
35
go/protein-translation/protein_translation_detailed_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
//go:build detailed
|
||||
// +build detailed
|
||||
|
||||
package protein
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func BenchmarkCodonDetailed(b *testing.B) {
|
||||
if testing.Short() {
|
||||
b.Skip("skipping benchmark in short mode.")
|
||||
}
|
||||
for _, test := range codonTestCases {
|
||||
b.Run(fmt.Sprintf("Codon%s", test.input), func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
FromCodon(test.input)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkProteinDetailed(b *testing.B) {
|
||||
if testing.Short() {
|
||||
b.Skip("skipping benchmark in short mode.")
|
||||
}
|
||||
for _, test := range proteinTestCases {
|
||||
b.Run(fmt.Sprintf("Protein%s", test.input), func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
FromRNA(test.input)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
189
go/protein-translation/protein_translation_test.go
Normal file
189
go/protein-translation/protein_translation_test.go
Normal file
@@ -0,0 +1,189 @@
|
||||
package protein
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestErrorsNotNil(t *testing.T) {
|
||||
if ErrStop == nil {
|
||||
t.Fatalf("FAIL: ErrStop cannot be nil")
|
||||
}
|
||||
if ErrInvalidBase == nil {
|
||||
t.Fatalf("FAIL: ErrInvalidBase cannot be nil")
|
||||
}
|
||||
}
|
||||
|
||||
type codonCase struct {
|
||||
input string
|
||||
expected string
|
||||
errorExpected error
|
||||
}
|
||||
|
||||
var codonTestCases = []codonCase{
|
||||
{
|
||||
"AUG",
|
||||
"Methionine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UUU",
|
||||
"Phenylalanine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UUC",
|
||||
"Phenylalanine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UUA",
|
||||
"Leucine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UUG",
|
||||
"Leucine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UCG",
|
||||
"Serine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UAU",
|
||||
"Tyrosine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UAC",
|
||||
"Tyrosine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UGU",
|
||||
"Cysteine",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UGG",
|
||||
"Tryptophan",
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UAA",
|
||||
"",
|
||||
ErrStop,
|
||||
},
|
||||
{
|
||||
"UAG",
|
||||
"",
|
||||
ErrStop,
|
||||
},
|
||||
{
|
||||
"UGA",
|
||||
"",
|
||||
ErrStop,
|
||||
},
|
||||
{
|
||||
"ABC",
|
||||
"",
|
||||
ErrInvalidBase,
|
||||
},
|
||||
}
|
||||
|
||||
func TestCodon(t *testing.T) {
|
||||
for _, test := range codonTestCases {
|
||||
actual, err := FromCodon(test.input)
|
||||
if test.errorExpected != nil {
|
||||
if test.errorExpected != err {
|
||||
t.Fatalf("FAIL: Protein translation test: %s\nExpected error: %q\nActual error: %q",
|
||||
test.input, test.errorExpected, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Fatalf("FAIL: Protein translation test: %s\nExpected: %s\nGot error: %q",
|
||||
test.input, test.expected, err)
|
||||
}
|
||||
if actual != test.expected {
|
||||
t.Fatalf("FAIL: Protein translation test: %s\nExpected: %s\nActual: %s",
|
||||
test.input, test.expected, actual)
|
||||
}
|
||||
t.Logf("PASS: Protein translation test: %s", test.input)
|
||||
}
|
||||
}
|
||||
|
||||
type rnaCase struct {
|
||||
input string
|
||||
expected []string
|
||||
errorExpected error
|
||||
}
|
||||
|
||||
var proteinTestCases = []rnaCase{
|
||||
{
|
||||
"AUGUUUUCUUAAAUG",
|
||||
[]string{"Methionine", "Phenylalanine", "Serine"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"AUGUUUUGG",
|
||||
[]string{"Methionine", "Phenylalanine", "Tryptophan"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"AUGUUUUAA",
|
||||
[]string{"Methionine", "Phenylalanine"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UGGUGUUAUUAAUGGUUU",
|
||||
[]string{"Tryptophan", "Cysteine", "Tyrosine"},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
"UGGAGAAUUAAUGGUUU",
|
||||
[]string{"Tryptophan"},
|
||||
ErrInvalidBase,
|
||||
},
|
||||
}
|
||||
|
||||
func TestProtein(t *testing.T) {
|
||||
for _, test := range proteinTestCases {
|
||||
actual, err := FromRNA(test.input)
|
||||
if test.errorExpected != nil {
|
||||
if test.errorExpected != err {
|
||||
t.Fatalf("FAIL: RNA translation test: %s\nExpected error: %q\nActual error: %q",
|
||||
test.input, test.errorExpected, err)
|
||||
}
|
||||
} else if err != nil {
|
||||
t.Fatalf("FAIL: RNA translation test: %s\nExpected: %s\nGot error: %q",
|
||||
test.input, test.expected, err)
|
||||
}
|
||||
if !reflect.DeepEqual(actual, test.expected) {
|
||||
t.Fatalf("FAIL: RNA Translation test: %s\nExpected: %q\nActual %q", test.input, test.expected, actual)
|
||||
}
|
||||
t.Logf("PASS: RNA translation test: %s", test.input)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCodon(b *testing.B) {
|
||||
if testing.Short() {
|
||||
b.Skip("skipping benchmark in short mode.")
|
||||
}
|
||||
for _, test := range codonTestCases {
|
||||
for i := 0; i < b.N; i++ {
|
||||
FromCodon(test.input)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkProtein(b *testing.B) {
|
||||
if testing.Short() {
|
||||
b.Skip("skipping benchmark in short mode.")
|
||||
}
|
||||
for _, test := range proteinTestCases {
|
||||
for i := 0; i < b.N; i++ {
|
||||
FromRNA(test.input)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user