On this page:
Instructions
1 Problem 1:   Translating RNA
Optional ungraded extension
8.13

Assignment 3: Translating RNA🔗

Goals: Learn to use the String class; practice working with lists; practice accumulators.

Instructions🔗

This is a standalone variant of Assignment 3.

Be very, very careful with naming. The solution files expect your submissions to use the class, interface, field, method, constructor, argument, and file names specified here.

The submission will be organized as follows:

1 Problem 1: Translating RNA🔗

For all questions in this problem, be sure to follow the design recipe carefully:

Note: you may want to use the String class’s .length() method, which returns the number of characters in the string.

In this problem, you are going to simulate part of the process of transforming DNA into proteins. We will represent a DNA template strand as an ILoString of length-1 strings representing the DNA bases "A", "T", "C" or "G". An RNA sequence is similar, except it uses the base "U" instead of "T".

Use exactly the following list representation, including the class, interface, field, and constructor names and types shown here. You may add methods as the problem requires, but do not rename these parts of the data definition.

// a list of strings interface ILoString {
}
 
// an empty list of strings class MtLoString implements ILoString {
MtLoString() { }
}
 
// a nonempty list of strings class ConsLoString implements ILoString {
String first;
ILoString rest;
 
ConsLoString(String first, ILoString rest) {
this.first = first;
this.rest = rest;
}
}
 
// a list of lists of strings interface ILoLoString {
}
 
// an empty list of lists of strings class MtLoLoString implements ILoLoString {
MtLoLoString() { }
}
 
// a nonempty list of lists of strings class ConsLoLoString implements ILoLoString {
ILoString first;
ILoLoString rest;
 
ConsLoLoString(ILoString first, ILoLoString rest) {
this.first = first;
this.rest = rest;
}
}

As a warmup problem (not graded; not required), design a method transcribe that produces the complementary RNA sequence from this DNA template strand by transforming each base:

DNA template base

RNA base

A

U

T

A

C

G

G

C

In this paragraph, RNA sequences are written as multi-letter strings for brevity, but in your representation, they will be lists of length-1 strings.

RNA is translated into proteins in three-letter chunks called codons. The codons of a protein do not overlap: in the RNA string "ACAUUG", starting from the beginning of the string, there are two distinct codons "ACA" and "UUG". Translation stops when it hits a stop codon (which is either "UAG", "UAA" or "UGA") or when there are simply no more codons left. At that point, the protein is finished, and the stop codon is not part of the finished protein. If bases remain after the stop codon, begin a new protein and a fresh three-base codon frame at the very next base. Do not skip bases while looking for a place to restart. Thus, one strand of RNA can produce many proteins. Represent a protein as an ILoString, where each string is a 3-letter codon.

The following edge cases are part of the required behavior:

For example, the RNA sequence "ACAGAUAG" translates into a single protein ("ACA", "GAU"): even though the last three bases are a stop codon, that is just a coincidence. The way the breakpoints fall between codons means that they get split up, and the last two bases just get ignored.

For another example, "ACAUAGUUG" translates into two proteins, each one codon long: "ACA" and "UUG".

Design a method translate that transforms an RNA sequence (an ILoString) into a list of proteins (i.e. an ILoLoString). This will be the only method we directly call to test your code; however, you will certainly need to design some helper methods. Our tests will not care what order you produce the proteins in, but they will care that each protein’s codons are in the correct order.

For the required translate method, translation begins at the very first base of the RNA sequence. Do not search for "AUG" before beginning. For this method, "AUG" is an ordinary non-stop codon.

Hint: you will certainly need to use at least one accumulator parameter in at least one helper method. There are several valid designs for this problem; work through a wish-list process to figure out what helpers you might want.

Hint: you probably do not need to define any methods on ILoLoString for this problem.

Hint: Be sure to test RNA sequences that produce proteins longer than just one codon: this will motivate needing at least one more helper method.

Optional ungraded extension🔗

This extension is optional practice and carries no course points.

The story above is certainly not a complete description of RNA translation. To be slightly more accurate: RNA only starts translating into proteins when it encounters the start codon "AUG".

Leave the required translate method unchanged. Instead, design a second method with this signature:

ILoLoString translateFromStartCodons();

This method skips bases until it encounters "AUG", includes that "AUG" as the first codon of a protein, and translates until a stop codon. After a stop codon, it resumes searching for the next "AUG"; any bases in the gap are ignored.

The required grader calls only translate; it will not call translateFromStartCodons. If you try this extension, test the additional method yourself and submit the assignment only once.