msbuddy 0.3.2__tar.gz → 0.3.4__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.3.2 → msbuddy-0.3.4}/PKG-INFO +3 -3
- {msbuddy-0.3.2 → msbuddy-0.3.4}/README.md +2 -2
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/cand.py +18 -14
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/load.py +2 -2
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/main.py +13 -13
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy.egg-info/PKG-INFO +3 -3
- {msbuddy-0.3.2 → msbuddy-0.3.4}/setup.py +1 -1
- {msbuddy-0.3.2 → msbuddy-0.3.4}/LICENSE +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/__init__.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/base.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/export.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/main_cmd.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/ml.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/query.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy/utils.py +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy.egg-info/SOURCES.txt +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy.egg-info/dependency_links.txt +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy.egg-info/entry_points.txt +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy.egg-info/requires.txt +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/msbuddy.egg-info/top_level.txt +0 -0
- {msbuddy-0.3.2 → msbuddy-0.3.4}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: msbuddy
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Molecular formula annotation for MS-based small molecule analysis.
|
|
5
5
|
Home-page: https://github.com/Philipbear/msbuddy
|
|
6
6
|
Author: Shipei Xing
|
|
@@ -79,7 +79,7 @@ msb_engine.annotate_formula()
|
|
|
79
79
|
result = msb_engine.get_summary()
|
|
80
80
|
```
|
|
81
81
|
See [demo mgf file](https://github.com/Philipbear/msbuddy/tree/main/demo).
|
|
82
|
-
One of the following fields is recommended to be included, which will be used as the query identifier: `TITLE`, `SPECTRUMID`, or `SPECTRUM_ID`.
|
|
82
|
+
One of the following fields is recommended to be included, which will be used as the query identifier: `TITLE`, `FEATURE_ID`, `SPECTRUMID`, or `SPECTRUM_ID`.
|
|
83
83
|
|
|
84
84
|
|
|
85
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:
|
|
@@ -89,7 +89,7 @@ msb_engine.load_usi(['mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036',
|
|
|
89
89
|
'mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037'])
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
Here is a test case on [Google Colab](https://colab.research.google.com/drive/
|
|
92
|
+
Here is a test case on [Google Colab](https://colab.research.google.com/drive/1oLIapoylGbh37ivhcAN-X4tK6l5kIIpf?usp=sharing).
|
|
93
93
|
|
|
94
94
|
### Other API functions
|
|
95
95
|
- parse a formula string (e.g., C6H12O6, 2H2O, C5H7NO2.HCl) ([read_formula_str](https://msbuddy.readthedocs.io/en/latest/pyapi.html#read_formula_str))
|
|
@@ -63,7 +63,7 @@ msb_engine.annotate_formula()
|
|
|
63
63
|
result = msb_engine.get_summary()
|
|
64
64
|
```
|
|
65
65
|
See [demo mgf file](https://github.com/Philipbear/msbuddy/tree/main/demo).
|
|
66
|
-
One of the following fields is recommended to be included, which will be used as the query identifier: `TITLE`, `SPECTRUMID`, or `SPECTRUM_ID`.
|
|
66
|
+
One of the following fields is recommended to be included, which will be used as the query identifier: `TITLE`, `FEATURE_ID`, `SPECTRUMID`, or `SPECTRUM_ID`.
|
|
67
67
|
|
|
68
68
|
|
|
69
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:
|
|
@@ -73,7 +73,7 @@ msb_engine.load_usi(['mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036',
|
|
|
73
73
|
'mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037'])
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
-
Here is a test case on [Google Colab](https://colab.research.google.com/drive/
|
|
76
|
+
Here is a test case on [Google Colab](https://colab.research.google.com/drive/1oLIapoylGbh37ivhcAN-X4tK6l5kIIpf?usp=sharing).
|
|
77
77
|
|
|
78
78
|
### Other API functions
|
|
79
79
|
- parse a formula string (e.g., C6H12O6, 2H2O, C5H7NO2.HCl) ([read_formula_str](https://msbuddy.readthedocs.io/en/latest/pyapi.html#read_formula_str))
|
|
@@ -235,11 +235,8 @@ def gen_candidate_formula(mf: MetaFeature, ppm: bool, ms1_tol: float, ms2_tol: f
|
|
|
235
235
|
# cf_list = _fill_in_db_existence(ms1_cand_form_ls, ms2_cand_form_ls,
|
|
236
236
|
# ms1_cand_form_str_ls, ms2_cand_form_str_ls)
|
|
237
237
|
|
|
238
|
-
# calculate neutral mass of the precursor ion
|
|
239
|
-
ion_mode = 1 if mf.adduct.pos_mode else -1
|
|
240
|
-
t_neutral_mass = (mf.mz * abs(mf.adduct.charge) - mf.adduct.net_formula.mass - ion_mode * 0.0005486) / mf.adduct.m
|
|
241
238
|
# calculate mz error
|
|
242
|
-
cf_list = _calc_mz_error(cf_list,
|
|
239
|
+
cf_list = _calc_mz_error(cf_list, mf.mz, ppm)
|
|
243
240
|
|
|
244
241
|
# if MS1 isotope data is available and >1 iso peaks, calculate isotope similarity
|
|
245
242
|
ms1_iso_available = mf.ms1_processed and len(mf.ms1_processed) > 1
|
|
@@ -247,27 +244,28 @@ def gen_candidate_formula(mf: MetaFeature, ppm: bool, ms1_tol: float, ms2_tol: f
|
|
|
247
244
|
for k, cf in enumerate(cf_list):
|
|
248
245
|
cf_list[k].ms1_isotope_similarity = _calc_ms1_iso_sim(cf, mf, max_isotope_cnt)
|
|
249
246
|
|
|
247
|
+
ms2_available = mf.ms2_processed
|
|
248
|
+
|
|
250
249
|
# retain top candidate formulas
|
|
251
|
-
mf.candidate_formula_list = _retain_top_cand_form(cf_list, ms1_tol, ms1_iso_available,
|
|
250
|
+
mf.candidate_formula_list = _retain_top_cand_form(cf_list, ms1_tol, ms1_iso_available, ms2_available, 350)
|
|
252
251
|
|
|
253
252
|
return mf
|
|
254
253
|
|
|
255
254
|
|
|
256
|
-
def _calc_mz_error(cf_list: List[CandidateFormula],
|
|
257
|
-
ppm: bool) -> List[CandidateFormula]:
|
|
255
|
+
def _calc_mz_error(cf_list: List[CandidateFormula], precursor_mz: float, ppm: bool) -> List[CandidateFormula]:
|
|
258
256
|
"""
|
|
259
257
|
Calculate mz error for each candidate formula.
|
|
260
258
|
:param cf_list: list of candidate formulas
|
|
261
|
-
:param
|
|
259
|
+
:param precursor_mz: precursor mz
|
|
262
260
|
:param ppm: whether to use ppm as the unit of tolerance
|
|
263
261
|
:return: list of candidate formulas
|
|
264
262
|
"""
|
|
265
263
|
if ppm:
|
|
266
264
|
for k, cf in enumerate(cf_list):
|
|
267
|
-
cf_list[k].mz_error = (cf.
|
|
265
|
+
cf_list[k].mz_error = (cf.charged_formula.mass - precursor_mz) / precursor_mz * 1e6
|
|
268
266
|
else:
|
|
269
267
|
for k, cf in enumerate(cf_list):
|
|
270
|
-
cf_list[k].mz_error = cf.
|
|
268
|
+
cf_list[k].mz_error = cf.charged_formula.mass - precursor_mz
|
|
271
269
|
return cf_list
|
|
272
270
|
|
|
273
271
|
|
|
@@ -692,11 +690,13 @@ def _fill_in_db_existence(ms1_cand_list: List[CandidateFormula], ms2_cand_list:
|
|
|
692
690
|
|
|
693
691
|
|
|
694
692
|
def _retain_top_cand_form(cf_list: List[CandidateFormula], ms1_tol: float, ms1_iso_available: bool,
|
|
695
|
-
top_n: int) -> List[CandidateFormula]:
|
|
693
|
+
ms2_available: bool, top_n: int) -> List[CandidateFormula]:
|
|
696
694
|
"""
|
|
697
695
|
Retain top candidate formulas by explained MS2 intensity, then by mz difference.
|
|
698
696
|
:param cf_list: candidate formula list
|
|
699
697
|
:param ms1_tol: MS1 tolerance
|
|
698
|
+
:param ms1_iso_available: whether MS1 isotope data is available
|
|
699
|
+
:param ms2_available: whether MS2 data is available
|
|
700
700
|
:param top_n: number of top candidate formulas to retain
|
|
701
701
|
:return: retained candidate formula list
|
|
702
702
|
"""
|
|
@@ -708,9 +708,13 @@ def _retain_top_cand_form(cf_list: List[CandidateFormula], ms1_tol: float, ms1_i
|
|
|
708
708
|
cf_list = sorted(cf_list, key=lambda x: (_calc_log_p_norm(x.mz_error, ms1_tol / 3) * 0.05 +
|
|
709
709
|
x.ms1_isotope_similarity), reverse=True)
|
|
710
710
|
else:
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
711
|
+
if ms2_available:
|
|
712
|
+
# sort candidate list by mz_error_log_p + 4 * exp_frag_int_pnt
|
|
713
|
+
cf_list = sorted(cf_list, key=lambda x: (_calc_log_p_norm(x.mz_error, ms1_tol / 3) + 4 * x.exp_ms2_sum_int),
|
|
714
|
+
reverse=True)
|
|
715
|
+
else:
|
|
716
|
+
# sort candidate list by abs mz_error, ascending
|
|
717
|
+
cf_list = sorted(cf_list, key=lambda x: abs(x.mz_error), reverse=False)
|
|
714
718
|
|
|
715
719
|
return cf_list[:top_n]
|
|
716
720
|
|
|
@@ -173,8 +173,8 @@ def load_mgf(file_path) -> List[MetaFeature]:
|
|
|
173
173
|
# if key (into all upper case) is 'PEPMASS', it is precursor mz
|
|
174
174
|
if key.upper() in ['PEPMASS', 'PRECURSOR_MZ']:
|
|
175
175
|
precursor_mz = float(value)
|
|
176
|
-
#
|
|
177
|
-
elif key.upper() in ['TITLE', 'SPECTRUMID', 'SPECTRUM_ID']:
|
|
176
|
+
# identifier
|
|
177
|
+
elif key.upper() in ['TITLE', 'FEATURE_ID', 'SPECTRUMID', 'SPECTRUM_ID']:
|
|
178
178
|
identifier = value.strip()
|
|
179
179
|
# if key is 'CHARGE' and charge is not set, it is charge
|
|
180
180
|
elif key.upper() == 'CHARGE':
|
|
@@ -232,7 +232,6 @@ class Msbuddy:
|
|
|
232
232
|
:return: None. Update self.data
|
|
233
233
|
"""
|
|
234
234
|
|
|
235
|
-
#@timeout(self.config.timeout_secs)
|
|
236
235
|
def _preprocess_and_gen_cand_nonparallel(meta_feature: MetaFeature, ps: MsbuddyConfig) -> MetaFeature:
|
|
237
236
|
"""
|
|
238
237
|
a wrapper function for data preprocessing and candidate formula space generation
|
|
@@ -543,30 +542,31 @@ if __name__ == '__main__':
|
|
|
543
542
|
|
|
544
543
|
start = time.time()
|
|
545
544
|
|
|
546
|
-
msb_config = MsbuddyConfig(ms_instr='
|
|
547
|
-
halogen=True, parallel=
|
|
545
|
+
msb_config = MsbuddyConfig(ms_instr='qtof', # supported: "qtof", "orbitrap" and "fticr"
|
|
546
|
+
halogen=True, parallel=True, n_cpu=10)
|
|
548
547
|
|
|
549
548
|
msb_engine = Msbuddy(msb_config)
|
|
550
549
|
|
|
551
|
-
msb_engine.load_mgf('/Users/shipei/Documents/projects/msbuddy/demo/input_file.mgf')
|
|
550
|
+
# msb_engine.load_mgf('/Users/shipei/Documents/projects/msbuddy/demo/input_file.mgf')
|
|
552
551
|
|
|
553
|
-
# mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000085143_chagas_neg_orbi' #
|
|
554
|
-
# mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000081463_tomato_pos' #
|
|
555
|
-
# mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000086988_fecal_neg_orbi' #
|
|
556
|
-
|
|
557
|
-
|
|
552
|
+
# mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000085143_chagas_neg_orbi' # 83
|
|
553
|
+
# mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000081463_tomato_pos' # 194
|
|
554
|
+
# mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000086988_fecal_neg_orbi' # 118
|
|
555
|
+
mgf_folder = '/Users/shipei/Documents/projects/msbuddy/results/lcms_datasets/MSV000081981_AmericanGutProject' # 146
|
|
556
|
+
msb_engine.load_mgf(str(mgf_folder + '/ms1_ms2.mgf'))
|
|
558
557
|
|
|
559
558
|
# cmd version
|
|
560
|
-
|
|
559
|
+
msb_engine.annotate_formula_cmd(pathlib.Path(str(mgf_folder + '/msbuddy_output')), True)
|
|
561
560
|
|
|
562
561
|
# annotate molecular formula
|
|
563
|
-
msb_engine.annotate_formula()
|
|
564
|
-
# retrieve the annotation result summary
|
|
565
|
-
result = msb_engine.get_summary()
|
|
562
|
+
# msb_engine.annotate_formula()
|
|
566
563
|
|
|
567
564
|
end = time.time()
|
|
568
565
|
print(end - start)
|
|
569
566
|
|
|
567
|
+
# retrieve the annotation result summary
|
|
568
|
+
result = msb_engine.get_summary()
|
|
569
|
+
|
|
570
570
|
print(result)
|
|
571
571
|
form_top1 = [r['formula_rank_1'] for r in result]
|
|
572
572
|
form_est_fdr = [r['estimated_fdr'] for r in result]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: msbuddy
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.4
|
|
4
4
|
Summary: Molecular formula annotation for MS-based small molecule analysis.
|
|
5
5
|
Home-page: https://github.com/Philipbear/msbuddy
|
|
6
6
|
Author: Shipei Xing
|
|
@@ -79,7 +79,7 @@ msb_engine.annotate_formula()
|
|
|
79
79
|
result = msb_engine.get_summary()
|
|
80
80
|
```
|
|
81
81
|
See [demo mgf file](https://github.com/Philipbear/msbuddy/tree/main/demo).
|
|
82
|
-
One of the following fields is recommended to be included, which will be used as the query identifier: `TITLE`, `SPECTRUMID`, or `SPECTRUM_ID`.
|
|
82
|
+
One of the following fields is recommended to be included, which will be used as the query identifier: `TITLE`, `FEATURE_ID`, `SPECTRUMID`, or `SPECTRUM_ID`.
|
|
83
83
|
|
|
84
84
|
|
|
85
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:
|
|
@@ -89,7 +89,7 @@ msb_engine.load_usi(['mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740036',
|
|
|
89
89
|
'mzspec:GNPS:GNPS-LIBRARY:accession:CCMSLIB00003740037'])
|
|
90
90
|
```
|
|
91
91
|
|
|
92
|
-
Here is a test case on [Google Colab](https://colab.research.google.com/drive/
|
|
92
|
+
Here is a test case on [Google Colab](https://colab.research.google.com/drive/1oLIapoylGbh37ivhcAN-X4tK6l5kIIpf?usp=sharing).
|
|
93
93
|
|
|
94
94
|
### Other API functions
|
|
95
95
|
- parse a formula string (e.g., C6H12O6, 2H2O, C5H7NO2.HCl) ([read_formula_str](https://msbuddy.readthedocs.io/en/latest/pyapi.html#read_formula_str))
|
|
@@ -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.3.
|
|
8
|
+
version="0.3.4",
|
|
9
9
|
author="Shipei Xing",
|
|
10
10
|
author_email="s1xing@health.ucsd.edu",
|
|
11
11
|
description="Molecular formula annotation for MS-based small molecule analysis.",
|
|
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
|
|
File without changes
|
|
File without changes
|