isodec 2.0.4__py3-none-win_arm64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. isodec/__init__.py +15 -0
  2. isodec/__main__.py +45 -0
  3. isodec/_version.py +3 -0
  4. isodec/altdecon.py +127 -0
  5. isodec/bin/fftw3.dll +0 -0
  6. isodec/bin/isodec_test.exe +0 -0
  7. isodec/bin/isodeclib.dll +0 -0
  8. isodec/bin/isodeclib.lib +0 -0
  9. isodec/bin/isogen.dll +0 -0
  10. isodec/bin/isogen.lib +0 -0
  11. isodec/bin/isogen_test.exe +0 -0
  12. isodec/bin/libmmd.dll +0 -0
  13. isodec/bin/svml_dispmd.dll +0 -0
  14. isodec/bin_to_header.py +56 -0
  15. isodec/c_interface.py +439 -0
  16. isodec/compare_tools.py +685 -0
  17. isodec/config.py +61 -0
  18. isodec/datatools.py +454 -0
  19. isodec/encoding.py +302 -0
  20. isodec/encoding_profile.py +257 -0
  21. isodec/engine.py +952 -0
  22. isodec/fragment_matching.py +139 -0
  23. isodec/fragment_view.py +107 -0
  24. isodec/fwhm.py +121 -0
  25. isodec/io.py +79 -0
  26. isodec/isotope.py +83 -0
  27. isodec/match.py +1192 -0
  28. isodec/match_profile.py +265 -0
  29. isodec/modelparams/phase_model_1.bin +0 -0
  30. isodec/modelparams/phase_model_1.pth +0 -0
  31. isodec/modelparams/phase_model_4.bin +0 -0
  32. isodec/modelparams/phase_model_4.pth +0 -0
  33. isodec/modelparams/phase_model_8.bin +0 -0
  34. isodec/modelparams/phase_model_8.pth +0 -0
  35. isodec/modelparams/phase_model_b_1_0.bin +0 -0
  36. isodec/modelparams/phase_model_b_1_0.pth +0 -0
  37. isodec/modelparams/phase_model_b_4_0.bin +0 -0
  38. isodec/modelparams/phase_model_b_4_0.pth +0 -0
  39. isodec/modelparams/phase_model_b_4_1.bin +0 -0
  40. isodec/modelparams/phase_model_b_4_1.pth +0 -0
  41. isodec/modelparams/phase_model_b_8_0.bin +0 -0
  42. isodec/modelparams/phase_model_b_8_0.pth +0 -0
  43. isodec/modelparams/phase_model_b_8_1.bin +0 -0
  44. isodec/modelparams/phase_model_b_8_1.pth +0 -0
  45. isodec/modelparams/phase_model_c_1_0.bin +0 -0
  46. isodec/modelparams/phase_model_c_1_0.pth +0 -0
  47. isodec/modelparams/phase_model_c_4_0.bin +0 -0
  48. isodec/modelparams/phase_model_c_4_0.pth +0 -0
  49. isodec/modelparams/phase_model_c_4_1.bin +0 -0
  50. isodec/modelparams/phase_model_c_4_1.pth +0 -0
  51. isodec/modelparams/phase_model_c_8_0.bin +0 -0
  52. isodec/modelparams/phase_model_c_8_0.pth +0 -0
  53. isodec/modelparams/phase_model_c_8_1.bin +0 -0
  54. isodec/modelparams/phase_model_c_8_1.pth +0 -0
  55. isodec/modelparams/phase_model_p_1_0.bin +0 -0
  56. isodec/modelparams/phase_model_p_1_0.pth +0 -0
  57. isodec/modelparams/phase_model_p_4_0.bin +0 -0
  58. isodec/modelparams/phase_model_p_4_0.pth +0 -0
  59. isodec/modelparams/phase_model_p_4_1.bin +0 -0
  60. isodec/modelparams/phase_model_p_4_1.pth +0 -0
  61. isodec/modelparams/phase_model_p_8_0.bin +0 -0
  62. isodec/modelparams/phase_model_p_8_0.pth +0 -0
  63. isodec/modelparams/phase_model_p_8_1.bin +0 -0
  64. isodec/modelparams/phase_model_p_8_1.pth +0 -0
  65. isodec/models.py +553 -0
  66. isodec/msalign_export.py +211 -0
  67. isodec/plots.py +254 -0
  68. isodec/runtime.py +279 -0
  69. isodec/tools.py +112 -0
  70. isodec/train.py +37 -0
  71. isodec/train_profile.py +102 -0
  72. isodec/trainingdata.py +211 -0
  73. isodec/trainingdata_profile.py +192 -0
  74. isodec-2.0.4.dist-info/METADATA +189 -0
  75. isodec-2.0.4.dist-info/RECORD +82 -0
  76. isodec-2.0.4.dist-info/WHEEL +5 -0
  77. isodec-2.0.4.dist-info/entry_points.txt +3 -0
  78. isodec-2.0.4.dist-info/licenses/LICENSE +28 -0
  79. isodec-2.0.4.dist-info/licenses/THIRD_PARTY_NOTICES.md +12 -0
  80. isodec-2.0.4.dist-info/licenses/extern/IsoGen/LICENSE +11 -0
  81. isodec-2.0.4.dist-info/licenses/extern/IsoGen/src/fftw/COPYING +340 -0
  82. isodec-2.0.4.dist-info/licenses/extern/IsoGen/src/fftw/COPYRIGHT +19 -0
isodec/__init__.py ADDED
@@ -0,0 +1,15 @@
1
+ """IsoDec charge-state assignment and deconvolution."""
2
+
3
+ from ._version import __version__
4
+ from .config import IsoDecConfig
5
+ from .c_interface import IsoDecWrapper
6
+ from .fragment_matching import match_fragments
7
+ from .runtime import IsoDecRuntime
8
+
9
+ __all__ = [
10
+ "IsoDecConfig",
11
+ "IsoDecRuntime",
12
+ "IsoDecWrapper",
13
+ "match_fragments",
14
+ "__version__",
15
+ ]
isodec/__main__.py ADDED
@@ -0,0 +1,45 @@
1
+ """Command-line interface for IsoDec."""
2
+
3
+ import argparse
4
+ import sys
5
+ from pathlib import Path
6
+
7
+ if not __package__:
8
+ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
9
+ __package__ = "isodec"
10
+
11
+ from .runtime import IsoDecRuntime
12
+
13
+
14
+ def build_parser():
15
+ parser = argparse.ArgumentParser(
16
+ prog="isodec",
17
+ description="Assign charge states and deconvolve isotopically resolved mass spectra.",
18
+ )
19
+ parser.add_argument("spectrum", type=Path, help="Input spectrum (TXT, DAT, CSV, NPZ, or a UniDec-supported format)")
20
+ parser.add_argument("-o", "--output", type=Path, help="Output TSV filename")
21
+ parser.add_argument("--centroided", action="store_true", help="Treat the input as centroid data")
22
+ parser.add_argument("--type", choices=("PEPTIDE", "RNA"), default="PEPTIDE", help="Analyte isotope model")
23
+ parser.add_argument("--quiet", action="store_true", help="Suppress progress output")
24
+ return parser
25
+
26
+
27
+ def main(argv=None):
28
+ args = build_parser().parse_args(argv)
29
+ if not args.spectrum.is_file():
30
+ raise SystemExit(f"Spectrum does not exist: {args.spectrum}")
31
+
32
+ engine = IsoDecRuntime(verbose=not args.quiet)
33
+ engine.analyte_type = args.type
34
+ engine.process_file(
35
+ str(args.spectrum),
36
+ assume_centroided=args.centroided,
37
+ verbose=not args.quiet,
38
+ )
39
+ output = args.output or args.spectrum.with_name(f"{args.spectrum.stem}_isodec.tsv")
40
+ engine.pks.export_tsv(output, report_multiple_monoisos=engine.config.report_multiple_monoisos)
41
+ return 0
42
+
43
+
44
+ if __name__ == "__main__":
45
+ raise SystemExit(main())
isodec/_version.py ADDED
@@ -0,0 +1,3 @@
1
+ """Single source of truth for the package version."""
2
+
3
+ __version__ = "2.0.4"
isodec/altdecon.py ADDED
@@ -0,0 +1,127 @@
1
+ import numpy as np
2
+ import matplotlib.pyplot as plt
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ if not __package__:
7
+ sys.path.insert(0, str(Path(__file__).resolve().parent.parent))
8
+ __package__ = "isodec"
9
+
10
+ from . import tools as ud
11
+
12
+ example = np.array(
13
+ [
14
+ [5.66785531e02, 1.47770838e06],
15
+ [5.67057354e02, 1.54980838e06],
16
+ [5.67507468e02, 5.21600520e07],
17
+ [5.67708173e02, 8.35557760e07],
18
+ [5.67908401e02, 7.28264240e07],
19
+ [5.68060254e02, 1.87337225e06],
20
+ [5.68108674e02, 4.35435520e07],
21
+ [5.68239256e02, 3.88155375e06],
22
+ [5.68309390e02, 2.05468060e07],
23
+ [5.68509951e02, 7.18109250e06],
24
+ [5.68707871e02, 2.30373500e06],
25
+ [5.69150563e02, 1.57598062e06],
26
+ [5.69243121e02, 1.96390440e07],
27
+ [5.69334393e02, 6.82677120e07],
28
+ [5.69425337e02, 1.22867432e08],
29
+ [5.69516492e02, 1.45702336e08],
30
+ [5.69607541e02, 1.20801936e08],
31
+ [5.69698595e02, 1.06786072e08],
32
+ [5.69789906e02, 6.56232960e07],
33
+ [5.69881208e02, 3.41013880e07],
34
+ [5.69972168e02, 1.70930360e07],
35
+ [5.70063432e02, 9.17621100e06],
36
+ [5.70699369e02, 1.96462650e06],
37
+ ]
38
+ )
39
+
40
+ import numpy as np
41
+ from scipy import signal
42
+
43
+ MAX_CHARGE = 50
44
+
45
+
46
+ def gen_thrash_arrays(centroids, startpad=10):
47
+ max_mz = centroids[-1, 0]
48
+ min_mz = centroids[0, 0]
49
+
50
+ additional = 4 - (max_mz - min_mz)
51
+ if additional < 0:
52
+ additional = 0
53
+ else:
54
+ max_mz += additional / 2
55
+ min_mz -= additional / 2
56
+
57
+ num_l = int((max_mz - min_mz) * MAX_CHARGE * 8)
58
+
59
+ intx = np.linspace(min_mz, max_mz, num_l)
60
+ if len(intx) <= 1:
61
+ return None, None, None, None, None, None
62
+
63
+ linear_data = ud.lintegrate(centroids, intx, fastmode=True)
64
+ if len(linear_data) <= 1:
65
+ return None, None, None, None, None, None
66
+
67
+ corry = signal.fftconvolve(linear_data[:, 1], linear_data[:, 1][::-1], mode='same')
68
+ maxposition = np.argmax(corry)
69
+ ac = corry[maxposition + startpad:]
70
+
71
+
72
+ acx = intx - intx[0]
73
+ acx = 1 / acx[startpad:len(ac) + startpad]
74
+
75
+ fft = np.fft.fft(linear_data[:, 1])
76
+ fft = np.abs(fft)
77
+ fft = fft[startpad:len(ac) + startpad]
78
+
79
+ fftx = np.fft.fftfreq(len(linear_data[:, 1]), d=(linear_data[1, 0] - linear_data[0, 0]))
80
+ fftx = fftx[startpad:len(ac) + startpad]
81
+ b1 = fftx < MAX_CHARGE
82
+ fft = fft[b1]
83
+ fftx = fftx[b1]
84
+
85
+ fft /= np.max(fft)
86
+ ac2 = ud.lintegrate(np.transpose([acx, ac]), fftx)
87
+
88
+
89
+ acx, ac = ac2[:, 0], ac2[:, 1]
90
+ ac /= np.max(ac)
91
+ mul = ac * fft
92
+ return linear_data, ac, fft, mul, fftx, acx
93
+
94
+ def thrash_predict(centroids):
95
+ linear_data, ac, fft, mul, fftx, acx = gen_thrash_arrays(centroids)
96
+ if linear_data is None or len(mul) == 0:
97
+ return 0
98
+ maxpos = np.argmax(mul)
99
+
100
+ charge = acx[maxpos]
101
+ return round(charge)
102
+
103
+
104
+ if __name__ == "__main__":
105
+ example = np.loadtxt("Z:\\Group Share\\JGP\\MockData\\mockdata_centroids.csv", delimiter=",")
106
+ example = ud.datachop(example, 326,327)
107
+ for i in range(len(example)):
108
+ plt.plot([example[i, 0], example[i, 0]], [0, example[i, 1]], color="black")
109
+ plt.show()
110
+
111
+
112
+
113
+ raw_data = example
114
+ charge_state = thrash_predict(raw_data)
115
+ print(charge_state)
116
+
117
+ linear_data, ac, fft, mul, fftx, acx = gen_thrash_arrays(raw_data)
118
+
119
+ plt.subplot(121)
120
+ plt.plot(linear_data[:, 0], linear_data[:, 1])
121
+ plt.subplot(122)
122
+ plt.plot(acx, mul, label="Mul")
123
+ plt.plot(acx, ac-1, label="AC")
124
+ plt.plot(fftx, fft-2, label="FFT")
125
+ plt.legend()
126
+ plt.show()
127
+
isodec/bin/fftw3.dll ADDED
Binary file
Binary file
Binary file
Binary file
isodec/bin/isogen.dll ADDED
Binary file
isodec/bin/isogen.lib ADDED
Binary file
Binary file
isodec/bin/libmmd.dll ADDED
Binary file
Binary file
@@ -0,0 +1,56 @@
1
+ """Convert a PyTorch model to a binary file and C header."""
2
+
3
+ from pathlib import Path
4
+
5
+ import torch
6
+
7
+
8
+ def pth_to_bin(pth_file, bin_file):
9
+ """Flatten a PyTorch state dictionary into a raw float32 binary file."""
10
+ pth_file = Path(pth_file)
11
+ bin_file = Path(bin_file)
12
+
13
+ state_dict = torch.load(pth_file, map_location="cpu", weights_only=True)
14
+ weights = torch.cat([tensor.flatten() for tensor in state_dict.values()])
15
+ weights.detach().cpu().numpy().tofile(bin_file)
16
+
17
+
18
+ def bin_to_header(bin_file, header_file, varname="model_weights"):
19
+ """Write the bytes from ``bin_file`` to a C array in ``header_file``."""
20
+ bin_file = Path(bin_file)
21
+ header_file = Path(header_file)
22
+ data = bin_file.read_bytes()
23
+ guard = f"{varname.upper()}_H"
24
+
25
+ with header_file.open("w", encoding="ascii", newline="\n") as outfile:
26
+ outfile.write(f"#ifndef {guard}\n")
27
+ outfile.write(f"#define {guard}\n\n")
28
+ outfile.write(f"// Generated from {bin_file.name}\n")
29
+ outfile.write(f"static const unsigned char {varname}[] = {{\n")
30
+
31
+ for start in range(0, len(data), 12):
32
+ chunk = data[start:start + 12]
33
+ values = ", ".join(f"0x{byte:02x}" for byte in chunk)
34
+ if start + 12 < len(data):
35
+ values += ","
36
+ outfile.write(f" {values}\n")
37
+
38
+ outfile.write("};\n")
39
+ outfile.write(f"static const unsigned int {varname}_len = {len(data)};\n\n")
40
+ outfile.write(f"#endif // {guard}\n")
41
+
42
+
43
+ if __name__ == "__main__":
44
+ isodec_dir = Path(__file__).resolve().parent
45
+
46
+ model_dir = isodec_dir / "modelparams"
47
+ input_pth = model_dir / "phase_model_8.pth"
48
+ output_bin = model_dir / "phase_model_8.bin"
49
+ output_header = isodec_dir / "src_cmake" / "phase_model_8.h"
50
+ variable_name = "phase_model_8_bin"
51
+
52
+ pth_to_bin(input_pth, output_bin)
53
+ print("Wrote binary model:", output_bin)
54
+
55
+ bin_to_header(output_bin, output_header, variable_name)
56
+ print("Wrote C header:", output_header)