CPS 006G, Fall 2004, Test Practice

This question is based on the code in the class ProteinConvert.java which is similar to code studied in class. You'll want to call methods in ProteinConvert.java in writing the code that answers this problem.

A protein can be coded by several different codons. For example, the protein Leucine is coded by "TTA", "TTG", "CTT", "CTC", "CTA", and "CTG" whereas Tryptophan is only coded by "TGG".

Write the method proteinIndex which returns the index in parameter dna at which the first occurrence of a codon coding the protein whose one-letter code is specified occurs. If there is no occurrence of the protein return -1. (We're ignoring ORFs in this problem.)

For example

method call result returned reason
proteinIndex("CCCCAATTTCCAGT","Q") 3 "CAA" occurs at index 3, "Q" encodes Glutamine
proteinIndex("CCCTAATTTCCAGT","Q") 10 "CAG" occurs at index 10, "Q" encodes Glutamine
proteinIndex("GGTGGCGGAGGG","G") 0 "GGT" occurs at index 0, "G" encodes Glycine
proteinIndex("CTTAGTAAGTTAGC", "R") -1 Arginine, "R", coded by AGA and AGG, doesn't occur

Write the method proteinIndex. You should not test with BlueJ/Eclipse, test by reasoning about the code you write.

/** * @param dna is a sequence of upper-case 'A', 'G', 'T', 'C' * @param protein is a single-character string with valid protein code * @return index of first occurrence of a codon for protein or -1 if none */ public int proteinIndex(String dna, String protein) { // write code here }

You can submit using Eclipse and the assignment name testpractice. Please include a README in your submission.


Owen L. Astrachan
Last modified: Sun Sep 26 14:42:08 EDT 2004