Edit: [/code] without /
I am TRYING to write a program that finds restriction sites in a DNA file and returns a picture and information box of the enzyme which cuts it. My problems are; a) I have no idea if my program works past opening the file directory. b) I dont know how to iterate through the file 6 characters at a time, moving 1 character along each time. I need to do this, then use the dictionary to get the enzyme that corresponds to the found restriction site....
I have included my code so far. If someone can atleast tell me how to check if my code is working that would be PERFECT.
from Tkinter import * from tkMessageBox import * from tkFileDialog import * #An example library of restriction enzymes and their recognition sites site_enz= {'GAATTC':'EcoRI','GGATTC':'BamHI','AAGCTT':'HindIII', 'CCCGGG':'Smal','GATATC':'EcoRV'} class RestrictionSites (object): """A class to find splice sites within an RNA sequence chosen by the user""" def __init__(self, master): self.master = master self.frame = Frame(master) self.frame.pack() # selecting the image to use self.image = PhotoImage(file="Opening Picture.gif") # create a canvas that fits the image used self.canvas = Canvas(self.frame, width=self.image.width(), height=self.image.height()) # aligning the image to the top left corner of the canvas self.canvas.create_image(0,0, anchor=NW, image=self.image) self.canvas.pack() # now I want to add a button underneath, cannot but canvas and # button on the same frame so need to create a new frame for button self.button_panel = Frame(self.frame) self.button_panel.pack(side=TOP) # sets the width and position of the start button self.start_button = Button(self.button_panel, text="Click to upload a single stranded DNA sequence 5'-3'", width=100, command=self.startbutton) self.start_button.pack() def startbutton (self): self.FindFile() def FindFile (self): #Save as dialog filename = askopenfilename(parent=root,initialdir="/",title='Please select a directory') #When I need the file I refer to this bit my_file=open(filename,'r') temp = my_file.read().upper() my_file.close() def valid_input(self): #Checks file is a valid DNA sequence while True: self.file=self.FindFile() self.file=self.file.upper() #Only these bases allowed good_bases = "ATCG" temp_sequence = '' for base in self.file: if base in good_bases: temp_sequence += base self.file = temp_sequence #Flag for error- assume OK at the start. bad_input = False #Check each base. for base in self.file: if base in good_bases: #Ok so far, check next base. continue else: #Not an RNA base, so flag the error. bad_input= True #Give the user the bad news print 'Sorry - that is not a DNA sequence, please try again.' #break from the 'for' loop break #By this stage the sequence has been checked. #If all is awell, break form the 'while' loop. if bad_input ==False: break #Otherwise the 'while' loop will go back for re-input. return self.file def find_site (self): """This function checks if there is a restriction site in the DNA""" if site_enz.has_key(site)==False: return '?' return site_enz.get(site) def find_rest_site( sequence, init_pos, restriction_site): #function to find six-base restriction sites in a DNA sequence #self.findfile is a string containing the DNA sequence #init_pos is the position to start searching from (to start from the beginning, set it to 0) #restriction_site is a string containing the sequence sought.... #but i need to get the site from the dictionary #the function returns a list of positions where the restriction site was found #if none are found then the list will be empty list_of_sites=[] end = len(sequence)-6 for pointer in range(init_pos, end): sixer = self.FindFile[pointer:pointer+6] if sixer==self.find_site: list_of_sites.append(pointer) print list_of_sites return list_of_sites #Main program #this root widget sets the title of the screen root = Tk() root.title #set this class to be an object app= RestrictionSites(root) #loops the class until the event happens and makes everything visible. root.mainloop()