primeiro commit com exercicios de Exercism realizados até esta data
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"authors": [
|
||||
"cptjackson"
|
||||
],
|
||||
"contributors": [
|
||||
"behrtam",
|
||||
"cmccandless",
|
||||
"Dog",
|
||||
"ikhadykin",
|
||||
"N-Parsons",
|
||||
"nmbrgts",
|
||||
"sjwarner-bp",
|
||||
"thomasjpfan",
|
||||
"tqa236",
|
||||
"yawpitch"
|
||||
],
|
||||
"files": {
|
||||
"solution": [
|
||||
"protein_translation.py"
|
||||
],
|
||||
"test": [
|
||||
"protein_translation_test.py"
|
||||
],
|
||||
"example": [
|
||||
".meta/example.py"
|
||||
]
|
||||
},
|
||||
"blurb": "Translate RNA sequences into proteins.",
|
||||
"source": "Tyler Long"
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"track":"python","exercise":"protein-translation","id":"8026e7b82d9e4f3cb2dea9fa4b08f665","url":"https://exercism.org/tracks/python/exercises/protein-translation","handle":"sanctushck","is_requester":true,"auto_approve":false}
|
||||
@@ -0,0 +1,130 @@
|
||||
# Help
|
||||
|
||||
## Correr os testes
|
||||
|
||||
Usamos o [pytest][pytest: Getting Started Guide] como executor de testes do nosso site.
|
||||
Vais precisar de instalar o `pytest` na tua máquina de desenvolvimento se quiseres correr os testes do percurso Python localmente.
|
||||
Também vais precisar de instalar os seguintes plugins do `pytest`:
|
||||
|
||||
- [pytest-cache][pytest-cache]
|
||||
- [pytest-subtests][pytest-subtests]
|
||||
|
||||
Encontras informação mais detalhada no [guia de testes de Python][Python track tests page] do nosso site.
|
||||
|
||||
|
||||
### Correr os testes
|
||||
|
||||
Para correres os testes incluídos, navega até à pasta onde o exercício está guardado usando o `cd` no teu terminal (_substitui `<exercise-folder-location>` abaixo pelo teu caminho_).
|
||||
Os ficheiros de teste terminam habitualmente em `_test.py` e são os mesmos testes que correm no site quando uma solução é submetida.
|
||||
|
||||
Linux/MacOS
|
||||
```bash
|
||||
$ cd <path/to/exercise-folder-location>
|
||||
```
|
||||
|
||||
Windows
|
||||
```powershell
|
||||
PS C:\Users\foobar> cd <path\to\exercise-folder-location>
|
||||
```
|
||||
|
||||
<br>
|
||||
|
||||
De seguida, corre o comando `pytest` no teu terminal, substituindo `<exercise_test.py>` pelo nome do ficheiro de teste:
|
||||
|
||||
Linux/MacOS
|
||||
```bash
|
||||
$ python3 -m pytest -o markers=task <exercise_test.py>
|
||||
==================== 7 passed in 0.08s ====================
|
||||
```
|
||||
|
||||
Windows
|
||||
```powershell
|
||||
PS C:\Users\foobar> py -m pytest -o markers=task <exercise_test.py>
|
||||
==================== 7 passed in 0.08s ====================
|
||||
```
|
||||
|
||||
|
||||
### Opções comuns
|
||||
- `-o` : substitui o `pytest.ini` predefinido (_podes usar esta opção para evitar avisos de marcadores_)
|
||||
- `-v` : ativa a saída detalhada.
|
||||
- `-x` : para de correr os testes na primeira falha.
|
||||
- `--ff` : corre as falhas do teste anterior antes de correr os outros casos de teste.
|
||||
|
||||
Para opções adicionais, usa `python3 -m pytest -h` ou `py -m pytest -h`.
|
||||
|
||||
|
||||
### Corrigir avisos
|
||||
|
||||
Se não usares `pytest -o markers=task` ao invocar o `pytest`, podes receber um `PytestUnknownMarkWarning` nos testes que usam a nossa nova sintaxe:
|
||||
|
||||
```bash
|
||||
PytestUnknownMarkWarning: Unknown pytest.mark.task - is this a typo? You can register custom marks to avoid this warning - for details, see https://docs.pytest.org/en/stable/mark.html
|
||||
```
|
||||
|
||||
Para evitares escrever `pytest -o markers=task` em todos os testes que corres, podes usar um ficheiro de configuração `pytest.ini`.
|
||||
Criámos um que podes descarregar a partir do nível de topo do diretório do percurso Python: [pytest.ini][pytest.ini].
|
||||
|
||||
Também podes criar o teu próprio ficheiro `pytest.ini` com o seguinte conteúdo:
|
||||
|
||||
```ini
|
||||
[pytest]
|
||||
markers =
|
||||
task: A concept exercise task.
|
||||
```
|
||||
|
||||
Colocar o ficheiro `pytest.ini` no diretório _root_ ou _working_ dos teus exercícios do percurso Python regista os marcadores e faz parar os avisos.
|
||||
Encontras mais informação sobre os marcadores do pytest na documentação do `pytest` sobre [marcar funções de teste][pytest: marking test functions with attributes] e na documentação do `pytest` sobre [trabalhar com marcadores personalizados][pytest: working with custom markers].
|
||||
|
||||
Encontras informação sobre como personalizar as configurações do pytest na documentação do `pytest` sobre [formatos de ficheiros de configuração][pytest: configuration file formats].
|
||||
|
||||
|
||||
### Estender o teu IDE ou editor de código
|
||||
|
||||
Muitos IDEs e editores de código têm suporte integrado para usar o `pytest` e outras ferramentas de qualidade de código.
|
||||
Podes encontrar algumas opções da comunidade na nossa [página de ferramentas do percurso Python][Python track tools page].
|
||||
|
||||
[Pytest: Getting Started Guide]: https://docs.pytest.org/en/latest/getting-started.html
|
||||
[Python track tools page]: https://exercism.org/docs/tracks/python/tools
|
||||
[Python track tests page]: https://exercism.org/docs/tracks/python/tests
|
||||
[pytest-cache]:http://pythonhosted.org/pytest-cache/
|
||||
[pytest-subtests]:https://github.com/pytest-dev/pytest-subtests
|
||||
[pytest.ini]: https://github.com/exercism/python/blob/main/pytest.ini
|
||||
[pytest: configuration file formats]: https://docs.pytest.org/en/6.2.x/customize.html#configuration-file-formats
|
||||
[pytest: marking test functions with attributes]: https://docs.pytest.org/en/6.2.x/mark.html#raising-errors-on-unknown-marks
|
||||
[pytest: working with custom markers]: https://docs.pytest.org/en/6.2.x/example/markers.html#working-with-custom-markers
|
||||
|
||||
## Submeter a tua solução
|
||||
|
||||
Podes submeter a tua solução com o comando `exercism submit protein_translation.py`.
|
||||
Este comando envia a tua solução para o site do Exercism e imprime o URL da página da solução.
|
||||
|
||||
É possível submeter uma solução incompleta, o que te permite:
|
||||
|
||||
- Ver como outras pessoas resolveram o exercício
|
||||
- Pedir ajuda a um mentor
|
||||
|
||||
## Precisas de ajuda?
|
||||
|
||||
Se quiseres ajuda para resolver o exercício, consulta as seguintes páginas:
|
||||
|
||||
- A [documentação do percurso Python](https://exercism.org/docs/tracks/python)
|
||||
- A [categoria de programação do percurso Python no fórum](https://forum.exercism.org/c/programming/python)
|
||||
- A [categoria de programação do Exercism no fórum](https://forum.exercism.org/c/programming/5)
|
||||
- As [Perguntas Frequentes](https://exercism.org/docs/using/faqs)
|
||||
|
||||
Se esses recursos não forem suficientes, podes submeter a tua solução (incompleta) para pedir mentoria.
|
||||
|
||||
Abaixo encontras alguns recursos para obter ajuda, caso tenhas problemas:
|
||||
|
||||
- [A PSF](https://www.python.org) aloja as transferências do Python, a documentação e recursos da comunidade.
|
||||
- Os [Fóruns da Comunidade Python](https://discuss.python.org/) servem para obter ajuda, discutir PEPs, falar com os principais contribuidores do Python e muito mais.
|
||||
- [A Comunidade do Exercism no Discord](https://exercism.org/r/discord)
|
||||
- [Os Fóruns de Discussão da Comunidade do Exercism](https://forum.exercsim.org)
|
||||
- A [Comunidade Python no Discord](https://pythondiscord.com/) é uma comunidade muito prestável e ativa.
|
||||
- O [/r/learnpython/](https://www.reddit.com/r/learnpython/) é um subreddit pensado para quem está a aprender Python.
|
||||
- O [#python no Libera.chat](https://www.python.org/community/irc/) é o sítio onde os programadores responsáveis pela linguagem se juntam e põem o trabalho em dia.
|
||||
- Os [Fóruns da Comunidade Free Code Camp](https://forum.freecodecamp.org/)
|
||||
- O [Pythontutor](http://pythontutor.com/) para percorrer pequenos excertos de código visualmente.
|
||||
|
||||
Além disso, o [StackOverflow](http://stackoverflow.com/questions/tagged/python) é um bom sítio para procurar o teu problema ou a tua dúvida e ver se já foi respondida.
|
||||
Se não foi, podes sempre [perguntar](https://stackoverflow.com/help/how-to-ask) ou [responder](https://stackoverflow.com/help/how-to-answer) à pergunta de outra pessoa.
|
||||
@@ -0,0 +1,66 @@
|
||||
# Tradução de proteínas
|
||||
|
||||
Bem-vindo ao Tradução de proteínas no percurso Python do Exercism.
|
||||
Se precisares de ajuda para correr os testes ou para submeter o teu código, consulta o `HELP.md`.
|
||||
|
||||
## Instructions
|
||||
|
||||
A tua tarefa é traduzir sequências de ARN em proteínas.
|
||||
|
||||
As cadeias de ARN são constituídas por sequências de três nucleótidos chamadas **codões**.
|
||||
Cada codão traduz-se num **aminoácido**.
|
||||
Quando se unem, esses aminoácidos formam uma proteína.
|
||||
|
||||
No mundo real existem 64 codões, que por sua vez correspondem a 20 aminoácidos.
|
||||
No entanto, neste exercício só vais usar alguns dos 64 possíveis.
|
||||
Estão listados a seguir:
|
||||
|
||||
| Codão | Aminoácido |
|
||||
| ------------------ | ------------- |
|
||||
| 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 |
|
||||
|
||||
Por exemplo, a string de ARN “AUGUUUUCU” tem três codões: “AUG”, “UUU” e “UCU”.
|
||||
Estes correspondem a Methionine, Phenylalanine e Serine.
|
||||
|
||||
## Codões “STOP”
|
||||
|
||||
Repara que, na tabela acima, há três **codões “STOP”**.
|
||||
Se encontrares algum destes codões, ignora o resto da sequência: a proteína está completa.
|
||||
|
||||
Por exemplo, “AUGUUUUCUUAAAUG” contém um codão STOP (“UAA”).
|
||||
Assim que chegamos a esse ponto, deixamos de processar.
|
||||
Por isso, só consideramos a parte anterior a ele (ou seja, “AUGUUUUCU”), e não os codões que vêm depois (ou seja, “AUG”).
|
||||
|
||||
Sabe mais sobre [tradução de proteínas na Wikipédia][protein-translation].
|
||||
|
||||
[protein-translation]: https://en.wikipedia.org/wiki/Translation_(biology)
|
||||
|
||||
## Source
|
||||
|
||||
### Created by
|
||||
|
||||
- @cptjackson
|
||||
|
||||
### Contributed to by
|
||||
|
||||
- @behrtam
|
||||
- @cmccandless
|
||||
- @Dog
|
||||
- @ikhadykin
|
||||
- @N-Parsons
|
||||
- @nmbrgts
|
||||
- @sjwarner-bp
|
||||
- @thomasjpfan
|
||||
- @tqa236
|
||||
- @yawpitch
|
||||
|
||||
### Based on
|
||||
|
||||
Tyler Long
|
||||
Binary file not shown.
BIN
Binary file not shown.
@@ -0,0 +1,31 @@
|
||||
codon_to_protein: dict[str, str] = {
|
||||
"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",
|
||||
}
|
||||
|
||||
stop_codons: list[str] = ["UAA", "UAG", "UGA"]
|
||||
|
||||
|
||||
def proteins(strand):
|
||||
protein: list[str] = []
|
||||
codon: str = ""
|
||||
for nucleotide in strand:
|
||||
codon += nucleotide
|
||||
if len(codon) == 3:
|
||||
if codon in stop_codons:
|
||||
break
|
||||
protein.append(codon_to_protein[codon])
|
||||
codon = ""
|
||||
return protein
|
||||
@@ -0,0 +1,141 @@
|
||||
# These tests are auto-generated with test data from:
|
||||
# https://github.com/exercism/problem-specifications/tree/main/exercises/protein-translation/canonical-data.json
|
||||
# File last updated on 2024-07-08
|
||||
|
||||
import unittest
|
||||
|
||||
from protein_translation import (
|
||||
proteins,
|
||||
)
|
||||
|
||||
|
||||
class ProteinTranslationTest(unittest.TestCase):
|
||||
def test_methionine_rna_sequence(self):
|
||||
value = "AUG"
|
||||
expected = ["Methionine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_phenylalanine_rna_sequence_1(self):
|
||||
value = "UUU"
|
||||
expected = ["Phenylalanine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_phenylalanine_rna_sequence_2(self):
|
||||
value = "UUC"
|
||||
expected = ["Phenylalanine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_leucine_rna_sequence_1(self):
|
||||
value = "UUA"
|
||||
expected = ["Leucine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_leucine_rna_sequence_2(self):
|
||||
value = "UUG"
|
||||
expected = ["Leucine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_serine_rna_sequence_1(self):
|
||||
value = "UCU"
|
||||
expected = ["Serine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_serine_rna_sequence_2(self):
|
||||
value = "UCC"
|
||||
expected = ["Serine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_serine_rna_sequence_3(self):
|
||||
value = "UCA"
|
||||
expected = ["Serine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_serine_rna_sequence_4(self):
|
||||
value = "UCG"
|
||||
expected = ["Serine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_tyrosine_rna_sequence_1(self):
|
||||
value = "UAU"
|
||||
expected = ["Tyrosine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_tyrosine_rna_sequence_2(self):
|
||||
value = "UAC"
|
||||
expected = ["Tyrosine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_cysteine_rna_sequence_1(self):
|
||||
value = "UGU"
|
||||
expected = ["Cysteine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_cysteine_rna_sequence_2(self):
|
||||
value = "UGC"
|
||||
expected = ["Cysteine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_tryptophan_rna_sequence(self):
|
||||
value = "UGG"
|
||||
expected = ["Tryptophan"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_stop_codon_rna_sequence_1(self):
|
||||
value = "UAA"
|
||||
expected = []
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_stop_codon_rna_sequence_2(self):
|
||||
value = "UAG"
|
||||
expected = []
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_stop_codon_rna_sequence_3(self):
|
||||
value = "UGA"
|
||||
expected = []
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_sequence_of_two_protein_codons_translates_into_proteins(self):
|
||||
value = "UUUUUU"
|
||||
expected = ["Phenylalanine", "Phenylalanine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_sequence_of_two_different_protein_codons_translates_into_proteins(self):
|
||||
value = "UUAUUG"
|
||||
expected = ["Leucine", "Leucine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_translate_rna_strand_into_correct_protein_list(self):
|
||||
value = "AUGUUUUGG"
|
||||
expected = ["Methionine", "Phenylalanine", "Tryptophan"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_translation_stops_if_stop_codon_at_beginning_of_sequence(self):
|
||||
value = "UAGUGG"
|
||||
expected = []
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_translation_stops_if_stop_codon_at_end_of_two_codon_sequence(self):
|
||||
value = "UGGUAG"
|
||||
expected = ["Tryptophan"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_translation_stops_if_stop_codon_at_end_of_three_codon_sequence(self):
|
||||
value = "AUGUUUUAA"
|
||||
expected = ["Methionine", "Phenylalanine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_translation_stops_if_stop_codon_in_middle_of_three_codon_sequence(self):
|
||||
value = "UGGUAGUGG"
|
||||
expected = ["Tryptophan"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_translation_stops_if_stop_codon_in_middle_of_six_codon_sequence(self):
|
||||
value = "UGGUGUUAUUAAUGGUUU"
|
||||
expected = ["Tryptophan", "Cysteine", "Tyrosine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
|
||||
def test_sequence_of_two_non_stop_codons_does_not_translate_to_a_stop_codon(self):
|
||||
value = "AUGAUG"
|
||||
expected = ["Methionine", "Methionine"]
|
||||
self.assertEqual(proteins(value), expected)
|
||||
Reference in New Issue
Block a user