Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Python | Schedule | Submit

Saint Louis University

Computer Science 150
Introduction to Object-Oriented Programming

Michael Goldwasser

Spring 2013

Dept. of Math & Computer Science

Programming Assignment 02

DNA Reversal

Due: 11:59pm, Tuesday, 5 February 2013


Contents:


Collaboration Policy

For this assignment, you are allowed to work with one other student if you wish (in fact, we suggest that you do so). If any student wishes to have a partner but has not been able to locate one, please let the instructor know so that we can match up partners.

Please make sure you adhere to the policies on academic integrity in this regard.


Overview

DNA can be modeled as a string of characters using the alphabet A, C, G, and T. One form of DNA mutation occurs when a substring of the DNA is reversed during the replication process. Usually, such a reversal occurs between what are termed inverted pairs, where some substring is followed later by its reversal.

As an example, consider the original DNA strand:

CGATTGAACATGTAAGTCCAATT
This example happens to have an inverted pair, with the original marker being TGAA and its subsequent reversed pair being AAGT as shown below.
CGATTGAACATGTAAGTCCAATT
It is possible that the entire slice of DNA delimited by those patterns could be inverted and reattached, since the bonds at each end will be locally the same. In that case, the resulting mutated DNA would appear as
CGATTGAATGTACAAGTCCAATT
In effect, the 13 character strand has been flipped, noting that the middle 5 characters TGTAC are effectively reversed relative to the original strand.

You are to design a program that works as follows. It should ask the user for an original DNA string as well as the particular pattern that is inverted. It should then locate the leftmost occurrence of that pattern, and the next subsequent occurrence of the inverted pattern. The output should be the mutated DNA, with the segment including the inverted pair reversed. An example session might proceed as follows (where the user input is shown in bold):

Enter a DNA sequence: CGATTGAACATGTAAGTCCATT
Enter the pattern: TGAA
Mutated DNA sequence: CGATTGAATGTACAAGTCCAATT

Formal Specifications

For the sake of this assignment, you may assume that the user enters valid input, defined as follows.

Your program is responsible for performing only the single mutation that occurs between the first occurrence of the pattern, and the next subsequent occurrence of the reversed pattern (that which is completely disjoint from the forward pattern).

You should make sure to test your program on a variety of inputs, not just the one example given above. However, you need not concern yourself with how your program behaves if given errant input that does not meet these formal specifications. (We will need to learn about conditional statements in Ch. 4 in order to write a program that gracefully handles such situations.)

To aid you in your testing, here are some other well-formed test cases that your program should properly handle (not that these are the only tests to consider):

original DNA forward pattern mutated DNA comments
CGATTGAACATGTAAGTCCATT TGAA CGATTGAATGTACAAGTCCATT first example
CGATTGAAGTTGTAAGTCCATT TGAA CGATTGAATGTTGAAGTCCATT reverse pattern must be disjoint from forward pattern
ATTGCACGTTACCTGCAT CGT ATTGCACGTCCATTGCAT reverse pattern only relevant when after forward pattern
CATGTTACATGTTA AT CATTGTACATGTTA only perform one mutation


Advice

This task can be accomplished with careful use of methods of the str class, and possibly the list class.

One challenge is the need to reverse strings. You will need to reverse the original marker to get its inverted form and later to reverse the substring between the marker pair. In an ideal world, the str class would support a reverse() method - but alas, no such method exists. However, negative slices can be used to produce a reversal. See the "For the Guru" box on page 55.

The other big challenge is to properly identified the portion of the DNA between the marker pair. Again, there is more than one way to accomplish this, but the most likely approach to take is to use the index method of a string to find the location of the markers and then to properly identify the strand between then. Once that is done, it should be possible to calculate the reversal of that intermediate strand, and to piece together the various portions of the DNA for the resulting output.


Submitting Your Assignment

You should create a new file, dna.py, which contains all of your own code. This file must be submitted electronically.

You should also submit a separate 'readme' text file. If you worked as a pair, please make this clear and briefly describe the contributions of each person in the effort.

Please see details regarding the submission process from the general programming web page, as well as a discussion of the late policy.


Grading Standards

The assignment is worth 10 points.


Extra Credit

We have suggested that the most natural solution to this assignment is based upon use of the index (or equivalently, the find) method of the str class.

Even without use of the index or find methods, it is still possible to accomplish the desired task based only upon the use of the other str and list methods we have discussed. For extra credit, give such a solution to this assignment.

So as not to risk losing points on the required part of the assignment due to a failed extra credit attempt, please submit an original version of your assignment in a file dna.py and the separate extra credit version in a file dnaExtra.py.


Michael Goldwasser
Last modified: Friday, 01 February 2013