unidec package

Subpackages

Submodules

unidec.DataCollector module

class unidec.DataCollector.DCDropTarget(window)

Bases: FileDropTarget

OnDropFiles(x, y, filenames)

When files are dropped, either open a single file or run in batch.

class unidec.DataCollector.DataCollector(parent, title, config=None, pks=None, *args, **kwargs)

Bases: Frame

check_cmaps()
load(savename)
load_x_from_peaks(e)
make_grid_plots(e)
make_shade_plot(val, window, color)
makeplot2()
menu_fcmaps(event)
menu_xcmaps(event)
on_2dgrid(e)
on_absolute_path(e)
on_add_x(e)
on_add_y(e)
on_animate(e)
on_animate2(e)
on_autocorr(e)
on_choose_dir(e)
on_defect(e)
on_doubledec(e)
on_export(e)
on_fitting(e=None)
on_hdf5_open(e)
on_kd_fit(e)
on_load(e)
on_local_path(e)
on_motion(xpos, ypos)
on_msms_norm(e)
on_run(e=None, vals=None)
on_save(e)
on_save_fig(e)
on_save_figPDF(e)
on_ylabel(e)
open_hdf5(path)
shade_plots(e)
update_get(e)
update_set(e)
class unidec.DataCollector.ListCtrlPanel(parent, list_type='X', size=(200, 400))

Bases: Panel

on_popup_four(event)
on_popup_one(event)
on_popup_three(event)
on_popup_two(event)
on_right_click(event)
class unidec.DataCollector.XValueListCtrl(parent, id_value, pos=wx.Point(-1, -1), size=wx.Size(-1, -1), style=0)

Bases: ListCtrl, ListCtrlAutoWidthMixin, TextEditMixin

add_line(val=0)
clear_list()
get_list()
get_maxes()
populate(listctrldata, colors=None)
class unidec.DataCollector.YValueListCtrl(parent, id_value, pos=wx.Point(-1, -1), size=wx.Size(-1, -1), style=0)

Bases: ListCtrl, ListCtrlAutoWidthMixin, TextEditMixin

add_line(file_name='file.txt', var1='count', var2=0)
clear_list()
get_list(fcmap='rainbow')
populate(listctrldata, colors=None)

unidec.GUniDec module

class unidec.GUniDec.UniDecApp(*args, **kwargs)

Bases: UniDecPres

Main UniDec GUI Application. Presenter contains UniDec engine at self.eng and main GUI window at self.view

after_pick_peaks()
after_unidec_run()

Plots to make after running UniDec. :return: None

init(*args, **kwargs)

Initialize Engine and View. Load defaults. :param args: :param kwargs: :return:

make_cube_plot(event=None)

Make cube plots for IMMS. :param event: unused event :return: None

make_im_plots()

Make Ion Mobility plots (but not cube plots) :return: None

makeplot1(e=None, intthresh=False, imfit=True)

Plot data and fit in self.view.plot1 and optionally in plot1fit :param e: unused event :return: None

makeplot6(e=None, show='height')

Plots bar chart of peak heights or areas in self.view.plot6. :param e: unused event :param show: What parameter to plot “height” will plot p.height for p in self.eng.pks.peaks “integral” will plot p.integral :return: None

on_2d_grid(e=None)

Opens 2D grid extraction window. Grid extraction parameters are stored at self.eng.config.gridparams. :param e: unused event :return: None

on_additional_parameters(e=None)

Open additional data parameter window, which hads some of the experimental and obscure variables. Window directly modifies self.eng.config. Saves config to file after window is closed. :param e: unused event :return: None

on_auto(e=None)

Prepare data, run unidec, and pick peaks. :param e: unused space for event :return: None

on_autoformat(e=None)
on_batch(e=None, flag=0, batchfiles=None)

Batch processing! Spawns a directory to select multiple files. Feeds the file names into a loop that: Opens the file (self.on_open_file) Prepares the data (self.on_dataprep_button) Runs UniDec (self.unidec_button) Picks Peaks (self.on_pick_peaks) Exports Peak Parameters (self.on_export_params) Saves State (self.on_save_state) If uses self.eng.config.batchflag to prevent certain things from plotting and all key parameters from changing. If batchflag is 2 (flag=1), all key paramters are kept, but the data ranges are refreshed from the individual files. :param e: event passed to some function (unused) :param flag: flag added to self.eng.config.batchflag :param batchfiles: List of files to run in batch. If None, will open dialog. :return:

on_batch2(e=None)

Runs batch processing without restricting the data ranges. The date range can be set ahead of time and will update independently for each file. Other parameters are fixed for the whole batch. :param e: unused event passed to self.on_batch :return: None

on_batch_raw(e=None, dirs=None, clip=True)

Batch process Waters .Raw files into .txt files. Opens a multiple directory dialog and then sends the results to self.eng.raw_process :param e: unused event :return: None

on_calibrate(e=None)
on_center_of_mass(e=None)

Determines the center of mass for the region zoomed on plot2. Get limits from plot2. Get Center of Mass from self.eng.center_of_mass Reports these as text on plot2. :param e: :return:

on_charge_plot(e=None)

Change peaks and plots so that the total charge distribution is plotted in plot2. Picks new peaks as each charge state and updates peakpanel. :param e: unused event :return: None

on_color_plot1d(e=None, filled=False)
on_data_collector(e=None)

Spawns separate DataCollector window. :param e: unused event :return: None

on_dataprep_button(e=None)

Prepares data. Runs eng.process_data() and then updates and plots in view :param e: unused space for event :return: None

on_delete(e=None)

Triggered on deletion or modification of selection in self.view.peakpanel. Replots everything with peaks involved to reflect ignored peaks. :param e: unused event :return: None

on_ex(e=0, pos=1)
on_export_params(e=None)

Runs self.eng.export_params(), which gets critical peak parameters and writes them to a file. :param e: event or arguments passed to self.eng.export_params() :return: None

on_fft_window(e)
on_file_name(e=None)

Opens window with default file names in it. Possible to tweak default paths here, but probably dangerous. :param e: unused event :return: None

on_fit_masses(e=None)

Using the peaks as a starting guess, it will fit the zero-charge mass spectrum to a set of overlapping peaks. Gets guesses using self.on_export_params() Calls self.eng.fit_all_masses() Then, plots resulting fit. Updates peakpanel to reflect normalized peak area based on fits. Export parameters from fit using self.on_export_params() and sending the “PostFit” argument :param e: event or argument passed to self.on_export_params :return: None

on_flip_mode(e=None)

Flips between MS and IM-MS mode :param e: wx event or anything (will flip if not 0) :return: None

on_flip_tabbed(e)

Flips between tabbed plots and a single window of plots :param e: wx Event or anything (will flip if not 0) :return: None

on_flip_twave(e)

Flips between T-Wave and Linear IM-MS :param e: wx Event or anything (will get value from Selection if not 0) :return: None

on_full(e=None)
on_gen_html_report(e=None)

Generates an HTML report of the current data and parameters. :param e: unused event :return: None

on_grid_decon(e)
on_iFAMS(e=None)
on_im_extract(e=None)

Open IM extraction window for extracting data from IM plots. Has to run unidec again with self.eng.config.zout=-1, which causes the export of all charge state slices of mass vs ccs plots. Normally only the faces of the mass vs ccs vs charge cube are output. :param e: unused event :return: None

on_im_tools(e=None)

Open IM Parameters tool window for guessing at IM parameters. :param e: unused event :return: None

on_import_wizard(e=None)

Opens Import Wizard for extreme file conversion. :param e: unused event :return: None

on_integrate(plot=True, filled=True)

Triggered by right click on plot2. Integrates peaks. If plot2 is zoomed out, it will use self.eng.autointegrate() to integrate the peaks. If plot2 is zoomed in to a single peak, the integral for that peak is recalculated from the plot limits. If plot2 is zoomed in to more than one peak, the integral is not set for a single peak but simply printed on the plot :param plot: Boolean, whether to add filled areas to plot. :return: None

on_kendrick(e=None)

Opens Kendrick Mass Defect Analysis window. :param e: unused event :return: None

on_label_avg_charge_states(e)
on_label_max_charge_states(e)
on_left_click(xpos, ypos)

Triggered by pubsub from plot windows. Gets a m/z peak near the click, stores it, and waits for another click. When two clicks has been performed, it tries to calculate the mass from their m/z value. :param xpos: x position fed from event :param ypos: y position fed from event :return: None

on_load_everything(e=None)
on_load_state(e=None, filenew=None)

Loads a saved file state by running self.eng.load_state and then updating self.view. Runs several engine components rather than importing. :param e: unused space for event :return: None

on_mass_process(e=None)

Updates config from the GUI, processes the zero-charge mass spectrum with the same parameters used for the raw data, then replots the zero-charge mass spectrum. :param e: unused event :return: None

on_mass_tools(e=None, show=True)

Opens masstools window. If a match was performed, it will update plot 6 and the peak panel. If the user decides to use simulated masses, it will make plot these new peaks. :param e: unused event :param show: Whether to thow the window (True) or simply match and return (False) :return: None

on_mql(e=None)
on_nativez_tools(e=None)

Opens Native Charge State analysis tools window. Parameters are stored in self.eng.config.zoffs. :param e: unused event :return: None

on_navia(e=None)
on_open(e=None)

Open dialog for file opening :param e: unused space for event :return: None

on_open_file(filename, directory, skipengine=False, refresh=False, **kwargs)

Opens a file. Run self.eng.open_file. :param filename: File name :param directory: Directory containing file :param skipengine: Boolean, Whether to skip running the engine (used when loading state) :return: None

on_open_kernel()

Opens a kernel file for use in DoubleDec deconvolution. :return: A string indicating the chosen file path

on_paste_spectrum(e=None)

Gets spectum from the clipboard, writes it to a new file, and then opens that new file. :param e: unused space for event :return: None

on_pdf_report(e=None)

Creates PDF report. First, writes figures to PDF. Then sends results to texmaker, which creates a .tex file. Finally, runs pdflatex as commandline subprocess to convert .tex to PDF. :param e: event passed to self.view.on_save_figur_pdf :return: None

on_pick_peaks(e=None)

Pick peaks and perform initial plots on them. :param e: unused space for event :return: None

on_plot_composite(e=None)

Plots a composite of isolated peaks that are selected. :param e: unused event :return: None

on_plot_isotope_distribution(e=0)
on_plot_nativeccs(e=None)

Plot native CCS as a red line on self.view.plot5mccs (mass vs ccs) plot. :param e: unused event :return: None

on_plot_offsets(e=None)

Transform the mass vs charge grid to a mass vs charge offset grid. Plot in self.view.plot5. :param e: unused event :return: None

on_plot_peaks(e=None)

Plots individual peaks as simulated spectra in plot 4. :param e: unused space for event :return: None

on_raw_open(e=None, dirname=None)

Opens a file dialog for opening a raw file. Runs self.eng.raw_process and then opens the processed file. :param e: unused space for event :return:

on_redo(e=None)
on_replot(e=None)

Refresh the parameters from the GUI and plot everything again with the new parameters. :param e: unused event :return: None

on_save_state(e=None, filenew=None)

Saves the state by running self.eng.save_state. If no file is specified, opens a file dialog. :param e: unused space for event :param filenew: Save state zip file name :return: None

on_score(e=0)
on_score2(e=0)
on_score_FDR(e=0)
on_score_label(e=0)
on_score_window(e=0)
on_smash()

Triggered by right click on plot1. Smashes the zoomed region to 0. Used to eliminate unwanted peaks. :return: None

on_super_batch(e=None)

Speedy, minimal batch procssing. Data must be processed in advance. Does not load file or process data. Simply writes the configuration with updated defaults to a conf.dat file. Then runs the conf.dat file with UniDec binary. Does not do any post processing. This function is useful for large data sets where you are using DataCollector or some other program to analyze the results outside of UniDec. It allows new parameters to be run with the maximum speed. :param e: unused event :return: None

on_undo(e=None)
on_unidec_button(e=None)

Runs UniDec, imports the results, and plots the output. :param e: unused space for event :return: None

on_unidec_path(e=None)

Opens file dialog to specify new UniDec binary. Only useful for advanced users or if something has gone horribly wrong. Modifies self.eng.config.UniDecPath and others. :param e: unused event :return: None

on_write_hdf5(e=None)
on_zerocharge_mass(e=None)

The old switcheroo. Takes the mass output and makes it the m/z input. Then changes some of the deconvolution parameters to reflect this. The reason for this type of function is to separate deconvolution from deisotoping when isotope mode is on. Deconvolution can be performed to generate a zero-charge mass spectrum, which can then be loaded as a new spectrum and deisotoped with isotope mode. Still a bit experimental… :param e: unused event :return: None

remake_mainwindow(tabbed=None)

unidec.ImportWizard module

class unidec.ImportWizard.ImportWizard(parent, dir=None)

Bases: Frame

add_file(evt)
auto(evt, file_path=None, filtered_lines=None)
close(evt)
export_file(evt)

Export import file for later import

export_then_load(evt)

save file then load it

get_folder_path(evt)

Get path to folder and place in txtctrl

on_folder_path_change(evt)
setup_frame()

unidec.Launcher module

class unidec.Launcher.Lview(parent)

Bases: Frame

button1(e=None)
button10(e=None)
button11(e=None)
button2(e=None)
button3(e=None)
button4(e=None)
button5(e=None)
button6(e=None)
button7(e=None)
button8(e=None)
button9(e=None)
class unidec.Launcher.Shell(*args, **kwargs)

Bases: object

class unidec.Launcher.UniDecLauncher(*args, **kwargs)

Bases: UniDecPres

Main UniDec GUI Application.

Presenter contains UniDec engine at self.eng and main GUI window at self.view

init(*args, **kwargs)
on_close(e=None)
unidec.Launcher.run_launcher(*args, **kwargs)

unidec.MetaUniDec module

class unidec.MetaUniDec.MetaUniDecBase(*args, **kwargs)

Bases: UniDecPres

Class for MetaUniDec functions that might want to be shared with UniChrom

export_vars()

Manual Test - Passed :return:

export_vars_dialog(e=None)

Manual Test - Passed :param e: :return:

import_vars(e=None)

Manual Test - Passed :param e: :return:

make2dplots(e=None)

Tested :param e: :return:

make_top(index=0)

Tested :param index: :return:

make_waterfall_plots(e=None)
makeplot1(e=None)

Tested :param e: :return:

makeplot2_mud(e=None)

Tested :param e: :return:

makeplot3()

Tested :return:

makeplot5()

Tested :return:

makeplot6(e=None, show=None)
makeplot7(fitgrid=None)

Tested :return:

makeplot8()
makeplot9(e=None)
on_2d_grid(e)

Manual test - Passed :param e: :return:

on_animate_2d(e=None, type='mass')

Manual Test - Passed :param e: :param type: :return:

on_animate_2d_mass(e=None)

Manual Test - Passed :param e: :return:

on_animate_2d_mz(e=None)

Manual Test - Passed :param e: :return:

on_animate_annotated_mass(e=None)

Manual Test - Passed :param e: :return:

on_animate_annotated_mz(e=None)
Returns:

on_animate_mass(e)

Manual Test - Passed :param e: :return:

on_animate_mz(e)

Manual Test - Passed :param e: :return:

on_auto(e=None)

Tested :param e: :return:

on_autocorr2(index)

Manual Test - Passed :param index: :return:

on_autocorr_window_mud(e=None)
on_charge_states_mud(e=None)
on_color_change(item, color)

Manual Test - Passed :param item: :param color: :return:

on_dataprep_button(e=None)

Tested :param e: :return:

on_delete_spectrum(indexes=None)

Tested :param indexes: :return:

on_export_params(e=None)

Runs self.eng.export_params(), which gets critical peak parameters and writes them to a file. Tested. :param e: event or arguments passed to self.eng.export_params() :return: None

on_fft_window(e)

Manual test - Passed :param e: :return:

on_fft_window2(index)

Manual Test - Passed :param index: :return:

on_filter_peaks_MUD(e=None)
on_full(e=None)
on_ignore(indexes)

Partly tested - Passed :param indexes: :return:

on_isolate(indexes)

Partly tested - Passed :param indexes: :return:

on_kendrick(e)

Manual Test - Passed :param e: :return:

on_mass_tools(e=None, show=True)

Opens masstools window. Manual Test - Passed

If a match was performed, it will update plot 6 and the peak panel. If the user decides to use simulated masses, it will make plot these new peaks. :param e: unused event :param show: Whether to thow the window (True) or simply match and return (False) :return: None

on_pick_peaks(e=None)

Tested :param e: :return:

on_pick_scanpeaks(e=None)
on_plot_composite(e=None)

Tested :param e: :return:

on_redo(e=None)

Manual Test :param e: :return:

on_repopulate()

Partly tested - Passed :return:

on_undo(e=None)

Manual Test :param e: :return:

on_unidec_button(e=None)

Tested :param e: :return:

plot_sums()

Tested :return:

recolor_spectra()
recursive_repack_hdf5(e=None)
rename_var1(e=None)

Manual Test - Passed :param e: :return:

rename_var2(e=None)

Manual Test - Passed :param e: :return:

repack_hdf5(e=None)
class unidec.MetaUniDec.UniDecApp(*args, **kwargs)

Bases: MetaUniDecBase

Main UniDec GUI Application.

Presenter contains UniDec engine at self.eng and main GUI window at self.view

add_files(paths)

Tested :param paths: :return:

init(*args, **kwargs)

Initialize Engine and View. Load defaults. Tested :param args: :param kwargs: :return:

make_image_plot(e=None)
makeplot6(e=None, show='height')

Plots bar chart of peak heights or areas. Tested :param e: unused event :param show: What parameter to plot “height” will plot p.height for p in self.eng.pks.peaks “integral” will plot p.integral :return: None

makeplot8()

Tested :return:

makeplot9(e=None)

Tested :param e: :return:

new_file(path)

Tested :param path: :return:

on_add_file(e=None)

Manual Test - Passed :param e: :return:

on_additional_filters(e=None)
on_additional_parameters(e=None)

Open additional data parameter window, which hads some of the experimental and obscure variables. Window directly modifies self.eng.config. Saves config to file after window is closed. Manual Test - Unused :param e: unused event :return: None

on_additional_plotting(e=None)
on_animate_help(e=None)
on_auto_import_help(e=None)
on_auto_match_help(e=None)
on_autocorr_help(e=None)
on_autoformat(e=None)
on_baseline_help(e=None)
on_batch_config(e=None)

Manual Test :param e: :return:

on_batch_cre(e=None)

Manual Test :param e: :return:

on_batch_extract(e=None)

Manual Test :param e: :return:

on_batch_help(e=None)
on_batch_run(e=None)

Manual Test :param e: :return:

on_data_collector(e=None)

Spawns separate DataCollector window. Manual Test - Failed :param e: unused event :return: None

on_data_processing(e=None)
on_delete(e=None)

Manual test - Passed :param e: :return:

on_exp_fit(e=None)
on_fft_help(e=None)
on_fit(fit='sig')
on_flip_tabbed(e=None)

Flips between tabbed plots and a single window of plots - Tested :param e: wx Event or anything (will flip if not 0) :return: None

on_getting_started(e=None)
on_hdf5_to_imzml(e=None)
on_imaging_viewer(e=None)
on_import_multiple_scans(e)
on_import_multiple_times(e)

Manual Test - Passed 2 RAW’s, 2 mzml :param e: :return:

on_import_mzml(e)

Manual Test - Passed :param e: :return:

on_import_mzml_scans(e)

Manual Test - Passed :param e: :return:

on_import_window(e=None)
on_imzml_to_hdf5(e=None)
on_left_click(xpos, ypos)

Triggered by pubsub from plot windows. Gets a m/z peak near the click, stores it, and waits for another click. When two clicks has been performed, it tries to calculate the mass from their m/z value. Manual Test - Passed :param xpos: x position fed from event :param ypos: y position fed from event :return: None

on_lin_fit(e=None)
on_new_file(e=None)

Manual Test - Passed :param e: :return:

on_oligomer_help(e=None)
on_open(e)

Manual Test - Passed :param e: :return:

on_open_csv(e)
Parameters:

e

Returns:

on_paste_spectrum(e=None)

Manual Test - Passed :param e: :return:

on_peak_selection(e=None)
on_peak_width_tool_help(e=None)
on_peak_window(e=None)
on_plate_viewer(e=None)
on_plot_window(e=None)
on_presets_help(e=None)
on_replot(e=None, plotsums=True)

Tested :param e: :return:

on_sig_fit(e=None)
on_ultra_meta(e=None)

Spawns separate DataCollector window. Manual Test - Failed :param e: unused event :return: None

on_unidec_parameters(e=None)
on_wizard(e=None)
open_csv(path)
open_file(path=None)

Tested :param path: :return:

peak_plots(e=None)

Called when peaks are picked or changed

remake_mainwindow(tabbed=None)

Tested :param tabbed: :return:

unidec.UPP module

class unidec.UPP.HelpDlg(num=1, *args, **kw)

Bases: Frame

help_frame()
open_in_browser(event)
class unidec.UPP.MyFileDropTarget(window)

Bases: FileDropTarget

OnDropFiles(x, y, filenames)

When files are dropped, either open a single file or run in batch.

class unidec.UPP.UPPApp(nrows=2, ncolumns=2, title='UniDec Processing Pipeline')

Bases: Frame

add_files(paths)
clear_all(event=None)
color_columns()
get_from_gui()
load_file(filename)
load_to_gui()
on_add_files(event=None)
on_exit(event=None)
on_help_page(event=None)
on_hide_columns(event=None, reset=False)
on_hide_empty_columns(event=None)
on_hide_height_columns(event=None, reset=False)
on_hide_percent_columns(event=None, reset=False)
on_load_file(event)
on_open_all_html(event)
on_open_global_html(event)
on_open_unidec(event)
on_run(event=None)
on_run_selected(event=None, rows=None)
on_save_file(event)
open_results_file(event)
open_unidec(row)
reset_hidden_columns()
update_progress(i, total_n)

unidec.UniChrom module

class unidec.UniChrom.ChromApp(*args, **kwargs)

Bases: MetaUniDecBase

batch_run(paths)
export_selection(e=None)
get_from_gui()
init(*args, **kwargs)
load_to_gui()
make_selection(index=0)
makeplotc(e=None)
on_batch_chrom1(e=None)
on_batch_chrom_dirs(e=None)
on_chrom_peaks(e=None)
on_clear_spectra(e=None)
on_delete(e=None)
on_list_add(starts, ends)
on_manual_add(e=None)
on_open(e=None)

Open dialog for file opening :param e: unused space for event :return: None

on_open_dir(e=None)
on_open_file(filename, directory, time_range=None, refresh=False)
on_open_hdf5(e=None)

Open dialog for file opening :param e: unused space for event :return: None

on_open_ud(e=None)
on_pick_peaks_individual(e=None)
on_replot(e=None, plotsums=True)
on_selection(min, max, plot=True)
on_selection_event(event)
on_single_charge_states(e=None)
on_single_delete(e=None)
on_single_differences(e=None)
on_single_label_masses(e=None)
on_sliding_window(e=None)
on_timepart(e=None)
on_unidec_run(e=None)
open_file(path, skip_eng=False, batch=False, refresh=False)
open_hdf5_file(path)
peak_plots(e=None)
plot_chrom_shading(e=None)
plot_single_mass()
plot_single_mz(e=None)
plot_single_pks()
quick_auto(e=None)
select_all(e=None)
update_hdf5(export=True)

unidec.UniChromCD module

class unidec.UniChromCD.UniChromCDApp(*args, **kwargs)

Bases: UniDecCDApp

Main UniDec GUI Application. Presenter contains UniDec engine at self.eng and main GUI window at self.view

add_eic(mzrange, zrange, color='b', plot=True, sarray=None, label=None)

Add an EIC to the list of chromatograms. Plot the chromatograms. :param mzrange: M/z range :param zrange: charge range :param color: Color of the plot. Default blue. :param plot: Whether to plot the chromatograms. Default True. :param sarray: Swoop array. Default None. :param label: Label for the chromatogram. Default None. :return: None

add_mass_eic(massrange, zrange=None, color=None, label=None, plot=True, ccs=False)
export_arrays()

Export the chromatograms and HT kernel to text files. :return: None

init(*args, **kwargs)

Initialize Engine and View. Load defaults. :param args: :param kwargs: :return:

load_chroms(fname=None, array=None)

Load chromatograms from a text file. Add them to the list. Plot the chromatograms. :param fname: Input file name :param array: Input array. Not currently used, but could be used to load from a numpy array rather than file. :return: None

make_2d_plot(e=None, face=1)

Creates 2D plots of charge, m/z, or mass vs time. General 2D plot function called by others :param e: Unused event :param face: Which face to plot against time. 1=charge, 2=m/z, 3=mass :return: None

make_charge_time_2dplot(e=None)

Creates a 2D plot of charge vs time :param e: Unused event :return: None

make_cube_plot(e=None, mass=False)

Creates a cube plot of mass or m/z vs charge vs time. Trys both regular and HT if possible. :param e: Unused event :param mass: Flag to plot mass vs charge vs time. Default False, which plots m/z vs charge vs time. :return: None

make_mass_cube_plot(e=None)

Creates a cube plot of mass vs charge vs time :param e: Unused event :return: None

make_mass_time_2dplot(e=None)

Creates a 2D plot of mass vs time :param e: Unused event :return: None

make_mz_time_2dplot(e=None)

Creates a 2D plot of m/z vs time :param e: Unused event :return: None

make_tic_plot()

Make the TIC Plot :return: None

on_auto_set_ct(e=None)

Automatically set the cycle index based on the autocorrelation. :param e: Unused event :return: None

on_autocorr2(index)

Launch an autocorrelation window for a given chromatogram. :param index: Index of chromatogram in the list :return: None

on_dataprep_button(e=None)

Run data preparation. Makes the TIC and clears the chromatogram list. :param e: Unused event :return: None

on_export_arrays(e=None)

Export the chromatograms and HT kernel to text files. :param e: Unused event :return: None

on_ignore_repopulate(e=None)

Event triggered by updates to the chromatogram list. Repopulate the list based on adjusted ignore flags. :param e: Unused event :return: None

on_load_chroms(e=None)

Load chromatograms from a file. Triggered by a button. :param e: Unused event :return: None

on_open_file(filename, directory, path=None, refresh=False)

Opens a file. Run self.eng.open_file. :param filename: File name :param directory: Directory containing file :param path: Full path to file :param refresh: Refresh the data ranges from the file. Default False. :return: None

on_pick_peaks(e=None)

Pick peaks. Runs the peak picking algorithm. Adds Mass EIC beyond conventional UCD. :param e: event (unused) :return: None

on_plot_kernel(e=None)

Plot the HT kernel :param e: Unused event :return: None

on_replot(e=None)

Refresh the parameters from the GUI and plot everything again with the new parameters. :param e: unused event :return: None

on_replot_chrom(e=None)
on_run_all_ht(e=None)

Button to trigger running HT on all data. Runs run_all_ht. :param e: Unused event. :return: None

on_run_ccs(e=None)

Run CCS calculation. Runs run_ccs. :param e: Unused event :return: None

on_run_eic_ccs(e=None)
on_run_eic_ht(e=None)

Button to run EIC HT. Runs run_eic_ht on each EIC that is extracted. :param e: Unused event :return: None

on_run_tic_ht(e=None)

Button to run TIC HT. Runs run_tic_ht. :param e: Unused event :return: None

on_select_massz_range(e=None)
on_select_mzz_region(e=None)

Trigged by right click of m/z vs z 2D plot. Triggers EIC creation and HT if already setup. :param e: Unused event :return: None

on_select_swoop(e=None)
on_select_time_range(e=None)

Event triggered by a click on the TIC plot. Select a time range and create a 2D m/z vs z sum from that time range post-HT. :param e: Unused event :return: None

on_select_time_range_decon(e=None)

Event triggered by a click on the TIC plot. Select a time range and create a 2D m/z vs z sum from that time range post-HT. :param e: Unused event :return: None

plot_chromatograms(e=None, save=True)

Plot all chromatograms in the list. Add a box to the 2D plot if the chromatogram is an EIC. :param e: Unused event :param save: Whether to save the output to a text file. Default True :return: None

plot_mass_for_eic()

Plot the mass for the EICs. :return: None

run_all_ht()

Run HT on all data. Clears the chromatogram list. Runs HT on each data point. Plots chromatograms after adding extracted TIC*_HT. :return: None

run_all_mass_transform(e=None)

Button to trigger running mass transform on all data. Runs transform_stacks. Creates mass TICs. :param e: Unused event. :return: None

run_eic_ht(mzrange, zrange, color='b', sarray=None)

Function to generate and HT an EIC. Adds both to list. Plots chromatograms. :param mzrange: M/z range :param zrange: Charge range :param color: Color of plot. Default blue. :param sarray: Swoop array. Default None. :return: None

run_tic_ht()

Runs HT on the TIC. Clears the chromatogram list. Runs HT on TIC. Adds both to list. Plots chromatograms. :return: None

save_chroms()

Save the chromatograms to a text file. :return: None

select_ht_range(range=None, raw=False)

Select a time range and create a 2D m/z vs z sum from that time range post-HT. :param range: Time range to select. Default None, which should be all times :return: None

unidec.UniDecCD module

class unidec.UniDecCD.UniDecCDApp(*args, **kwargs)

Bases: UniDecApp

Main UniDecCD GUI Application. Presenter contains UniDecCD engine at self.eng and main GUI window at self.view

dataprep()
init(*args, **kwargs)

Initialize Engine and View. Load defaults. :param args: :param kwargs: :return:

make_mzmass_plot(e=None, discrete=True)
make_mzmass_plot_continuous(e=None)
makeplot1(e=None)

Plot data and fit in self.view.plot1 and optionally in plot1fit :param e: unused event :return: None

makeplot3(e=None)

Plot m/z vs charge data in 2D in self.view.plot3 :param e: unused event :param plot: Plot object. Default is None, which will set plot to self.view.plot3 :return: None

on_batch(e=None, flag=0, batchfiles=None)

Batch processing! Spawns a directory to select multiple files. Feeds the file names into a loop that: Opens the file (self.on_open_file) Prepares the data (self.on_dataprep_button) Runs UniDec (self.unidec_button) Picks Peaks (self.on_pick_peaks) Exports Peak Parameters (self.on_export_params) Saves State (self.on_save_state) If uses self.eng.config.batchflag to prevent certain things from plotting and all key parameters from changing. If batchflag is 2 (flag=1), all key paramters are kept, but the data ranges are refreshed from the individual files. :param e: event passed to some function (unused) :param flag: flag added to self.eng.config.batchflag :param batchfiles: List of files to run in batch. If None, will open dialog. :return:

on_calibrate(e=None)
on_compare(e=None)

Open dialog for file opening :param e: unused space for event :return: None

on_compare2(e=None)
on_compare_proc(e=None)
on_dataprep_button(e=None)

Prepares data. Runs eng.process_data() and then updates and plots in view :param e: unused space for event :return: None

on_exe_mode(exemode=True)
on_gen_html_report(e=None)

Generates an HTML report of the current data and parameters. :param e: unused event :return: None

on_open(e=None)

Open dialog for file opening :param e: unused space for event :return: None

on_open_cdms_file(filename, directory, path=None, refresh=False)

Opens a file. Run self.eng.open_file. :param filename: File name :param directory: Directory containing file :return: None

on_open_file(filename, directory, path=None, refresh=False)

Opens a file. Run self.eng.open_file. :param filename: File name :param directory: Directory containing file :param path: Full path to file :param refresh: Refresh the data ranges from the file. Default False. :return: None

on_peak_width_tool(e=None)

Open peak width tool window. After it has returned, update the GUI to reflect the new peak widths. :param e: unused event :return: None

on_pick_peaks(e=None)

Pick peaks and perform initial plots on them. :param e: unused space for event :return: None

on_refresh(e=None)
on_replot(e=None)

Refresh the parameters from the GUI and plot everything again with the new parameters. :param e: unused event :return: None

on_smash()

Triggered by right click on plot1. Smashes the zoomed region to 0. Used to eliminate unwanted peaks. :return: None

on_stori(e=None, dirname=None)
on_unidec_button(e=None)

Runs UniDec, imports the results, and plots the output. :param e: unused space for event :return: None

pick_peaks(e=None)

Pick peaks and perform initial plots on them. :param e: unused space for event :return: None

plotkernel(e=None)
plotnoise(e=None)
remake_mainwindow(tabbed=None)

unidec.batch module

class unidec.batch.UniDecBatchProcessor(parent=None)

Bases: object

get_file_path(row, use_converted=True)
get_mod_files(row)
get_tol(row)
open_all_html()
open_global_html()
run_correct_pair(row, pks=None)

Run Correct Pair workflow on a single row. This is the main function for running Correct Pair on a single pandas row. :param row: The row from the rundf to run Correct Pair on. :param pks: The peaks to use for Correct Pair. If None, use the peaks from the engine. :return: row: The updated row with Correct Pair results.

run_dar(row, pks=None)

Run DAR workflow on a single row. This is the main function for running DAR on a single pandas row. :param row: The row from the rundf to run DAR on. :param pks: The peaks to use for DAR. If None, use the peaks from the engine. :return: row: The updated row with DAR results.

run_df(df=None, decon=True, use_converted=True, interactive=False, write_html=True, write_xlsx=True, write_peaks=True)
run_file(file=None, decon=True, use_converted=True, interactive=False)
write_peaks(outfile=None)
write_xlsx(outfile=None)
unidec.batch.check_for_floatable(row, key)
unidec.batch.check_for_value(row, key, correcttypetuple)
unidec.batch.check_for_word_in_keys(df, word='Correct')
unidec.batch.find_file(fname, folder, use_converted=True)
unidec.batch.get_time_range(row)
unidec.batch.remove_columns(df, key)
unidec.batch.set_param_from_row(eng, row, dirname='')
unidec.batch.set_row_merge(topdf, subdf, indexes)

unidec.engine module

class unidec.engine.UniDec(*args, **kwargs)

Bases: UniDecEngine

autocorrelation(massdat=None)

Performs autocorrelation on mass data. Result is stored as self.data.autocorr. Picks peaks greater than 0 using peak detection parameters in config file. Peaks are stored as a peak structure at self.autopeaks

Param:

massdat Data on which to run autocorrelation. Default is None, in which case self.data.massdat is used.

Returns:

float. First peak in autocorrelation.

autointegrate(ztab=None)

Perform automatic integration of peaks.

If self.config.integrateup is empty, the upperbound becomes self.config.peakwindow. If self.config.integratelb is empty, the lowerbound becomes -self.config.peakwindow.

Integral range for each peak is set to peak.integralrange. Integral value is set to peak.integral.

If ztab parameter is set to a list of charge states, it will integrate the mass vs charge grid at each individual charge state. Otherwise, this is ignored. :param ztab: List of charge states (default = None) :return: zarea: P x Z array where P is the number of peaks and Z is the number of charge states. Each value of the array is the integral of peak P at charge state Z.

autorun(auto_peak_width=True, silent=False)
center_of_mass(data=None, limits=None)

Return the center of mass and weighted standard deviation for data within some limits. If data is None, self.data.massdat is used. If limits is None, the whole range is used. :param data: mass data to determine center of mass :param limits: limits to restrict the calculation :return: com, std (center of mass, weighted standard deviation)

convolve_peaks()

Convolve Peaks with Peak Shape :return: None

dscore(xfwhm=2, power=2)

Combined score should include:

  1. Fit to data -> Uniqueness Score

  2. Background -> Uniqueness Score

  3. Unique evidence for each peak -> Uniqueness Score

  4. Noise -> M Score

  5. Consistent peak shape -> M Score

  6. Charge state distribution -> Z_Score

  7. FWHM -> Penalties for poor FWHM

Returns:

estimate_FDR()
estimate_areas()
export_params(e=None, silent=False)

Export a number of different parameters about the peaks into different text files. :param e: if e is “PostFit”, it will output mass fit parameters as well :param silent: if True, it will not print the output file names :return: None

filter_peaks(minscore=0.4)
fit_all_masses()

Fit all masses to a series of peaks, with initial guesses defined by the peak parameters. :return: self.massfitdat, self.massfit (fit to data, fit parameters)

get_charge_peaks()

Determines total charge distribution. Imports each charge state as a peak in self.pks. Will overwrite mass peaks. :return: cpeaks (Z x 2 array of (charge state, intensity))

get_mzstack(xfwhm=2)
get_spectrum_peaks(threshold=0.05, window=None)
get_zstack(xfwhm=1)
kendrick_continuous(ref_mass=None, centermode=0, nbins=50, transformmode=0, xaxistype=1)

Runs continuous Kendrick analysis on self.data.massdat :param ref_mass: Kendrick mass. Default is self.config.kendrickmass if it is already set and >0. Otherwise, default is oligomer mass (self.config.molig) :param centermode: Set range for normalization 0=(0,1),1=(-0.5,0.5). Default is 0. :param nbins: Set mass defect axis density. Default is 50 bins. :param transformmode: Set type of transformation. 0=Interpolation. 1=Integration. Default is 0. :param xaxistype: Set x-axis dimensions. 0=Kendrick Mass Number, 1=Mass Number * Kendrick Mass. Default is 1. :return: mass grid, mass defect grid, intensity grid. All with shape (len(self.data.massdat),nbins)

kendrick_peaks(kmass=None, centermode=1)

Run Kendrick analysis on peaks (self.pks object) :param kmass: Kendrick mass. Default is prior kendrick mass if it exists and is >0. Otherwise, default is oligomer mass (self.config.molig) :param centermode: Set range for normalization 1=(0,1),0=(-0.5,0.5) :return: Array of [mass,defect] for each peak in self.pks.

label_plot_correct(ax, matches)
load_state(load_path)

Load unidec state from a zip save file.

Note: save_state is located under unidectools (ud.savestate) :param load_path: .zip file to load :return: True is successful, False if failed

make_plot(massrange=None, autorange=True, show=True)
makeplot1(plot=None, intthresh=False, imfit=True, config=None)

Plot data and fit in self.view.plot1 and optionally in plot1fit :param plot: plot to use :param intthresh: if True, plot intensity threshold :param imfit: if True, plot IM fit :param config: config to use, default is self.config :return: plot object

makeplot1im(plot1im=None, plot1fit=None, imfit=False)
mass_grid_to_f_grid()

Convert the mass vs charge grid to a mass vs charge offset grid.

Calculates the charge offset for each (mass,charge) point, creates a new axis of regularly spaced charge offsets (oaxis), and the interpolates a new grid of (mass, offset) from oaxis, which is output as outgrid. :return: oxais, outgrid: offset axis (N) and offset grid (M x N)

normalize_peaks()

Noamlize everything in the peaks accoring to the type set in self.config.peaknorm 0 = No normalization 1 = Normalize the max value to 1 2 = Normalize the sum to 1 :return: None

open_file(file_name, file_directory=None, time_range=None, refresh=False, load_results=False, *args, **kwargs)

Open text or mzML file. Will create _unidecfiles directory if it does not exist.

If it finds a _conf.dat file in _unidecfiles, it will import the old configuration. Otherwise, it keeps the existing configuration but resets file names.

If silent=True is passed in kwargs, prints are suppressed. :param: file_name: Name of file to open. May be in x y or x y z text format or in mzML format. May be tab or space delimited :param file_directory: Directory in which filename is located. Default is current directory. If None, will get from file_name. :param time_range: Array or tuple of (start, end) times to load from data file. Default is to load all. :param refresh: If True, will refresh the data file even if it already exists. :param load_results: If True, will load the results from the _unidecfiles directory. :return: None

open_test_spectrum(masslist=None, n=1, **kwargs)
pass_data_in(data, n=1, dirname=None, fname=None, **kwargs)
pick_peaks(calc_dscore=True)

Detect, Normalize, and Output Peaks :return: None

pks_csscore(xfwhm=2)
pks_fscore()
pks_mscore(xfwhm=2, power=2)
pks_uscore(xfwhm=2, power=1)
process_data(**kwargs)

Process data according to parameters in config.

Checks certain parameters to make sure the limits make sense. Will accept silent=True kwarg to suppress printing. :return: None

process_mass_data()

Apply the same parameters used to process the data to process the mass distribution. Linearization parameters are ignored, but smoothing, baseline subtraction, normalization, and intensity threshold all apply. :return: None

raw_process(dirname, inflag=False, binsize=1)

Processes Water’s Raw files into .txt using external calls to: self.config.cdcreaderpath for IM-MS

MS is processed by modules.waters_importer.Importer

Default files are created with the header of the .raw file plus: _rawdata.txt for MS _imraw.txt for IM-MS :param dirname: .raw directory name :param inflag: If True, it will put the output .txt file inside the existing .raw directory. If False, it will put the file in the same directory that contains the .raw directory :param binsize: Parameter for IM-MS to specify the m/z bin size for conversion. If binsize=0, the conversion will be at full resolution (which is huge), so the default is every 1 m/z. :return: self.config.filename, self.config.dirname (name and location of created file)

run_unidec(silent=False, efficiency=False)

Runs unidec.

Checks that everything is set to go and then places external call to:

self.config.UniDecPath for MS self.config.UniDecIMPath for IM-MS

If successful, calls self.unidec_imports() If not, prints the error code. :param silent: If True, it will suppress printing the output from unidec :param efficiency: Passed to self.unidec_imports() :return: out (stdout from external unidec call)

save_state(file_name)
setup_peaks(peaks)
unidec_imports(efficiency=False, everything=False)

Imports files output from the unidec core executable into self.data. :param efficiency: If True, it will ignore the larger files to speed up the run. :param everything: If True, it will import all files, even the large ones. :return: None

unidec.engine.score_minimum(height, minimum)

unidec.tools module

unidec.tools.FD_gauss_wavelet(length, width)
unidec.tools.auto_noise_level(datatop, buffer=10)
unidec.tools.auto_peak_width(datatop, psfun=None, singlepeak=False)
unidec.tools.autocorr(datatop, config=None, window=10)

Note: ASSUMES LINEARIZED DATA :param datatop: 1D data :param config: Config file (optional file) :param window: Window for peak detection, default 10 data points :return: Autocorr spectrum, peaks in autocorrelation.

unidec.tools.average_bin_size(datatop)
unidec.tools.broaden(aligned)

Take a list of aligned peaks and broaden each so that they achieve maximum overlap with the broadest one. :param aligned: Array (N x M x 2). N is the number of peaks, M is the number of data points, 2 is (x,y) :return: combined, aligned: The combined total of all the aligned and broaded individual peaks.

unidec.tools.cal_data(datatop, poly_coeff=None)
unidec.tools.calc_FWHM(peak, data)
unidec.tools.calc_local_mins(data, w)
unidec.tools.calc_swoop(sarray, adduct_mass=1)
unidec.tools.cconv(a, b)

Circular convolution of two lists :param a: N-length array :param b: N-length array :return: Convolution

unidec.tools.center_of_mass(data, start=None, end=None, relative_cutoff=None, power=1.0)
unidec.tools.color_map_array(array, cmap, alpha)

For a specified array of values, map the intensity to a specified RGB color defined by cmap (output as topcm). For each color, create a color map where the color is constant but the transparency changes (output as cmarr). :param array: Values :param cmap: Color map :param alpha: Max Alpha value (transparency) [0,1] :return: cmarr, topcm (list of transparent color maps, list of RGB colors for array values)

unidec.tools.combine(array2)
unidec.tools.combine_all(array2)
unidec.tools.commonprefix(args)
unidec.tools.continuous_wavelet_transform(a, widths, wavelet_type='Ricker')

Perform a continuous wavelet transform at multiple widths. :param a: 1D numpy array of data (length N) :param widths: List of widths (length W) of transform defined with respect to the data points in a :param wavelet_type: Type of wavelet. Either “Ricker” (Mexican Hat) or “Morlet” (Gabor) :return: cwt_matrix (The continuous wavelet transform at the defined widths in a (W x N) array)

unidec.tools.conv_peak_shape_kernel(xaxis, psfun, fwhm)

Creation of an efficient peak shape kernel for circular convolutions.

Note: peak width must be in units of index not value of x-axis. To get this take fwhm/binsize. :param xaxis: Array of x axis values :param psfun: Integer

0=Gaussian 1=Lorentzian 2=Split Gaussian/Lorentzian

Parameters:

fwhm – Full width half max of peak (in units matching data indexes not values)

Returns:

Peak shape kernel centered at 0.

unidec.tools.correlation_integration(dat1, dat2, alpha=0.01, plot_corr=False, **kwargs)

Perform MacCoss method (https://pubs.acs.org/doi/pdf/10.1021/ac034790h) of getting peak intensities :param dat1: Denominator peak :param dat2: Numerator peak :param alpha: 1-confidence level :param plot_corr: Boolean flag, if True, will plot the results :param kwargs: keywords (unused dump) :return: slope, cierr, rsquared, slope_std_error * np.sqrt(n), pvalue slope of line (ratio of peak areas) cierr (confidence interval for error) rsquared (R squared value for linear fit) slope_std_error * np.sqrt(n) (standard deviation of slope fit) pvalue (probability that slope is nonzero)

unidec.tools.create_color_cycle(seq='bgrcmk')
unidec.tools.data_extract(data, x, extract_method, window=None, **kwargs)

Assumes a sorted array in data[:,0] :param data: :param x: :param extract_method: :param window: :return:

unidec.tools.data_extract_grid(data, xarray, extract_method=1, window=0)
unidec.tools.datachop(datatop, newmin, newmax)

Chops the range of the data. The [:,0] column of the data is the column that will be indexed. :param datatop: Data array :param newmin: Minimum value of chopped data :param newmax: Maximum value of chopped data :return: New data limited between the two bounds

unidec.tools.datacompsub(datatop, buff)

Complex background subtraction.

Taken from Massign Paper

First creates an array that matches the data but has the minimum value within a window of +/- buff. Then, smooths the minimum array with a Gaussian filter of width buff * 2 to form the background array. Finally, subtracts the background array from the data intensities.

Parameters:
  • datatop – Data array

  • buff – Width parameter

Returns:

Subtracted data

unidec.tools.dataexport(datatop, fname, header='')
unidec.tools.dataexportbin(datatop, fname)
unidec.tools.dataprep(datatop, config, peaks=True, intthresh=True, silent=False)

Main function to process 1D MS data. The order is:

Crop Data (datacrop) Correct for detector efficiency (detectoreff) Smooth (gsmooth) Remove duplicates (removeduplicates) Linearize (linearize or nonlinearize) Baseline subtraction (datasimpsub or datacompsub or simply data[:,1]-np.amin(data[:,1]) Normalization (normalize) Intensity Threshold with a threshold of 0 (intthresh)

Parameters:
  • datatop – Raw data array (N x 2)

  • config – UniDecConfig object

  • peaks – Boolean to perform peak detection

  • intthresh – Boolean to perform intensity thresholding

  • silent – Boolean to suppress output

Returns:

Processed data

unidec.tools.datasimpsub(datatop, buff)

Simple subtraction of a linear background.

The first n and last n data points are averaged. A line is drawn between the two averages. This line is then subtracted from the [:,1] column of the data. :param datatop: Data array (N x 2) (m/z, intensity) :param buff: Integer, n. :return: Subtracted data

unidec.tools.decimal_formatter(a, template)
unidec.tools.detectoreff(datatop, va)

Incorporate a model of TOF detector efficiency used by CHAMP to correct the intensity values. :param datatop: Data array (N x 2) :param va: TOF acceleration voltage in kV (I think…) :return: Detector corrected data (N x 2)

unidec.tools.double_fft_diff(mzdata, diffrange=None, binsize=0.1, pad=None, preprocessed=False)
unidec.tools.exe_call(call, silent=False)

Run the binary specified in the call. If silent is False (default), the output from exepath will be printed to the standard out. If silent is True, the output is suppressed.

Parameters:
  • call – Call arguments to be passed ot the shell

  • silent – Whether to print the output of exepath to the standard out

Returns:

Standard error of exepath execution

unidec.tools.extract_from_data_matrix(xaxis, matrix, midpoint, extract_method=0, window=0)
unidec.tools.fake_log(data, percent=50)
unidec.tools.fft(data, phases=False)
unidec.tools.fft_diff(data, diffrange=None)
unidec.tools.fft_process(mzdata, diffrange=None, binsize=0.1, pad=None, preprocessed=False)
unidec.tools.find_kernel_file(kernel_path)
unidec.tools.fix_double_zeros(processed_data, new_data)
unidec.tools.fix_textpos(pos, maxval)
unidec.tools.gaussian_backgroud_subtract(datatop, sig)
unidec.tools.get_color_from_index(index, seq='custom1')
unidec.tools.get_glyco_indexes(oligomerlist, printoutput=False)
unidec.tools.get_importer(path)
unidec.tools.get_luminance(color, type=2)
unidec.tools.get_max_time(path)
unidec.tools.get_polarity(path, importer=None)
unidec.tools.get_swoop_mz_minmax(mz, i)
unidec.tools.get_tvalue(dof, ci=0.99)

Get t-value for a given degrees of freedom and confidence interval :param dof: Degrees of freedom :param ci: Confidence interval level (default is 0.99, 99% confidence) :return: T value

unidec.tools.get_z_offset(mass, charge)

For a given mass and charge combination, calculate the charge offset parameter. :param mass: Mass in Da :param charge: Charge State :return: Difference between charge and predicted native charge of the mass

unidec.tools.get_zvalue(ci=0.99)

Get z-value for area under a Gaussian for a given confidence level :param ci: Confidence interval level (default is 0.99, 99% confidence) :return: Z-value

unidec.tools.gsmooth(datatop, sig)

Smooths the data with a Gaussian filter of width sig. :param datatop: Data array :param sig: Width of Gaussian Array :return: Smoothed Data

unidec.tools.header_test(path, deletechars=None, delimiter=' |\t', strip_end_space=True)

A quick test of a file to remove any problems from the header.

If scans through each line of an input file specificed by path and count the number of lines that cannot be completely converted to floats. It breaks the loop on the first hit that is entirely floats, so any header lines blow that will not be counted. :param path: Path of file to be scanned :param deletechars: Characters to be removed from the file before scanning :param delimiter: Delimiter to be used in the file :param strip_end_space: Boolean to strip the end space from the line :return: Integer length of the number of header lines

unidec.tools.index_to_oname(index, startindex, names)
unidec.tools.integrate(data, start, end)
unidec.tools.intensitythresh(datatop, thresh)

Sets an intensity threshold. Everything below the threshold is set to 0. :param datatop: Data array :param thresh: Threshold value :return: Thresholded array.

unidec.tools.intensitythresh_del(datatop, thresh)

Sets an intensity threshold. Everything below the threshold is set to 0. :param datatop: Data array :param thresh: Threshold value :return: Thresholded array.

unidec.tools.intensitythresh_sub(datatop, thresh)

Sets an intensity threshold. Everything below the threshold is set to 0. Everything else is subtracted by threshold. :param datatop: Data array :param thresh: Threshold value :return: Thresholded array.

unidec.tools.interp_pos(array, target)

On a given array, interpolate the position of the target :param array: Array :param target: Value :return: Interpolated index of value in array.

unidec.tools.interp_val(data, target)

On a given array, interpolate the value of the target :param data: data array :param target: Value :return: Interpolated index of value in array.

unidec.tools.isempty(thing)

Checks wether the thing, a list or array, is empty :param thing: Object to check :return: Boolean, True if not empty

unidec.tools.kendrick_analysis(massdat, kendrickmass, centermode=1, nbins=50, transformmode=1, xaxistype=1, massrange=None)
unidec.tools.lengths(array)
unidec.tools.limit_data(data, start, end)
unidec.tools.linear_axis(raw_data)
unidec.tools.linear_interpolation(x1, x2, x)
Parameters:
  • x1

  • x2

  • x

Returns:

float(x - x1) / float(x2 - x1)

unidec.tools.linearize(datatop, binsize, linflag)

Linearize data by defined x-axis bin size by either interpolation or integration :param datatop: Data array (N x 2) :param binsize: Spacing between first two m/z points :param linflag: Integer flag indicating the type of linearization.

0=Integration with Linear Axis (constant m/z) 1=Integration with Nonlinear Axis (constant resolution: mz / delta mz)

3=Interpolation with Linear Axis 4=Interpolation with Nonlinear Axis

Returns:

Linearized data

unidec.tools.lintegrate(datatop, intx, fastmode=False)

Linearize x-axis by integration.

Each intensity value in the old data gets proportionally added into the new x-axis.

The total sum of the intensity values should be constant. :param datatop: Data array :param intx: New x-axis for data :param fastmode: If True, uses a faster but less accurate method of integration that just picks the nearest point. :return: Integration of intensity from original data onto the new x-axis. Same shape as the old data but new length.

unidec.tools.linterpolate(datatop, intx)

Linearize x-axis by interpolation.

The new x-axis is interpolated on the old data and the corresponding intensities and picked out.

Parameters:
  • datatop – Data array

  • intx – New x-axis

Returns:

Interpolation of intensity from original data onto the new x-axis. Same shape as the old data but new length.

unidec.tools.load_mz_file(path, config=None, time_range=None, imflag=0)

Loads a text or mzml file :param path: File path to load :param config: UniDecConfig object :return: Data array

unidec.tools.localmax(array, start, end)
unidec.tools.localmax2(array, index, window)
unidec.tools.localmaxpos(data, start, end)
unidec.tools.make_all_matches(oligos)
unidec.tools.make_alpha_cmap(rgb_tuple, alpha)

Make color map where RGB specified in tup :param rgb_tuple: Tuple of RGB vaalues [0,1] :param alpha: Maximum Alpha (Transparency) [0,1] :return: Color map dictionary with a constant color but varying transprency

unidec.tools.make_isolated_match(oligos)
unidec.tools.make_peak_shape(xaxis, psfun, fwhm, mid, norm_area=False, speedy=False)

Make a peak of width fwhm centered at mid for given x axis.

Note: peak width must be in units of index not value of x-axis. To get this take fwhm/binsize. :param xaxis: Array of x axis values :param psfun: Integer

0=Gaussian 1=Lorentzian 2=Split Gaussian/Lorentzian

Parameters:
  • fwhm – Full width half max of peak (in units matching data indexes not values)

  • mid – Midpoint of peak

Returns:

Peak shape centered at midpoint .

unidec.tools.make_peaks_mztab(mzgrid, pks, adductmass, index=None)

For each peak in pks, get the charge state distribution.

The intensity at each charge state is determined from mzgrid and stored in a list as peak.mztab. An array of the results is also output for help speeding up make_peaks_mztab_spectrum

Parameters:
  • mzgrid – 2D grid of m/z vs charge (N x Z)

  • pks – Peaks object (length P)

  • adductmass – Mass of electrospray adduct.

Returns:

P x Z array

unidec.tools.make_peaks_mztab_spectrum(mzgrid, pks, data2, mztab, index=None)

Used for plotting the dots in plot 4.

Perform the same things as make_peaks_mztab, but instead of using the deconvolved intensities, it takes the intensity directly from the spectrum. :param mzgrid: m/z grid (N x Z) :param pks: Peaks object :param data2: Processed data 1D :param mztab: Prior mztab from make_peaks_mztab :return: mztab but with intensities replaced by value at the spectrum.

unidec.tools.makeconvspecies(processed_data, pks, config)

For data and peaks, create a simulated spectrum of each peak. Assumes p.mztab has been set for each p in pks.peaks by make_peaks_mztab Also makes pks.composite, which is a sum of all the simulated spectra. :param processed_data: Processed 2D MS data (data2, N x 2) :param pks: Peaks object (P Peak objects in pks.peaks) :param config: UniDecConfig object :return: Array of simulated spectra (P x N)

unidec.tools.makespecfun(i, k, peaks_masses, adductmass, charges, xvals, ftab, xmax, xmin)

Small helper function to speed things up. May be more better way to do this, but I found this to be fastest. :param i: peak mass index :param k: charge index :param peaks_masses: peak masses list :param adductmass: Adduct mass :param charges: charge list :param xvals: x-values from data :param ftab: List of interpolation functions :param xmax: Maximum x value :param xmin: Minimum x value :return:

unidec.tools.mass_weighted_average(value, weights)
unidec.tools.match(pks, oligomasslist, oligonames, oligomerlist, tolerance=None, return_numbers=False)
unidec.tools.match_dirs_recursive(topdir, ending='.raw')
unidec.tools.match_files(directory, string, exclude=None)
unidec.tools.match_files_recursive(topdir, ending='.raw')
unidec.tools.mergedata(data1, data2)

Uses a 1D intepolation to merge the intensity of data2 into the axis of data1 :param data1: Reference data (N x 2 array) :param data2: Data to merge (M x 2 array) :return: data2 interpolated into the same axis as data1 (N x 2)

unidec.tools.mergedata2d(x1, y1, x2, y2, z2, method='linear')

Uses a 2D interpolation to merge a 2D grid of data from one set of axes to another.

Requires rectangular grids of all inputs such as might be created by numpy.meshgrid. :param x1: Reference x-value grid (N x M) :param y1: Reference y-value grid (N x M) :param x2: Data x-value grid (N2 x M2) :param y2: Data y-value grid (N2 x M2) :param z2: Data intensity grdi (N2 x M2) :return: z2 interpolated onto x1 y1 2D grid (N x M)

unidec.tools.mergedata2dexact(x1, y1, x2, y2, z2)
unidec.tools.mergepeaks(peaks1, peaks2, window)

Merge a test list of peaks to a reference list.

Each peak in peaks2 is matched to the closest peak in peak1. If it within some defined threshold, the new peak replaces that closes peak in the matched list. If no new peaks are matched to a reference peak, that peaks mass is unchanged but intensity is set to 0.

Parameters:
  • peaks1 – Reference peaks (P x 2)

  • peaks2 – Test peaks (R x 2)

  • window – Tolerance window of the x values

Returns:

Intensity of peaks2 matched to values of peaks1 (P x 2)

unidec.tools.nearest(array, target)

In a sorted array, quickly find the position of the element closest to the target. :param array: Array :param target: Value :return: np.argmin(np.abs(array - target))

unidec.tools.nearestunsorted(array, target)

In an unsorted array, find the position of the element closest to the target.

For a sorted array, the method nearest will be faster. :param array: Array :param target: Value :return: np.argmin(np.abs(array - target))

unidec.tools.noise_level2(ticdat, percent=0.75, number_stddevs=3)
unidec.tools.nonlinear_axis(start, end, res)

Creates a nonlinear axis with the m/z values spaced with a defined and constant resolution. :param start: Minimum m/z value :param end: Maximum m/z value :param res: Resolution of the axis ( m / delta m) :return: One dimensional array of the nonlinear axis.

unidec.tools.nonlinearize(datatop, num_compressed)

Compress the data in a simple and nonlinear way. :param datatop: Data array (N x 2) :param num_compressed: :return:

unidec.tools.nonlinstickconv(xvals, mztab, fwhm, psfun)

Python-based Nonlinear convolution. First makes a stick spectrum. Then, convolved with peak shape kernel. :param xvals: x-axis :param mztab: mztab from make_peaks_mztab :param fwhm: Full width half max :param psfun: Peak shape function integer :return: Convolved output

unidec.tools.normalize(datatop)

Normalize the data so that the maximum intensity is 1.

maxval = np.amax(datatop[:, 1]) datatop[:, 1] = datatop[:, 1] / maxval

Parameters:

datatop – Data array (N x 2)

Returns:

Normalized data array (N x 2)

unidec.tools.normalize_extracts(grid, norm_method=0)
unidec.tools.pad_data(linear_mzdata, pad_until=50000)
unidec.tools.pad_data_length(linear_mzdata, pad_until_length=50000)
unidec.tools.pad_two_power(data)
unidec.tools.pair_glyco_matches(oligomasslist, oligonames, oligomerlist)
unidec.tools.peakdetect(data, config=None, window=10, threshold=0, ppm=None, norm=True)

Simple peak detection algorithm.

Detects a peak if a given data point is a local maximum within plus or minus config.peakwindow. Peaks must also be above a threshold of config.peakthresh * max_data_intensity.

The mass and intensity of peaks meeting these criteria are output as a P x 2 array.

Parameters:
  • data – Mass data array (N x 2) (mass intensity)

  • config – UniDecConfig object

  • window – Tolerance window of the x values

  • threshold – Threshold of the y values

  • ppm – Tolerance window in ppm

  • norm – Whether to normalize the data before peak detection

Returns:

Array of peaks positions and intensities (P x 2) (mass intensity)

unidec.tools.peakdetect_nonlinear(data, config=None, window=1, threshold=0)

Simple peak detection algorithm.

Detects a peak if a given data point is a local maximum within plus or minus config.peakwindow. Peaks must also be above a threshold of config.peakthresh * max_data_intensity.

The mass and intensity of peaks meeting these criteria are output as a P x 2 array.

Parameters:
  • data – Mass data array (N x 2) (mass intensity)

  • config – UniDecConfig object

Returns:

Array of peaks positions and intensities (P x 2) (mass intensity)

unidec.tools.peaks_error_FWHM(pks, data, level=0.5)

Calculates the error of each peak in pks using FWHM. Looks for the left and right point of the peak that is 1/2 the peaks max intensity, rightmass - leftmass = error :param pks: :param data: self.data.massdat :return:

unidec.tools.peaks_error_mean(pks, data, ztab, massdat, config)

Calculates error using the masses at different charge states. For each peak, finds the local max of the peak at each charge state, and does a weighted mean and weighted std. dev. :param pks: :param data: self.data.massgrid :param ztab: self.data.ztab :param massdat: self.data.massdat :param config: self.config :return:

unidec.tools.polydispersity_index(massdat)
unidec.tools.polynomial_background_subtract(datatop, polynomial_order=4, width=20, cutoff_percent=0.25)
unidec.tools.predict_charge(mass)

Give predicted native charge state of species of defined mass https://www.pnas.org/content/107/5/2007.long :param mass: Mass in Da :return: Float, predicted average native charge state

unidec.tools.remove_middle_zeros(data)
unidec.tools.remove_noise(datatop, percent=None, silent=True)
unidec.tools.removeduplicates(datatop)

Cleans up data that may have the same x value multiple times. Each nonunique x gets merged into a single unique x with the sum of all of the nonunique intensities. :param datatop: Data array (N x 2) :return: Data with unique x values

unidec.tools.rfft(data, nmult=1)
unidec.tools.round_to_nearest(n, m)
unidec.tools.safedivide(a, b)

Divide numpy arrays b from a. Define a/0=0 to avoid zero division error. :param a: Numerator :param b: Denominator :return: a/b

unidec.tools.safedivide1(a, b)
unidec.tools.savetxt(fname, datatop)
unidec.tools.savgol(ydata, window=None, order=2)
unidec.tools.savgol_background_subtract(datatop, width, cutoff_percent=0.25)
unidec.tools.simchargefit(x2)
unidec.tools.simp_string_to_value(s)

Try to convert string to float. Raise False if not possible. :param s: String :return: Float if possible. Otherwise, False

unidec.tools.simple_extract(data, x, zero_edge=True)
unidec.tools.simple_mass_defect(mass, refmass, centermode=1, normtype=1)
unidec.tools.single_cwt(a, width, wavelet_type='Ricker')

Perform a continuous wavelet transform at a single defined width. :param a: 1D numpy array of data (length N) :param width: Width of transform defined with respect to the data points in a :param wavelet_type: Type of wavelet. Either “Ricker” (Mexican Hat) or “Morlet” (Gabor) :return: cwt, wavelet Continous wavelet transform and wavelet of choice, both as numpy arrays of length N.

unidec.tools.smartdecode(string)
unidec.tools.smash(data, midpoint, window)
unidec.tools.smash2d(data, midpoint, window, ymidpoint, ywindow)
unidec.tools.solve_for_mass(mz1, mz2, adductmass=1.007276467)

Simple function to solve for mass from two adjacent charge state peaks in m/z. :param mz1: Smaller m/z value (charge = z1) :param mz2: Larger m/z value (charge = z2 = z1 + 1) :param adductmass: Mass of electrospray adduct (default = Hydrogen) :return: mass, z1, z2

unidec.tools.sparse(rawdata)
unidec.tools.stepmax(array, index)
unidec.tools.stickconv(mztab, kernel)

Make stick spectrum and then convolves with kernel. :param mztab: mztab from make_peaks_mztab :param kernel: peak shape kernel :return: Convolved output

unidec.tools.sticks_only(mztab, kernel)

Make stick spectrum and then convolves with kernel. :param mztab: mztab from make_peaks_mztab :param kernel: peak shape kernel :return: Convolved output

unidec.tools.string_to_int(s, default=False)

Try to convert string to integer. :param s: String :return: Integer if possible. Otherwise, False

unidec.tools.string_to_value(s)

Try to convert string to float. :param s: String :return: Float if possible. Otherwise, empty string.

unidec.tools.strip_char_from_string(s, char)

Strip a character from a string :param s: String :param char: Character to strip :return: String without character

unidec.tools.subtract_and_divide(pks, basemass, refguess, outputall=False)
unidec.tools.unidec_call(config, silent=False, conv=False, **kwargs)

Run the unidec binary specified by exepath with the configuration file specified by configfile. If silent is False (default), the output from exepath will be printed to the standard out. If silent is True, the output is suppressed.

The binary is run as a commandline subprocess with a call of (for example):

unidec.exe conf.dat

Parameters:
  • config – Config object

  • silent – Whether to print the output of exepath to the standard out

  • conv – Whether to call the convolution function only rather than the standard deconvolution

  • kwargs

Returns:

Standard error of exepath execution

unidec.tools.unsparse(rawdata)
unidec.tools.waters_convert2(path, config=None, outfile=None, time_range=None)
unidec.tools.weighted_avg(values, weights)
unidec.tools.weighted_std(values, weights)

Calculate weighted standard deviation. :param values: Values :param weights: Weights :return: Weighted standard deviation.

unidec.tools.wide_sse(dat1, dat2, sig)

Tests the sum of squared errors between two sets of data where the second has been convolved with a Gaussian :param dat1: Reference list of intensities. :param dat2: Test spectrum list of intensities to broaden. :param sig: Sigma for Gaussian filter :return: SSE between dat1 and broadedned dat1 (float)

unidec.tools.win_autocorr_grid(rawdata, binsize, wbin, window_fwhm, diffrange)
unidec.tools.win_fft_diff(rawdata, binsize=0.05, sigma=1000, diffrange=None, norm=True)
unidec.tools.win_fft_grid(rawdata, binsize, wbin, window_fwhm, diffrange, norm=True)
unidec.tools.win_fft_grid_single(rawdata, binsize, wbin, window_fwhm, diffrange, norm=True)
unidec.tools.windowed_autocorr(data, mean, sigma, diffrange=None)
unidec.tools.windowed_fft(data, mean, sigma, diffrange=None, norm=True)
unidec.tools.windowed_fft_single(data, mean, sigma, diffrange=None, norm=True)
unidec.tools.zip_folder(save_path, directory=None)

Zips a directory specified by save_path into a zip file for saving. :param save_path: Path to save to zip :return: None

unidec.tools.zipdir(path, zip_handle)

Zips all the files in the path into the zip_handle :param path: Directory path :param zip_handle: Handle of the zip file that is being created :return: None

Module contents