Skip to content

Commit

Permalink
1 new exercise: protein-translation (#125)
Browse files Browse the repository at this point in the history
* adding protein-translation

* fixed config.json for protein-translation

* fixing .cut file + proof

* Update exercises/practice/protein-translation/bin/fetch-cobolcheck.ps1

Co-authored-by: Victor Goff <[email protected]>

* Update exercises/practice/protein-translation/src/protein-translation.cob

Co-authored-by: Victor Goff <[email protected]>

* Sync the `scrabble-score` exercise's docs with the latest data. (#126)

* Sync the `all-your-base` exercise's docs with the latest data. (#127)

* Simplify test workflow (#129)

* Format config.json file (#131)

* file patterns (#132)

* Add file patterns

* Update files keys

* Pre-fetch cobolcheck (#130)

* Pre-fetch cobolcheck

* Use home dir

* Fetch cobolcheck on windows

* Allow for pre-installed cobolcheck

* from appveyor to sourceforge (#128)

* from appveyor to sourceforge

* different server

* 7z

* 7z

* yaml issue fixed

* slashes

* 7z oddities

* directories

* $HOME ?

* atbash tweak

* cache management fix

* commented out extraneous DISPLAY in proof.ci.cob files

* eol issue

* line ends fixed

* strangenesses

* SPACE instead of "" in CUT files

* Trim additional line

* Debug

* Try simplify environment variables

* More debugging

* More tweaking

* Fix path

* Fix path

* Fix path

* Fix env

* Streamline

* eof is lf

* acronym

* acronym

* sqrt

* Fix paths

* Fix cache path

---------

Co-authored-by: Erik Schierboom <[email protected]>

* Try fix Windows caching (#133)

* Try fix caching

* Try fix cache path

* Try include cobolcheck

* Try include cobolcheck

* Use home dir

* Use home dir

* Update proof.ci.cob (#135)

function all intrinsic on its own line

* Cache on linux (#134)

* Try install

* CONCAT -> CONCATENATE

* CONCATENATE is two-fer

---------

Co-authored-by: Bruce Axtens <[email protected]>

---------

Co-authored-by: Bruce Axtens <[email protected]>
Co-authored-by: Victor Goff <[email protected]>
Co-authored-by: Erik Schierboom <[email protected]>
  • Loading branch information
4 people committed Apr 20, 2024
1 parent 40ed166 commit 835af7f
Show file tree
Hide file tree
Showing 12 changed files with 684 additions and 0 deletions.
8 changes: 8 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,14 @@
"prerequisites": [],
"difficulty": 3
},
{
"slug": "protein-translation",
"name": "Protein Translation",
"uuid": "95e2d8d7-31a6-4734-a353-c4688ef8494f",
"practices": [],
"prerequisites": [],
"difficulty": 3
},
{
"slug": "pascals-triangle",
"name": "Pascal's Triangle",
Expand Down
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"
}
96 changes: 96 additions & 0 deletions exercises/practice/protein-translation/.meta/proof.ci.cob
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
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 WS-PROTEIN.
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
GOBACK
WHEN " "
MOVE TEMP TO WS-PROTEIN
MOVE SPACES TO TEMP
GOBACK
WHEN "STOP"
MOVE TEMP TO WS-PROTEIN
MOVE SPACES TO TEMP
GOBACK
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 835af7f

Please sign in to comment.