Skip to content

Commit

Permalink
adding protein-translation
Browse files Browse the repository at this point in the history
  • Loading branch information
kapitaali committed Apr 16, 2024
1 parent 581c08e commit e2ecc24
Show file tree
Hide file tree
Showing 11 changed files with 678 additions and 0 deletions.
42 changes: 42 additions & 0 deletions exercises/practice/protein-translation/.docs/instructions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# 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))
42 changes: 42 additions & 0 deletions exercises/practice/protein-translation/.docs/introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Introduction

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))
22 changes: 22 additions & 0 deletions exercises/practice/protein-translation/.meta/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"authors": [
"kapitaali"
],
"files": {
"solution": [
"src/protein-translation.cob"
],
"test": [
"tst/protein-translation/protein-translation.cut"
],
"example": [
".meta/proof.ci.cob"
],
"invalidator": [
"test.sh",
"test.ps1"
]
},
"blurb": "Translate RNA sequences into proteins.",
"source": "Tyler Long"
}
95 changes: 95 additions & 0 deletions exercises/practice/protein-translation/.meta/proof.ci.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
IDENTIFICATION DIVISION.
PROGRAM-ID. PROTEIN-TRANSLATION.
AUTHOR. kapitaali.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-INPUT PIC X(60).
01 WS-PROTEIN PIC X(120) VALUE SPACES.
01 TEMP PIC X(120) VALUE SPACES.
01 WS-ERROR PIC X(60).
01 PROT PIC X(3) VALUE SPACES.
01 CHECKED PIC X(14) VALUE SPACES.
01 INDX PIC 99 VALUE 1.
01 LEN PIC 99.
01 A PIC 99.

PROCEDURE DIVISION.

TRANSLATE-CODON.
MOVE SPACES TO WS-PROTEIN.
MOVE WS-INPUT TO PROT.
PERFORM CHECK-CODON.
EVALUATE CHECKED
WHEN "ERROR" MOVE "Invalid codon" TO WS-ERROR
WHEN "STOP" MOVE " " TO WS-PROTEIN
WHEN OTHER MOVE CHECKED TO WS-PROTEIN
END-EVALUATE.


CHECK-CODON.
MOVE SPACES TO CHECKED.
EVALUATE PROT
WHEN " " MOVE " " TO CHECKED
WHEN "AUG" MOVE "Methionine" TO CHECKED
WHEN "UUU" MOVE "Phenylalanine" TO CHECKED
WHEN "UUC" MOVE "Phenylalanine" TO CHECKED
WHEN "UUA" MOVE "Leucine" TO CHECKED
WHEN "UUG" MOVE "Leucine" TO CHECKED
WHEN "UCU" MOVE "Serine" TO CHECKED
WHEN "UCC" MOVE "Serine" TO CHECKED
WHEN "UCA" MOVE "Serine" TO CHECKED
WHEN "UCG" MOVE "Serine" TO CHECKED
WHEN "UAU" MOVE "Tyrosine" TO CHECKED
WHEN "UAC" MOVE "Tyrosine" TO CHECKED
WHEN "UGU" MOVE "Cysteine" TO CHECKED
WHEN "UGC" MOVE "Cysteine" TO CHECKED
WHEN "UGG" MOVE "Tryptophan" TO CHECKED
WHEN "UAA" MOVE "STOP" TO CHECKED
WHEN "UAG" MOVE "STOP" TO CHECKED
WHEN "UGA" MOVE "STOP" TO CHECKED
WHEN OTHER MOVE "ERROR" TO CHECKED
END-EVALUATE.


STR-LENGTH.
MOVE 0 TO LEN.
PERFORM VARYING A FROM FUNCTION LENGTH(CHECKED)
BY -1 UNTIL CHECKED(A:1) <> " "
ADD 1 TO LEN
END-PERFORM.
COMPUTE LEN = FUNCTION LENGTH(CHECKED) - LEN.


TRANSLATE-RNA.
PERFORM UNTIL WS-INPUT = " "
MOVE WS-INPUT(1:3) TO PROT
PERFORM CHECK-CODON
PERFORM STR-LENGTH
EVALUATE CHECKED
WHEN "ERROR"
MOVE "Invalid codon" TO WS-ERROR
MOVE SPACES TO TEMP
MOVE SPACES TO WS-PROTEIN
EXIT PARAGRAPH
WHEN " "
MOVE TEMP TO WS-PROTEIN
MOVE SPACES TO TEMP
EXIT PARAGRAPH
WHEN "STOP"
MOVE TEMP TO WS-PROTEIN
MOVE SPACES TO TEMP
EXIT PARAGRAPH
WHEN OTHER
IF INDX > 1
MOVE "," TO TEMP(INDX:1)
ADD 1 TO INDX
END-IF
MOVE CHECKED TO TEMP(INDX:LEN)
ADD LEN TO INDX
END-EVALUATE
MOVE WS-INPUT(4:56) TO WS-INPUT(1:56)
END-PERFORM.
MOVE TEMP TO WS-PROTEIN.
MOVE SPACES TO TEMP.
MOVE 1 TO INDX.
63 changes: 63 additions & 0 deletions exercises/practice/protein-translation/bin/fetch-cobolcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash

# This file is a copy of the
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet file.
# Please submit bugfixes/improvements to the above file to ensure that all tracks benefit from the changes.

# set -eo pipefail

readonly LATEST='https://api.github.com/repos/0xE282B0/cobol-check/releases/latest'

case "$(uname)" in
Darwin*) os='mac' ;;
Linux*) os='linux' ;;
Windows*) os='windows' ;;
MINGW*) os='windows' ;;
MSYS_NT-*) os='windows' ;;
*) os='linux' ;;
esac

case "${os}" in
windows*) ext='.exe' ;;
*) ext='' ;;
esac

arch="$(uname -m)"

curlopts=(
--silent
--show-error
--fail
--location
--retry 3
)

if [[ -n "${GITHUB_TOKEN}" ]]; then
curlopts+=(--header "authorization: Bearer ${GITHUB_TOKEN}")
fi

suffix="${os}-${arch}${ext}"

get_download_url() {
curl "${curlopts[@]}" --header 'Accept: application/vnd.github.v3+json' "${LATEST}" |
grep "\"browser_download_url\": \".*/download/.*/cobol-check.*${suffix}\"$" |
cut -d'"' -f4
}

main() {
if [[ -d ./bin ]]; then
output_dir="./bin"
elif [[ $PWD == */bin ]]; then
output_dir="$PWD"
else
echo "Error: no ./bin directory found. This script should be ran from a repo root." >&2
return 1
fi

output_path="${output_dir}/cobolcheck${ext}"
download_url="$(get_download_url)"
curl "${curlopts[@]}" --output "${output_path}" "${download_url}"
chmod +x "${output_path}"
}

main
28 changes: 28 additions & 0 deletions exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# This file is a copy of the
# https://github.com/exercism/configlet/blob/main/scripts/fetch-configlet.ps1 file.
# Please submit bugfixes/improvements to the above file to ensure that all tracks
# benefit from the changes.

$ErrorActionPreference = "Stop"
$ProgressPreference = "SilentlyContinue"

$requestOpts = @{
Headers = If ($env:GITHUB_TOKEN) { @{ Authorization = "Bearer ${env:GITHUB_TOKEN}" } } Else { @{ } }
MaximumRetryCount = 3
RetryIntervalSec = 1
}

$arch = If ([Environment]::Is64BitOperatingSystem) { "amd64" } Else { "x86" }
$fileName = "cobol-check-windows-$arch.exe"

Function Get-DownloadUrl {
$latestUrl = "https://api.github.com/repos/0xE282B0/cobol-check/releases/latest"
Invoke-RestMethod -Uri $latestUrl -PreserveAuthorizationOnRedirect @requestOpts
| Select-Object -ExpandProperty assets
| Where-Object { $_.browser_download_url -match $FileName }
| Select-Object -ExpandProperty browser_download_url
}

$downloadUrl = Get-DownloadUrl
$outputFile = Join-Path -Path $PSScriptRoot -ChildPath "cobolcheck.exe"
Invoke-WebRequest -Uri $downloadUrl -OutFile $outputFile @requestOpts
Loading

0 comments on commit e2ecc24

Please sign in to comment.