Skip to content

Commit

Permalink
Merge pull request #34 from michaelmarty/v3
Browse files Browse the repository at this point in the history
V3
  • Loading branch information
michaelmarty authored Aug 29, 2019
2 parents a94086c + 02fdd37 commit 50dbdaa
Show file tree
Hide file tree
Showing 35 changed files with 1,969 additions and 760 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,7 @@ unidec_bin/Example Data/POPC_Nanodiscs_unidecfiles/POPC_Nanodiscs_Total_2D_Mass_
unidec_bin/Example Data/BSA_unidecfiles/BSA_chargedata.dat
unidec_bin/Example Data/BSA_unidecfiles/BSA_chargedata_areas.dat
unidec_bin/Example Data/BSA_unidecfiles/BSA_peakparam.dat
/__pycache__/
unidec_bin/Example Data/GroEL HCD UniDec_unidecfiles/GroEL HCD UniDec_peak_areas.dat


21 changes: 16 additions & 5 deletions GUniDec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import unidec_modules.IM_functions as IM_func
from unidec_modules import Extract2D, peakwidthtools, masstools, miscwindows, \
MassDefects, mainwindow, nativez, ManualSelectionWindow, AutocorrWindow, fft_window, GridDecon, isotopetools
from unidec_modules.isolated_packages import FileDialogs, texmaker
from unidec_modules.isolated_packages import FileDialogs, texmaker, score_window
import datacollector
import import_wizard
import unidec_modules.IM_windows as IM_wind
Expand Down Expand Up @@ -126,6 +126,8 @@ def on_open_file(self, filename, directory, skipengine=False, **kwargs):
:param skipengine: Boolean, Whether to skip running the engine (used when loading state)
:return: None
"""
# tstart =time.perf_counter()

# Clear other plots and panels
self.view.peakpanel.clear_list()
self.view.clear_all_plots()
Expand All @@ -145,6 +147,7 @@ def on_open_file(self, filename, directory, skipengine=False, **kwargs):
if self.eng.config.batchflag != 1:
self.view.controls.ctlminmz.SetValue(str(np.amin(self.eng.data.data2[:, 0])))
self.view.controls.ctlmaxmz.SetValue(str(np.amax(self.eng.data.data2[:, 0])))

# Plot 1D
if self.eng.config.batchflag == 0:
self.view.plot1.plotrefreshtop(self.eng.data.data2[:, 0], self.eng.data.data2[:, 1], "Data", "m/z",
Expand All @@ -156,17 +159,20 @@ def on_open_file(self, filename, directory, skipengine=False, **kwargs):
if self.eng.config.batchflag == 0:
self.view.plot1im.contourplot(self.eng.data.rawdata3, self.eng.config, xlab="m/z (Th)",
ylab="Arrival Time (ms)", title="IM-MS Data")
#tstart = time.perf_counter()
# Load Config to GUI
self.import_config()
self.view.SetStatusText("Ready", number=5)

#print("ImportConfig: %.2gs" % (time.perf_counter() - tstart))
if False:
try:
self.eng.unidec_imports(everything=True)
self.eng.unidec_imports(everything=False)
self.after_unidec_run()
except:
pass

#print("ImportData: %.2gs" % (time.perf_counter() - tstart))

def on_save_state(self, e=None, filenew=None):
"""
Saves the state by running self.eng.save_state. If no file is specified, opens a file dialog.
Expand Down Expand Up @@ -301,7 +307,7 @@ def on_paste_spectrum(self, e=None):
os.chdir(newdir)
np.savetxt(fname, data)
print("Saved Pasted Spectrum as File:", fname, " in directory:", newdir)
self.on_open_file(fname, newdir)
self.on_open_file(fname, newdir, pasted=True)
else:
print("Paste failed, got: ", data)
except Exception as e:
Expand All @@ -324,6 +330,7 @@ def on_dataprep_button(self, e=None):
self.view.SetStatusText("Data Prep", number=5)
self.export_config(self.eng.config.confname)
self.eng.process_data()
self.eng.get_auto_peak_width(set=False)
self.import_config()
self.view.clear_all_plots()
self.view.plot1.plotrefreshtop(self.eng.data.data2[:, 0], self.eng.data.data2[:, 1], "Data Sent to UniDec",
Expand All @@ -343,7 +350,7 @@ def on_dataprep_button(self, e=None):
self.view.SetStatusText("R\u00B2 ", number=3)
self.view.SetStatusText("Data Prep Done", number=5)
tend = time.perf_counter()
# print "Data Prep Done. Time: %.2gs" % (tend - tstart)
print("Data Prep Done. Time: %.2gs" % (tend - tstart))
pass

def on_unidec_button(self, e=None):
Expand Down Expand Up @@ -491,6 +498,7 @@ def makeplot1(self, e=None):
"m/z (Th)", "Normalized Intensity", "Data", self.eng.config, nopaint=True)
try:
self.view.plot1.plotadd(self.eng.data.data2[:, 0], self.eng.data.fitdat, 'red', "Fit Data")
pass
except:
pass
if self.eng.config.aggressiveflag != 0 and len(self.eng.data.baseline) == len(self.eng.data.fitdat):
Expand Down Expand Up @@ -1658,6 +1666,9 @@ def on_score2(self, e=0):
self.on_score_window()

def on_score_window(self, e=0):
self.on_score()
sw = score_window.ScoreFrame(self.view)
sw.populate(self.eng.pks)
pass

# def on_remove_noise_points(self, e=0):
Expand Down
61 changes: 54 additions & 7 deletions metaunidec/gui_elements/list_ctrls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@


class YValueListCtrl(wx.ListCtrl, listmix.ListCtrlAutoWidthMixin, listmix.TextEditMixin):
def __init__(self, parent, id_value, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
def __init__(self, parent, id_value, config=None, pos=wx.DefaultPosition, size=wx.DefaultSize, style=0):
wx.ListCtrl.__init__(self, parent, id_value, pos, size, style)
listmix.ListCtrlAutoWidthMixin.__init__(self)
listmix.TextEditMixin.__init__(self)
self.config = config
self.InsertColumn(0, "Index")
self.InsertColumn(1, "Variable 1")
self.InsertColumn(2, "Variable 2")
Expand All @@ -28,10 +29,16 @@ def __init__(self, parent, id_value, pos=wx.DefaultPosition, size=wx.DefaultSize
self.SetColumnWidth(1, width=75)
self.SetColumnWidth(2, width=75)
self.SetColumnWidth(3, width=75)
self.freeze_reorder = False
self.parent = parent

def populate(self, dataset, colors=None):
self.DeleteAllItems()
colormap = cm.get_cmap('rainbow', dataset.len)
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
Expand Down Expand Up @@ -69,9 +76,38 @@ def populate(self, dataset, colors=None):
self.colors = colors
self.rename_column(1, dataset.v1name)
self.rename_column(2, dataset.v2name)
self.freeze_reorder = False

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 clear_list(self):
self.DeleteAllItems()
self.freeze_reorder = False

def add_line(self, var1="count", var2=0):
if var1 == "count":
Expand All @@ -83,8 +119,8 @@ def add_line(self, var1="count", var2=0):

def get_list(self):
count = self.GetItemCount()
#colormap = cm.get_cmap('rainbow', count)
#peakcolors = colormap(np.arange(count))
# colormap = cm.get_cmap('rainbow', count)
# peakcolors = colormap(np.arange(count))
peakcolors = self.get_colors()
list_output = []
for i in range(0, count):
Expand All @@ -105,11 +141,12 @@ def get_list(self):
list_output.append(sublist)

indexes = np.array([i[0] for i in list_output])
if np.any(indexes != np.arange(0, len(list_output))):
if np.any(indexes != np.arange(0, len(list_output))) and not self.freeze_reorder:
list_output = self.reorder(list_output)
return list_output

def reorder(self, list):
print("Reordering...")
newlist = []
indexes = np.array([i[0] for i in list])
sind = np.sort(indexes)
Expand All @@ -122,10 +159,12 @@ def reorder(self, list):
newlist.append(list[index])
self.data.spectra = newspectra
self.repopulate()
self.parent.pres.eng.data.export_hdf5()
return newlist

def repopulate(self):
self.populate(self.data, self.colors)
self.freeze_reorder = False
pass

def rename_column(self, num, text):
Expand All @@ -148,9 +187,10 @@ def __init__(self, parent, pres, size=(200, 400)):
id_value = wx.ID_ANY
self.selection = []
self.pres = pres
self.config = self.pres.eng.config
sizer = wx.BoxSizer(wx.VERTICAL)

self.list = YValueListCtrl(self, id_value, size=size, style=wx.LC_REPORT | wx.BORDER_NONE)
self.list = YValueListCtrl(self, id_value, config=self.config, size=size, style=wx.LC_REPORT | wx.BORDER_NONE)

sizer.Add(self.list, 1, wx.EXPAND)
self.SetSizer(sizer)
Expand Down Expand Up @@ -233,8 +273,13 @@ def on_popup_four(self, event):
self.selection.append(item)
for i in range(0, num):
self.list.DeleteItem(self.selection[num - i - 1])
self.list.freeze_reorder = True
self.pres.on_ignore(self.selection)

if self.list.GetItemCount() < 1:
print("Ignored everything; repopulating...")
self.on_popup_six()

def on_popup_five(self, event):
item = self.list.GetFirstSelected()
num = self.list.GetSelectedItemCount()
Expand All @@ -247,9 +292,11 @@ def on_popup_five(self, event):
for i in range(tot - 1, -1, -1):
if not np.any(np.array(self.selection) == i):
self.list.DeleteItem(i)
self.list.freeze_reorder = True
self.pres.on_isolate(self.selection)

def on_popup_six(self, event):
def on_popup_six(self, event=None):
self.list.get_list()
self.list.repopulate()
self.pres.on_repopulate()

Expand Down
Loading

0 comments on commit 50dbdaa

Please sign in to comment.