mirror of
https://github.com/Xevion/exercism.git
synced 2025-12-09 16:07:08 -06:00
92 lines
3.5 KiB
Markdown
92 lines
3.5 KiB
Markdown
# Protein Translation
|
|
|
|
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))
|
|
|
|
## Exception messages
|
|
|
|
Sometimes it is necessary to raise an exception. When you do this, you should include a meaningful error message to
|
|
indicate what the source of the error is. This makes your code more readable and helps significantly with debugging. Not
|
|
every exercise will require you to raise an exception, but for those that do, the tests will only pass if you include
|
|
a message.
|
|
|
|
To raise a message with an exception, just write it as an argument to the exception type. For example, instead of
|
|
`raise Exception`, you should write:
|
|
|
|
```python
|
|
raise Exception("Meaningful message indicating the source of the error")
|
|
```
|
|
|
|
## Running the tests
|
|
|
|
To run the tests, run the appropriate command below ([why they are different](https://github.com/pytest-dev/pytest/issues/1629#issue-161422224)):
|
|
|
|
- Python 2.7: `py.test protein_translation_test.py`
|
|
- Python 3.4+: `pytest protein_translation_test.py`
|
|
|
|
Alternatively, you can tell Python to run the pytest module (allowing the same command to be used regardless of Python version):
|
|
`python -m pytest protein_translation_test.py`
|
|
|
|
### Common `pytest` options
|
|
|
|
- `-v` : enable verbose output
|
|
- `-x` : stop running tests on first failure
|
|
- `--ff` : run failures from previous test before running other test cases
|
|
|
|
For other options, see `python -m pytest -h`
|
|
|
|
## Submitting Exercises
|
|
|
|
Note that, when trying to submit an exercise, make sure the solution is in the `$EXERCISM_WORKSPACE/python/protein-translation` directory.
|
|
|
|
You can find your Exercism workspace by running `exercism debug` and looking for the line that starts with `Workspace`.
|
|
|
|
For more detailed information about running tests, code style and linting,
|
|
please see [Running the Tests](http://exercism.io/tracks/python/tests).
|
|
|
|
## Source
|
|
|
|
Tyler Long
|
|
|
|
## Submitting Incomplete Solutions
|
|
|
|
It's possible to submit an incomplete solution so you can see how others have completed the exercise.
|