CS 178 Programming with Multimedia Objects

Divide and Conquer and Incremental Program Development

Prepared by: Aditya Mathur

For use during Lectures on on November 8 and 10 , 2004

During these two lectures you will you learn:

  • How to solve a programming problem using the techniques of divide and conquer and incremental development.

The problem

Our goal is to write a Java applet that allows a user to type in a DNA sequence and get it converted to a protein sequence. The applet must detect and inform the user of any invalid or incomplete DNA sequence. The applet must allow the user to specify the starting point in the DNA sequence from where conversion is to begin. The program must be robust to user errors such as typing an invalid neucleotide character, or an invalid starting point.


Understanding the problem

A DNA consists of a sequence of neucleotides. We consider four types of neucleotides: symbolized by A, C, T, and G. A sample DNA seqeunce is:

ATGGAAGTATTTAAATAG

A protein is a sequence of amino acids. We consider 20 amino acids indicated by letter codes such as A, R, N, etc.

DNA's are responsible for encoding protein sequences. Thus given a DNA sequence and the genetic code, it is possible to determine the protein sequence this DNA is reponsible for.

A codon is a triplet consisting of three neucleotides. For example, TCA, ACC, CCC are codons. For each codon, the genetic code tells us the corresponding amino acid. For example, the amino acids corresponding to codons TCA, ACC, CCC are, respectively, S, T, and P. Three special codons TAG, TGA, and TAA corespond to the code STOP.

Given the genetic code, the DNA neucleotide sequence given above can be translated into the following protein sequence:

M E V F K STOP

In the above example we began the conversion from the first element in the given DNA. However, the starting point can be different than 1. For example, if the starting point is 2, then we start translating to a protein seqeunce from the second letter in the DNA sequence. In this case the DNA sequence given earlier will be translated to:

W K Y L N


Solving the problem

We divide the problem in two two parts:

Part 1: Design and coding of the user interface.

Part 2: Design and coding of DNA to Protein conversion.

Though the problem has been divided into two parts, please note that the solutions to the two parts are related. For example, the conversion will begin only when the user requests for it using the interface. As you know well, the user interface code, usually inside the init() method, gets linked to the other portions of the code via event processing such as that takes place inside the actionPerformed method.

Part 1: Design and coding of the user interface.

You might begin by laying out the GUI on a piece of paper. Then map the GUI elements to Java. Our GUI consists of a frame with BorderLayout. There is a panel on the left of the frame. This panel contains two buttons labeled Convert and Done. The Convert button is pressed afterthe user has typed in the DNA sequence. The Done button is pressed when te user wants to get rid of the frame.

The top portion of the frame contains the welcome message. The right portion has a text field where the user can type the start position from where conversion of DNA to protein sequence must begin. The bottom portion of the frame is a text area where the user types in the DNA sequence. The center portion of the frame displays the codons and the protein sequence. The GUI and the code to generate it follows. Notice that the frame appears on its own somewhere on the sren and not on the applet screen. You could avoid the frame and instead use the BorderLayout directly on the applet.

Notice that we have not gone into the details of the GUI coding. This is because the coding in this example is straightforward and involves adding to the frame the widgets mentioned earlier. We assume that you know how a frame and a panel are created and how widgets are added in the different areas of the frame.

Source for the GUI

Part 2: Design and coding of DNA to Protein conversion.

Prepared by: Aditya Mathur, Nov 10, 2004