Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write in Python 3. DNA can be modeled as a string of characters using the alphabet A, C, G, and T. One form of
Please write in Python 3.
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 and disjoint 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 Specifications For the sake of this assignment, you may assume that the user enters valid input, defined as follows The designated pattern will appear at least once within the original DNA sequence The original DNA strand will contain at least one occurrence of the reversed pattern that occurs com- pletely after the first occurrence of the forward pattern. (Although there may be additional occurrences of the reversed pattern elsewhere.) Your program is responsible for performing only the single mutation that occurs between the first occur rence of the pattern, and the next subsequent occurrence of the reversed pattern (that which is completely disjoint from the forward pattern) 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. 8 in order to write a program that gracefully handles such situations.) This task can be accomplished with careful use of methods of the str class, and possibly the list class. There tend to be two different schools of thought for how to accomplish the underlying string manipulations: One approach is to make use of the index method of a string to find the location of the markers, and then to properly identify the indices of the strand between them using string slicing to extract it. 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. Another approach is to make extensive use of the split method of the string class, using the marker and later the reverse marker as the pattern upon which you split. Then the pieces that results can be manipulated before reassembling the resulting DNA strand. Using either strategy, there is a low-level task of needing to reverse a string. This arises both 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 (as in sample[: -1])Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started