def OnToggle(self, evt): '''When any togglebutton is pressed''' AA = [] clicked_color = '#A2CD5A' unclicked_color = '#EEEEEE' if self.Ala.GetValue(): AA.append('A') self.Ala.SetBackgroundColour(clicked_color) else: self.Ala.SetBackgroundColour(unclicked_color) if self.Val.GetValue(): AA.append('V') self.Val.SetBackgroundColour(clicked_color) else: self.Val.SetBackgroundColour(unclicked_color) if self.Ile.GetValue(): AA.append('I') self.Ile.SetBackgroundColour(clicked_color) else: self.Ile.SetBackgroundColour(unclicked_color) if self.Leu.GetValue(): AA.append('L') self.Leu.SetBackgroundColour(clicked_color) else: self.Leu.SetBackgroundColour(unclicked_color) if self.Met.GetValue(): AA.append('M') self.Met.SetBackgroundColour(clicked_color) else: self.Met.SetBackgroundColour(unclicked_color) if self.Phe.GetValue(): AA.append('F') self.Phe.SetBackgroundColour(clicked_color) else: self.Phe.SetBackgroundColour(unclicked_color) if self.Tyr.GetValue(): AA.append('Y') self.Tyr.SetBackgroundColour(clicked_color) else: self.Tyr.SetBackgroundColour(unclicked_color) if self.Trp.GetValue(): AA.append('W') self.Trp.SetBackgroundColour(clicked_color) else: self.Trp.SetBackgroundColour(unclicked_color) if self.Asp.GetValue(): AA.append('D') self.Asp.SetBackgroundColour(clicked_color) else: self.Asp.SetBackgroundColour(unclicked_color) if self.Glu.GetValue(): AA.append('E') self.Glu.SetBackgroundColour(clicked_color) else: self.Glu.SetBackgroundColour(unclicked_color) if self.Asn.GetValue(): AA.append('N') self.Asn.SetBackgroundColour(clicked_color) else: self.Asn.SetBackgroundColour(unclicked_color) if self.Gln.GetValue(): AA.append('Q') self.Gln.SetBackgroundColour(clicked_color) else: self.Gln.SetBackgroundColour(unclicked_color) if self.Ser.GetValue(): AA.append('S') self.Ser.SetBackgroundColour(clicked_color) else: self.Ser.SetBackgroundColour(unclicked_color) if self.Thr.GetValue(): AA.append('T') self.Thr.SetBackgroundColour(clicked_color) else: self.Thr.SetBackgroundColour(unclicked_color) if self.Arg.GetValue(): AA.append('R') self.Arg.SetBackgroundColour(clicked_color) else: self.Arg.SetBackgroundColour(unclicked_color) if self.His.GetValue(): AA.append('H') self.His.SetBackgroundColour(clicked_color) else: self.His.SetBackgroundColour(unclicked_color) if self.Lys.GetValue(): AA.append('K') self.Lys.SetBackgroundColour(clicked_color) else: self.Lys.SetBackgroundColour(unclicked_color) if self.Cys.GetValue(): AA.append('C') self.Cys.SetBackgroundColour(clicked_color) else: self.Cys.SetBackgroundColour(unclicked_color) if self.Gly.GetValue(): AA.append('G') self.Gly.SetBackgroundColour(clicked_color) else: self.Gly.SetBackgroundColour(unclicked_color) if self.Pro.GetValue(): AA.append('P') self.Pro.SetBackgroundColour(clicked_color) else: self.Pro.SetBackgroundColour(unclicked_color) if len(AA) > 0: codon, target, offtarget, possibleAA = mbc.run(AA) self.mixed_base_codon.SetReadOnly(False) self.mixed_base_codon.SetText(codon) self.mixed_base_codon.SetReadOnly(True) targetstring = '' for entry in target: #make string with the target AA if targetstring == '': targetstring += entry else: targetstring += ', ' + entry offtargetstring = '' for entry in offtarget: #make string with the offtarget AA if offtargetstring == '': offtargetstring += entry else: offtargetstring += ', ' + entry self.target_hits.SetLabel('Target amino acids: ' + targetstring) self.offtarget_hits.SetLabel('Off-target amino acids: ' + offtargetstring) #set the yellow buttons to indicate which AA are possible without further off-target hits possible_color = '#FFFF99' if 'A' in possibleAA and self.Ala.GetValue() == False: self.Ala.SetBackgroundColour(possible_color) if 'V' in possibleAA and self.Val.GetValue() == False: self.Val.SetBackgroundColour(possible_color) if 'I' in possibleAA and self.Ile.GetValue() == False: self.Ile.SetBackgroundColour(possible_color) if 'L' in possibleAA and self.Leu.GetValue() == False: self.Leu.SetBackgroundColour(possible_color) if 'M' in possibleAA and self.Met.GetValue() == False: self.Met.SetBackgroundColour(possible_color) if 'F' in possibleAA and self.Phe.GetValue() == False: self.Phe.SetBackgroundColour(possible_color) if 'Y' in possibleAA and self.Tyr.GetValue() == False: self.Tyr.SetBackgroundColour(possible_color) if 'W' in possibleAA and self.Trp.GetValue() == False: self.Trp.SetBackgroundColour(possible_color) if 'D' in possibleAA and self.Asp.GetValue() == False: self.Asp.SetBackgroundColour(possible_color) if 'E' in possibleAA and self.Glu.GetValue() == False: self.Glu.SetBackgroundColour(possible_color) if 'N' in possibleAA and self.Asn.GetValue() == False: self.Asn.SetBackgroundColour(possible_color) if 'Q' in possibleAA and self.Gln.GetValue() == False: self.Gln.SetBackgroundColour(possible_color) if 'S' in possibleAA and self.Ser.GetValue() == False: self.Ser.SetBackgroundColour(possible_color) if 'T' in possibleAA and self.Thr.GetValue() == False: self.Thr.SetBackgroundColour(possible_color) if 'R' in possibleAA and self.Arg.GetValue() == False: self.Arg.SetBackgroundColour(possible_color) if 'H' in possibleAA and self.His.GetValue() == False: self.His.SetBackgroundColour(possible_color) if 'K' in possibleAA and self.Lys.GetValue() == False: self.Lys.SetBackgroundColour(possible_color) if 'C' in possibleAA and self.Cys.GetValue() == False: self.Cys.SetBackgroundColour(possible_color) if 'G' in possibleAA and self.Gly.GetValue() == False: self.Gly.SetBackgroundColour(possible_color) if 'P' in possibleAA and self.Pro.GetValue() == False: self.Pro.SetBackgroundColour(possible_color) #make list of all codons in degenerate triplet codonlist = dna.UnAmb(codon) #count how many times each AA is coded for by these codons self.AA_count = mbc.count_codon_list(codonlist) #plot graph self.update_plot() else: self.mixed_base_codon.SetReadOnly(False) self.mixed_base_codon.SetText('None') self.mixed_base_codon.SetReadOnly(True) self.target_hits.SetLabel('Target amino acids: ') self.offtarget_hits.SetLabel('Off-target amino acids: ') self.AA_count = { 'A': 0, 'C': 0, 'E': 0, 'D': 0, 'G': 0, 'F': 0, 'I': 0, 'H': 0, 'K': 0, 'M': 0, 'L': 0, 'N': 0, 'Q': 0, 'P': 0, 'S': 0, 'R': 0, 'T': 0, 'W': 0, 'V': 0, 'Y': 0, 'stop': 0 } self.update_plot()
def OnToggle(self, evt): '''When any togglebutton is pressed''' AA = [] clicked_color = '#A2CD5A' unclicked_color = '#EEEEEE' if self.Ala.GetValue(): AA.append('A') self.Ala.SetBackgroundColour(clicked_color) else: self.Ala.SetBackgroundColour(unclicked_color) if self.Val.GetValue(): AA.append('V') self.Val.SetBackgroundColour(clicked_color) else: self.Val.SetBackgroundColour(unclicked_color) if self.Ile.GetValue(): AA.append('I') self.Ile.SetBackgroundColour(clicked_color) else: self.Ile.SetBackgroundColour(unclicked_color) if self.Leu.GetValue(): AA.append('L') self.Leu.SetBackgroundColour(clicked_color) else: self.Leu.SetBackgroundColour(unclicked_color) if self.Met.GetValue(): AA.append('M') self.Met.SetBackgroundColour(clicked_color) else: self.Met.SetBackgroundColour(unclicked_color) if self.Phe.GetValue(): AA.append('F') self.Phe.SetBackgroundColour(clicked_color) else: self.Phe.SetBackgroundColour(unclicked_color) if self.Tyr.GetValue(): AA.append('Y') self.Tyr.SetBackgroundColour(clicked_color) else: self.Tyr.SetBackgroundColour(unclicked_color) if self.Trp.GetValue(): AA.append('W') self.Trp.SetBackgroundColour(clicked_color) else: self.Trp.SetBackgroundColour(unclicked_color) if self.Asp.GetValue(): AA.append('D') self.Asp.SetBackgroundColour(clicked_color) else: self.Asp.SetBackgroundColour(unclicked_color) if self.Glu.GetValue(): AA.append('E') self.Glu.SetBackgroundColour(clicked_color) else: self.Glu.SetBackgroundColour(unclicked_color) if self.Asn.GetValue(): AA.append('N') self.Asn.SetBackgroundColour(clicked_color) else: self.Asn.SetBackgroundColour(unclicked_color) if self.Gln.GetValue(): AA.append('Q') self.Gln.SetBackgroundColour(clicked_color) else: self.Gln.SetBackgroundColour(unclicked_color) if self.Ser.GetValue(): AA.append('S') self.Ser.SetBackgroundColour(clicked_color) else: self.Ser.SetBackgroundColour(unclicked_color) if self.Thr.GetValue(): AA.append('T') self.Thr.SetBackgroundColour(clicked_color) else: self.Thr.SetBackgroundColour(unclicked_color) if self.Arg.GetValue(): AA.append('R') self.Arg.SetBackgroundColour(clicked_color) else: self.Arg.SetBackgroundColour(unclicked_color) if self.His.GetValue(): AA.append('H') self.His.SetBackgroundColour(clicked_color) else: self.His.SetBackgroundColour(unclicked_color) if self.Lys.GetValue(): AA.append('K') self.Lys.SetBackgroundColour(clicked_color) else: self.Lys.SetBackgroundColour(unclicked_color) if self.Cys.GetValue(): AA.append('C') self.Cys.SetBackgroundColour(clicked_color) else: self.Cys.SetBackgroundColour(unclicked_color) if self.Gly.GetValue(): AA.append('G') self.Gly.SetBackgroundColour(clicked_color) else: self.Gly.SetBackgroundColour(unclicked_color) if self.Pro.GetValue(): AA.append('P') self.Pro.SetBackgroundColour(clicked_color) else: self.Pro.SetBackgroundColour(unclicked_color) if len(AA) > 0: codon, target, offtarget, possibleAA = mbc.run(AA) self.mixed_base_codon.SetReadOnly(False) self.mixed_base_codon.SetText(codon) self.mixed_base_codon.SetReadOnly(True) targetstring = '' for entry in target: #make string with the target AA if targetstring == '': targetstring += entry else: targetstring += ', '+entry offtargetstring = '' for entry in offtarget: #make string with the offtarget AA if offtargetstring == '': offtargetstring += entry else: offtargetstring += ', '+entry self.target_hits.SetLabel('Target amino acids: '+targetstring) self.offtarget_hits.SetLabel('Off-target amino acids: '+offtargetstring) #set the yellow buttons to indicate which AA are possible without further off-target hits possible_color = '#FFFF99' if 'A' in possibleAA and self.Ala.GetValue() == False: self.Ala.SetBackgroundColour(possible_color) if 'V' in possibleAA and self.Val.GetValue() == False: self.Val.SetBackgroundColour(possible_color) if 'I' in possibleAA and self.Ile.GetValue() == False: self.Ile.SetBackgroundColour(possible_color) if 'L' in possibleAA and self.Leu.GetValue() == False: self.Leu.SetBackgroundColour(possible_color) if 'M' in possibleAA and self.Met.GetValue() == False: self.Met.SetBackgroundColour(possible_color) if 'F' in possibleAA and self.Phe.GetValue() == False: self.Phe.SetBackgroundColour(possible_color) if 'Y' in possibleAA and self.Tyr.GetValue() == False: self.Tyr.SetBackgroundColour(possible_color) if 'W' in possibleAA and self.Trp.GetValue() == False: self.Trp.SetBackgroundColour(possible_color) if 'D' in possibleAA and self.Asp.GetValue() == False: self.Asp.SetBackgroundColour(possible_color) if 'E' in possibleAA and self.Glu.GetValue() == False: self.Glu.SetBackgroundColour(possible_color) if 'N' in possibleAA and self.Asn.GetValue() == False: self.Asn.SetBackgroundColour(possible_color) if 'Q' in possibleAA and self.Gln.GetValue() == False: self.Gln.SetBackgroundColour(possible_color) if 'S' in possibleAA and self.Ser.GetValue() == False: self.Ser.SetBackgroundColour(possible_color) if 'T' in possibleAA and self.Thr.GetValue() == False: self.Thr.SetBackgroundColour(possible_color) if 'R' in possibleAA and self.Arg.GetValue() == False: self.Arg.SetBackgroundColour(possible_color) if 'H' in possibleAA and self.His.GetValue() == False: self.His.SetBackgroundColour(possible_color) if 'K' in possibleAA and self.Lys.GetValue() == False: self.Lys.SetBackgroundColour(possible_color) if 'C' in possibleAA and self.Cys.GetValue() == False: self.Cys.SetBackgroundColour(possible_color) if 'G' in possibleAA and self.Gly.GetValue() == False: self.Gly.SetBackgroundColour(possible_color) if 'P' in possibleAA and self.Pro.GetValue() == False: self.Pro.SetBackgroundColour(possible_color) #make list of all codons in degenerate triplet codonlist = dna.UnAmb(codon) #count how many times each AA is coded for by these codons self.AA_count = mbc.count_codon_list(codonlist) #plot graph self.update_plot() else: self.mixed_base_codon.SetReadOnly(False) self.mixed_base_codon.SetText('None') self.mixed_base_codon.SetReadOnly(True) self.target_hits.SetLabel('Target amino acids: ') self.offtarget_hits.SetLabel('Off-target amino acids: ') self.AA_count = {'A':0, 'C':0, 'E':0, 'D':0, 'G':0, 'F':0, 'I':0, 'H':0, 'K':0, 'M':0, 'L':0, 'N':0, 'Q':0, 'P':0, 'S':0, 'R':0, 'T':0, 'W':0, 'V':0, 'Y':0, 'stop':0} self.update_plot()
def Draw(self, dc): self.xc = self.size[0]/3 #centre of codon circle in x self.yc = self.size[1]/2 #centre of codon circle in y self.Radius = self.yc/1.2 target_color = '#CCFF66' possible_color = '#FFFF66' offtarget_color = '#FF9966' nucleotide_color = '#8B835F' coding_nucleotide_color = '#4B4424' #for coloring the nucleotides encoded by the ambigous codon line_color = '#8B835F' #for lines first_nucleotide_thickness = self.Radius/3 second_nucleotide_thickness = 2*(self.Radius/3)/3 third_nucleotide_thickness = 1*(self.Radius/3)/3 amino_acid_thickness = self.Radius/2.25 dc.SetBackground(wx.Brush("White")) dc.Clear() # make sure you clear the bitmap! gcdc = wx.GCDC(dc) gcdc.SetPen(wx.Pen(colour='#666666', width=0)) #make a hidden dc to which features can be drawn in uinique colors and later used for hittests self.hidden_dc = wx.MemoryDC() self.hidden_dc.SelectObject(wx.EmptyBitmap(self.ClientSize[0], self.ClientSize[1])) self.hidden_dc.SetBackground(wx.Brush("White")) self.hidden_dc.Clear() # make sure you clear the bitmap! #set up a dictionary to keep track of which color belongs to what object self.catalog = {} #for matching features with the unique colors self.catalog['(255, 255, 255, 255)'] = False #the background is white, have to add that key unique_color = (0,0,0) #draw reset button ## draw a reset button here ## #draw first nucleotide radius = first_nucleotide_thickness thickness = first_nucleotide_thickness font = wx.Font(pointSize=thickness/1.5, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_BOLD, weight=wx.FONTWEIGHT_BOLD) gcdc.SetFont(font) gcdc.SetBrush(wx.Brush("#ffe7ab")) nucleotides = ['U', 'C', 'A', 'G'] for i in range(len(nucleotides)): start_angle = 0 + 90*i finish_angle = 90+90*i pointlist = self.make_arc(self.xc, self.yc, start_angle, finish_angle, radius, thickness, step=5) gcdc.DrawPolygon(pointlist) x1, y1 = self.AngleToPoints(self.xc, self.yc, radius/2, finish_angle-(finish_angle-start_angle)/2) #if nucleotide is part of degenerate codon it should have a different color gcdc.SetTextForeground((nucleotide_color)) if self.codon is not False: if nucleotides[i].replace('U','T') in dna.UnAmb(self.codon[0]): gcdc.SetTextForeground((coding_nucleotide_color)) gcdc.DrawText(nucleotides[i], x1-radius/4, y1-radius/2.8) #draw second nucleotide radius = first_nucleotide_thickness+second_nucleotide_thickness thickness = second_nucleotide_thickness font = wx.Font(pointSize=thickness/2, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_BOLD, weight=wx.FONTWEIGHT_BOLD) gcdc.SetFont(font) gcdc.SetBrush(wx.Brush("#ffd976")) nucleotides = ['UU', 'UC', 'UA', 'UG','CU', 'CC', 'CA', 'CG','AU', 'AC', 'AA', 'AG', 'GU', 'GC', 'GA', 'GG'] for i in range(len(nucleotides)): start_angle = 0 + 22.5*i finish_angle = 22.5+22.5*i pointlist = self.make_arc(self.xc, self.yc, start_angle, finish_angle, radius, thickness, step=0.5) gcdc.DrawPolygon(pointlist) x1, y1 = self.AngleToPoints(self.xc, self.yc, radius/1.2, finish_angle-(finish_angle-start_angle)/2) #if nucleotide is part of degenerate codon it should have a different color gcdc.SetTextForeground((nucleotide_color)) if self.codon is not False: # print('first') # print('nuc', nucleotides[i].replace('U','T')) # print('cod', dna.UnAmb(self.codon[0:2])) if nucleotides[i].replace('U','T') in dna.UnAmb(self.codon[0:2]): gcdc.SetTextForeground((coding_nucleotide_color)) gcdc.DrawText(nucleotides[i][1], x1-radius/14, y1-radius/10) #draw third nucleotide radius = first_nucleotide_thickness+second_nucleotide_thickness+third_nucleotide_thickness thickness = third_nucleotide_thickness font = wx.Font(pointSize=thickness/2, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_BOLD, weight=wx.FONTWEIGHT_BOLD) gcdc.SetFont(font) gcdc.SetBrush(wx.Brush("#ffc700")) nucleotides = ['UUU', 'UUC', 'UUA', 'UUG','UCU', 'UCC', 'UCA', 'UCG','UAU', 'UAC', 'UAA', 'UAG', 'UGU', 'UGC', 'UGA', 'UGG',\ 'CUU', 'CUC', 'CUA', 'CUG','CCU', 'CCC', 'CCA', 'CCG','CAU', 'CAC', 'CAA', 'CAG', 'CGU', 'CGC', 'CGA', 'CGG',\ 'AUU', 'AUC', 'AUA', 'AUG','ACU', 'ACC', 'ACA', 'ACG','AAU', 'AAC', 'AAA', 'AAG', 'AGU', 'AGC', 'AGA', 'AGG',\ 'GUU', 'GUC', 'GUA', 'GUG','GCU', 'GCC', 'GCA', 'GCG','GAU', 'GAC', 'GAA', 'GAG', 'GGU', 'GGC', 'GGA', 'GGG'] for i in range(len(nucleotides)): start_angle = 0 + 5.625*i finish_angle = 5.625+5.625*i pointlist = self.make_arc(self.xc, self.yc, start_angle, finish_angle, radius, thickness, step=0.1) gcdc.DrawPolygon(pointlist) x1, y1 = self.AngleToPoints(self.xc, self.yc, radius/1.1, finish_angle-(finish_angle-start_angle)/2) #if nucleotide is part of degenerate codon it should have a different color gcdc.SetTextForeground((nucleotide_color)) if self.codon is not False: if nucleotides[i].replace('U','T') in dna.UnAmb(self.codon): gcdc.SetTextForeground((coding_nucleotide_color)) gcdc.DrawText(nucleotides[i][2], x1-radius/30, y1-radius/24) #draw amino acids radius = first_nucleotide_thickness+second_nucleotide_thickness+third_nucleotide_thickness+amino_acid_thickness thickness = amino_acid_thickness font = wx.Font(pointSize=third_nucleotide_thickness/2, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_NORMAL, weight=wx.FONTWEIGHT_NORMAL) gcdc.SetFont(font) gcdc.SetTextForeground(('#000000')) AA = ['F', 'L', 'S', 'Y', 'stop', 'C', 'stop2', 'W', 'L2', 'P', 'H', 'Q', 'R', 'I', 'M', 'T', 'N', 'K', 'S2', 'R2', 'V', 'A', 'D', 'E', 'G'] AA_width = {'F':2, 'L':2, 'S':4, 'Y':2, 'stop':2, 'C':2, 'stop2':1, 'W':1, 'L2':4, 'P':4, 'H':2, 'Q':2, 'R':4, 'I':3, 'M':1, 'T':4, 'N':2, 'K':2, 'S2':2, 'R2':2, 'V':4, 'A':4, 'D':2, 'E':2, 'G':4} AA_full = {'F':'Phenylalanine', 'L':'Leucine', 'S':'Serine', 'Y':'Tyrosine', 'stop':'Stop', 'C':'Cysteine', 'stop2':'Stop', 'W':'Tryptophan', 'L2':'Leucine', 'P':'Proline', 'H':'Histidine', 'Q':'Glutamine', 'R':'Arginine', 'I':'Isoleucine', 'M':'Methionine', 'T':'Threonine', 'N':'Asparagine', 'K':'Lysine', 'S2':'Serine', 'R2':'Arginine', 'V':'Valine', 'A':'Alanine', 'D':'Aspartic acid', 'E':'Glutamic acid', 'G':'Glycine'} finish_angle = 0 #basic draw of the amino acid segments and names for i in range(len(AA)): #draw the amino acid segments gcdc.SetPen(wx.Pen(colour='#666666', width=0)) if AA[i].replace('2','') in self.target: #if current AA is a selected one gcdc.SetBrush(wx.Brush(target_color)) elif AA[i].replace('2','') in self.offtarget: #if it is in the off-targets list gcdc.SetBrush(wx.Brush(offtarget_color)) elif AA[i].replace('2','') in self.possible: #if current AA is among the ones that may be selected without further off-targets gcdc.SetBrush(wx.Brush(possible_color)) else: #otherwise use standard color gcdc.SetBrush(wx.Brush("#fff2d1")) start_angle = finish_angle finish_angle = start_angle+5.625*AA_width[AA[i]] pointlist = self.make_arc(self.xc, self.yc, start_angle, finish_angle, radius, thickness, step=0.1) gcdc.DrawPolygon(pointlist) #draw hidden color which is used for hittests unique_color = self.GetNextRGB(unique_color) #get color for drawing unique colors on the hidden dc self.catalog[str(unique_color+(255,))] = AA[i] self.hidden_dc.SetPen(wx.Pen(colour=unique_color, width=0)) self.hidden_dc.SetBrush(wx.Brush(colour=unique_color)) self.hidden_dc.DrawPolygon(pointlist) #draw lines angle = start_angle gcdc.SetPen(wx.Pen(colour=line_color, width=1)) if angle in [0,90,180,270]: radius = 0 elif angle % 22.5 == 0: radius = first_nucleotide_thickness elif angle % 5.625 ==0: radius = first_nucleotide_thickness+second_nucleotide_thickness x1, y1 = self.AngleToPoints(self.xc, self.yc, radius, angle) radius = radius = first_nucleotide_thickness+second_nucleotide_thickness+third_nucleotide_thickness+amino_acid_thickness x2, y2 = self.AngleToPoints(self.xc, self.yc, radius, angle) gcdc.DrawLine(x1, y1, x2, y2) #draw text text_angle = finish_angle-(finish_angle-start_angle)/2 if finish_angle <= 180: text_extent = gcdc.GetTextExtent(AA_full[AA[i]]) text_radius = (first_nucleotide_thickness+second_nucleotide_thickness+third_nucleotide_thickness)*1.05 #need to adjust for text height. Imagine right angled triangle. Adjecent is radius. Opposite is half of the text height. Calculate tan angle. tanangle = (0.5*text_extent[1])/text_radius #calculate the Tan(angle) radians = math.atan(tanangle) #negate the Tin part and get radians degrees = radians*(180/math.pi) #convert radians to degrees text_position_angle = text_angle-degrees tx, ty = self.AngleToPoints(self.xc, self.yc, text_radius, text_position_angle) gcdc.DrawRotatedText(AA_full[AA[i]], tx, ty, -text_angle+90) else: text_extent = gcdc.GetTextExtent(AA_full[AA[i]]) text_radius = (first_nucleotide_thickness+second_nucleotide_thickness+third_nucleotide_thickness)*1.05 + text_extent[0] #need to adjust for text height. Imagine right angled triangle. Adjecent is radius. Opposite is half of the text height. Calculate tan angle. tanangle = (0.5*text_extent[1])/text_radius #calculate the Tan(angle) radians = math.atan(tanangle) #negate the Tin part and get radians degrees = radians*(180/math.pi) #convert radians to degrees text_position_angle = text_angle+degrees tx, ty = self.AngleToPoints(self.xc, self.yc, text_radius, text_position_angle) gcdc.DrawRotatedText(AA_full[AA[i]], tx, ty, -text_angle-90) #now draw the highlighted ones finish_angle = 0 gcdc.SetPen(wx.Pen(colour='#FF0000', width=1)) gcdc.SetBrush(wx.Brush(colour=(0,0,0,0))) for i in range(len(AA)): #if current AA is highlighted, redraw that segment with a different pen start_angle = finish_angle finish_angle = start_angle+5.625*AA_width[AA[i]] if AA[i].replace('2', '') == self.highlighted: #if highlighted AA is the current one pointlist = self.make_arc(self.xc, self.yc, start_angle, finish_angle, radius, thickness, step=0.1) gcdc.DrawPolygon(pointlist) #write what the ambigous codon is point_size = int(self.Radius/8) font = wx.Font(pointSize=point_size, family=wx.FONTFAMILY_SWISS, style=wx.ITALIC, weight=wx.FONTWEIGHT_NORMAL) gcdc.SetFont(font) gcdc.SetTextForeground((line_color)) x = self.size[0]*0.62 y = self.size[1]*0.1 text = 'Codon:' gcdc.DrawText(text, x, y) x = self.size[0]*0.75 point_size = int(self.Radius/6) font = wx.Font(pointSize=point_size, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_BOLD, weight=wx.FONTWEIGHT_BOLD) gcdc.SetFont(font) gcdc.SetTextForeground((coding_nucleotide_color)) if self.codon is False: text = '' else: text = self.codon gcdc.DrawText(text, x, y) #and the bases they code for if self.codon is not False: #get text position based on the ambigous codon first_x = x + gcdc.GetTextExtent(text[0:1])[0] - gcdc.GetTextExtent(text[0])[0]/2 second_x = x + gcdc.GetTextExtent(text[0:2])[0] - gcdc.GetTextExtent(text[1])[0]/2 third_x = x + gcdc.GetTextExtent(text[0:3])[0] - gcdc.GetTextExtent(text[2])[0]/2 start_y = y + gcdc.GetTextExtent(text[0])[1] #set new text size point_size = int(self.Radius/18) font = wx.Font(pointSize=point_size, family=wx.FONTFAMILY_SWISS, style=wx.FONTSTYLE_ITALIC, weight=wx.FONTWEIGHT_NORMAL) gcdc.SetFont(font) gcdc.SetTextForeground((coding_nucleotide_color)) first = dna.UnAmb(self.codon[0]) second = dna.UnAmb(self.codon[1]) third = dna.UnAmb(self.codon[2]) first_y = start_y for i in range(0, len(first)): text = first[i] #adjust for the size of that text pos_x = first_x - gcdc.GetTextExtent(text)[0]/2 gcdc.DrawText(text, pos_x, first_y) first_y += point_size second_y = start_y for i in range(0, len(second)): text = second[i] #adjust for the size of that text pos_x = second_x - gcdc.GetTextExtent(text)[0]/2 gcdc.DrawText(text, pos_x, second_y) second_y += point_size third_y = start_y for i in range(0, len(third)): text = third[i] #adjust for the size of that text pos_x = third_x - gcdc.GetTextExtent(text)[0]/2 gcdc.DrawText(text, pos_x, third_y) third_y += point_size #draw key width = self.Radius/16 height = self.Radius/16 point_size = int(self.Radius/20) font = wx.Font(pointSize=point_size, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_NORMAL, weight=wx.FONTWEIGHT_NORMAL) gcdc.SetFont(font) gcdc.SetTextForeground(('#666666')) #target key text = 'Target AA' x = 10 y = 10 gcdc.SetBrush(wx.Brush(target_color)) gcdc.SetPen(wx.Pen(colour='#666666', width=0)) gcdc.DrawRectangle(x, y, width, height) gcdc.DrawText(text, x+width*1.2, y) #possible key text = 'Possible AA' x = 10 y += point_size*1.5 gcdc.SetBrush(wx.Brush(possible_color)) gcdc.SetPen(wx.Pen(colour='#E6E65C', width=1)) gcdc.DrawRectangle(x, y, width, height) gcdc.DrawText(text, x+width*1.2, y) #possible key text = 'Off-target AA' x = 10 y += point_size*1.5 gcdc.SetBrush(wx.Brush(offtarget_color)) gcdc.SetPen(wx.Pen(colour='#666666', width=0)) gcdc.DrawRectangle(x, y, width, height) gcdc.DrawText(text, x+width*1.2, y) ## draw graph ## AA_order = ('A', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 'S', 'T', 'V', 'W', 'Y', 'stop') AA_full = {'F':'Phenylalanine', 'L':'Leucine', 'S':'Serine', 'Y':'Tyrosine', 'stop':'Stop', 'C':'Cysteine', 'stop2':'Stop', 'W':'Tryptophan', 'L2':'Leucine', 'P':'Proline', 'H':'Histidine', 'Q':'Glutamine', 'R':'Arginine', 'I':'Isoleucine', 'M':'Methionine', 'T':'Threonine', 'N':'Asparagine', 'K':'Lysine', 'S2':'Serine', 'R2':'Arginine', 'V':'Valine', 'A':'Alanine', 'D':'Aspartic acid', 'E':'Glutamic acid', 'G':'Glycine'} originx = self.size[0]*0.75 #centre of plot in x originy = self.size[1]*0.45 #centre of plot in y sizex = self.size[0]*0.2 sizey = self.size[1]*0.5 xspacing = sizex/7 yspacing = float(sizey)/float(21) tick_size = sizex/30 #draw background rectangle gcdc.SetBrush(wx.Brush("#fff2d1")) gcdc.SetPen(wx.Pen(colour=line_color, width=0)) gcdc.DrawRectangle(originx, originy, sizex, sizey) #frame gcdc.SetPen(wx.Pen(line_color)) gcdc.DrawLine(originx, originy, originx+sizex, originy) #top line... #DrawLine(self, x1, y1, x2, y2) gcdc.DrawLine(originx+sizex, originy, originx+sizex, originy+sizey) #right line gcdc.DrawLine(originx+sizex, originy+sizey, originx, originy+sizey) #bottom line gcdc.DrawLine(originx, originy+sizey, originx, originy) #left line #title point_size = int(sizex/12) font = wx.Font(pointSize=point_size, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_NORMAL, weight=wx.FONTWEIGHT_NORMAL) gcdc.SetFont(font) gcdc.SetTextForeground((line_color)) title = 'Codon count for each AA' gcdc.DrawText(title, originx, originy-gcdc.GetTextExtent(text)[1]*2) #y labels (amino acids) point_size = int(self.Radius/18) font = wx.Font(pointSize=point_size, family=wx.FONTFAMILY_SWISS, style=wx.FONTWEIGHT_NORMAL, weight=wx.FONTWEIGHT_NORMAL) gcdc.SetFont(font) gcdc.SetTextForeground((line_color)) for i in range(0, 21): amino_acid = AA_full[str(AA_order[i])] gcdc.DrawText(amino_acid, originx-gcdc.GetTextExtent(amino_acid)[0]-tick_size, originy+(yspacing*i)-gcdc.GetTextExtent(amino_acid)[1]/2+yspacing/2) #x labels (count) for i in range(1, 7): gcdc.DrawText(str(i), originx+xspacing*i-gcdc.GetTextExtent('6')[0]/2, originy-gcdc.GetTextExtent('6')[1]-tick_size/2) #x ticks # for i in range(1, 7): # gcdc.DrawLine(originx+(xspacing*i), originy, originx+(xspacing*i), originy+tick_size) # gcdc.DrawLine(originx+(xspacing*i), originy+sizey, originx+(xspacing*i), originy+sizey-tick_size) # #y ticks # for i in range(1, 22): # gcdc.DrawLine(originx, originy+(yspacing*i), originx+tick_size, originy+(yspacing*i)) # gcdc.DrawLine(originx+sizex, originy+(yspacing*i), originx+sizex-tick_size, originy+(yspacing*i)) #draw bars if self.codon is not False: self.AA_count = mbc.count_codon_list(dna.UnAmb(self.codon)) for i in range(0, 21): AA = AA_order[i] if AA in self.target: #if current AA is a selected one gcdc.SetBrush(wx.Brush(target_color)) elif AA in self.offtarget: #if it is in the off-targets list gcdc.SetBrush(wx.Brush(offtarget_color)) else: gcdc.SetBrush(wx.Brush('#666666')) count = self.AA_count[AA] gcdc.DrawRectangle(originx, originy+yspacing*i+yspacing*0.1, count*xspacing, yspacing*0.8) #(x, y, w, h)