msbuddy 0.2.0__tar.gz → 0.2.2__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.
- {msbuddy-0.2.0 → msbuddy-0.2.2}/PKG-INFO +27 -11
- {msbuddy-0.2.0 → msbuddy-0.2.2}/README.md +26 -10
- msbuddy-0.2.2/msbuddy/__init__.py +3 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/cand.py +84 -6
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/load.py +6 -6
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/main.py +1 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/utils.py +16 -1
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy.egg-info/PKG-INFO +27 -11
- {msbuddy-0.2.0 → msbuddy-0.2.2}/setup.py +1 -1
- msbuddy-0.2.0/msbuddy/__init__.py +0 -1
- {msbuddy-0.2.0 → msbuddy-0.2.2}/LICENSE +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/base.py +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/export.py +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/main_cmd.py +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/ml.py +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy/query.py +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy.egg-info/SOURCES.txt +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy.egg-info/dependency_links.txt +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy.egg-info/entry_points.txt +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy.egg-info/requires.txt +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/msbuddy.egg-info/top_level.txt +0 -0
- {msbuddy-0.2.0 → msbuddy-0.2.2}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: msbuddy
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Bottom-up MS/MS interrogation-based molecular formula annotation for mass spectrometry data.
|
|
5
5
|
Home-page: https://github.com/Philipbear/msbuddy
|
|
6
6
|
Author: Shipei Xing
|
|
@@ -20,7 +20,13 @@ License-File: LICENSE
|
|
|
20
20
|
[](https://msbuddy.readthedocs.io/en/latest/?badge=latest)
|
|
21
21
|
[](https://github.com/Philipbear/msbuddy)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
<p align="center">
|
|
24
|
+
<img src="https://github.com/Philipbear/msbuddy/blob/main/logo/logo.svg" alt="Sample Image" height="100"/>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
`msbuddy` is developed for molecular formula analysis in MS-based metabolomics studies.
|
|
29
|
+
|
|
24
30
|
`msbuddy` is able to provide formula annotations for queries:
|
|
25
31
|
* with or without MS1 isotopic pattern
|
|
26
32
|
* with or without MS/MS spectra
|
|
@@ -30,7 +36,7 @@ The minimum requirement for a msbuddy query is a single _m/z_ value and its ioni
|
|
|
30
36
|
|
|
31
37
|
**Official documentation** is available at https://msbuddy.readthedocs.io/en/latest/.
|
|
32
38
|
|
|
33
|
-
**msbuddy ver 0.2.
|
|
39
|
+
**msbuddy ver 0.2.1** is now released. See [change log](https://github.com/Philipbear/msbuddy/blob/main/changelog.md) for details.
|
|
34
40
|
|
|
35
41
|
## Citation
|
|
36
42
|
> S. Xing et al. BUDDY: molecular formula discovery via bottom-up MS/MS interrogation. **Nature Methods** 2023. [DOI: 10.1038/s41592-023-01850-x](https://doi.org/10.1038/s41592-023-01850-x)
|
|
@@ -45,20 +51,21 @@ pip install msbuddy
|
|
|
45
51
|
|
|
46
52
|
To install a specific version, see PyPI [release history](https://pypi.org/project/msbuddy/#history).
|
|
47
53
|
|
|
48
|
-
## Python usage
|
|
54
|
+
## Python usage
|
|
49
55
|
|
|
56
|
+
### Quick start ([docs](https://msbuddy.readthedocs.io/en/latest/quickstart.html))
|
|
50
57
|
As a quick start, we here load a mgf file and annotate the molecular formula for each query.
|
|
51
58
|
All the configurations are specified in the [`MsbuddyConfig`](https://msbuddy.readthedocs.io/en/latest/pyapi.html#msbuddy.MsbuddyConfig) class.
|
|
52
|
-
**Parallel computing** is supported.
|
|
59
|
+
**Parallel computing** is [supported](https://msbuddy.readthedocs.io/en/latest/quickstart.html).
|
|
53
60
|
|
|
54
61
|
```python
|
|
55
62
|
from msbuddy import Msbuddy, MsbuddyConfig
|
|
56
63
|
|
|
57
64
|
# instantiate a MsbuddyConfig object
|
|
58
|
-
msb_config = MsbuddyConfig(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
msb_config = MsbuddyConfig(# highly recommended to specify
|
|
66
|
+
ms_instr='orbitrap', # supported: "qtof", "orbitrap" and "fticr"
|
|
67
|
+
# whether to consider halogen atoms FClBrI
|
|
68
|
+
halogen=False)
|
|
62
69
|
|
|
63
70
|
# instantiate a Msbuddy object
|
|
64
71
|
msb_engine = Msbuddy(msb_config)
|
|
@@ -72,6 +79,8 @@ msb_engine.annotate_formula()
|
|
|
72
79
|
# retrieve the annotation result summary
|
|
73
80
|
result = msb_engine.get_summary()
|
|
74
81
|
```
|
|
82
|
+
See [demo mgf file](https://github.com/Philipbear/msbuddy/tree/main/demo).
|
|
83
|
+
|
|
75
84
|
|
|
76
85
|
MS/MS spectra can be loaded via their [USIs](https://www.biorxiv.org/content/10.1101/2020.05.09.086066v2) if they are publicly available:
|
|
77
86
|
```python
|
|
@@ -79,7 +88,14 @@ MS/MS spectra can be loaded via their [USIs](https://www.biorxiv.org/content/10.
|
|
|
79
88
|
msb_engine.load_usi(['mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036',
|
|
80
89
|
'mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037'])
|
|
81
90
|
```
|
|
82
|
-
|
|
91
|
+
|
|
92
|
+
### Other API functions
|
|
93
|
+
- generate molecular formulas from a neutral mass (mass_to_formula)
|
|
94
|
+
- generate molecular formulas from a charged _m/z_ value (mz_to_formula)
|
|
95
|
+
- predict formula feasibility using a deep learning model (predict_formula_feasibility)
|
|
96
|
+
- enumerate all possible subformulas of a given precursor formula (enumerate_subform_arr)
|
|
97
|
+
|
|
98
|
+
See more in the [documentation](https://msbuddy.readthedocs.io/en/latest/pyapi.html).
|
|
83
99
|
|
|
84
100
|
## Command-line tool ([docs](https://msbuddy.readthedocs.io/en/latest/cmdapi.html))
|
|
85
101
|
|
|
@@ -95,7 +111,7 @@ for a single USI string (from FT-ICR, for example):
|
|
|
95
111
|
```bash
|
|
96
112
|
msbuddy -usi <usi_string> -output <output_folder> -ms fticr
|
|
97
113
|
```
|
|
98
|
-
or a csv file ([
|
|
114
|
+
or a csv file ([template files](https://github.com/Philipbear/msbuddy/tree/main/demo)) containing multiple USI strings (QTOF in this example):
|
|
99
115
|
```bash
|
|
100
116
|
msbuddy -csv <csv_file> -output <output_folder> -ms qtof -details
|
|
101
117
|
```
|
|
@@ -4,7 +4,13 @@
|
|
|
4
4
|
[](https://msbuddy.readthedocs.io/en/latest/?badge=latest)
|
|
5
5
|
[](https://github.com/Philipbear/msbuddy)
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
<p align="center">
|
|
8
|
+
<img src="https://github.com/Philipbear/msbuddy/blob/main/logo/logo.svg" alt="Sample Image" height="100"/>
|
|
9
|
+
</p>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
`msbuddy` is developed for molecular formula analysis in MS-based metabolomics studies.
|
|
13
|
+
|
|
8
14
|
`msbuddy` is able to provide formula annotations for queries:
|
|
9
15
|
* with or without MS1 isotopic pattern
|
|
10
16
|
* with or without MS/MS spectra
|
|
@@ -14,7 +20,7 @@ The minimum requirement for a msbuddy query is a single _m/z_ value and its ioni
|
|
|
14
20
|
|
|
15
21
|
**Official documentation** is available at https://msbuddy.readthedocs.io/en/latest/.
|
|
16
22
|
|
|
17
|
-
**msbuddy ver 0.2.
|
|
23
|
+
**msbuddy ver 0.2.1** is now released. See [change log](https://github.com/Philipbear/msbuddy/blob/main/changelog.md) for details.
|
|
18
24
|
|
|
19
25
|
## Citation
|
|
20
26
|
> S. Xing et al. BUDDY: molecular formula discovery via bottom-up MS/MS interrogation. **Nature Methods** 2023. [DOI: 10.1038/s41592-023-01850-x](https://doi.org/10.1038/s41592-023-01850-x)
|
|
@@ -29,20 +35,21 @@ pip install msbuddy
|
|
|
29
35
|
|
|
30
36
|
To install a specific version, see PyPI [release history](https://pypi.org/project/msbuddy/#history).
|
|
31
37
|
|
|
32
|
-
## Python usage
|
|
38
|
+
## Python usage
|
|
33
39
|
|
|
40
|
+
### Quick start ([docs](https://msbuddy.readthedocs.io/en/latest/quickstart.html))
|
|
34
41
|
As a quick start, we here load a mgf file and annotate the molecular formula for each query.
|
|
35
42
|
All the configurations are specified in the [`MsbuddyConfig`](https://msbuddy.readthedocs.io/en/latest/pyapi.html#msbuddy.MsbuddyConfig) class.
|
|
36
|
-
**Parallel computing** is supported.
|
|
43
|
+
**Parallel computing** is [supported](https://msbuddy.readthedocs.io/en/latest/quickstart.html).
|
|
37
44
|
|
|
38
45
|
```python
|
|
39
46
|
from msbuddy import Msbuddy, MsbuddyConfig
|
|
40
47
|
|
|
41
48
|
# instantiate a MsbuddyConfig object
|
|
42
|
-
msb_config = MsbuddyConfig(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
49
|
+
msb_config = MsbuddyConfig(# highly recommended to specify
|
|
50
|
+
ms_instr='orbitrap', # supported: "qtof", "orbitrap" and "fticr"
|
|
51
|
+
# whether to consider halogen atoms FClBrI
|
|
52
|
+
halogen=False)
|
|
46
53
|
|
|
47
54
|
# instantiate a Msbuddy object
|
|
48
55
|
msb_engine = Msbuddy(msb_config)
|
|
@@ -56,6 +63,8 @@ msb_engine.annotate_formula()
|
|
|
56
63
|
# retrieve the annotation result summary
|
|
57
64
|
result = msb_engine.get_summary()
|
|
58
65
|
```
|
|
66
|
+
See [demo mgf file](https://github.com/Philipbear/msbuddy/tree/main/demo).
|
|
67
|
+
|
|
59
68
|
|
|
60
69
|
MS/MS spectra can be loaded via their [USIs](https://www.biorxiv.org/content/10.1101/2020.05.09.086066v2) if they are publicly available:
|
|
61
70
|
```python
|
|
@@ -63,7 +72,14 @@ MS/MS spectra can be loaded via their [USIs](https://www.biorxiv.org/content/10.
|
|
|
63
72
|
msb_engine.load_usi(['mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036',
|
|
64
73
|
'mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037'])
|
|
65
74
|
```
|
|
66
|
-
|
|
75
|
+
|
|
76
|
+
### Other API functions
|
|
77
|
+
- generate molecular formulas from a neutral mass (mass_to_formula)
|
|
78
|
+
- generate molecular formulas from a charged _m/z_ value (mz_to_formula)
|
|
79
|
+
- predict formula feasibility using a deep learning model (predict_formula_feasibility)
|
|
80
|
+
- enumerate all possible subformulas of a given precursor formula (enumerate_subform_arr)
|
|
81
|
+
|
|
82
|
+
See more in the [documentation](https://msbuddy.readthedocs.io/en/latest/pyapi.html).
|
|
67
83
|
|
|
68
84
|
## Command-line tool ([docs](https://msbuddy.readthedocs.io/en/latest/cmdapi.html))
|
|
69
85
|
|
|
@@ -79,7 +95,7 @@ for a single USI string (from FT-ICR, for example):
|
|
|
79
95
|
```bash
|
|
80
96
|
msbuddy -usi <usi_string> -output <output_folder> -ms fticr
|
|
81
97
|
```
|
|
82
|
-
or a csv file ([
|
|
98
|
+
or a csv file ([template files](https://github.com/Philipbear/msbuddy/tree/main/demo)) containing multiple USI strings (QTOF in this example):
|
|
83
99
|
```bash
|
|
84
100
|
msbuddy -csv <csv_file> -output <output_folder> -ms qtof -details
|
|
85
101
|
```
|
|
@@ -19,9 +19,9 @@ import numpy as np
|
|
|
19
19
|
from brainpy import isotopic_variants
|
|
20
20
|
from numba import njit
|
|
21
21
|
|
|
22
|
-
from msbuddy.base import Formula, CandidateFormula, MS2Explanation, MetaFeature
|
|
22
|
+
from msbuddy.base import Formula, CandidateFormula, MS2Explanation, MetaFeature, check_adduct, Adduct
|
|
23
23
|
from msbuddy.query import check_common_frag, check_common_nl, query_precursor_mass, query_fragnl_mass
|
|
24
|
-
from msbuddy.utils import form_arr_to_str, enumerate_subformula
|
|
24
|
+
from msbuddy.utils import form_arr_to_str, enumerate_subformula, read_formula, SubformulaResult, FormulaResult
|
|
25
25
|
|
|
26
26
|
|
|
27
27
|
class FragExplanation:
|
|
@@ -705,7 +705,7 @@ def _calc_subform_mass(subform_arr: np.array, adduct_charge: int) -> np.array:
|
|
|
705
705
|
|
|
706
706
|
|
|
707
707
|
@njit
|
|
708
|
-
def _dbe_subform_filter(subform_arr: np.array) -> np.array:
|
|
708
|
+
def _dbe_subform_filter(subform_arr: np.array, cutoff: float) -> np.array:
|
|
709
709
|
"""
|
|
710
710
|
Filter subformulas by DBE.
|
|
711
711
|
:param subform_arr: 2D array, each row is a subformula array
|
|
@@ -714,7 +714,7 @@ def _dbe_subform_filter(subform_arr: np.array) -> np.array:
|
|
|
714
714
|
dbe_arr = subform_arr[:, 0] + 1 - (subform_arr[:, 1] + subform_arr[:, 4] + subform_arr[:, 3] + subform_arr[:, 2]
|
|
715
715
|
+ subform_arr[:, 5] + subform_arr[:, 8] + subform_arr[:, 6]) / 2 + \
|
|
716
716
|
(subform_arr[:, 7] + subform_arr[:, 10]) / 2
|
|
717
|
-
dbe_bool_arr = dbe_arr >=
|
|
717
|
+
dbe_bool_arr = dbe_arr >= cutoff
|
|
718
718
|
return dbe_bool_arr
|
|
719
719
|
|
|
720
720
|
|
|
@@ -774,6 +774,7 @@ def _assign_ms2_explanation(mf: MetaFeature, cf: CandidateFormula, pre_charged_a
|
|
|
774
774
|
:return: CandidateFormula object
|
|
775
775
|
"""
|
|
776
776
|
candidate_space = None
|
|
777
|
+
ion_mode_int = 1 if mf.adduct.pos_mode else -1
|
|
777
778
|
for i in range(len(mf.ms2_processed.mz_array)):
|
|
778
779
|
# retrieve all indices of mass within tolerance
|
|
779
780
|
this_ms2_tol = ms2_tol if not ppm else ms2_tol * mf.ms2_processed.mz_array[i] * 1e-6
|
|
@@ -785,10 +786,9 @@ def _assign_ms2_explanation(mf: MetaFeature, cf: CandidateFormula, pre_charged_a
|
|
|
785
786
|
# retrieve all subformulas within tolerance
|
|
786
787
|
this_subform_arr = subform_arr[idx_list, :]
|
|
787
788
|
this_mass = mass_arr[idx_list]
|
|
788
|
-
ion_mode_int = 1 if mf.adduct.pos_mode else -1
|
|
789
789
|
|
|
790
790
|
# dbe filter (DBE >= -1)
|
|
791
|
-
bool_arr_1 = _dbe_subform_filter(this_subform_arr)
|
|
791
|
+
bool_arr_1 = _dbe_subform_filter(this_subform_arr, -1.)
|
|
792
792
|
|
|
793
793
|
# SENIOR rules filter, a soft version
|
|
794
794
|
bool_arr_2 = _senior_subform_filter(this_subform_arr)
|
|
@@ -831,3 +831,81 @@ def _assign_ms2_explanation(mf: MetaFeature, cf: CandidateFormula, pre_charged_a
|
|
|
831
831
|
candidate_form.ms1_isotope_similarity = cf.ms1_isotope_similarity # copy ms1_isotope_similarity
|
|
832
832
|
|
|
833
833
|
return candidate_form
|
|
834
|
+
|
|
835
|
+
|
|
836
|
+
def assign_subformula(ms2_mz: List, precursor_formula: str, adduct: str,
|
|
837
|
+
ms2_tol: float = 10, ppm: bool = True,
|
|
838
|
+
dbe_cutoff: float = -1.0) -> Union[List[SubformulaResult], None]:
|
|
839
|
+
"""
|
|
840
|
+
Assign subformulas to a given MS2 spectrum with a given precursor formula and adduct. Radical ions are considered.
|
|
841
|
+
:param ms2_mz: MS2 m/z list
|
|
842
|
+
:param precursor_formula: precursor formula string, uncharged
|
|
843
|
+
:param adduct: adduct string, e.g., [M+H]+
|
|
844
|
+
:param ms2_tol: MS2 tolerance
|
|
845
|
+
:param ppm: whether MS2 tolerance is in ppm
|
|
846
|
+
:param dbe_cutoff: float, DBE cutoff
|
|
847
|
+
:return: a list of SubformulaResult objects
|
|
848
|
+
"""
|
|
849
|
+
assert len(ms2_mz) > 0, "MS2 m/z list is empty."
|
|
850
|
+
|
|
851
|
+
# convert precursor formula to array
|
|
852
|
+
form_arr = read_formula(precursor_formula)
|
|
853
|
+
if form_arr is None:
|
|
854
|
+
return None
|
|
855
|
+
|
|
856
|
+
# convert adduct to array
|
|
857
|
+
valid_adduct, pos_mode = check_adduct(adduct)
|
|
858
|
+
if not valid_adduct:
|
|
859
|
+
raise ValueError("Invalid adduct string.")
|
|
860
|
+
ion = Adduct(adduct, pos_mode)
|
|
861
|
+
ion_mode_int = 1 if pos_mode else -1
|
|
862
|
+
|
|
863
|
+
# enumerate all subformulas
|
|
864
|
+
pre_charged_arr = form_arr * ion.m + ion.net_formula.array
|
|
865
|
+
subform_arr = enumerate_subformula(pre_charged_arr)
|
|
866
|
+
|
|
867
|
+
# mono mass
|
|
868
|
+
mass_arr = _calc_subform_mass(subform_arr, ion.charge)
|
|
869
|
+
|
|
870
|
+
# assign ms2 explanation
|
|
871
|
+
out_list = []
|
|
872
|
+
for k, mz in enumerate(ms2_mz):
|
|
873
|
+
# retrieve all indices of mass within tolerance
|
|
874
|
+
this_ms2_tol = ms2_tol if not ppm else ms2_tol * mz * 1e-6
|
|
875
|
+
idx_list = np.where(abs(mz - mass_arr) <= this_ms2_tol)[0]
|
|
876
|
+
|
|
877
|
+
if len(idx_list) == 0:
|
|
878
|
+
out_list.append(SubformulaResult(k, []))
|
|
879
|
+
continue
|
|
880
|
+
|
|
881
|
+
# retrieve all subformulas within tolerance
|
|
882
|
+
this_subform_arr = subform_arr[idx_list, :]
|
|
883
|
+
this_mass = mass_arr[idx_list]
|
|
884
|
+
|
|
885
|
+
# dbe filter (DBE >= dbe_cutoff)
|
|
886
|
+
bool_arr_1 = _dbe_subform_filter(this_subform_arr, dbe_cutoff)
|
|
887
|
+
|
|
888
|
+
# SENIOR rules filter, a soft version
|
|
889
|
+
bool_arr_2 = _senior_subform_filter(this_subform_arr)
|
|
890
|
+
|
|
891
|
+
# valid subformula check
|
|
892
|
+
bool_arr_3 = _valid_subform_check(this_subform_arr, pre_charged_arr)
|
|
893
|
+
|
|
894
|
+
# combine filters
|
|
895
|
+
bool_arr = bool_arr_1 & bool_arr_2 & bool_arr_3
|
|
896
|
+
this_subform_arr = this_subform_arr[bool_arr, :]
|
|
897
|
+
this_mass = this_mass[bool_arr]
|
|
898
|
+
|
|
899
|
+
# if no valid subformula, skip
|
|
900
|
+
if this_subform_arr.shape[0] == 0:
|
|
901
|
+
out_list.append(SubformulaResult(k, []))
|
|
902
|
+
continue
|
|
903
|
+
|
|
904
|
+
# create SubformulaResult object
|
|
905
|
+
subform_list = []
|
|
906
|
+
for j in range(this_subform_arr.shape[0]):
|
|
907
|
+
form = Formula(this_subform_arr[j, :], ion_mode_int, this_mass[j])
|
|
908
|
+
subform_list.append(FormulaResult(form.__str__(), form.mass, mz))
|
|
909
|
+
out_list.append(SubformulaResult(k, subform_list))
|
|
910
|
+
|
|
911
|
+
return out_list
|
|
@@ -161,10 +161,10 @@ def load_mgf(file_path) -> List[MetaFeature]:
|
|
|
161
161
|
key, value = _line.split('=', 1)
|
|
162
162
|
key, value = key.strip(), value.strip()
|
|
163
163
|
# if key (into all upper case) is 'PEPMASS', it is precursor mz
|
|
164
|
-
if key.upper()
|
|
164
|
+
if key.upper() in ['PEPMASS', 'PRECURSOR_MZ']:
|
|
165
165
|
precursor_mz = float(value)
|
|
166
166
|
# if key is 'TITLE', it is identifier
|
|
167
|
-
elif key.upper() in ['TITLE', '
|
|
167
|
+
elif key.upper() in ['TITLE', 'SPECTRUMID', 'SPECTRUM_ID']:
|
|
168
168
|
identifier = value.strip()
|
|
169
169
|
# if key is 'CHARGE' and charge is not set, it is charge
|
|
170
170
|
elif key.upper() == 'CHARGE':
|
|
@@ -295,12 +295,12 @@ def load_usi(usi_list: Union[str, List[str]],
|
|
|
295
295
|
continue
|
|
296
296
|
return data_list
|
|
297
297
|
|
|
298
|
-
#
|
|
299
|
-
# # test
|
|
300
|
-
# if __name__ == '__main__':
|
|
301
|
-
# init_db()
|
|
302
298
|
|
|
299
|
+
# test
|
|
300
|
+
# if __name__ == '__main__':
|
|
303
301
|
#################
|
|
302
|
+
# init_db()
|
|
303
|
+
|
|
304
304
|
# import joblib
|
|
305
305
|
# compile all these databases
|
|
306
306
|
|
|
@@ -25,7 +25,7 @@ alphabet = ["C", "H", "Br", "Cl", "F", "I", "K", "N", "Na", "O", "P", "S"]
|
|
|
25
25
|
|
|
26
26
|
class FormulaResult:
|
|
27
27
|
"""
|
|
28
|
-
|
|
28
|
+
FormulaResult class, for mass_to_formula function
|
|
29
29
|
"""
|
|
30
30
|
|
|
31
31
|
def __init__(self, formula: str, mass: float, t_mass: float):
|
|
@@ -40,6 +40,21 @@ class FormulaResult:
|
|
|
40
40
|
self.mass_error_ppm = self.mass_error / t_mass * 1e6
|
|
41
41
|
|
|
42
42
|
|
|
43
|
+
class SubformulaResult:
|
|
44
|
+
"""
|
|
45
|
+
SubformulaResult class, for assign_subformula function
|
|
46
|
+
"""
|
|
47
|
+
|
|
48
|
+
def __init__(self, idx: int, subform_list: List[FormulaResult]):
|
|
49
|
+
"""
|
|
50
|
+
Constructor
|
|
51
|
+
:param idx: index of the fragment ion
|
|
52
|
+
:param subform_list: list of FormulaResult objects
|
|
53
|
+
"""
|
|
54
|
+
self.idx = idx
|
|
55
|
+
self.subform_list = subform_list
|
|
56
|
+
|
|
57
|
+
|
|
43
58
|
def read_formula(form: str) -> np.array:
|
|
44
59
|
"""
|
|
45
60
|
read neutral formula string and return a 12-dim array, return None if invalid
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: msbuddy
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Bottom-up MS/MS interrogation-based molecular formula annotation for mass spectrometry data.
|
|
5
5
|
Home-page: https://github.com/Philipbear/msbuddy
|
|
6
6
|
Author: Shipei Xing
|
|
@@ -20,7 +20,13 @@ License-File: LICENSE
|
|
|
20
20
|
[](https://msbuddy.readthedocs.io/en/latest/?badge=latest)
|
|
21
21
|
[](https://github.com/Philipbear/msbuddy)
|
|
22
22
|
|
|
23
|
-
|
|
23
|
+
<p align="center">
|
|
24
|
+
<img src="https://github.com/Philipbear/msbuddy/blob/main/logo/logo.svg" alt="Sample Image" height="100"/>
|
|
25
|
+
</p>
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
`msbuddy` is developed for molecular formula analysis in MS-based metabolomics studies.
|
|
29
|
+
|
|
24
30
|
`msbuddy` is able to provide formula annotations for queries:
|
|
25
31
|
* with or without MS1 isotopic pattern
|
|
26
32
|
* with or without MS/MS spectra
|
|
@@ -30,7 +36,7 @@ The minimum requirement for a msbuddy query is a single _m/z_ value and its ioni
|
|
|
30
36
|
|
|
31
37
|
**Official documentation** is available at https://msbuddy.readthedocs.io/en/latest/.
|
|
32
38
|
|
|
33
|
-
**msbuddy ver 0.2.
|
|
39
|
+
**msbuddy ver 0.2.1** is now released. See [change log](https://github.com/Philipbear/msbuddy/blob/main/changelog.md) for details.
|
|
34
40
|
|
|
35
41
|
## Citation
|
|
36
42
|
> S. Xing et al. BUDDY: molecular formula discovery via bottom-up MS/MS interrogation. **Nature Methods** 2023. [DOI: 10.1038/s41592-023-01850-x](https://doi.org/10.1038/s41592-023-01850-x)
|
|
@@ -45,20 +51,21 @@ pip install msbuddy
|
|
|
45
51
|
|
|
46
52
|
To install a specific version, see PyPI [release history](https://pypi.org/project/msbuddy/#history).
|
|
47
53
|
|
|
48
|
-
## Python usage
|
|
54
|
+
## Python usage
|
|
49
55
|
|
|
56
|
+
### Quick start ([docs](https://msbuddy.readthedocs.io/en/latest/quickstart.html))
|
|
50
57
|
As a quick start, we here load a mgf file and annotate the molecular formula for each query.
|
|
51
58
|
All the configurations are specified in the [`MsbuddyConfig`](https://msbuddy.readthedocs.io/en/latest/pyapi.html#msbuddy.MsbuddyConfig) class.
|
|
52
|
-
**Parallel computing** is supported.
|
|
59
|
+
**Parallel computing** is [supported](https://msbuddy.readthedocs.io/en/latest/quickstart.html).
|
|
53
60
|
|
|
54
61
|
```python
|
|
55
62
|
from msbuddy import Msbuddy, MsbuddyConfig
|
|
56
63
|
|
|
57
64
|
# instantiate a MsbuddyConfig object
|
|
58
|
-
msb_config = MsbuddyConfig(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
65
|
+
msb_config = MsbuddyConfig(# highly recommended to specify
|
|
66
|
+
ms_instr='orbitrap', # supported: "qtof", "orbitrap" and "fticr"
|
|
67
|
+
# whether to consider halogen atoms FClBrI
|
|
68
|
+
halogen=False)
|
|
62
69
|
|
|
63
70
|
# instantiate a Msbuddy object
|
|
64
71
|
msb_engine = Msbuddy(msb_config)
|
|
@@ -72,6 +79,8 @@ msb_engine.annotate_formula()
|
|
|
72
79
|
# retrieve the annotation result summary
|
|
73
80
|
result = msb_engine.get_summary()
|
|
74
81
|
```
|
|
82
|
+
See [demo mgf file](https://github.com/Philipbear/msbuddy/tree/main/demo).
|
|
83
|
+
|
|
75
84
|
|
|
76
85
|
MS/MS spectra can be loaded via their [USIs](https://www.biorxiv.org/content/10.1101/2020.05.09.086066v2) if they are publicly available:
|
|
77
86
|
```python
|
|
@@ -79,7 +88,14 @@ MS/MS spectra can be loaded via their [USIs](https://www.biorxiv.org/content/10.
|
|
|
79
88
|
msb_engine.load_usi(['mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036',
|
|
80
89
|
'mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037'])
|
|
81
90
|
```
|
|
82
|
-
|
|
91
|
+
|
|
92
|
+
### Other API functions
|
|
93
|
+
- generate molecular formulas from a neutral mass (mass_to_formula)
|
|
94
|
+
- generate molecular formulas from a charged _m/z_ value (mz_to_formula)
|
|
95
|
+
- predict formula feasibility using a deep learning model (predict_formula_feasibility)
|
|
96
|
+
- enumerate all possible subformulas of a given precursor formula (enumerate_subform_arr)
|
|
97
|
+
|
|
98
|
+
See more in the [documentation](https://msbuddy.readthedocs.io/en/latest/pyapi.html).
|
|
83
99
|
|
|
84
100
|
## Command-line tool ([docs](https://msbuddy.readthedocs.io/en/latest/cmdapi.html))
|
|
85
101
|
|
|
@@ -95,7 +111,7 @@ for a single USI string (from FT-ICR, for example):
|
|
|
95
111
|
```bash
|
|
96
112
|
msbuddy -usi <usi_string> -output <output_folder> -ms fticr
|
|
97
113
|
```
|
|
98
|
-
or a csv file ([
|
|
114
|
+
or a csv file ([template files](https://github.com/Philipbear/msbuddy/tree/main/demo)) containing multiple USI strings (QTOF in this example):
|
|
99
115
|
```bash
|
|
100
116
|
msbuddy -csv <csv_file> -output <output_folder> -ms qtof -details
|
|
101
117
|
```
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r", encoding="utf-8") as fh:
|
|
|
5
5
|
|
|
6
6
|
setuptools.setup(
|
|
7
7
|
name="msbuddy",
|
|
8
|
-
version="0.2.
|
|
8
|
+
version="0.2.2",
|
|
9
9
|
author="Shipei Xing",
|
|
10
10
|
author_email="s1xing@health.ucsd.edu",
|
|
11
11
|
description="Bottom-up MS/MS interrogation-based molecular formula annotation for mass spectrometry data.",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
from .main import Msbuddy, MsbuddyConfig
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|