Skip to content

Commit

Permalink
Merge pull request #38 from michaelmarty/v3
Browse files Browse the repository at this point in the history
Version 4.1.2
  • Loading branch information
michaelmarty authored Jan 21, 2020
2 parents e29690d + 825b8d6 commit 7c78c45
Show file tree
Hide file tree
Showing 26 changed files with 287 additions and 103 deletions.
2 changes: 1 addition & 1 deletion datacollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ def on_save(self, e):
dlg = wx.FileDialog(self, "Save Collection in JSON Format", self.directory, self.savename, "*.json")
if dlg.ShowModal() == wx.ID_OK:
self.savename = dlg.GetPath()
with open(self.savename, "w") as outfile:
with open(self.savename, "w+") as outfile:
json.dump(outdict, outfile)
print("Saved: ", self.savename)
dlg.Destroy()
Expand Down
2 changes: 2 additions & 0 deletions metaunidec/gui_elements/ud_menu_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,8 @@ def __init__(self, parent, config, pres):
self.experimentalmenu.AppendSeparator()
self.menulinreg = self.experimentalmenu.Append(wx.ID_ANY, "Linear Regression")
self.parent.Bind(wx.EVT_MENU, self.pres.on_linreg, self.menulinreg)
self.menusubdiv = self.experimentalmenu.Append(wx.ID_ANY, "Subtract and Divide")
self.parent.Bind(wx.EVT_MENU, self.pres.sub_div, self.menusubdiv)
#self.menuAdditionalParameters = self.experimentalmenu.Append(wx.ID_ANY, "Additional Parameters",
# "Adjust some experimental parameters")
# self.parent.Bind(wx.EVT_MENU, self.pres.on_additional_parameters, self.menuAdditionalParameters)
Expand Down
2 changes: 1 addition & 1 deletion metaunidec/mudeng.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def export_spectra(self, e=None):
outfile = self.config.outfname + "_" + str(s.var1) + ".txt"
np.savetxt(outfile, s.rawdata)
print(outfile)
self.config.config_export(self.config.outfname + "_config.dat")
self.config.config_export(self.config.outfname + "_conf.dat")

def batch_set_config(self, paths):
for p in paths:
Expand Down
4 changes: 2 additions & 2 deletions metaunidec/ultrameta.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ def on_save(self, e):
dlg = wx.FileDialog(self, "Save Collection in JSON Format", self.directory, self.savename, "*.json", wx.FD_SAVE)
if dlg.ShowModal() == wx.ID_OK:
self.savename = dlg.GetPath()
with open(self.savename, "w") as outfile:
with open(self.savename, "w+") as outfile:
json.dump(outdict, outfile)
print("Saved: ", self.savename)
dlg.Destroy()
Expand Down Expand Up @@ -461,7 +461,7 @@ def run_hdf5(self, path):
print("Error3: File Not Found:", path)
return
out = mudeng.metaunidec_call(self.config, "-ultraextract", path=path)
if out is not 0:
if out != 0:
self.SetStatusText("ERROR with File: " + path, number=2)
print("ERROR C: File", path, out)

Expand Down
10 changes: 10 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,16 @@ The main GUI class is GUniDec.UniDecApp.

## Change Log

v.4.1.2

**Added button in UniDec to turn off data normalization.** Note: the beta values will be automatically scaled to match this.

Renamed the parameter ZScore in the UniScore calculation to CSScore. Added R squared to the UniScore calculation.

Added several experimental subtract and divide features. Tweaks to linear regression experimental feature.

Bug fixes and compatibility updates.

v.4.1.1

Added right click feature to color peaks by their scores.
Expand Down
30 changes: 22 additions & 8 deletions unidec.py
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ def run_unidec(self, silent=False, efficiency=False):
if out == 0:
self.unidec_imports(efficiency)
if not silent:
print("File Name: ", self.config.filename, "R Sqaured: ", self.config.error)
print("File Name: ", self.config.filename, "R Squared: ", self.config.error)
return out
else:
print("UniDec Run Error:", out)
Expand Down Expand Up @@ -1177,7 +1177,7 @@ def pks_mscore(self, xfwhm=2, pow=2):
# print("Peak Mass:", p.mass, "Peak Shape Score", avg, p.mscore)
p.mscore = avg

def pks_zscore(self, xfwhm=2):
def pks_csscore(self, xfwhm=2):
try:
if len(self.pks.peaks[0].zstack) < 1:
self.get_zstack(xfwhm=xfwhm)
Expand Down Expand Up @@ -1219,8 +1219,8 @@ def pks_zscore(self, xfwhm=2):
else:
badarea += val - low

p.z_score = 1 - ud.safedivide1(badarea, zs)
# print(badarea, zs, p.z_score)
p.cs_score = 1 - ud.safedivide1(badarea, zs)
# print(badarea, zs, p.cs_score)

def get_mzstack(self, xfwhm=2):
zarr = np.reshape(self.data.mzgrid[:, 2], (len(self.data.data2), len(self.data.ztab)))
Expand Down Expand Up @@ -1344,6 +1344,15 @@ def pks_fscore(self):
fscore2 = self.score_minimum(height, umin)
# print("Fscore5", fscore2, umin, height)
p.fscore *= fscore2
'''
def tscore(self):
try:
tscore = 1 - np.sum(np.abs(self.data.fitdat - self.data.data2[:, 1])) / np.sum(self.data.data2[:, 1])
except Exception as e:
print("Error in Tscore: ", e)
tscore = 0
self.data.tscore = tscore
return tscore'''

def dscore(self, xfwhm=2, pow=2):
"""
Expand All @@ -1362,27 +1371,32 @@ def dscore(self, xfwhm=2, pow=2):

self.pks_mscore(xfwhm=xfwhm, pow=pow)
self.pks_uscore(pow=pow, xfwhm=xfwhm)
self.pks_zscore(xfwhm=xfwhm)
self.pks_csscore(xfwhm=xfwhm)
self.pks_fscore()
#self.tscore()
tscores = []
ints = []
for p in self.pks.peaks:
scores = np.array([p.mscore, p.uscore, p.z_score, p.fscore]) # p.rsquared,
scores = np.array([p.mscore, p.uscore, p.fscore, p.cs_score]) # p.rsquared,
p.dscore = np.product(scores)
p.lscore = np.product(scores[:-1])
tscores.append(p.dscore)
ints.append(p.height)
print("Mass:", p.mass,
"Peak Shape:", round(p.mscore * 100, 2),
"Uniqueness:", round(p.uscore * 100, 2),
# "Fitting R^2", round(p.rsquared * 100, 2),
"Charge:", round(p.z_score * 100, 2),
"Charge:", round(p.cs_score * 100, 2),
"FWHM:", round(p.fscore * 100, 2),
"Combined:", round(p.dscore * 100, 2))
# print(p.intervalFWHM)
ints = np.array(ints)
self.pks.uniscore = ud.weighted_avg(tscores, ints ** pow)
self.pks.uniscore = ud.weighted_avg(tscores, ints ** pow) * self.config.error
print("R Squared:", self.config.error)
#print("TScore:", self.data.tscore)
print("Average Peaks Score (UniScore):", self.pks.uniscore)


def filter_peaks(self, minscore=0.4):
# w = deepcopy(self.config.peakwindow)
# t = deepcopy(self.config.peakthresh)
Expand Down
1 change: 1 addition & 0 deletions unidec_bin/Example Data/ADH_unidecfiles/ADH_conf.dat
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ spectracmap rainbow
publicationmode 1
isotopemode 0
peaknorm 1
datanorm 1
baselineflag 1.0
orbimode 0
integratelb -1000.0
Expand Down
5 changes: 3 additions & 2 deletions unidec_bin/Example Data/BSA_unidecfiles/BSA_conf.dat
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ subbuff 0.0
subtype 2
smooth 0.0
mzbins 0.0
peakwindow 50.0
peakthresh 0.025
peakwindow 500.0
peakthresh 0.01
peakplotthresh 0.1
plotsep 0.025
intthresh 0.0
Expand All @@ -45,6 +45,7 @@ spectracmap rainbow
publicationmode 1
isotopemode 0
peaknorm 1
datanorm 1
baselineflag 1.0
orbimode 0
integratelb -1000.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mtabsig 0.0
minmz 10079.027219759617
maxmz 13777.256263028847
subbuff 0.0
subtype 0
subtype 2
smooth 0.0
mzbins 0.0
peakwindow 50000.0
Expand All @@ -45,6 +45,7 @@ spectracmap rainbow
publicationmode 1
isotopemode 0
peaknorm 1
datanorm 1
baselineflag 1.0
orbimode 0
integratelb -1000.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ massub 160000.0
masslb 80000.0
msig 1.0
molig 760.0
massbins 10.0
massbins 1.0
mtabsig 0.0
minmz 8761.430704083608
maxmz 12864.965623887581
Expand Down
Binary file modified unidec_bin/UniDec.exe
Binary file not shown.
Binary file modified unidec_bin/libiomp5md.dll
Binary file not shown.
16 changes: 16 additions & 0 deletions unidec_modules/gui_elements/ud_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@ def __init__(self, parent, config, pres, panel, iconfile):
gbox1b.Add(wx.StaticText(panel1b, label="Intensity Threshold: "), (i, 0), flag=wx.ALIGN_CENTER_VERTICAL)
i += 1



self.ctladductmass = wx.TextCtrl(panel1b, value='', size=size1)
gbox1b.Add(self.ctladductmass, (i, 1), span=(1, 1))
gbox1b.Add(wx.StaticText(panel1b, label="Adduct Mass (Da): "), (i, 0), flag=wx.ALIGN_CENTER_VERTICAL)
Expand All @@ -202,16 +204,27 @@ def __init__(self, parent, config, pres, panel, iconfile):
i += 1

if self.config.imflag == 0:


self.ctldatareductionpercent = wx.TextCtrl(panel1b, value="", size=size1)
gbox1b.Add(self.ctldatareductionpercent, (i, 1), span=(1, 1))
gbox1b.Add(wx.StaticText(panel1b, label="Data Reduction (%): "), (i, 0), flag=wx.ALIGN_CENTER_VERTICAL)
i += 1

self.ctldatanorm = wx.CheckBox(panel1b, label="Normalize Data")
self.ctldatanorm.SetValue(True)
gbox1b.Add(self.ctldatanorm, (i, 0), span=(1, 2))
i += 1

self.ctlbintype = wx.Choice(panel1b, -1, size=(240, 50),
choices=["Linear m/z (Constant " + '\N{GREEK CAPITAL LETTER DELTA}' + "m/z)",
"Linear resolution (Constant (m/z)/(" + '\N{GREEK CAPITAL LETTER DELTA}' + "m/z))",
"Nonlinear", "Linear Interpolated", "Linear Resolution Interpolated"])
gbox1b.Add(self.ctlbintype, (i, 0), span=(1, 2))
i += 1



else:
self.ctlconvertflag = wx.CheckBox(panel1b, label="Compress when converting to .txt")
self.ctlconvertflag.SetValue(True)
Expand Down Expand Up @@ -697,6 +710,7 @@ def import_config_to_gui(self):
self.ctlmanualassign.SetValue(self.config.manualfileflag)
self.ctlisotopemode.SetSelection(self.config.isotopemode)
self.ctlorbimode.SetValue(self.config.orbimode)
self.ctldatanorm.SetValue(self.config.datanorm)
self.ctlbintype.SetSelection(int(self.config.linflag))
self.ctlpsig.SetValue(str(self.config.psig))
self.ctlbeta.SetValue(str(self.config.beta))
Expand Down Expand Up @@ -827,6 +841,7 @@ def export_gui_to_config(self, e=None):
self.config.reductionpercent = ud.string_to_value(self.ctldatareductionpercent.GetValue())
self.config.isotopemode = int(self.ctlisotopemode.GetSelection())
self.config.orbimode = int(self.ctlorbimode.GetValue())
self.config.datanorm = int(self.ctldatanorm.GetValue())
self.config.psig = ud.string_to_value(self.ctlpsig.GetValue())
self.config.beta = ud.string_to_value(self.ctlbeta.GetValue())
self.config.manualfileflag = int(self.ctlmanualassign.GetValue())
Expand Down Expand Up @@ -957,6 +972,7 @@ def setup_tool_tips(self):
self.ctlminnativez.SetToolTip(wx.ToolTip("Minimum offset from a native charge state"))
self.ctlmaxnativez.SetToolTip(wx.ToolTip("Maximum offset from a native charge state"))
if self.config.imflag == 0:
self.ctldatanorm.SetToolTip(wx.ToolTip("Normalize Data and Results"))
self.ctldatareductionpercent.SetToolTip(
wx.ToolTip(
"Reduces the amount of data by removing everything below a threshold.\nSets the threshold to fit the percentage of data to remove."))
Expand Down
11 changes: 8 additions & 3 deletions unidec_modules/gui_elements/ud_menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ def __init__(self, parent, config, pres, tabbed):
self.experimentalmenu.AppendSeparator()
self.menuAdditionalParameters = self.experimentalmenu.Append(wx.ID_ANY, "Additional Parameters",
"Adjust some experimental parameters")

self.experimentalmenu.AppendSeparator()
self.menulinreg = self.experimentalmenu.Append(wx.ID_ANY, "Linear Regression")
self.parent.Bind(wx.EVT_MENU, self.pres.on_linreg, self.menulinreg)
self.menusubdiv = self.experimentalmenu.Append(wx.ID_ANY, "Subtract and Divide")
self.parent.Bind(wx.EVT_MENU, self.pres.sub_div, self.menusubdiv)

self.experimentalmenu.AppendSeparator()

self.menuscore1 = self.experimentalmenu.Append(wx.ID_ANY, "Show Peak Scores", "Show Peak Scores")
Expand Down Expand Up @@ -325,9 +332,7 @@ def __init__(self, parent, config, pres, tabbed):
self.menutheomass = self.experimentalmenu.Append(wx.ID_ANY, "Plot Theoretical Mass")
self.parent.Bind(wx.EVT_MENU, self.pres.plot_theo_mass, self.menutheomass)

self.experimentalmenu.AppendSeparator()
self.menulinreg = self.experimentalmenu.Append(wx.ID_ANY, "Linear Regression")
self.parent.Bind(wx.EVT_MENU, self.pres.on_linreg, self.menulinreg)


# self.menucentroid = self.experimentalmenu.Append(wx.ID_ANY, "Get Centroid at FWHM")
# self.parent.Bind(wx.EVT_MENU, self.pres.on_centroid, self.menucentroid)
Expand Down
8 changes: 4 additions & 4 deletions unidec_modules/isolated_packages/score_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def scr(score):


def scr2(p):
scores = [p.dscore, p.uscore, p.mscore, p.z_score, p.fscore]
scores = [p.dscore, p.uscore, p.mscore, p.cs_score, p.fscore]
strings = [scr(s) for s in scores]
out = ""
for s in strings:
Expand All @@ -40,7 +40,7 @@ def score_plots(eng):
plt.figure()
plt.subplot(131)
plt.title(
"Combined Score: " + str(round(p.dscore * 100, 2)) + "\nCharge Score: " + str(round(p.z_score * 100, 2))
"Combined Score: " + str(round(p.dscore * 100, 2)) + "\nCharge Score: " + str(round(p.cs_score * 100, 2))
)
plt.plot(ztab, sumz)
plt.plot(p.zdist[:, 0], p.zdist[:, 1], color="k")
Expand Down Expand Up @@ -147,7 +147,7 @@ def populate(self, pks):
l = len(pks.peaks)

collabels = ["Mass", "Intensity", "DScore", "Uniqueness/Fit", "Peak Shape",
"Charge Dist.", "FWHM Penalties"]
"Charge Dist.", "FWHM Penalties", "Limited Score (DScore without CSScore)"]

cl = len(collabels)
self.CreateGrid(l + 1, cl)
Expand All @@ -168,7 +168,7 @@ def populate(self, pks):
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.z_score, p.fscore]
scores = [p.dscore, p.uscore, p.mscore, p.cs_score, p.fscore, p.lscore]
scores = deepcopy(scores)
cindex = 2
for s in scores:
Expand Down
2 changes: 1 addition & 1 deletion unidec_modules/isolated_packages/texmaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def MakeTexReport(fname, config, path, peaks, labels, names, color, figureflags)
['$\\bigcirc$', '$\\bigtriangledown$', '$\\bigtriangleup$', '$\\triangleright$',
'$\\square$', '$\\lozenge$', '$\\bigstar$']]))

f = open(fname, 'w')
f = open(fname, 'w+')
f.write("\\documentclass{article}\n")
f.write("\\usepackage{graphicx}\n")
f.write("\\usepackage{amsmath}\n")
Expand Down
5 changes: 3 additions & 2 deletions unidec_modules/peakstructure.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,18 @@ def __init__(self):
self.mzstack = []
self.mscore = 0
self.uscore = 0
self.z_score = 0
self.cs_score = 0
self.rsquared = 0
self.fscore = 0
self.dscore = 0
self.lscore = 0
self.mdist = None
self.zdist = None

def line_out(self, type="Full"):
if type == "Full":
outputs = [self.mass, self.centroid, self.height, self.area, self.textmarker, self.match, self.matcherror,
self.integral, self.diff, self.avgcharge, self.dscore]
self.integral, self.diff, self.avgcharge, self.dscore, self.lscore]
elif type == "Basic":
outputs = [self.mass, self.height, self.integral]
else:
Expand Down
6 changes: 3 additions & 3 deletions unidec_modules/tims_import_wizard/data_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def auto_from_wizard(lines, exedir):
for index in mapper:
if l[index] == "None":
l[index] = None
if mapper[index] is not '':
if mapper[index] != '':
try:
parse[conv[mapper[index]]] = l[index]
except Exception as e:
Expand Down Expand Up @@ -201,7 +201,7 @@ def MakeUniDecConfig(job_kwargs):
else:
twaveflag = 1

f = open(filename, 'w')
f = open(filename, 'w+')
f.write("twaveflag " + str(twaveflag) + "\n")
f.write("mzbins " + str(job_kwargs[tt.BIN]) + "\n")
if job_kwargs[tt.PUSHER] is not None:
Expand Down Expand Up @@ -412,7 +412,7 @@ def parse_file(file_path, exp_type='linear', collision=None, debug=False, dir=No

out[tt.DRIFT_V] = search_extern(file_path, 'Transfer Collision Energy')

if out[tt.TYPE] is not 'ms':
if out[tt.TYPE] != 'ms':
# try to grab the pusher frequency from the stat code
# pusher = get_stat_code(file_path, 76, dir=exedir)
pusher = get_stat_name(file_path, "Transport RF")
Expand Down
Loading

0 comments on commit 7c78c45

Please sign in to comment.