-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
V3
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from pyopenms import * | ||
import unidec.engine as unidec | ||
import time | ||
import numpy as np | ||
import unidec.tools as ud | ||
|
||
|
||
def ms1_processing(path, outpath=None, fullms1=True, agressive_speed=False): | ||
# Start timer | ||
begin = time.perf_counter() | ||
# Set outpath | ||
if outpath is None: | ||
outpath = path[:-8] + "_deconvolved" | ||
# Load file | ||
exp = MSExperiment() | ||
MzMLFile().load(path, exp) | ||
|
||
# Check number of scans | ||
num_scans = exp.getNrSpectra() | ||
print("Number of Scans:", num_scans) | ||
|
||
# Set up output experiment | ||
out_exp = MSExperiment() | ||
|
||
# Create a UniDec engine | ||
eng = unidec.UniDec() | ||
|
||
# Set some defaults | ||
eng.config.numit = 10 | ||
if agressive_speed: | ||
print("Running agressive settings") | ||
# Bin together every 10 datapoints to drop the resolution by 10x | ||
eng.config.mzbins = 10 | ||
# Remove 80% of the data | ||
eng.config.reductionpercent = 80 | ||
# Set an intensity threshold of 1e6 | ||
eng.config.intthresh = 1e6 | ||
# Turn off normalization | ||
eng.datanorm = 0 | ||
eng.peaknorm = 0 | ||
|
||
# Loop through spectra | ||
for i, spec in enumerate(exp): | ||
# Get MS level | ||
ms_level = spec.getMSLevel() | ||
if ms_level != 1: | ||
# Append to output experiment | ||
out_exp.addSpectrum(spec) | ||
else: | ||
print("MS Level:", ms_level, i) | ||
# Get the m/z and intensity values | ||
mz, intensity = spec.get_peaks() | ||
inputdata = np.transpose([mz, intensity]) | ||
inputdata = ud.dataprep(inputdata, eng.config) | ||
|
||
if len(inputdata) < 2: | ||
continue | ||
|
||
# Run UniDec | ||
eng.pass_data_in(inputdata, silent=True, refresh=True) | ||
eng.process_data(silent=True) | ||
eng.run_unidec(silent=True, efficiency=True) | ||
|
||
if fullms1: | ||
# Get the mass and intensity values | ||
try: | ||
mass, intensity = eng.data.massdat[:, 0], eng.data.massdat[:, 1] | ||
except: | ||
mass, intensity = [], [] | ||
|
||
# Update the old spectrum | ||
spec2 = spec | ||
spec2.set_peaks((mass, intensity)) | ||
out_exp.addSpectrum(spec2) | ||
|
||
else: | ||
# Create a new spectrum | ||
spec2 = spec | ||
try: | ||
peaks = eng.pick_peaks() | ||
spec2.set_peaks((peaks[:, 0], peaks[:, 1])) | ||
except: | ||
spec2.set_peaks(([], [])) | ||
|
||
|
||
out_exp.addSpectrum(spec2) | ||
|
||
# Write the output experiment to a file | ||
MzMLFile().store(outpath + ".mzML", out_exp) | ||
|
||
|
||
print("Total Time:", time.perf_counter() - begin) | ||
|
||
|
||
if __name__ == "__main__": | ||
# set paths | ||
path = "C:\\Data\\TabbData\\20170105_L_MaD_ColC4_Ecoli20161108-10_01_ms1.mzML.gz" | ||
|
||
# Run the function | ||
ms1_processing(path, fullms1=False, agressive_speed=False) |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import numpy as np | ||
import matplotlib.pyplot as plt | ||
import h5py | ||
from pyopenms import * | ||
from unidec.modules import hdf5_tools as hd | ||
|
||
|
||
def write_hdf5_to_mzml(hdf5_path, outfile=None, plot=False): | ||
""" | ||
Write the HDF5 data from MetaUniDec or UniChrom to an mzML file | ||
:param hdf5_path: the path to the HDF5 file | ||
:param outfile: optional, the path to the output file. Will default to the same path as the HDF5 file with the extension changed to _deconvolved.mzML | ||
:param plot: whether to plot the data | ||
:return: None | ||
""" | ||
if outfile is None: | ||
outfile = os.path.splitext(hdf5_path)[0] + "_deconvolved.mzML" | ||
|
||
# Load the HDF5 data | ||
massaxis = hd.get_data(hdf5_path, "ms_dataset", "mass_axis") | ||
massgrid = hd.get_data(hdf5_path, "ms_dataset", "mass_grid") | ||
|
||
# Reshape the data | ||
num = int(len(massgrid) / len(massaxis)) | ||
massgrid = massgrid.reshape(int(num), len(massaxis)) | ||
print("Data Shape:", np.shape(massgrid)) | ||
|
||
# Get the scan start times | ||
try: | ||
times = hd.get_metadata(hdf5_path, "timestart") | ||
except: | ||
times = np.arange(0, num) | ||
|
||
|
||
# Write the data to an mzML file | ||
exp = MSExperiment() | ||
for i in range(0, num): | ||
spec = MSSpectrum() | ||
spec.setRT(times[i]) | ||
spec.set_peaks((massaxis, massgrid[i])) | ||
exp.addSpectrum(spec) | ||
MzMLFile().store(outfile, exp) | ||
print("Wrote Data to:", outfile) | ||
|
||
# plot the data | ||
if plot: | ||
for d in massgrid: | ||
plt.plot(massaxis, d) | ||
plt.show() | ||
|
||
|
||
if __name__ == "__main__": | ||
# Path to the HDF5 file | ||
hdf5_path = "../unidec/bin/Example Data/UniChrom/SEC_Native_Herceptin.hdf5" | ||
# Write the data to an mzML file | ||
write_hdf5_to_mzml(hdf5_path, plot=True) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
rem update version in pyproject.toml and enginebase | ||
rem commit to svn and git | ||
rem Run Tests on test_GUI and test_MUD | ||
rem build pyinstaller | ||
rem build docker and commit | ||
rem build wheel, test, and commit | ||
rem python -m build -o .\distpypi | ||
rem python -m twine upload --repository testpypi .\distpypi\* --config-file .pypirc (check that old wheels are deleted) | ||
rem update docs with .\unidec_docs\make.bat html | ||
rem paste docs into UniDecDocumentation and push to git | ||
|
||
echo "Building" | ||
C:\Python310\Scripts\pyinstaller.exe GUniDec.spec --noconfirm | ||
rem call "C:\Python\UniDec3\dist\UniDec_Windows\GUI_UniDec.exe" |
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.