msfiddle 2.0.0__tar.gz → 2.1.0__tar.gz

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 (46) hide show
  1. msfiddle-2.1.0/PKG-INFO +285 -0
  2. msfiddle-2.1.0/README.md +244 -0
  3. msfiddle-2.1.0/msfiddle/__init__.py +60 -0
  4. msfiddle-2.1.0/msfiddle/api.py +1123 -0
  5. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/download.py +11 -1
  6. msfiddle-2.1.0/msfiddle/external_results.py +380 -0
  7. msfiddle-2.1.0/msfiddle/main.py +295 -0
  8. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/utils/msms_utils.py +2 -2
  9. msfiddle-2.1.0/msfiddle.egg-info/PKG-INFO +285 -0
  10. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle.egg-info/SOURCES.txt +6 -0
  11. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle.egg-info/requires.txt +3 -0
  12. {msfiddle-2.0.0 → msfiddle-2.1.0}/setup.py +5 -2
  13. msfiddle-2.1.0/tests/test_api.py +262 -0
  14. msfiddle-2.1.0/tests/test_download.py +15 -0
  15. msfiddle-2.1.0/tests/test_external_results.py +282 -0
  16. msfiddle-2.1.0/tests/test_main.py +17 -0
  17. {msfiddle-2.0.0 → msfiddle-2.1.0}/tests/test_msms_utils.py +1 -0
  18. msfiddle-2.0.0/PKG-INFO +0 -159
  19. msfiddle-2.0.0/README.md +0 -121
  20. msfiddle-2.0.0/msfiddle/__init__.py +0 -60
  21. msfiddle-2.0.0/msfiddle/main.py +0 -497
  22. msfiddle-2.0.0/msfiddle.egg-info/PKG-INFO +0 -159
  23. {msfiddle-2.0.0 → msfiddle-2.1.0}/LICENSE +0 -0
  24. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/config/fiddle_tcn_casmi.yml +0 -0
  25. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/config/fiddle_tcn_demo.yml +0 -0
  26. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/config/fiddle_tcn_demo_wo_da.yml +0 -0
  27. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/config/fiddle_tcn_embl.yml +0 -0
  28. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/config/fiddle_tcn_orbitrap.yml +0 -0
  29. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/config/fiddle_tcn_qtof.yml +0 -0
  30. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/dataset.py +0 -0
  31. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/demo/input_msms.mgf +0 -0
  32. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/demo/output_buddy.csv +0 -0
  33. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/demo/output_fiddle.csv +0 -0
  34. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/demo/output_fiddle_all.csv +0 -0
  35. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/demo/output_sirius.csv +0 -0
  36. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/model_tcn.py +0 -0
  37. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/utils/__init__.py +0 -0
  38. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/utils/mol_utils.py +0 -0
  39. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/utils/pkl_utils.py +0 -0
  40. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle/utils/refine_utils.py +0 -0
  41. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle.egg-info/dependency_links.txt +0 -0
  42. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle.egg-info/entry_points.txt +0 -0
  43. {msfiddle-2.0.0 → msfiddle-2.1.0}/msfiddle.egg-info/top_level.txt +0 -0
  44. {msfiddle-2.0.0 → msfiddle-2.1.0}/setup.cfg +0 -0
  45. {msfiddle-2.0.0 → msfiddle-2.1.0}/tests/test_mol_utils.py +0 -0
  46. {msfiddle-2.0.0 → msfiddle-2.1.0}/tests/test_refine_utils.py +0 -0
@@ -0,0 +1,285 @@
1
+ Metadata-Version: 2.4
2
+ Name: msfiddle
3
+ Version: 2.1.0
4
+ Summary: A package for predicting chemical formulas from tandem mass spectra
5
+ Home-page: https://github.com/JosieHong/msfiddle
6
+ Author: Yuhui Hong
7
+ Author-email: josieexception@outlook.com
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Topic :: Scientific/Engineering :: Chemistry
12
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
13
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
14
+ Classifier: Topic :: Scientific/Engineering :: Medical Science Apps.
15
+ Requires-Python: >=3.8
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy<2.0.0,>=1.20.0
19
+ Requires-Dist: pandas>=2.0.0
20
+ Requires-Dist: tqdm>=4.60.0
21
+ Requires-Dist: pyyaml>=6.0
22
+ Requires-Dist: scikit-learn>=1.0.0
23
+ Requires-Dist: scipy>=1.8.0
24
+ Requires-Dist: pyarrow>=10.0.0
25
+ Requires-Dist: rdkit>=2022.03.5
26
+ Requires-Dist: molmass
27
+ Requires-Dist: pyteomics
28
+ Provides-Extra: inference
29
+ Requires-Dist: torch; extra == "inference"
30
+ Dynamic: author
31
+ Dynamic: author-email
32
+ Dynamic: classifier
33
+ Dynamic: description
34
+ Dynamic: description-content-type
35
+ Dynamic: home-page
36
+ Dynamic: license-file
37
+ Dynamic: provides-extra
38
+ Dynamic: requires-dist
39
+ Dynamic: requires-python
40
+ Dynamic: summary
41
+
42
+ # msfiddle
43
+
44
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
45
+ [![PyPI](https://img.shields.io/pypi/v/msfiddle)](https://pypi.org/project/msfiddle/)
46
+ [![Documentation](https://readthedocs.org/projects/msfiddle/badge/?version=latest)](https://msfiddle.readthedocs.io)
47
+
48
+ `msfiddle` is the PyPI package for FIDDLE, a deep learning method for chemical
49
+ formula prediction from tandem mass spectra (MS/MS).
50
+
51
+ ## Highlights
52
+
53
+ * Predict molecular formulas from MS/MS spectra with pre-trained FIDDLE models.
54
+ * Use the package from the command line, from native Python arrays, or from MGF files.
55
+ * Reuse loaded models for efficient batched prediction in Python applications.
56
+ * Incorporate BUDDY and SIRIUS candidate outputs in file-based workflows.
57
+
58
+ Paper: https://www.nature.com/articles/s41467-025-66060-9
59
+
60
+ Documentation: https://msfiddle.readthedocs.io
61
+
62
+ For the full experimental codebase, see https://github.com/JosieHong/FIDDLE.
63
+
64
+ ## Installation
65
+
66
+ ```bash
67
+ pip install msfiddle # base install, no PyTorch
68
+ pip install "msfiddle[inference]" # base install + PyTorch (needed for predictions and the CLI)
69
+ ```
70
+
71
+ For a custom PyTorch build (CUDA, ROCm, Apple Silicon, etc.), install torch
72
+ first via the [official guide](https://pytorch.org/get-started/locally/), then
73
+ `pip install msfiddle`.
74
+
75
+ ## Usage
76
+
77
+ ### Command-line interface
78
+
79
+ Download the pre-trained checkpoints before running predictions:
80
+ ```bash
81
+ # Download models to the default location (~/.msfiddle/check_point)
82
+ msfiddle-download-models
83
+
84
+ # Or specify a custom location and models
85
+ msfiddle-download-models --destination /path/to/models \
86
+ --models fiddle_tcn_qtof fiddle_rescore_qtof
87
+ ```
88
+
89
+ All `msfiddle` 2.x releases reuse the FIDDLE `v2.0.0` checkpoint assets.
90
+
91
+ Run the packaged demo:
92
+ ```bash
93
+ msfiddle --demo --result_path ./output_demo.csv --device 0
94
+ ```
95
+
96
+ Run the demo on CPU:
97
+ ```bash
98
+ msfiddle --demo --result_path ./output_demo.csv --device 0 --no_cuda
99
+ ```
100
+
101
+ Run prediction on your own [MGF file](#mgf-input):
102
+ ```bash
103
+ msfiddle --test_data /path/to/data.mgf \
104
+ --instrument_type orbitrap \
105
+ --result_path /path/to/results.csv \
106
+ --device 0
107
+ ```
108
+
109
+ `--instrument_type` accepts `orbitrap` (default) or `qtof`. If checkpoints are
110
+ missing, the CLI exits with instructions to run `msfiddle-download-models`.
111
+
112
+ ### Python API
113
+
114
+ Use `predict_from_spectrum` for one-off prediction from native MS/MS arrays:
115
+
116
+ ```python
117
+ from msfiddle import predict_from_spectrum
118
+
119
+ candidates = predict_from_spectrum(
120
+ mz_array=[60.0, 85.0, 100.0, 125.0, 150.0],
121
+ intensity_array=[10.0, 50.0, 20.0, 35.0, 15.0],
122
+ precursor_mz=180.063,
123
+ adduct="[M+H]+",
124
+ top_k=5,
125
+ instrument_type="orbitrap",
126
+ collision_energy="Unknown",
127
+ device="cpu",
128
+ )
129
+ ```
130
+
131
+ For repeated or batched prediction, reuse `MsFiddlePredictor` so checkpoints are
132
+ loaded once:
133
+ ```python
134
+ from msfiddle import MsFiddlePredictor
135
+
136
+ predictor = MsFiddlePredictor(instrument_type="orbitrap", device="cpu")
137
+
138
+ results = predictor.predict_batch(
139
+ [
140
+ {
141
+ "id": "sample-1",
142
+ "mz_array": [60.0, 85.0, 100.0, 125.0, 150.0],
143
+ "intensity_array": [10.0, 50.0, 20.0, 35.0, 15.0],
144
+ "precursor_mz": 180.063,
145
+ "adduct": "[M+H]+",
146
+ "collision_energy": "Unknown",
147
+ }
148
+ ]
149
+ )
150
+ ```
151
+
152
+ Python APIs do not download model checkpoints unless `download_models=True` is passed.
153
+
154
+ ## Input and output formats
155
+
156
+ ### CSV output
157
+
158
+ The CLI writes a CSV file with one row per spectrum. Key columns include:
159
+
160
+ | Column | Description |
161
+ | --- | --- |
162
+ | `ID` | Spectrum title from the MGF file. |
163
+ | `Mass` | Neutral mass calculated from precursor m/z and adduct. |
164
+ | `Pred Formula` | Initial formula predicted by the neural model. |
165
+ | `Pred Mass` | Model-predicted mass. |
166
+ | `Pred Atom Num` | Model-predicted atom count. |
167
+ | `Pred H/C Num` | Model-predicted H/C count. |
168
+ | `Refined Formula (0..4)` | Ranked refined formula candidates for the default top-5 output. |
169
+ | `Refined Mass (0..4)` | Masses for the default top-5 refined candidates. |
170
+ | `Rescore (0..4)` | Confidence scores for the default top-5 refined candidates. |
171
+
172
+ ### API output
173
+
174
+ The Python `predict_from_spectrum()` API returns a list of candidate dictionaries:
175
+ ```python
176
+ [
177
+ {
178
+ "formula": "C8H10O",
179
+ "score": 0.94,
180
+ "mass": 122.073,
181
+ "metadata": {...},
182
+ }
183
+ ]
184
+ ```
185
+
186
+ `predict_batch()` returns one record per input spectrum with `id`, `candidates`,
187
+ and `metadata`.
188
+
189
+ ### Native/original BUDDY and SIRIUS outputs
190
+
191
+ Use the same MGF input file to generate native
192
+ [BUDDY/msbuddy](https://msbuddy.readthedocs.io/en/latest/cmdapi.html) and
193
+ [SIRIUS](https://v6.docs.sirius-ms.io/cli/) outputs. `msfiddle` accepts these
194
+ native/original files directly through `--buddy_path` and `--sirius_path`. The
195
+ older msfiddle-normalized CSV formats documented in `docs/formats.rst` are
196
+ **deprecated** and will be removed in `msfiddle` 3.0.0; loading them emits a
197
+ `DeprecationWarning`.
198
+
199
+ ```bash
200
+ msbuddy -mgf /path/to/data.mgf \
201
+ -output /path/to/buddy_output \
202
+ -ms orbitrap \
203
+ -p -n_cpu 12 \
204
+ -d -hal
205
+ ```
206
+
207
+ `msbuddy` writes `msbuddy_result_summary.tsv`; `-d` also writes detailed
208
+ per-query `formula_results.tsv` files. Pass either the summary file or the
209
+ output directory to `--buddy_path`. The full output directory is preferred
210
+ because it includes per-candidate FDR scores for ranks beyond rank 1.
211
+
212
+ ```bash
213
+ sirius --input /path/to/data.mgf \
214
+ --project /path/to/sirius_project \
215
+ formulas --profile orbitrap
216
+
217
+ sirius --project /path/to/sirius_project \
218
+ summaries --top-k-summary=5 \
219
+ --output /path/to/sirius_output
220
+ ```
221
+
222
+ SIRIUS writes a project space and exports summary files such as
223
+ `formula_identifications.tsv`. Pass either a formula-identification summary file
224
+ or the summary output directory to `--sirius_path`.
225
+ SIRIUS 6 may require `sirius login` before formula computation.
226
+
227
+ ### MGF input
228
+
229
+ The required MGF fields are `TITLE`, `PRECURSOR_MZ`, `PRECURSOR_TYPE`, and
230
+ `COLLISION_ENERGY`:
231
+ ```mgf
232
+ BEGIN IONS
233
+ TITLE=EMBL_MCF_2_0_HRMS_Library000529
234
+ PEPMASS=111.02016
235
+ CHARGE=1-
236
+ PRECURSOR_TYPE=[M-H]-
237
+ PRECURSOR_MZ=111.02016
238
+ COLLISION_ENERGY=50.0
239
+ SMILES=[H]c1c([H])n([H])c(=O)n([H])c1=O
240
+ FORMULA=C4H4N2O2
241
+ THEORETICAL_PRECURSOR_MZ=111.019453
242
+ PPM=6.368253318682487
243
+ SIMULATED_PRECURSOR_MZ=111.01946768634916
244
+ 41.0148 0.329893
245
+ 41.9986 89.226766
246
+ 55.8055 0.200544
247
+ 56.2625 0.194617
248
+ 67.0304 0.330612
249
+ 68.0258 0.402906
250
+ 111.0203 100.0
251
+ 112.0515 1.2809
252
+ END IONS
253
+ ```
254
+
255
+ ## Advanced Usage
256
+
257
+ Inspect checkpoint paths:
258
+ ```bash
259
+ msfiddle-checkpoint-paths
260
+ ```
261
+
262
+ Use custom config and checkpoint paths:
263
+ ```bash
264
+ msfiddle --test_data /path/to/data.mgf \
265
+ --config_path /path/to/config.yml \
266
+ --resume_path /path/to/tcn_model.pt \
267
+ --rescore_resume_path /path/to/rescore_model.pt \
268
+ --result_path /path/to/results.csv \
269
+ --device 0
270
+ ```
271
+
272
+ ## Citation
273
+
274
+ ```
275
+ @article{hong2025fiddle,
276
+ title={FIDDLE: a deep learning method for chemical formulas prediction from tandem mass spectra},
277
+ author={Hong, Yuhui and Li, Sujun and Ye, Yuzhen and Tang, Haixu},
278
+ journal={Nature Communications},
279
+ volume={16},
280
+ number={1},
281
+ pages={11102},
282
+ year={2025},
283
+ publisher={Nature Publishing Group UK London}
284
+ }
285
+ ```
@@ -0,0 +1,244 @@
1
+ # msfiddle
2
+
3
+ [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
4
+ [![PyPI](https://img.shields.io/pypi/v/msfiddle)](https://pypi.org/project/msfiddle/)
5
+ [![Documentation](https://readthedocs.org/projects/msfiddle/badge/?version=latest)](https://msfiddle.readthedocs.io)
6
+
7
+ `msfiddle` is the PyPI package for FIDDLE, a deep learning method for chemical
8
+ formula prediction from tandem mass spectra (MS/MS).
9
+
10
+ ## Highlights
11
+
12
+ * Predict molecular formulas from MS/MS spectra with pre-trained FIDDLE models.
13
+ * Use the package from the command line, from native Python arrays, or from MGF files.
14
+ * Reuse loaded models for efficient batched prediction in Python applications.
15
+ * Incorporate BUDDY and SIRIUS candidate outputs in file-based workflows.
16
+
17
+ Paper: https://www.nature.com/articles/s41467-025-66060-9
18
+
19
+ Documentation: https://msfiddle.readthedocs.io
20
+
21
+ For the full experimental codebase, see https://github.com/JosieHong/FIDDLE.
22
+
23
+ ## Installation
24
+
25
+ ```bash
26
+ pip install msfiddle # base install, no PyTorch
27
+ pip install "msfiddle[inference]" # base install + PyTorch (needed for predictions and the CLI)
28
+ ```
29
+
30
+ For a custom PyTorch build (CUDA, ROCm, Apple Silicon, etc.), install torch
31
+ first via the [official guide](https://pytorch.org/get-started/locally/), then
32
+ `pip install msfiddle`.
33
+
34
+ ## Usage
35
+
36
+ ### Command-line interface
37
+
38
+ Download the pre-trained checkpoints before running predictions:
39
+ ```bash
40
+ # Download models to the default location (~/.msfiddle/check_point)
41
+ msfiddle-download-models
42
+
43
+ # Or specify a custom location and models
44
+ msfiddle-download-models --destination /path/to/models \
45
+ --models fiddle_tcn_qtof fiddle_rescore_qtof
46
+ ```
47
+
48
+ All `msfiddle` 2.x releases reuse the FIDDLE `v2.0.0` checkpoint assets.
49
+
50
+ Run the packaged demo:
51
+ ```bash
52
+ msfiddle --demo --result_path ./output_demo.csv --device 0
53
+ ```
54
+
55
+ Run the demo on CPU:
56
+ ```bash
57
+ msfiddle --demo --result_path ./output_demo.csv --device 0 --no_cuda
58
+ ```
59
+
60
+ Run prediction on your own [MGF file](#mgf-input):
61
+ ```bash
62
+ msfiddle --test_data /path/to/data.mgf \
63
+ --instrument_type orbitrap \
64
+ --result_path /path/to/results.csv \
65
+ --device 0
66
+ ```
67
+
68
+ `--instrument_type` accepts `orbitrap` (default) or `qtof`. If checkpoints are
69
+ missing, the CLI exits with instructions to run `msfiddle-download-models`.
70
+
71
+ ### Python API
72
+
73
+ Use `predict_from_spectrum` for one-off prediction from native MS/MS arrays:
74
+
75
+ ```python
76
+ from msfiddle import predict_from_spectrum
77
+
78
+ candidates = predict_from_spectrum(
79
+ mz_array=[60.0, 85.0, 100.0, 125.0, 150.0],
80
+ intensity_array=[10.0, 50.0, 20.0, 35.0, 15.0],
81
+ precursor_mz=180.063,
82
+ adduct="[M+H]+",
83
+ top_k=5,
84
+ instrument_type="orbitrap",
85
+ collision_energy="Unknown",
86
+ device="cpu",
87
+ )
88
+ ```
89
+
90
+ For repeated or batched prediction, reuse `MsFiddlePredictor` so checkpoints are
91
+ loaded once:
92
+ ```python
93
+ from msfiddle import MsFiddlePredictor
94
+
95
+ predictor = MsFiddlePredictor(instrument_type="orbitrap", device="cpu")
96
+
97
+ results = predictor.predict_batch(
98
+ [
99
+ {
100
+ "id": "sample-1",
101
+ "mz_array": [60.0, 85.0, 100.0, 125.0, 150.0],
102
+ "intensity_array": [10.0, 50.0, 20.0, 35.0, 15.0],
103
+ "precursor_mz": 180.063,
104
+ "adduct": "[M+H]+",
105
+ "collision_energy": "Unknown",
106
+ }
107
+ ]
108
+ )
109
+ ```
110
+
111
+ Python APIs do not download model checkpoints unless `download_models=True` is passed.
112
+
113
+ ## Input and output formats
114
+
115
+ ### CSV output
116
+
117
+ The CLI writes a CSV file with one row per spectrum. Key columns include:
118
+
119
+ | Column | Description |
120
+ | --- | --- |
121
+ | `ID` | Spectrum title from the MGF file. |
122
+ | `Mass` | Neutral mass calculated from precursor m/z and adduct. |
123
+ | `Pred Formula` | Initial formula predicted by the neural model. |
124
+ | `Pred Mass` | Model-predicted mass. |
125
+ | `Pred Atom Num` | Model-predicted atom count. |
126
+ | `Pred H/C Num` | Model-predicted H/C count. |
127
+ | `Refined Formula (0..4)` | Ranked refined formula candidates for the default top-5 output. |
128
+ | `Refined Mass (0..4)` | Masses for the default top-5 refined candidates. |
129
+ | `Rescore (0..4)` | Confidence scores for the default top-5 refined candidates. |
130
+
131
+ ### API output
132
+
133
+ The Python `predict_from_spectrum()` API returns a list of candidate dictionaries:
134
+ ```python
135
+ [
136
+ {
137
+ "formula": "C8H10O",
138
+ "score": 0.94,
139
+ "mass": 122.073,
140
+ "metadata": {...},
141
+ }
142
+ ]
143
+ ```
144
+
145
+ `predict_batch()` returns one record per input spectrum with `id`, `candidates`,
146
+ and `metadata`.
147
+
148
+ ### Native/original BUDDY and SIRIUS outputs
149
+
150
+ Use the same MGF input file to generate native
151
+ [BUDDY/msbuddy](https://msbuddy.readthedocs.io/en/latest/cmdapi.html) and
152
+ [SIRIUS](https://v6.docs.sirius-ms.io/cli/) outputs. `msfiddle` accepts these
153
+ native/original files directly through `--buddy_path` and `--sirius_path`. The
154
+ older msfiddle-normalized CSV formats documented in `docs/formats.rst` are
155
+ **deprecated** and will be removed in `msfiddle` 3.0.0; loading them emits a
156
+ `DeprecationWarning`.
157
+
158
+ ```bash
159
+ msbuddy -mgf /path/to/data.mgf \
160
+ -output /path/to/buddy_output \
161
+ -ms orbitrap \
162
+ -p -n_cpu 12 \
163
+ -d -hal
164
+ ```
165
+
166
+ `msbuddy` writes `msbuddy_result_summary.tsv`; `-d` also writes detailed
167
+ per-query `formula_results.tsv` files. Pass either the summary file or the
168
+ output directory to `--buddy_path`. The full output directory is preferred
169
+ because it includes per-candidate FDR scores for ranks beyond rank 1.
170
+
171
+ ```bash
172
+ sirius --input /path/to/data.mgf \
173
+ --project /path/to/sirius_project \
174
+ formulas --profile orbitrap
175
+
176
+ sirius --project /path/to/sirius_project \
177
+ summaries --top-k-summary=5 \
178
+ --output /path/to/sirius_output
179
+ ```
180
+
181
+ SIRIUS writes a project space and exports summary files such as
182
+ `formula_identifications.tsv`. Pass either a formula-identification summary file
183
+ or the summary output directory to `--sirius_path`.
184
+ SIRIUS 6 may require `sirius login` before formula computation.
185
+
186
+ ### MGF input
187
+
188
+ The required MGF fields are `TITLE`, `PRECURSOR_MZ`, `PRECURSOR_TYPE`, and
189
+ `COLLISION_ENERGY`:
190
+ ```mgf
191
+ BEGIN IONS
192
+ TITLE=EMBL_MCF_2_0_HRMS_Library000529
193
+ PEPMASS=111.02016
194
+ CHARGE=1-
195
+ PRECURSOR_TYPE=[M-H]-
196
+ PRECURSOR_MZ=111.02016
197
+ COLLISION_ENERGY=50.0
198
+ SMILES=[H]c1c([H])n([H])c(=O)n([H])c1=O
199
+ FORMULA=C4H4N2O2
200
+ THEORETICAL_PRECURSOR_MZ=111.019453
201
+ PPM=6.368253318682487
202
+ SIMULATED_PRECURSOR_MZ=111.01946768634916
203
+ 41.0148 0.329893
204
+ 41.9986 89.226766
205
+ 55.8055 0.200544
206
+ 56.2625 0.194617
207
+ 67.0304 0.330612
208
+ 68.0258 0.402906
209
+ 111.0203 100.0
210
+ 112.0515 1.2809
211
+ END IONS
212
+ ```
213
+
214
+ ## Advanced Usage
215
+
216
+ Inspect checkpoint paths:
217
+ ```bash
218
+ msfiddle-checkpoint-paths
219
+ ```
220
+
221
+ Use custom config and checkpoint paths:
222
+ ```bash
223
+ msfiddle --test_data /path/to/data.mgf \
224
+ --config_path /path/to/config.yml \
225
+ --resume_path /path/to/tcn_model.pt \
226
+ --rescore_resume_path /path/to/rescore_model.pt \
227
+ --result_path /path/to/results.csv \
228
+ --device 0
229
+ ```
230
+
231
+ ## Citation
232
+
233
+ ```
234
+ @article{hong2025fiddle,
235
+ title={FIDDLE: a deep learning method for chemical formulas prediction from tandem mass spectra},
236
+ author={Hong, Yuhui and Li, Sujun and Ye, Yuzhen and Tang, Haixu},
237
+ journal={Nature Communications},
238
+ volume={16},
239
+ number={1},
240
+ pages={11102},
241
+ year={2025},
242
+ publisher={Nature Publishing Group UK London}
243
+ }
244
+ ```
@@ -0,0 +1,60 @@
1
+ """
2
+ msfiddle: A package for predicting chemical formulas from tandem mass spectra
3
+ """
4
+
5
+ from importlib.metadata import PackageNotFoundError, version as _pkg_version
6
+
7
+ try:
8
+ __version__ = _pkg_version("msfiddle")
9
+ except PackageNotFoundError: # running from a source checkout without install
10
+ __version__ = "0.0.0+unknown"
11
+
12
+ from .api import (
13
+ MsFiddlePredictor,
14
+ predict_batch_from_spectra,
15
+ predict_from_mgf,
16
+ predict_from_spectrum,
17
+ )
18
+ from .utils.mol_utils import vector_to_formula, formula_to_vector
19
+ from .utils.msms_utils import mass_calculator
20
+ from .utils.refine_utils import formula_refinement
21
+ from .download import check_models_exist, download_models, get_model_path
22
+
23
+
24
+ def __getattr__(name):
25
+ """Lazy-load torch-dependent components only when accessed."""
26
+ if name in ("MS2FNet_tcn", "FormulaEncoder", "RescoreHead"):
27
+ from .model_tcn import FormulaEncoder, MS2FNet_tcn, RescoreHead
28
+
29
+ globals()["MS2FNet_tcn"] = MS2FNet_tcn
30
+ globals()["FormulaEncoder"] = FormulaEncoder
31
+ globals()["RescoreHead"] = RescoreHead
32
+ return globals()[name]
33
+ if name in ("test_step", "rescore_candidates"):
34
+ from .main import rescore_candidates, test_step
35
+
36
+ globals()["test_step"] = test_step
37
+ globals()["rescore_candidates"] = rescore_candidates
38
+ return globals()[name]
39
+ raise AttributeError(f"module 'msfiddle' has no attribute {name!r}")
40
+
41
+
42
+ __all__ = [
43
+ "__version__",
44
+ "MsFiddlePredictor",
45
+ "predict_from_spectrum",
46
+ "predict_batch_from_spectra",
47
+ "predict_from_mgf",
48
+ "MS2FNet_tcn",
49
+ "FormulaEncoder",
50
+ "RescoreHead",
51
+ "formula_refinement",
52
+ "mass_calculator",
53
+ "vector_to_formula",
54
+ "formula_to_vector",
55
+ "test_step",
56
+ "rescore_candidates",
57
+ "download_models",
58
+ "check_models_exist",
59
+ "get_model_path",
60
+ ]