def dnaseq_read(self,newprotein=None,fileinput=None,variable='DNAseq',var2='dnaseqfile'): """Read in DNA Sequences and display them above the main sequence""" self.data['newprotein']=newprotein # If a file is provided use that, otherwise open the dialog if fileinput == None: dnaseqfile = self.open_file() else: dnaseqfile = fileinput self.data[var2]=dnaseqfile # Load the DNA sequence data # - only simple file format supported at the moment if self.data[var2]: S=DNA_sequence.sequence() seqfile=self.data[var2] DNAseq=S.read_DNA_sequence(seqfile) # Check the DNA sequence ok,DNAseq=mutation.check_DNA(DNAseq) if not ok: # Give a warning import tkMessageBox tkMessageBox.showwarning("DNA sequence", 'DNA sequence contains invalid characters: %s' %DNAseq ,parent=self.master) return self.data[variable]=DNAseq self.update_sequence_window() # Activate/Deactivate buttons self.projectChanged() return dnaseqfile
def get_characteristics(self,primer,Tm_method): """Get the characteristics (hairpin prop, selfcomplementarity) of a primer""" # # Extract the DNA sequence # primer_seq=primer['sequence'] import mutation ok,primer_seq=mutation.check_DNA(primer_seq) if ok: # # Hairpin propensity # prop,numscore=mutation.hairpin_propensity(primer_seq) if numscore < 8: score = 'OK' elif numscore >= 8: score = 'BAD' text_hairpin='%s (%2d matches)' %(score,numscore) # # Self complementarity # complementarity_dict,maxselfscore = mutation.self_complementarity_propensity(primer_seq) if maxselfscore < 8: text = 'OK' elif maxselfscore >= 8: text = 'BAD' text_selfcompl='%s (%2d matches)' %(text,maxselfscore) # # Melting temperature # Tm,mismatches,Tm_method_used=mutation.get_primer_Tm(DNAseq=primer['template_DNA'],primer=primer_seq,primer_start=primer['startpos'],method=Tm_method) return text_hairpin,text_selfcompl,Tm,Tm_method_used,mismatches return 'DNA sequenece not ok','DNA sequence not ok','DNA sequenece not ok','DNA sequence not ok'
def save_primer_from_edit(self, parent_window=None): """Save the primer in the DB when doing a primer Edit""" if not parent_window: parent_window = self.eval_win # Check if the primer name has been changed first, and ask for confirmation of rename if self.primername_var.get() != self.edit_primer_name or not self.edit_primer_name: import tkMessageBox ok = tkMessageBox.askyesno('Primer Name altered', 'Rename primer and save?\n', parent=parent_window) if not ok: self.primername_var.set(self.edit_primer_name) return #rename primer based on value in entry widget else: new_name=self.primername_var.get() if new_name: #only rename if there isn't already a primer with the same name if not self.data['primer_dict'].has_key(new_name): self.data['primer_dict'][new_name]=self.data['primer_dict'][self.edit_primer_name].copy() del self.data['primer_dict'][self.edit_primer_name] self.edit_primer_name = new_name self.i_parent.new_name = new_name #otherwise don't allow rename else: tkMessageBox.showwarning('Primer name already present', 'Primer name already present.\nPlease choose another name', parent=parent_window) return # Update the sequence and description fields for the primer DNA=self.eval_var.get() # Validation check if primer is changed (maybe by mistake) if not DNA: ok = tkMessageBox.askyesno('No sequence entered', 'No sequence entered.\nDo you wish to save anyway?', parent=parent_window) if not ok: return import mutation ok,DNA_sequence=mutation.check_DNA(DNA) self.data['primer_dict'][self.edit_primer_name]['sequence']=DNA_sequence self.data['primer_dict'][self.edit_primer_name]['description']=self.descr_var.get() #print 'Primer Info:',self.edit_primer_name,self.data['primer_dict'][self.edit_primer_name] # Clear all graphics if getattr(self,'pDB',None): self.pDB.clear_pDB_objects() # Close the window self.eval_win.destroy() return
def get_characteristics(self, primer, Tm_method): """Get the characteristics (hairpin prop, selfcomplementarity) of a primer""" # # Extract the DNA sequence # primer_seq = primer['sequence'] import mutation ok, primer_seq = mutation.check_DNA(primer_seq) if ok: # # Hairpin propensity # prop, numscore = mutation.hairpin_propensity(primer_seq) if numscore < 8: score = 'OK' elif numscore >= 8: score = 'BAD' text_hairpin = '%s (%2d matches)' % (score, numscore) # # Self complementarity # complementarity_dict, maxselfscore = mutation.self_complementarity_propensity( primer_seq) if maxselfscore < 8: text = 'OK' elif maxselfscore >= 8: text = 'BAD' text_selfcompl = '%s (%2d matches)' % (text, maxselfscore) # # Melting temperature # Tm, mismatches, Tm_method_used = mutation.get_primer_Tm( DNAseq=primer['template_DNA'], primer=primer_seq, primer_start=primer['startpos'], method=Tm_method) return text_hairpin, text_selfcompl, Tm, Tm_method_used, mismatches return 'DNA sequenece not ok', 'DNA sequence not ok', 'DNA sequenece not ok', 'DNA sequence not ok'
def dnaseq_read(self, newprotein=None, fileinput=None, variable='DNAseq', var2='dnaseqfile'): """Read in DNA Sequences and display them above the main sequence""" self.data['newprotein'] = newprotein # If a file is provided use that, otherwise open the dialog if fileinput == None: dnaseqfile = self.open_file() else: dnaseqfile = fileinput self.data[var2] = dnaseqfile # Load the DNA sequence data # - only simple file format supported at the moment if self.data[var2]: S = DNA_sequence.sequence() seqfile = self.data[var2] DNAseq = S.read_DNA_sequence(seqfile) # Check the DNA sequence ok, DNAseq = mutation.check_DNA(DNAseq) if not ok: # Give a warning import tkMessageBox tkMessageBox.showwarning( "DNA sequence", 'DNA sequence contains invalid characters: %s' % DNAseq, parent=self.master) return self.data[variable] = DNAseq self.update_sequence_window() # Activate/Deactivate buttons self.projectChanged() return dnaseqfile
def save_primer(self,parent_window=None,openpdbWin=None, this_primer=None, calledby=None ): """Saves primers to database""" # Get the parent window right if not parent_window: parent_window=self.eval_win # Save the primer to the primer library if not self.data.has_key('primer_dict'): self.data['primer_dict']={} # Find the next unique name for x in range(1000): nextname='primer_%3d' %x if not self.data['primer_dict'].has_key(nextname): break # Get a name for the primer # If calling from primer design just use little dialog, otherwise use if calledby=='from design': print 'Saving primer from design window' done=None result = self.get_text_input(parent_window,[['name',20],['description',30]]) if not result: return None primer_name=result[0] description=result[1] else: primer_name=self.primername_var.get() description=self.descr_var.get() if not primer_name: tkMessageBox.showwarning('Invalid primer name', 'I need a real primer name to store this primer', parent=parent_window) return print 'Setting name to',primer_name print 'Setting description to',description # Store the primer if not this_primer: DNA=self.eval_var.get() if not DNA: ok = tkMessageBox.askyesno('No sequence entered', 'No sequence entered.\nDo you wish to save anyway?') if not ok: return ok,sequence=mutation.check_DNA(DNA) if ok: self.data['primer_dict'][primer_name]={'description':description,'sequence':sequence,'startpos':None, 'hairpin_prop':self.eval_hairpin.get(), 'self-compl':self.eval_primerdimer.get(), 'introduced_sites':'Unknown'} self.primer_save_ok(primer_name,parent_window) #pass name of primer back to parent window for highlighting self.i_parent.new_name = primer_name parent_window.destroy() print 'Primer Info:',self.data['primer_dict'][primer_name] else: tkMessageBox.showwarning('Invalid primer','Cannot store an invalid primer',parent=parent_window) return else: # If we already have all the data then save it this_primer['description']=description self.data['primer_dict'][primer_name]=this_primer.copy() self.primer_save_ok(primer_name,parent_window) # Clear all the graphics if getattr(self,'pDB',None): self.pDB.clear_pDB_objects() # If calling from mutagenic design, handle refresh of pdb here if calledby == 'from design' and openpdbWin != None: openpdbWin.show_pDB_contents() openpdbWin.highlight_primer(primer_name) openpdbWin.display_details() return
def update_eval(self,event=None): # # Calculate primer-dimer and secondary structure # import mutation primer_seq=self.eval_var.get() ok,primer_seq=mutation.check_DNA(primer_seq) # # Score the sequence # if ok: prop,numscore=mutation.hairpin_propensity(primer_seq) if numscore < 8: score = 'OK' # score = numscore elif numscore >= 8: score = 'BAD' #score = numscore self.eval_hairpin.set('%s (%2d matches)' %(score,numscore)) # # Primer-Dimer # complementarity_dict,maxselfscore = mutation.self_complementarity_propensity (primer_seq) if maxselfscore < 8: text = 'OK' elif maxselfscore >= 8: text = 'BAD' self.eval_primerdimer.set('%s (%2d matches)' %(text,maxselfscore)) # # Tm # # See if we can align the primer # Tm=None if self.data.has_key('DNAseq'): if self.data['DNAseq']: import primer_alignment A=primer_alignment.dummy_align_primer(self) # # Find all possible binding sites for the primer # sites=A.find_primer_binding_sites(primer_seq,self.data['DNAseq']) # # Print the number of binding sites # best_score=0 best_position=None scores=[] first_neg=1 for position,score in sites: scores.append(score) # # Find the best position # if score>best_score: best_score=score best_position=position Tm,mistmatches,Tm_method_used=mutation.get_primer_Tm(DNAseq=self.data['DNAseq'], primer=primer_seq, primer_start=best_position, method=self.Tm_method.get()) # # Draw the primer on the screen in the best position # this_primer={} this_primer['sequence']=primer_seq this_primer['startpos']=best_position # # Draw the new primer # self.pDB.display_primer(this_primer) if not Tm: Tm,mistmatches,Tm_method_used=mutation.get_primer_Tm(DNAseq=None, primer=primer_seq, primer_start=None, method=self.Tm_method.get()) self.eval_Tm.set('%5.2f' %Tm) self.eval_Tm_method.set(Tm_method_used) else: self.eval_hairpin.set('Invalid DNA sequence') self.eval_primerdimer.set('Invalid DNA sequence') self.eval_Tm.set('Invalid DNA sequence') return
def save_primer(self, parent_window=None, openpdbWin=None, this_primer=None, calledby=None): """Saves primers to database""" # Get the parent window right if not parent_window: parent_window = self.eval_win # Save the primer to the primer library if not self.data.has_key('primer_dict'): self.data['primer_dict'] = {} # Find the next unique name for x in range(1000): nextname = 'primer_%3d' % x if not self.data['primer_dict'].has_key(nextname): break # Get a name for the primer # If calling from primer design just use little dialog, otherwise use if calledby == 'from design': print 'Saving primer from design window' done = None result = self.get_text_input(parent_window, [['name', 20], ['description', 30]]) if not result: return None primer_name = result[0] description = result[1] else: primer_name = self.primername_var.get() description = self.descr_var.get() if not primer_name: tkMessageBox.showwarning( 'Invalid primer name', 'I need a real primer name to store this primer', parent=parent_window) return print 'Setting name to', primer_name print 'Setting description to', description # Store the primer if not this_primer: DNA = self.eval_var.get() if not DNA: ok = tkMessageBox.askyesno( 'No sequence entered', 'No sequence entered.\nDo you wish to save anyway?') if not ok: return ok, sequence = mutation.check_DNA(DNA) if ok: self.data['primer_dict'][primer_name] = { 'description': description, 'sequence': sequence, 'startpos': None, 'hairpin_prop': self.eval_hairpin.get(), 'self-compl': self.eval_primerdimer.get(), 'introduced_sites': 'Unknown' } self.primer_save_ok(primer_name, parent_window) #pass name of primer back to parent window for highlighting self.i_parent.new_name = primer_name parent_window.destroy() print 'Primer Info:', self.data['primer_dict'][primer_name] else: tkMessageBox.showwarning('Invalid primer', 'Cannot store an invalid primer', parent=parent_window) return else: # If we already have all the data then save it this_primer['description'] = description self.data['primer_dict'][primer_name] = this_primer.copy() self.primer_save_ok(primer_name, parent_window) # Clear all the graphics if getattr(self, 'pDB', None): self.pDB.clear_pDB_objects() # If calling from mutagenic design, handle refresh of pdb here if calledby == 'from design' and openpdbWin != None: openpdbWin.show_pDB_contents() openpdbWin.highlight_primer(primer_name) openpdbWin.display_details() return
def save_primer_from_edit(self, parent_window=None): """Save the primer in the DB when doing a primer Edit""" if not parent_window: parent_window = self.eval_win # Check if the primer name has been changed first, and ask for confirmation of rename if self.primername_var.get( ) != self.edit_primer_name or not self.edit_primer_name: import tkMessageBox ok = tkMessageBox.askyesno('Primer Name altered', 'Rename primer and save?\n', parent=parent_window) if not ok: self.primername_var.set(self.edit_primer_name) return #rename primer based on value in entry widget else: new_name = self.primername_var.get() if new_name: #only rename if there isn't already a primer with the same name if not self.data['primer_dict'].has_key(new_name): self.data['primer_dict'][new_name] = self.data[ 'primer_dict'][self.edit_primer_name].copy() del self.data['primer_dict'][self.edit_primer_name] self.edit_primer_name = new_name self.i_parent.new_name = new_name #otherwise don't allow rename else: tkMessageBox.showwarning( 'Primer name already present', 'Primer name already present.\nPlease choose another name', parent=parent_window) return # Update the sequence and description fields for the primer DNA = self.eval_var.get() # Validation check if primer is changed (maybe by mistake) if not DNA: ok = tkMessageBox.askyesno( 'No sequence entered', 'No sequence entered.\nDo you wish to save anyway?', parent=parent_window) if not ok: return import mutation ok, DNA_sequence = mutation.check_DNA(DNA) self.data['primer_dict'][ self.edit_primer_name]['sequence'] = DNA_sequence self.data['primer_dict'][ self.edit_primer_name]['description'] = self.descr_var.get() #print 'Primer Info:',self.edit_primer_name,self.data['primer_dict'][self.edit_primer_name] # Clear all graphics if getattr(self, 'pDB', None): self.pDB.clear_pDB_objects() # Close the window self.eval_win.destroy() return
def update_eval(self, event=None): # # Calculate primer-dimer and secondary structure # import mutation primer_seq = self.eval_var.get() ok, primer_seq = mutation.check_DNA(primer_seq) # # Score the sequence # if ok: prop, numscore = mutation.hairpin_propensity(primer_seq) if numscore < 8: score = 'OK' # score = numscore elif numscore >= 8: score = 'BAD' #score = numscore self.eval_hairpin.set('%s (%2d matches)' % (score, numscore)) # # Primer-Dimer # complementarity_dict, maxselfscore = mutation.self_complementarity_propensity( primer_seq) if maxselfscore < 8: text = 'OK' elif maxselfscore >= 8: text = 'BAD' self.eval_primerdimer.set('%s (%2d matches)' % (text, maxselfscore)) # # Tm # # See if we can align the primer # Tm = None if self.data.has_key('DNAseq'): if self.data['DNAseq']: import primer_alignment A = primer_alignment.dummy_align_primer(self) # # Find all possible binding sites for the primer # sites = A.find_primer_binding_sites( primer_seq, self.data['DNAseq']) # # Print the number of binding sites # best_score = 0 best_position = None scores = [] first_neg = 1 for position, score in sites: scores.append(score) # # Find the best position # if score > best_score: best_score = score best_position = position Tm, mistmatches, Tm_method_used = mutation.get_primer_Tm( DNAseq=self.data['DNAseq'], primer=primer_seq, primer_start=best_position, method=self.Tm_method.get()) # # Draw the primer on the screen in the best position # this_primer = {} this_primer['sequence'] = primer_seq this_primer['startpos'] = best_position # # Draw the new primer # self.pDB.display_primer(this_primer) if not Tm: Tm, mistmatches, Tm_method_used = mutation.get_primer_Tm( DNAseq=None, primer=primer_seq, primer_start=None, method=self.Tm_method.get()) self.eval_Tm.set('%5.2f' % Tm) self.eval_Tm_method.set(Tm_method_used) else: self.eval_hairpin.set('Invalid DNA sequence') self.eval_primerdimer.set('Invalid DNA sequence') self.eval_Tm.set('Invalid DNA sequence') return