def write_current_primers(self,filename='current_order.txt'): """Write currently selected primers to a space-delimited file This is formatted to be uploaded to the MGW website for ordering""" if not filename: print 'no filename given' return if not self.primers.curselection(): print 'primer database is empty or no selection' return # Get currently selected primers into a list tmp_selection=self.primers.curselection() selection=[] for num in tmp_selection: selection.append(int(num)) primers={} first=1 # Now figure out the selected primers and store them in primers for primer_num in selection: name_selected=self.primer_order[primer_num] primers[name_selected]=self.parent.data['primer_dict'][name_selected] #fd=open(filename,'wb') self.DumpPDB = [] import mutation for entry in primers: tmp = [] tmp.append(entry+'_for') tmp.append(' ') tmp.append(primers[entry]['sequence']) reverse=mutation.get_reverse_complementary(primers[entry]['sequence']) tmp.append('\n') tmp.append(entry+'_rev') tmp.append(' ') tmp.append(reverse) tmp.append('\n') self.DumpPDB.append(tmp) try: fd=open(filename,'a') for line in self.DumpPDB: str = '' for S in line: str = str+S fd.write(str+'\n') fd.close() print "File written ",filename except: print "error: could not write file ",filename from PEATDB.textFrame import textFrame self.order_frame = textFrame(self, 'Current primers') self.order_frame.load_text(self.DumpPDB) fd.close() return
def find_primer_binding_sites(self, primer_seq, DNA_seq): '''Find all possible binding sites for the primer in the DNA_seq - also probe the reverse strand''' binding_sites = self.find_primer_binding_sites_1(primer_seq, DNA_seq) # Reverse complement strand rev_compl = mutation.get_reverse_complementary(DNA_seq) rev_binding_sites = self.find_primer_binding_sites_1( primer_seq, rev_compl, 1) return binding_sites + rev_binding_sites
def find_primer_binding_sites(self,primer_seq,DNA_seq): '''Find all possible binding sites for the primer in the DNA_seq - also probe the reverse strand''' binding_sites=self.find_primer_binding_sites_1(primer_seq,DNA_seq) # Reverse complement strand rev_compl = mutation.get_reverse_complementary(DNA_seq) rev_binding_sites = self.find_primer_binding_sites_1(primer_seq,rev_compl,1) return binding_sites+rev_binding_sites
def apply_primer_to_DNA(self,this_primer,DNA_seq,position): """Construct new DNA sequence. If we have a negative position, then it's a reverse strand primer""" if position<0: import mutation position=abs(int(position)) repl_seq=mutation.get_reverse_complementary(this_primer['sequence']) position=len(DNA_seq)-(position+len(repl_seq)) else: repl_seq=this_primer['sequence'] # Construct the new DNA new_DNA=DNA_seq[:position]+repl_seq+DNA_seq[position+len(repl_seq):] return new_DNA
def display_detailed_results(self,junk=None): """Figure out the selected primer and display in textbox""" selection=int(str(self.primer_result.curselection()[0])) name_selected=self.primer_order[selection] this_primer=self.foundprimers[name_selected] self.detailed_results.delete(1.0,END) # Insert the template DNA sequence this_primer['template_DNA']=self.data['DNAseq'] # Get the alignment this_primer['startpos']=self.pDB.align_primer(this_primer) # Make sure that we have the updated the characteristics of the primer import evaluate_primer EVAL=evaluate_primer.evaluate_primer() hairpin,selfcompl,Tm_inpos,Tm_method_used,mismatches=EVAL.get_characteristics(this_primer,self.Tm_method.get()) this_primer['hairpin_prop']=hairpin this_primer['self-compl']=selfcompl # Show all the info on the primer self.detailed_results.insert(END,'Primer: %s \n' %name_selected) self.detailed_results.insert(END,'Length: %3d bases\n' %(len(this_primer['sequence']))) self.detailed_results.insert(END,"Forward 5' %s 3'\n" %this_primer['sequence']) # Show the reverse complementary sequence import mutation self.detailed_results.insert(END,"Reverse complementary: 5' %s 3'\n" %mutation.get_reverse_complementary(this_primer['sequence'])) # Show the characteristics of the primer text='-----------------------\nCharacteristics\nTm (aligned): %5.2f (%s)\n' %(Tm_inpos,Tm_method_used) self.detailed_results.insert(END,text) text='Hairpin: %s, \nself-sim: %s, \nrestr. site differences: ' %(this_primer['hairpin_prop'], this_primer['self-compl']) self.detailed_results.insert(END,text) # Show the recognition sequence for the enzyme(s) unique_added,unique_removed,non_unique_added,non_unique_removed=self.pDB.get_primer_restriction_differences(this_primer) enz_specs=self.RS.enzymes_regexs inserted=None for enz in unique_added.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END,enz+'(+)*, ') inserted=1 for enz in unique_removed.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END,enz+'(-)*, ') inserted=1 for enz in non_unique_added.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END,enz+'(+), ') inserted=1 for enz in non_unique_removed.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END,enz+'(-), ') inserted=1 # If there were no differences in the restriction map, then write that if inserted==None: self.detailed_results.insert(END,'None') # Delete all graphic objects from last round for obj in self.detailed_objs.keys(): self.seqframe.delete(obj) # Align the primer this_primer['startpos']=self.pDB.align_primer(this_primer) # Draw the new primer #print self.pDB_open.__dict__.keys() #self.pDB.primers.selection_clear() self.pDB_open.clear_pDB_objects() self.pDB.display_primer(this_primer) return
def display_detailed_results(self, junk=None): """Figure out the selected primer and display in textbox""" selection = int(str(self.primer_result.curselection()[0])) name_selected = self.primer_order[selection] this_primer = self.foundprimers[name_selected] self.detailed_results.delete(1.0, END) # Insert the template DNA sequence this_primer['template_DNA'] = self.data['DNAseq'] # Get the alignment this_primer['startpos'] = self.pDB.align_primer(this_primer) # Make sure that we have the updated the characteristics of the primer import evaluate_primer EVAL = evaluate_primer.evaluate_primer() hairpin, selfcompl, Tm_inpos, Tm_method_used, mismatches = EVAL.get_characteristics( this_primer, self.Tm_method.get()) this_primer['hairpin_prop'] = hairpin this_primer['self-compl'] = selfcompl # Show all the info on the primer self.detailed_results.insert(END, 'Primer: %s \n' % name_selected) self.detailed_results.insert( END, 'Length: %3d bases\n' % (len(this_primer['sequence']))) self.detailed_results.insert( END, "Forward 5' %s 3'\n" % this_primer['sequence']) # Show the reverse complementary sequence import mutation self.detailed_results.insert( END, "Reverse complementary: 5' %s 3'\n" % mutation.get_reverse_complementary(this_primer['sequence'])) # Show the characteristics of the primer text = '-----------------------\nCharacteristics\nTm (aligned): %5.2f (%s)\n' % ( Tm_inpos, Tm_method_used) self.detailed_results.insert(END, text) text = 'Hairpin: %s, \nself-sim: %s, \nrestr. site differences: ' % ( this_primer['hairpin_prop'], this_primer['self-compl']) self.detailed_results.insert(END, text) # Show the recognition sequence for the enzyme(s) unique_added, unique_removed, non_unique_added, non_unique_removed = self.pDB.get_primer_restriction_differences( this_primer) enz_specs = self.RS.enzymes_regexs inserted = None for enz in unique_added.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END, enz + '(+)*, ') inserted = 1 for enz in unique_removed.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END, enz + '(-)*, ') inserted = 1 for enz in non_unique_added.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END, enz + '(+), ') inserted = 1 for enz in non_unique_removed.keys(): if enz_specs.has_key(enz): self.detailed_results.insert(END, enz + '(-), ') inserted = 1 # If there were no differences in the restriction map, then write that if inserted == None: self.detailed_results.insert(END, 'None') # Delete all graphic objects from last round for obj in self.detailed_objs.keys(): self.seqframe.delete(obj) # Align the primer this_primer['startpos'] = self.pDB.align_primer(this_primer) # Draw the new primer #print self.pDB_open.__dict__.keys() #self.pDB.primers.selection_clear() self.pDB_open.clear_pDB_objects() self.pDB.display_primer(this_primer) return
def display_single_primer(self,selection,focus,delete): """Display a single primer - focus on it if focus is true, and delete previous graphics and text objects if delete is true""" name_selected=self.primer_order[selection] #print 'SELECTION=',selection this_primer = self.parent.data['primer_dict'][name_selected] self.current_primers_shown.append(this_primer) self.parent.primer_displayed=1 #tells DNAtool that a primer is currently shown self.details.config(state=NORMAL) if delete: self.details.delete(1.0,END) # Align the primer # If we do not have a DNA sequence then we cannot do it this_primer['startpos']=None if self.parent.data.has_key('DNAseq'): if self.parent.data['DNAseq']: # Find all possible binding sites for the primer sites=self.find_primer_binding_sites(this_primer['sequence'],self.parent.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 # Set the primer start for the primer characteristics this_primer['startpos']=best_position this_primer['template_DNA']=self.parent.data['DNAseq'] # Show all the info on the primer self.details.tag_config('n', foreground='blue') self.details.insert(END,'Primer: %s \n' %name_selected, 'n') self.details.insert(END,'Description: %s \n' %(this_primer['description'])) self.details.insert(END,'Length: %3d bases\n' %(len(this_primer['sequence']))) self.details.insert(END,"Forward 5' %s 3'\n\n" %this_primer['sequence']) # Show the reverse complementary sequence import mutation self.details.insert(END,"Reverse complementary: 5' %s 3'\n" %mutation.get_reverse_complementary(this_primer['sequence'])) # Make sure that we have the updated the characteristics of the primer if not this_primer.has_key('template_DNA'): return import evaluate_primer EVAL=evaluate_primer.evaluate_primer() hairpin,selfcompl,Tm_inpos,Tm_method_used,mismatches=EVAL.get_characteristics(this_primer,self.parent.Tm_method.get()) this_primer['hairpin_prop']=hairpin this_primer['self-compl']=selfcompl this_primer['introduced_sites']='Unknown' # Show the characteristics of the primer text='-----------------------\nCharacteristics\nTm (in aligned position): %5.2f (%s)\n' %(Tm_inpos,Tm_method_used) self.details.insert(END,text) text='Hairpin: %s, \nself-sim: %s, \nrestr. site differences: ' %(this_primer['hairpin_prop'], this_primer['self-compl']) self.details.insert(END,text) # Show the recognition sequence for the enzyme(s) self.details.insert(END,'Unique sites are marked with a "*"\n') unique_added,unique_removed,non_unique_added,non_unique_removed=self.get_primer_restriction_differences(this_primer) enz_specs=self.parent.RS.enzymes_regexs inserted=None for enz in unique_added.keys(): if enz_specs.has_key(enz): self.details.insert(END,enz+'(+)*, ') inserted=1 for enz in unique_removed.keys(): if enz_specs.has_key(enz): self.details.insert(END,enz+'(-)*, ') inserted=1 for enz in non_unique_added.keys(): if enz_specs.has_key(enz): self.details.insert(END,enz+'(+), ') inserted=1 for enz in non_unique_removed.keys(): if enz_specs.has_key(enz): self.details.insert(END,enz+'(-), ') inserted=1 # If there were no differences in the restriction map, then write that if inserted==None: self.details.insert(END,'None') # Delete all graphic objects from last round if delete: if not getattr(self.parent,'detailed_objs',None): self.parent.detailed_objs = {} for obj in self.parent.detailed_objs.keys(): self.parent.seqframe.delete(obj) if getattr(self.parent,'tempsites',None): self.parent.tempsites.remove(obj) # Print guidelines for this primer scores.sort() diff=scores[-1]-scores[-2] self.details.insert(END,'\nDifference in # of matches between two best sites: %2d\n' %diff) if diff<5: self.details.insert(END,'WARNING: Primer is not unique!\n') if scores[-1]!=len(this_primer['sequence']): self.details.insert(END,'\nWARNING: No perfectly matching binding site.\n') # Print the number of mismatches as a control if this_primer['startpos']>0: self.details.insert(END,'\nDisplaying position: %4d on forward strand\n' %this_primer['startpos']) else: self.details.insert(END,'\nDisplaying position: %4d on reverse strand\n' %(-this_primer['startpos'])) self.details.insert(END,'Number of mismatches: %d\n\n' %mismatches) # Display the primer match=self.display_primer(this_primer,focus) # Show the binding site self.details.insert(END,'\n==================================\n') site=sites[0][0] if site<0: site=len(this_primer['sequence'])+site # DNA_stretch=self.parent.data['DNAseq'][site:site+len(this_primer['sequence'])] self.details.insert(END,'Primer %s\n %s\nDNASeq %s\n' %(this_primer['sequence'],match,DNA_stretch)) # Print summary of all binding sites self.details.insert(END,'\n---------------------\nSummary of best binding sites\n') self.details.insert(END,'Forward strand:\n') first_neg=1 for site,score in sites: if site<0: site=site*-1 if first_neg: first_neg=None self.details.insert(END,'Reverse compl. strand:\n') self.details.insert(END,'Position: %4d, matches: %2d\n' %(site,score)) self.details.insert(END,'\n') self.details.config(state=DISABLED) # Return the sites for use in highlighting start_position=self.get_real_primer_position(this_primer) return [start_position,start_position+len(this_primer['sequence'])]