masscube 1.2.6__tar.gz → 1.2.7__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 (27) hide show
  1. {masscube-1.2.6 → masscube-1.2.7}/PKG-INFO +1 -1
  2. {masscube-1.2.6 → masscube-1.2.7}/pyproject.toml +1 -1
  3. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/annotation.py +52 -14
  4. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/normalization.py +8 -4
  5. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/stats.py +1 -1
  6. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/visualization.py +3 -3
  7. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/workflows.py +0 -1
  8. {masscube-1.2.6 → masscube-1.2.7}/src/masscube.egg-info/PKG-INFO +1 -1
  9. {masscube-1.2.6 → masscube-1.2.7}/LICENSE +0 -0
  10. {masscube-1.2.6 → masscube-1.2.7}/README.md +0 -0
  11. {masscube-1.2.6 → masscube-1.2.7}/setup.cfg +0 -0
  12. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/__init__.py +0 -0
  13. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/alignment.py +0 -0
  14. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/classifier_builder.py +0 -0
  15. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/feature_detection.py +0 -0
  16. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/feature_evaluation.py +0 -0
  17. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/feature_grouping.py +0 -0
  18. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/mzpkl.py +0 -0
  19. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/network.py +0 -0
  20. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/params.py +0 -0
  21. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/raw_data_utils.py +0 -0
  22. {masscube-1.2.6 → masscube-1.2.7}/src/masscube/utils_functions.py +0 -0
  23. {masscube-1.2.6 → masscube-1.2.7}/src/masscube.egg-info/SOURCES.txt +0 -0
  24. {masscube-1.2.6 → masscube-1.2.7}/src/masscube.egg-info/dependency_links.txt +0 -0
  25. {masscube-1.2.6 → masscube-1.2.7}/src/masscube.egg-info/entry_points.txt +0 -0
  26. {masscube-1.2.6 → masscube-1.2.7}/src/masscube.egg-info/requires.txt +0 -0
  27. {masscube-1.2.6 → masscube-1.2.7}/src/masscube.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: masscube
3
- Version: 1.2.6
3
+ Version: 1.2.7
4
4
  Summary: Accurate and fast data processing for metabolomics
5
5
  Author-email: Huaxu Yu <yhxchem@outlook.com>
6
6
  Maintainer-email: Huaxu Yu <yhxchem@outlook.com>
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "masscube"
7
- version = "1.2.6"
7
+ version = "1.2.7"
8
8
  authors = [
9
9
  { name="Huaxu Yu", email="yhxchem@outlook.com" },
10
10
  ]
@@ -219,8 +219,15 @@ def annotate_aligned_features(features, params, num=5):
219
219
  entropy_search = load_ms2_db(params.ms2_library_path)
220
220
 
221
221
  # ion mode filtering
222
- ion_mode_mask = np.array([1 if (entropy_search[i]['ion_mode'].lower() == params.ion_mode) else 0 for
223
- i in range(len(entropy_search.precursor_mz_array))], dtype=bool)
222
+ ion_mode_mask = []
223
+ for i in range(len(entropy_search.precursor_mz_array)):
224
+ if 'ion_mode' in entropy_search[i]:
225
+ ion_mode_mask.append(1 if (entropy_search[i]['ion_mode'].lower() == params.ion_mode) else 0)
226
+ elif 'ionmode' in entropy_search[i]:
227
+ ion_mode_mask.append(1 if (entropy_search[i]['ionmode'].lower() == params.ion_mode) else 0)
228
+ else:
229
+ ion_mode_mask.append(0)
230
+ ion_mode_mask = np.array(ion_mode_mask, dtype=bool)
224
231
 
225
232
  if params.consider_rt:
226
233
  rt_arr = np.zeros(len(entropy_search.precursor_mz_array))+np.inf
@@ -326,20 +333,27 @@ def annotate_features(d, sim_tol=None, fuzzy_search=True, ms2_library_path=None,
326
333
  """
327
334
 
328
335
  if ms2_library_path is None:
329
- search_engine = load_ms2_db(d.params.ms2_library_path)
336
+ entropy_search = load_ms2_db(d.params.ms2_library_path)
330
337
  else:
331
- search_engine = load_ms2_db(ms2_library_path)
338
+ entropy_search = load_ms2_db(ms2_library_path)
332
339
 
333
340
  # ion mode filtering
334
- ion_mode_mask = np.array([1 if (search_engine[i]['ion_mode'].lower() == d.params.ion_mode) else 0 for
335
- i in range(len(search_engine.precursor_mz_array))], dtype=bool)
341
+ ion_mode_mask = []
342
+ for i in range(len(entropy_search.precursor_mz_array)):
343
+ if 'ion_mode' in entropy_search[i]:
344
+ ion_mode_mask.append(1 if (entropy_search[i]['ion_mode'].lower() == d.params.ion_mode) else 0)
345
+ elif 'ionmode' in entropy_search[i]:
346
+ ion_mode_mask.append(1 if (entropy_search[i]['ionmode'].lower() == d.params.ion_mode) else 0)
347
+ else:
348
+ ion_mode_mask.append(0)
349
+ ion_mode_mask = np.array(ion_mode_mask, dtype=bool)
336
350
 
337
351
  if sim_tol is None:
338
352
  sim_tol = d.params.ms2_sim_tol
339
353
 
340
354
  if consider_rt:
341
- rt_arr = np.zeros(len(search_engine.precursor_mz_array))+np.inf
342
- for i, ms2 in enumerate(search_engine):
355
+ rt_arr = np.zeros(len(entropy_search.precursor_mz_array))+np.inf
356
+ for i, ms2 in enumerate(entropy_search):
343
357
  if 'retention_time' in ms2:
344
358
  rt_arr[i] = ms2['retention_time']
345
359
 
@@ -350,10 +364,10 @@ def annotate_features(d, sim_tol=None, fuzzy_search=True, ms2_library_path=None,
350
364
 
351
365
  matched = None
352
366
  matched_peak_num = None
353
- signals = search_engine.clean_spectrum_for_search(precursor_mz=f.mz, peaks=f.ms2.signals, precursor_ions_removal_da=2.0)
367
+ signals = entropy_search.clean_spectrum_for_search(precursor_mz=f.mz, peaks=f.ms2.signals, precursor_ions_removal_da=2.0)
354
368
  if len(signals) == 0:
355
369
  continue
356
- scores, peak_nums = search_engine.identity_search(precursor_mz=f.mz, peaks=signals, ms1_tolerance_in_da=d.params.mz_tol_ms1,
370
+ scores, peak_nums = entropy_search.identity_search(precursor_mz=f.mz, peaks=signals, ms1_tolerance_in_da=d.params.mz_tol_ms1,
357
371
  ms2_tolerance_in_da=d.params.mz_tol_ms2, output_matched_peak_number=True)
358
372
  scores = ion_mode_mask
359
373
  if consider_rt:
@@ -361,7 +375,7 @@ def annotate_features(d, sim_tol=None, fuzzy_search=True, ms2_library_path=None,
361
375
  scores_rt = scores * rt_boo
362
376
  idx = np.argmax(scores_rt)
363
377
  if scores_rt[idx] > sim_tol:
364
- matched = search_engine[idx]
378
+ matched = entropy_search[idx]
365
379
  matched = {k.lower():v for k,v in matched.items()}
366
380
  matched_peak_num = peak_nums[idx]
367
381
  _assign_annotation_results_to_feature(f, score=scores_rt[idx], matched=matched, matched_peak_num=matched_peak_num,
@@ -370,18 +384,18 @@ def annotate_features(d, sim_tol=None, fuzzy_search=True, ms2_library_path=None,
370
384
  if matched is None:
371
385
  idx = np.argmax(scores)
372
386
  if scores[idx] > sim_tol:
373
- matched = search_engine[idx]
387
+ matched = entropy_search[idx]
374
388
  matched = {k.lower():v for k,v in matched.items()}
375
389
  matched_peak_num = peak_nums[idx]
376
390
  _assign_annotation_results_to_feature(f, score=scores[idx], matched=matched, matched_peak_num=matched_peak_num,
377
391
  search_mode='identity_search')
378
392
 
379
393
  if matched is None and fuzzy_search:
380
- scores = search_engine.hybrid_search(precursor_mz=f.mz, peaks=signals, ms1_tolerance_in_da=d.params.mz_tol_ms1,
394
+ scores = entropy_search.hybrid_search(precursor_mz=f.mz, peaks=signals, ms1_tolerance_in_da=d.params.mz_tol_ms1,
381
395
  ms2_tolerance_in_da=d.params.mz_tol_ms2)
382
396
  idx = np.argmax(scores)
383
397
  if scores[idx] > sim_tol:
384
- matched = search_engine[idx]
398
+ matched = entropy_search[idx]
385
399
  matched_peak_num = None
386
400
  _assign_annotation_results_to_feature(f, score=scores[idx], matched=matched, matched_peak_num=matched_peak_num,
387
401
  search_mode='fuzzy_search')
@@ -579,6 +593,30 @@ def index_msp_to_pkl(msp_path, output_path=None):
579
593
  pickle.dump(entropy_search, open(os.path.join(output_path, file_name + ".pkl"), 'wb'))
580
594
 
581
595
 
596
+ def index_json_to_pkl(json_path, output_path=None):
597
+ """
598
+ A function to index JSON file to pickle format.
599
+
600
+ Parameters
601
+ ----------
602
+ json_path : str
603
+ The path to the JSON file.
604
+ output_path : str
605
+ The path to the output pickle file.
606
+ """
607
+
608
+ file_name = os.path.basename(json_path).split(".")[0]
609
+
610
+ if output_path is None:
611
+ output_path = os.path.dirname(json_path)
612
+
613
+ db = json.load(open(json_path, 'r'))
614
+ entropy_search = FlashEntropySearch()
615
+ entropy_search.build_index(db)
616
+
617
+ pickle.dump(entropy_search, open(os.path.join(output_path, file_name + ".pkl"), 'wb'))
618
+
619
+
582
620
  def _correct_db(db):
583
621
  """
584
622
  Correct the MS2 database by changing the key names.
@@ -331,6 +331,9 @@ def lowess_normalization(array, is_qc, it=3, batch_ids=None, frac=None):
331
331
 
332
332
  # only use qc data > 0 for normalization
333
333
  valid_idx = is_qc & (array > 0)
334
+
335
+ if np.sum(valid_idx) < 3:
336
+ return {'model': None, 'fit_curve': None, 'normed_arr': array}
334
337
 
335
338
  if batch_ids is None:
336
339
  batch_ids = np.zeros(len(array), dtype=int)
@@ -372,9 +375,10 @@ def lowess_normalization(array, is_qc, it=3, batch_ids=None, frac=None):
372
375
  tmp_normed = int_arr_corr[is_qc]
373
376
  tmp = tmp[tmp > 0]
374
377
  tmp_normed = tmp_normed[tmp_normed > 0]
375
- if (len(tmp) == 0) or (len(tmp_normed) == 0) or (np.std(tmp_normed) / np.mean(tmp_normed) > np.std(tmp) / np.mean(tmp)):
376
- int_arr_corr = array
377
- models = [None] * len(unique_batch_ids)
378
- fitted_y = np.ones(len(array))
378
+ if (len(tmp) == 0) or (len(tmp_normed) == 0):
379
+ if np.std(tmp_normed) / np.mean(tmp_normed) > np.std(tmp) / np.mean(tmp):
380
+ int_arr_corr = array
381
+ models = [None] * len(unique_batch_ids)
382
+ fitted_y = np.ones(len(array))
379
383
 
380
384
  return {'model': models, 'fit_curve': fitted_y, 'normed_arr': int_arr_corr}
@@ -194,7 +194,7 @@ def umap_analysis(feature_table, params):
194
194
  df = df[(~df['is_qc']) & (~df['is_blank'])]
195
195
  n = df.iloc[:, 0].values
196
196
  data_arr = feature_table[n].values # samples in columns and features in rows
197
- keys = [i for i in df.columns[1:] if i not in ['is_qc', 'is_blank', 'analytical_order', 'time']]
197
+ keys = [i for i in df.columns[1:] if i not in ['is_qc', 'is_blank', 'analytical_order', 'time', 'ABSOLUTE_PATH', 'VALID']]
198
198
 
199
199
  # UMAP analysis
200
200
  data_arr = data_arr.T
@@ -310,10 +310,10 @@ def plot_lowess_normalization(arr, fit_curve, arr_new, is_qc_or_sample, qc_idx,
310
310
  # use color band to show the 95% confidence interval
311
311
  tmp_new = arr_new[qc_idx]
312
312
  tmp_new = tmp_new[tmp_new > 0]
313
- y_up = np.median(tmp_new) + 1.96 * np.std(tmp_new)
314
- y_down = np.median(tmp_new) - 1.96 * np.std(tmp_new)
315
- plt.fill_between(v, y_down, y_up, color='lightblue', alpha=0.5)
316
313
  if len(tmp_new) > 2:
314
+ y_up = np.median(tmp_new) + 1.96 * np.std(tmp_new)
315
+ y_down = np.median(tmp_new) - 1.96 * np.std(tmp_new)
316
+ plt.fill_between(v, y_down, y_up, color='lightblue', alpha=0.5)
317
317
  rsd = np.std(tmp_new) / np.mean(tmp_new) * 100
318
318
  else:
319
319
  rsd = np.nan
@@ -267,7 +267,6 @@ def untargeted_metabolomics_workflow(path=None, return_results=False, only_proce
267
267
  # STEP 5. signal normalization
268
268
  if params.signal_normalization:
269
269
  print("Step 5: Running signal normalization...")
270
- print(params.plot_normalization)
271
270
  if params.plot_normalization:
272
271
  feature_table = signal_normalization(feature_table, params.sample_metadata, params.signal_norm_method, output_plot_path=params.normalization_dir)
273
272
  else:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: masscube
3
- Version: 1.2.6
3
+ Version: 1.2.7
4
4
  Summary: Accurate and fast data processing for metabolomics
5
5
  Author-email: Huaxu Yu <yhxchem@outlook.com>
6
6
  Maintainer-email: Huaxu Yu <yhxchem@outlook.com>
File without changes
File without changes
File without changes
File without changes