def recolor(self): dataset = self.data try: colormap = cm.get_cmap(self.config.spectracmap, dataset.len) except: print("Failed to get spectra cmap", self.config) colormap = cm.get_cmap('rainbow', dataset.len) peakcolors = colormap(np.arange(dataset.len)) colors = peakcolors for i in range(0, dataset.len): s = dataset.spectra[i] index = int(s.index) # print(s.index, s.var1) if colors is not None: color = wx.Colour(int(round(colors[i][0] * 255)), int(round(colors[i][1] * 255)), int(round(colors[i][2] * 255)), alpha=255) self.SetItemBackgroundColour(index, col=color) luminance = ud.get_luminance(color, type=2) # print(wx.Colour(colout), luminance) if luminance < luminance_cutoff: self.SetItemTextColour(index, col=white_text) else: self.SetItemTextColour(index, col=black_text) s.color = colors[i] self.colors = colors
def populate(self, pks): self.ClearGrid() l = len(pks.peaks) collabels = [ "Mass", "Intensity", "DScore", "Uniqueness/Fit", "Peak Shape", "Charge Dist.", "FWHM Penalties", "Limited Score (DScore without CSScore)" ] cl = len(collabels) self.CreateGrid(l + 1, cl) w = 120 for i, c in enumerate(collabels): self.SetCellValue(0, i, c) self.SetColSize(i, width=w) self.SetCellFont( 0, i, wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) self.SetColSize(0, width=75) self.SetColSize(1, width=75) colormap = cm.get_cmap('RdYlGn') norm = Normalize(vmin=0, vmax=1) for index, p in enumerate(pks.peaks): i = index + 1 self.SetCellValue(i, 0, str(p.mass)) self.SetCellFont( i, 0, wx.Font(10, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL, wx.FONTWEIGHT_BOLD)) self.SetCellValue(i, 1, str(p.height)) scores = [ p.dscore, p.uscore, p.mscore, p.cs_score, p.fscore, p.lscore ] scores = deepcopy(scores) cindex = 2 for s in scores: self.SetCellValue(i, cindex, scr(s)) color = colormap(norm(s)) color = wx.Colour(int(round(color[0] * 255)), int(round(color[1] * 255)), int(round(color[2] * 255)), alpha=255) self.SetCellBackgroundColour(i, cindex, color) luminance = ud.get_luminance(color, type=2) if luminance < luminance_cutoff: self.SetCellTextColour(i, cindex, white_text) else: self.SetCellTextColour(i, cindex, black_text) cindex += 1
def on_popup_five(self, event=None): """ Spawns a dialog for the first selected item to select the color. Redraws the list control with the new colors and then triggers an EVT_DELETE_SELECTION_2. :param event: Unused Event :return: None """ # Change Color item = self.list_ctrl.GetFirstSelected() col = self.list_ctrl.GetItemBackgroundColour(item) print("Color In:", col) col = wx.Colour(int(col[0]), int(col[1]), int(col[2]), alpha=int(col.alpha)) col2 = wx.ColourData() col2.SetColour(col) colout = col2 dlg = wx.ColourDialog(None, data=col2) if dlg.ShowModal() == wx.ID_OK: coloutdlg = dlg.GetColourData() colout = deepcopy(coloutdlg.GetColour()) print("Color Out", colout) dlg.Destroy() else: dlg.Destroy() return topcolor = ([colout[0] / 255., colout[1] / 255., colout[2] / 255.]) self.list_ctrl.SetItemBackgroundColour(item, col=colout) luminance = ud.get_luminance(wx.Colour(colout), type=2) #print(wx.Colour(colout), luminance) if luminance < luminance_cutoff: self.list_ctrl.SetItemTextColour(item, col=white_text) else: self.list_ctrl.SetItemTextColour(item, col=black_text) peak = tofloat(self.list_ctrl.GetItem(item, col=1).GetText()) i = ud.nearest(self.pks.masses, peak) self.pks.peaks[i].color = topcolor num = self.list_ctrl.GetSelectedItemCount() for i in range(1, num): item = self.list_ctrl.GetNextSelected(item) self.list_ctrl.SetItemBackgroundColour(item, col=colout) if luminance < luminance_cutoff: self.list_ctrl.SetItemTextColour(item, col=white_text) else: self.list_ctrl.SetItemTextColour(item, col=black_text) peak = tofloat(self.list_ctrl.GetItem(item, col=1).GetText()) i = ud.nearest(self.pks.masses, peak) self.pks.peaks[i].color = topcolor newevent = wx.PyCommandEvent(self.EVT_DELETE_SELECTION_2._getEvtType(), self.GetId()) self.GetEventHandler().ProcessEvent(newevent)
def populate(self, dataset, colors=None): self.DeleteAllItems() try: colormap = cm.get_cmap(self.config.spectracmap, dataset.len) except: print("Failed to get spectra cmap", self.config) colormap = cm.get_cmap('rainbow', dataset.len) peakcolors = colormap(np.arange(dataset.len)) if colors is None: colors = peakcolors for i in range(0, dataset.len): s = dataset.spectra[i] index = self.InsertItem(dataset.len, str(s.index)) try: self.SetItem(index, 1, str(s.var1)) except: self.SetItem(index, 1, str(i)) try: self.SetItem(index, 2, str(s.var2)) except: self.SetItem(index, 2, str(0)) try: self.SetItem(index, 3, s.name) except: self.SetItem(index, 3, "") self.SetItemData(index, i) if colors is not None: color = wx.Colour(int(round(colors[i][0] * 255)), int(round(colors[i][1] * 255)), int(round(colors[i][2] * 255)), alpha=255) self.SetItemBackgroundColour(index, col=color) luminance = ud.get_luminance(color, type=2) # print(wx.Colour(colout), luminance) if luminance < luminance_cutoff: self.SetItemTextColour(index, col=white_text) else: self.SetItemTextColour(index, col=black_text) s.color = colors[i] self.data = dataset self.colors = colors self.rename_column(1, dataset.v1name) self.rename_column(2, dataset.v2name) self.freeze_reorder = False
def on_popup_seven(self, event=None): """ Spawns a dialog for the first selected item to select the color. Redraws the list control with the new colors and then triggers an EVT_DELETE_SELECTION_2. :param event: Unused Event :return: None """ # Change Color item = self.list.GetFirstSelected() col = self.list.GetItemBackgroundColour(item) print("Color In:", col) col = wx.Colour(int(col[0]), int(col[1]), int(col[2]), alpha=int(col.alpha)) col2 = wx.ColourData() col2.SetColour(col) colout = col2 dlg = wx.ColourDialog(None, data=col2) if dlg.ShowModal() == wx.ID_OK: colout = dlg.GetColourData() colout = deepcopy(colout.GetColour()) print("Color Out", colout) dlg.Destroy() self.list.SetItemBackgroundColour(item, col=colout) colout = colout.Get(includeAlpha=True) luminance = ud.get_luminance(wx.Colour(colout), type=2) colout = ([ colout[0] / 255., colout[1] / 255., colout[2] / 255., colout[3] / 255. ]) if luminance < luminance_cutoff: self.list.SetItemTextColour(item, col=white_text) else: self.list.SetItemTextColour(item, col=black_text) self.pres.on_color_change(item, colout)
def add_data(self, pks, show="area", collab1="Mass (Da)"): """ Add data from a Peaks object to the list_ctrl :param pks: Peaks object :param show: Keyword describing what to show in column 1 area = p.area integral = p.integral diff = p.diff :param collab1: Column 1 label :return: None """ self.list_ctrl.DeleteAllItems() self.pks = pks col = self.list_ctrl.GetColumn(3) if not self.meta: col.SetText("Area") if show == "avgcharge": col.SetText("Avg. Charge") if "score" in show: col.SetText("DScore") self.list_ctrl.SetColumn(3, col) self.list_ctrl.SetColumnWidth(3, 65) try: col = self.list_ctrl.GetColumn(1) col.SetText(collab1) self.list_ctrl.SetColumn(1, col) self.list_ctrl.SetColumnWidth(1, -2) except Exception as e: pass for i in range(0, self.pks.plen): p = pks.peaks[i] self.list_ctrl.InsertItem(i, p.textmarker) # self.list_ctrl.SetItem(i, 1, str(p.mass)) if p.mass == round(p.mass): p.mass = int(p.mass) self.list_ctrl.SetItem(i, 1, f'{p.mass:,}') else: self.list_ctrl.SetItem(i, 1, f'{float(str(p.mass)):,}') self.list_ctrl.SetItem(i, 2, "%.2f" % p.height) try: if show == "area": self.list_ctrl.SetItem(i, 3, str(p.area)) elif show == "integral": self.list_ctrl.SetItem(i, 3, "%.2f" % p.integral) elif show == "diff": self.list_ctrl.SetItem(i, 3, str(p.diff)) elif show == "avgcharge": self.list_ctrl.SetItem(i, 3, str(p.avgcharge)) elif show == "mscore": self.list_ctrl.SetItem(i, 3, str(np.round(p.mscore * 100, 2))) elif show == "dscore": self.list_ctrl.SetItem(i, 3, str(np.round(p.dscore * 100, 2))) else: self.list_ctrl.SetItem(i, 3, "") except (ValueError, AttributeError, TypeError): self.list_ctrl.SetItem(i, 3, "") self.list_ctrl.SetItem(i, 4, str(p.label)) self.list_ctrl.SetItemData(i, i) color = wx.Colour(int(round(p.color[0] * 255)), int(round(p.color[1] * 255)), int(round(p.color[2] * 255)), alpha=255) self.list_ctrl.SetItemBackgroundColour(i, col=color) # textcolor = wx.Colour(255 - color.Red(), 255 - color.Green(), 255-color.Blue()) #Inverted. Looks bad. luminance = ud.get_luminance(color, type=2) #print(color, luminance) if luminance < luminance_cutoff: self.list_ctrl.SetItemTextColour(i, col=white_text) self.remove = [] listmix.ColumnSorterMixin.__init__(self, 4)
def score_plots2(eng, save=False): import matplotlib.pyplot as plt from matplotlib import rcParams rcParams['ps.useafm'] = True rcParams['ps.fonttype'] = 42 rcParams['pdf.fonttype'] = 42 colormap = cm.get_cmap('RdYlGn') norm = Normalize(vmin=0, vmax=1) plt.rcParams.update({'font.size': 10}) fig = plt.figure(figsize=[4, 3]) p1 = plt.subplot(211) plt.plot(eng.data.data2[:, 0], eng.data.data2[:, 1] * 100, color="k") plt.xlabel("$\it{m/z}$") p1.get_yaxis().set_ticks([0, 50, 100]) p1.get_yaxis().set_ticklabels(["0", '%', "100"]) p1.spines['top'].set_visible(False) p1.spines['right'].set_visible(False) plt.ylim(0, 100) plt.xlim(np.amin(eng.data.data2[:, 0]), np.amax(eng.data.data2[:, 0])) p2 = plt.subplot(212) plt.plot(eng.data.massdat[:, 0] / 1000., eng.data.massdat[:, 1], color="k") plt.xlabel("Mass (kDa)") p2.get_yaxis().set_ticks([0, 50, 100]) p2.get_yaxis().set_ticklabels(["0", '%', "100"]) p2.spines['top'].set_visible(False) p2.spines['right'].set_visible(False) plt.ylim(0, 100) xmin = np.amin(eng.data.massdat[:, 0]) / 1000 xmax = np.amax(eng.data.massdat[:, 0]) / 1000 plt.xlim(xmin, xmax) offset = 0.2 * np.amax(eng.data.massdat[:, 1]) for k, p in enumerate(eng.pks.peaks): text = str(int(round(p.dscore * 100))) color = colormap(norm(p.dscore)) lum = ud.get_luminance(color) if lum > luminance_cutoff / 255.: #print(p.mass, lum, color) color = np.array(color) * 0.8 color[3] = 1 p2.text(p.mass / 1000., p.height + offset, text, horizontalalignment="center", verticalalignment="top", color=color) pass text = "UniScore=" + str(int(round(eng.pks.uniscore * 100))) color = colormap(norm(eng.pks.uniscore)) p2.text(xmax, 100, text, horizontalalignment="right", verticalalignment="top", color=color) plt.tight_layout() if save: fig.savefig("Fig1.pdf") fig.savefig("Fig1.png") # plt.show() return fig