Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,19 @@
"unlocked_by": "difference-of-squares",
"uuid": "d0dcc898-ec38-4822-9e3c-1a1829c9b2d9"
},
{
"core": false,
"difficulty": 3,
"slug": "protein-translation",
"topics": [
"arrays",
"conditionals",
"loops",
"strings"
],
"unlocked_by": "rna-transcription",
"uuid": "1bea45f6-021e-0a80-1e53-afcd9f9a8df08c01126"
},
{
"core": false,
"difficulty": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

class ProteinTranslator {

private static final String[] METHIONINE = {"AUG"};
private static final String[] PHENYLALANINE = {"UUU", "UUC"};
private static final String[] LEUCINE = {"UUA", "UUG"};
private static final String[] SERINE = {"UCU", "UCC", "UCA", "UCG"};
private static final String[] TYROSINE = {"UAU", "UAC"};
private static final String[] CYSTEINE = {"UGU", "UGC"};
private static final String[] TRYPTOPHAN = {"UGG"};
private static final String[] STOP = {"UAA", "UAG", "UGA"};

List<String> translate(String rnaSequence) {

List<String> proteinList = new ArrayList<String>();

for (int i = 0; i < rnaSequence.length(); i += 3) {
String codon = rnaSequence.substring(i, i+3);

if (Arrays.asList(METHIONINE).contains(codon)) {
proteinList.add("Methionine");
} else if (Arrays.asList(PHENYLALANINE).contains(codon)) {
proteinList.add("Phenylalanine");
} else if (Arrays.asList(LEUCINE).contains(codon)) {
proteinList.add("Leucine");
} else if (Arrays.asList(SERINE).contains(codon)) {
proteinList.add("Serine");
} else if (Arrays.asList(TYROSINE).contains(codon)) {
proteinList.add("Tyrosine");
} else if (Arrays.asList(CYSTEINE).contains(codon)) {
proteinList.add("Cysteine");
} else if (Arrays.asList(TRYPTOPHAN).contains(codon)) {
proteinList.add("Tryptophan");
} else if (Arrays.asList(STOP).contains(codon)) {
break;
} else {
throw new IllegalArgumentException("Invalid input");
}

}

return proteinList;
}
}
58 changes: 58 additions & 0 deletions exercises/protein-translation/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#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", "UAG", "AUG"` =>

Protein: `"Methionine", "Phenylalanine", "Serine"`

Note the stop codon 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))

# Running the tests

You can run all the tests for an exercise by entering

```sh
$ gradle test
```

in your terminal.

## Source

Tyler Long

## Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.
18 changes: 18 additions & 0 deletions exercises/protein-translation/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
apply plugin: "java"
apply plugin: "eclipse"
apply plugin: "idea"

repositories {
mavenCentral()
}

dependencies {
testCompile "junit:junit:4.12"
}

test {
testLogging {
exceptionFormat = 'full'
events = ["passed", "failed", "skipped"]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import java.util.List;

class ProteinTranslator {

List<String> translate(String rnaSequence) {
throw new UnsupportedOperationException("Delete this statement and write your own implementation.");
}
}
179 changes: 179 additions & 0 deletions exercises/protein-translation/src/test/java/ProteinTranslatorTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.assertEquals;

public class ProteinTranslatorTest {

private ProteinTranslator proteinTranslator;

@Before
public void setUp() {
proteinTranslator = new ProteinTranslator();
}

@Test
public void testMethionineRnaSequence() {
List<String> expected = Arrays.asList("Methionine");
assertEquals(expected, proteinTranslator.translate("AUG"));
}

@Ignore("Remove to run test")
@Test
public void testPhenylalanineRnaSequence1() {
List<String> expected = Arrays.asList("Phenylalanine");
assertEquals(expected, proteinTranslator.translate("UUU"));
}

@Ignore("Remove to run test")
@Test
public void testPhenylalanineRnaSequence2() {
List<String> expected = Arrays.asList("Phenylalanine");
assertEquals(expected, proteinTranslator.translate("UUC"));
}

@Ignore("Remove to run test")
@Test
public void testLeucineRnaSequence1() {
List<String> expected = Arrays.asList("Leucine");
assertEquals(expected, proteinTranslator.translate("UUA"));
}

@Ignore("Remove to run test")
@Test
public void testLeucineRnaSequence2() {
List<String> expected = Arrays.asList("Leucine");
assertEquals(expected, proteinTranslator.translate("UUG"));
}

@Ignore("Remove to run test")
@Test
public void testSerineRnaSequence1() {
List<String> expected = Arrays.asList("Serine");
assertEquals(expected, proteinTranslator.translate("UCU"));
}

@Ignore("Remove to run test")
@Test
public void testSerineRnaSequence2() {
List<String> expected = Arrays.asList("Serine");
assertEquals(expected, proteinTranslator.translate("UCC"));
}

@Ignore("Remove to run test")
@Test
public void testSerineRnaSequence3() {
List<String> expected = Arrays.asList("Serine");
assertEquals(expected, proteinTranslator.translate("UCA"));
}

@Ignore("Remove to run test")
@Test
public void testSerineRnaSequence4() {
List<String> expected = Arrays.asList("Serine");
assertEquals(expected, proteinTranslator.translate("UCG"));
}

@Ignore("Remove to run test")
@Test
public void testTyrosineRnaSequence1() {
List<String> expected = Arrays.asList("Tyrosine");
assertEquals(expected, proteinTranslator.translate("UAU"));
}

@Ignore("Remove to run test")
@Test
public void testTyrosineRnaSequence2() {
List<String> expected = Arrays.asList("Tyrosine");
assertEquals(expected, proteinTranslator.translate("UAC"));
}

@Ignore("Remove to run test")
@Test
public void testCysteineRnaSequence1() {
List<String> expected = Arrays.asList("Cysteine");
assertEquals(expected, proteinTranslator.translate("UGU"));
}

@Ignore("Remove to run test")
@Test
public void testCysteineRnaSequence2() {
List<String> expected = Arrays.asList("Cysteine");
assertEquals(expected, proteinTranslator.translate("UGC"));
}

@Ignore("Remove to run test")
@Test
public void testTryptophanRnaSequence1() {
List<String> expected = Arrays.asList("Tryptophan");
assertEquals(expected, proteinTranslator.translate("UGG"));
}

@Ignore("Remove to run test")
@Test
public void testStopRnaSequence1() {
List<String> expected = Arrays.asList();
assertEquals(expected, proteinTranslator.translate("UAA"));
}

@Ignore("Remove to run test")
@Test
public void testStopRnaSequence2() {
List<String> expected = Arrays.asList();
assertEquals(expected, proteinTranslator.translate("UAG"));
}

@Ignore("Remove to run test")
@Test
public void testStopRnaSequence3() {
List<String> expected = Arrays.asList();
assertEquals(expected, proteinTranslator.translate("UGA"));
}

@Ignore("Remove to run test")
@Test
public void testTranslationOfRnaToProteinList() {
List<String> expected = Arrays.asList("Methionine","Phenylalanine","Tryptophan");
assertEquals(expected, proteinTranslator.translate("AUGUUUUGG"));
}

@Ignore("Remove to run test")
@Test
public void testTranslationStopsIfStopCodonAtBeginning() {
List<String> expected = Arrays.asList();
assertEquals(expected, proteinTranslator.translate("UAGUGG"));
}

@Ignore("Remove to run test")
@Test
public void testTranslationStopsIfStopCodonAtEnd1() {
List<String> expected = Arrays.asList("Tryptophan");
assertEquals(expected, proteinTranslator.translate("UGGUAG"));
}

@Ignore("Remove to run test")
@Test
public void testTranslationStopsIfStopCodonAtEnd2() {
List<String> expected = Arrays.asList("Methionine", "Phenylalanine");
assertEquals(expected, proteinTranslator.translate("AUGUUUUAA"));
}

@Ignore("Remove to run test")
@Test
public void testTranslationStopsIfStopCodonInMiddle1() {
List<String> expected = Arrays.asList("Tryptophan");
assertEquals(expected, proteinTranslator.translate("UGGUAGUGG"));
}

@Ignore("Remove to run test")
@Test
public void testTranslationStopsIfStopCodonInMiddle2() {
List<String> expected = Arrays.asList("Tryptophan","Cysteine","Tyrosine");
assertEquals(expected, proteinTranslator.translate("UGGUGUUAUUAAUGGUUU"));
}

}
1 change: 1 addition & 0 deletions exercises/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ include 'phone-number'
include 'pig-latin'
include 'poker'
include 'prime-factors'
include 'protein-translation'
include 'pythagorean-triplet'
include 'queen-attack'
include 'raindrops'
Expand Down