# no description, look for one in the hello() function # CGATTGAACATTAAGTCCAATT import sys def main(): hello() DNA=raw_input("Please, enter a DNA string (use only letters A,C,G, and T):") # Checking whether the DNA string provided by the user consists only of # A,C,G, and T check=True for char in DNA: if (char != "A" and char != "C" and char != "G" and char != "T" ): check = False break if check == True: # if DNA string consists only of A,C,G, and T p=raw_input("Please, enter a pattern (a substring of DNA):") pos1=DNA.find(p) #finds the occureence of the pattern in DNA string, # and returns the index of the leftmost element of the pattern if pos1 != -1: length=len(p) # length of pattern (needed for adjustment of position1) pos1=pos1+length # adjusting position1 p_inv=p[::-1] # inverting original pattern pos2=DNA.find(p_inv,pos1) # looking for inverted pattern starting from # position 2 if pos2 != -1: # next two lines take a a substring in between positions 1 and 2, # and invert it DNA_piece = DNA[pos1:pos2] DNA_inv_piece = DNA_piece[::-1] # building the mutated DNA: getting the first part (not mutated), # attaching mutated part, attaching the tail (non-mutated) DNA_muttd=DNA[:pos1] + DNA_inv_piece + DNA[pos2:] # presenting the results to the user print "Original DNA sequence:", DNA print "Inverted pattern:",p, "and",p_inv print "Mutated DNA sequence:",DNA_muttd else: print "No inverted pattern,", p_inv,", is found in given DNA sequence." print "The DNA sequence is left unchanged" else: print "No such pattern is found in DNA sequence." print "The DNA sequence is left unchanged" else: # if the DNA string has other symbols than A,C,G, and T print "The string in incorrect. It has symbols other that A,C,G, or T" print "Exiting the program .... Have a good day!" def hello(): print "Hello!" print "Welcome to the program that shows one of the possible DNA mutations" print "You will be asked to input a DNA string (it should be composed ", print "of letters A,C,G, and T only). And then you will be aslo asked to " print "provide a pattern (any substring of DNA string)." print "The program then will try to locate the inverted pattern, " print "and if succeeds, the substring between this inverted pattern will be " print "reversed" main()