Skip to content

Commit

Permalink
Merge pull request #99 from michaelmarty/v3
Browse files Browse the repository at this point in the history
Version 7.0.2
  • Loading branch information
michaelmarty authored Aug 27, 2024
2 parents 61fde9b + e376a7e commit c2d4ca4
Show file tree
Hide file tree
Showing 51 changed files with 4,281 additions and 187 deletions.
8 changes: 6 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ TestSpectra
default_conf.dat
unidec_src/cfunction/x64
unidec_src/cfunction/libmypfunc32.dll
Scripts/MTM/unidec_tests.py
Scripts/MTM/Old/unidec_tests.py
pyinstaller_64.bat
pyinstaller_64_dist.bat
/Scripts/MTM/fft_test.py
Expand All @@ -36,7 +36,7 @@ todo.txt
unidec/bin/Other_builds/
unidec_src/Old
test_GUI.py
Scripts/MTM/test_UniDec.py
Scripts/MTM/Old/test_UniDec.py
unidec/metaunidec/test_MUD.py
unidec/bin/CDCReaderOld.exe
Scripts/MTM/Old/fft_test.py
Expand Down Expand Up @@ -268,4 +268,8 @@ hashing.py
PublicScripts/MutantCycleAnalysis/Mutant Cycle Analysis/
unidec/modules/gui_elements/UniDec.mplstyle
.eggs/
Dockerfile_isodec
unidec/recent.txt
unidec/src/UniDec/


4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FROM python:3.9-bullseye
FROM python:3.11.9-bookworm

# C dependencies
RUN apt-get update && apt-get install -y libgtk-3-dev libwxgtk3.0-gtk3-dev libfftw3-dev hdf5-tools libhdf5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
RUN apt-get update && apt-get install -y libfftw3-dev hdf5-tools libhdf5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*

# To Run GUI
RUN pip install setuptools attrdict attrdict3 numpy pymzml networkx natsort h5py matplotlib scipy pyteomics mpld3 pandas plotly
Expand Down
6 changes: 6 additions & 0 deletions GUniDec.spec
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from PyInstaller import compat
import matplotlib
import sys
import hashlib
import shutil


def hashfile(path):
Expand Down Expand Up @@ -159,6 +160,11 @@ coll = COLLECT(exe,
path = "C:\\Python\\UniDec3\\dist\\UniDec_Windows\\GUI_UniDec.exe"
import subprocess

dst = "C:\\Python\\UniDec3\\dist\\UniDec_Windows\\obo"
src = "C:\\Python\\UniDec3\\dist\\UniDec_Windows\\_internal\\obo"

shutil.copytree(src, dst)

print("Testing Software...", path)

out = subprocess.call(path)
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
UniDec License:

Copyright (c) 2016, University of Oxford
2017-2023, University of Arizona
2017-2024, Arizona Board of Regents on behalf of the University of Arizona
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
12 changes: 12 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,24 @@ Of course, using the pre-compiled version means you don't need to know Python at

v.7.0.2

Improvements to UPP outputs. Fixed issue with reports getting overwritten if the same file is used in multiple rows with UPP.

Added new options in MetaUniDec for Average Charge State Plotting. Added exports of text files for fits and fitdata.

Added new pre-import intensity filter for UCD, which should help with memory crashes on large data files.

Fixed bug opening mzML files with new build.

Fixed bug with smashflag on UPP.

Fixed a few display and interface bugs on UCCD and UCD.

Fixed Waters Data Conversion Wizard issue with Trapping Collision Energy (eV). Stopped it from closing by default when the conversion is initiated.

Fixed bug with KD fitting on DataCollector. Fixed bug with UltraMeta.

Fixed bugs with UCD Thermo imports and with Thermo header information for resolution.

v.7.0.1

Continued development and tweaks to UniChromCD. Bug fixes and GUI improvements. Added multiplex spectrum cropping. New HT sequences.
Expand Down
2 changes: 1 addition & 1 deletion unidec/DataCollector.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def __init__(self, parent, title, config=None, pks=None, *args, **kwargs):
# self.on_run(0)
self.on_fitting()
if True and platform.node() == 'MTM-VOSTRO':
path = "Z:\mtmarty\Data\Others\Miranda\collection2.json"
path = "Z:\\mtmarty\\Data\\Others\\Miranda\\collection2.json"
self.load(path)
try:
# testdir = "C:\Python\unidec\unidec_src\unidec\\x64\Release"
Expand Down
Empty file added unidec/IsoDec/__init__.py
Empty file.
63 changes: 63 additions & 0 deletions unidec/IsoDec/__main__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import sys
import getopt
import argparse
import os
import platform
sys.path.append("..")

if platform.system() == "Windows":
udpath = "C:\\Python\\UniDec3"
elif platform.system() == "Linux":
udpath = "/home/u17/mtmarty/UniDec"

sys.path.append(udpath)


def main(*args, **kwargs):
print(sys.argv)
print("Running Command Line IsoDec")

try:
opts, args = getopt.getopt(sys.argv[1:], "f:o:", ["file=", "out="])
except getopt.GetoptError as e:
print("Error in Argv. Likely unknown option: ", sys.argv, e)
print("Known options: -f, -o")
return None

print("ARGS:", args)
print("KWARGS:", kwargs)
print("OPTS:", opts)
infile = None
outfile = None
if opts is not None:
for opt, arg in opts:
if opt in ("-f", "--file"):
infile = arg
print("Opening File:", infile)
if opt in ("-o", "--out"):
outfile = arg
print("Output File:", outfile)

if "train" in args:
from unidec.IsoDec.train import main
main()

if "generate" in args:
print("Generating Pkl Files")
if infile is None:
print("No Input File Specified")
return None
from unidec.IsoDec.trainingdata import process_file
process_file(infile)

if "generate_script" in args:
print("Generating Pkl Files")
directory = os.getcwd()
print("Directory:", directory)
from unidec.IsoDec.generate import generate_all
generate_all(directory)



if __name__ == '__main__':
main()
138 changes: 138 additions & 0 deletions unidec/IsoDec/c_interface.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
import ctypes
import os
import numpy as np
from unidec.IsoDec.match import MatchedPeak, MatchedCollection
from unidec.modules.isotopetools import fast_calc_averagine_isotope_dist
from unidec.IsoDec.plots import *
import unidec.tools as ud

example = np.array([[5.66785531e+02, 1.47770838e+06],
[5.67057354e+02, 1.54980838e+06],
[5.67507468e+02, 5.21600520e+07],
[5.67708173e+02, 8.35557760e+07],
[5.67908401e+02, 7.28264240e+07],
[5.68060254e+02, 1.87337225e+06],
[5.68108674e+02, 4.35435520e+07],
[5.68239256e+02, 3.88155375e+06],
[5.68309390e+02, 2.05468060e+07],
[5.68509951e+02, 7.18109250e+06],
[5.68707871e+02, 2.30373500e+06],
[5.69150563e+02, 1.57598062e+06],
[5.69243121e+02, 1.96390440e+07],
[5.69334393e+02, 6.82677120e+07],
[5.69425337e+02, 1.22867432e+08],
[5.69516492e+02, 1.45702336e+08],
[5.69607541e+02, 1.20801936e+08],
[5.69698595e+02, 1.06786072e+08],
[5.69789906e+02, 6.56232960e+07],
[5.69881208e+02, 3.41013880e+07],
[5.69972168e+02, 1.70930360e+07],
[5.70063432e+02, 9.17621100e+06],
[5.70699369e+02, 1.96462650e+06]])

dllpath = "C:\\Python\\UniDec3\\unidec\\IsoDec\\src\\isodec\\x64\\Release\\isodeclib.dll"

isodist = ctypes.c_float * 128
matchedinds = ctypes.c_int * 32
#print(isodist)
class MPStruct(ctypes.Structure):
_fields_ = [('mz', ctypes.c_float),
('z', ctypes.c_int),
('monoiso', ctypes.c_float),
('peakmass', ctypes.c_float),
('avgmass', ctypes.c_float),
('area', ctypes.c_float),
('peakint', ctypes.c_float),
('matchedindsiso', ctypes.c_int * 64),
('matchedindsexp', ctypes.c_int * 64),
('isomz', isodist),
('isodist', isodist),
('isomass', isodist),
('startindex', ctypes.c_int),
('endindex', ctypes.c_int),
]


class IsoDecWrapper:
def __init__(self, dllpath=dllpath, modelpath=b"C:\\Python\\UniDec3\\unidec\\IsoDec\\phase_model_2.bin"):
# void process_spectrum(const double* cmz, const double* cint, const int n, const char* fname, int* charge)
self.c_lib = ctypes.CDLL(dllpath)
self.c_lib.predict_charge.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(ctypes.c_int)]

self.c_lib.process_spectrum.argtypes = [ctypes.POINTER(ctypes.c_float), ctypes.POINTER(ctypes.c_float),
ctypes.c_int, ctypes.c_char_p, ctypes.POINTER(MPStruct)]
self.modelpath = ctypes.c_char_p(modelpath)

def predict_charge(self, centroids):
cmz = centroids[:, 0].astype(np.float32)
cint = centroids[:, 1].astype(np.float32)
n = len(cmz)
charge = ctypes.c_int(0)
self.c_lib.predict_charge(cmz.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
cint.ctypes.data_as(ctypes.POINTER(ctypes.c_float)), n, self.modelpath,
ctypes.byref(charge))
print(charge.value)
return charge.value

def process_spectrum(self, centroids, pks=None, config=None):
#print("Running C Interface")
cmz = centroids[:, 0].astype(np.float32)
cint = centroids[:, 1].astype(np.float32)
n = len(cmz)
# print(n)
elems = (MPStruct * n)()
matchedpeaks = ctypes.cast(elems, ctypes.POINTER(MPStruct))
nmatched = self.c_lib.process_spectrum(cmz.ctypes.data_as(ctypes.POINTER(ctypes.c_float)),
cint.ctypes.data_as(ctypes.POINTER(ctypes.c_float)), n, self.modelpath,
matchedpeaks)
# print(nmatched)
if pks is None:
pks = MatchedCollection()
for p in matchedpeaks[:nmatched]:
if p.z == 0:
continue
pk = MatchedPeak(p.z, p.mz)
pk.monoiso = p.monoiso
pk.peakmass = p.peakmass
pk.avgmass = p.avgmass

if config is not None:
pk.scan = config.activescan
pk.ms_order = config.activescanorder
pk.rt = config.activescanrt

isodist = np.array(p.isodist)
isomz = np.array(p.isomz)
isomass = np.array(p.isomass)

b1 = isodist > np.amax(isodist) * 0.001
isodist = isodist[b1]
isomz = isomz[b1]
isomass = isomass[b1]
pk.matchedintensity = np.sum(isodist)
pk.isodist = np.transpose((isomz, isodist))
pk.massdist = np.transpose((isomass, isodist))

pk.startindex = p.startindex
pk.endindex = p.endindex

pk.isodist = fast_calc_averagine_isotope_dist(p.monoiso, p.z)
#pk.isodist[:,0] /= float(p.z)
pk.isodist[:,1] *= p.peakint
pks.add_peak(pk)
pks.add_pk_to_masses(pk, 10)
return pks


if __name__ == "__main__":
filepath = "C:\\Data\\IsoNN\\test2.txt"
#filepath = "C:\\Data\\IsoNN\\test9.txt"
spectrum = np.loadtxt(filepath, skiprows=0)
#spectrum = ud.datachop(spectrum, 702, 708)

wrapper = IsoDecWrapper()
#wrapper.process_spectrum(spectrum)
pks = wrapper.process_spectrum(spectrum)
#exit()
plot_pks(pks, centroids=spectrum, show=True, title="C Interface")
Loading

0 comments on commit c2d4ca4

Please sign in to comment.