masscube 1.2.3__tar.gz → 1.2.5__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.3 → masscube-1.2.5}/PKG-INFO +3 -2
  2. {masscube-1.2.3 → masscube-1.2.5}/pyproject.toml +2 -2
  3. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/annotation.py +11 -7
  4. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/feature_detection.py +19 -12
  5. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/network.py +0 -1
  6. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/params.py +3 -3
  7. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/raw_data_utils.py +99 -102
  8. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/stats.py +3 -1
  9. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/visualization.py +38 -31
  10. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/workflows.py +4 -1
  11. {masscube-1.2.3 → masscube-1.2.5}/src/masscube.egg-info/PKG-INFO +3 -2
  12. {masscube-1.2.3 → masscube-1.2.5}/LICENSE +0 -0
  13. {masscube-1.2.3 → masscube-1.2.5}/README.md +0 -0
  14. {masscube-1.2.3 → masscube-1.2.5}/setup.cfg +0 -0
  15. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/__init__.py +0 -0
  16. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/alignment.py +0 -0
  17. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/classifier_builder.py +0 -0
  18. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/feature_evaluation.py +0 -0
  19. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/feature_grouping.py +0 -0
  20. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/mzpkl.py +0 -0
  21. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/normalization.py +0 -0
  22. {masscube-1.2.3 → masscube-1.2.5}/src/masscube/utils_functions.py +0 -0
  23. {masscube-1.2.3 → masscube-1.2.5}/src/masscube.egg-info/SOURCES.txt +0 -0
  24. {masscube-1.2.3 → masscube-1.2.5}/src/masscube.egg-info/dependency_links.txt +0 -0
  25. {masscube-1.2.3 → masscube-1.2.5}/src/masscube.egg-info/entry_points.txt +0 -0
  26. {masscube-1.2.3 → masscube-1.2.5}/src/masscube.egg-info/requires.txt +0 -0
  27. {masscube-1.2.3 → masscube-1.2.5}/src/masscube.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: masscube
3
- Version: 1.2.3
3
+ Version: 1.2.5
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>
@@ -23,6 +23,7 @@ Requires-Dist: ms_entropy==1.3.4
23
23
  Requires-Dist: scikit-learn>=1.3.2
24
24
  Requires-Dist: statsmodels>=0.14.2
25
25
  Requires-Dist: umap-learn>=0.5.7
26
+ Dynamic: license-file
26
27
 
27
28
  # MassCube
28
29
 
@@ -1,10 +1,10 @@
1
1
  [build-system]
2
- requires = ["setuptools>=61.0"]
2
+ requires = ["setuptools>=66.1.0"]
3
3
  build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "masscube"
7
- version = "1.2.3"
7
+ version = "1.2.5"
8
8
  authors = [
9
9
  { name="Huaxu Yu", email="yhxchem@outlook.com" },
10
10
  ]
@@ -40,6 +40,7 @@ Within each block, key is defined as:
40
40
  - INCHIKEY: the InChIKey
41
41
  - INSTRUMENTTYPE: the instrument type
42
42
  - COLLISIONENERGY: the collision energy
43
+ - DATABASE: the database name
43
44
  - COMMENT: the comment
44
45
  - Num Peaks: the number of peaks
45
46
  - [mz1 intensity1]: the m/z and intensity of each fragment
@@ -59,6 +60,7 @@ Example:
59
60
  INCHIKEY: COLNVLDHVKWLRT-QMMMGPOBSA-N
60
61
  INSTRUMENTTYPE: LC-ESI-QFT
61
62
  COLLISIONENERGY: 35.0 eV
63
+ DATABASE: EMBL-MCF_spec98214
62
64
  COMMENT: DB#=EMBL-MCF_spec98214; origin=EMBL - Metabolomics Core Facility Spectral Library
63
65
  Num Peaks: 7
64
66
  103.054 15
@@ -69,7 +71,7 @@ Example:
69
71
  149.059 16
70
72
  166.086 56
71
73
 
72
- 3. json format
74
+ 3. a list of dictionaries (or json format)
73
75
 
74
76
  A list of dictionaries, each dictionary contains the following keys:
75
77
 
@@ -84,10 +86,11 @@ A list of dictionaries, each dictionary contains the following keys:
84
86
  "ontology": the ontology of the compound
85
87
  "smiles": the SMILES string
86
88
  "inchikey": the InChIKey
87
- "instrumenttype": the instrument type
88
- "collisionenergy": the collision energy
89
+ "instrument_type": the instrument type
90
+ "collision_energy": the collision energy
91
+ "database": the database name
89
92
  "comment": the comment
90
- "num peaks": the number of peaks
93
+ "num_peaks": the number of peaks
91
94
  "peaks": a list of lists, each sublist contains two elements: m/z and intensity: [[mz1, intensity1], [mz2, intensity2], ...]
92
95
  }
93
96
 
@@ -103,10 +106,11 @@ Example:
103
106
  "ontology": "Phenylalanine and derivatives",
104
107
  "smiles": "C1=CC=C(C=C1)C[C@@H](C(=O)O)N",
105
108
  "inchikey": "COLNVLDHVKWLRT-QMMMGPOBSA-N",
106
- "instrumenttype": "LC-ESI-QFT",
107
- "collisionenergy": "35.0 eV",
109
+ "instrument_type": "LC-ESI-QFT",
110
+ "collision_energy": "35.0 eV",
111
+ "database": "EMBL-MCF_spec98214"
108
112
  "comment": "DB#=EMBL-MCF_spec98214; origin=EMBL - Metabolomics Core Facility Spectral Library",
109
- "num peaks": "7",
113
+ "num_peaks": "7",
110
114
  "peaks": [["103.054", "15"], ["107.049", "14"], ["120.081", "1000"], ["121.084", "16"], ["131.049", "41"], ["149.059", "16"], ["166.086", "56"]],
111
115
  }
112
116
 
@@ -266,8 +266,8 @@ def detect_features(d):
266
266
  return final_features
267
267
 
268
268
 
269
- def segment_feature(feature, sigma=1.2, prominence_ratio=0.05, distance=10, peak_height_tol=1000,
270
- length_tol=5, sse_tol=0.6):
269
+ def segment_feature(feature, sigma=1.2, prominence_ratio=0.05, distance=5, peak_height_tol=1000,
270
+ length_tol=5, sse_tol=0.3):
271
271
  """
272
272
  Function to segment a feature into multiple features based on the edge detection.
273
273
 
@@ -293,14 +293,10 @@ def segment_feature(feature, sigma=1.2, prominence_ratio=0.05, distance=10, peak
293
293
  """
294
294
 
295
295
  # if peak height is too low or the length is too short, skip segmentation
296
- if feature.peak_height < peak_height_tol or feature.length < length_tol:
297
- return [feature]
298
-
299
- # correction for peak with limited scan number
300
296
  peak_tmp = feature.signals[:,1]
301
- if np.sum(peak_tmp > peak_height_tol) < 12:
302
- sigma = 0.5*sigma
303
- distance = 3
297
+ dp = np.sum(peak_tmp > peak_height_tol)
298
+ if feature.peak_height < peak_height_tol or dp < length_tol:
299
+ return [feature]
304
300
 
305
301
  # add zero to the front and the end of the signal to facilitate the edge detection
306
302
  peak_tmp = np.concatenate(([0], peak_tmp, [0]))
@@ -308,11 +304,22 @@ def segment_feature(feature, sigma=1.2, prominence_ratio=0.05, distance=10, peak
308
304
  feature.sse = squared_error_to_smoothed_curve(original_signal=peak_tmp, fit_signal=ss)
309
305
  if feature.sse > sse_tol:
310
306
  return [feature]
311
- peaks, _ = find_peaks(ss, prominence=np.max(ss)*prominence_ratio, distance=distance)
307
+
308
+ # correction of prominence ratio and sigma based on noise level and data points
309
+ prominence_ratio = np.clip(0.03, prominence_ratio * feature.sse * 20, 0.1)
310
+ prominence = np.max(ss)*prominence_ratio
311
+ sigma = np.clip(0.5, sigma * dp / 33, 1.2)
312
+ ss = gaussian_filter1d(peak_tmp, sigma=sigma) # recalculate the smoothed signal
313
+
314
+ peaks, _ = find_peaks(ss, prominence=prominence, distance=distance)
315
+
316
+ # baseline filter
312
317
  peaks = peaks - 1 # correct the index
318
+
319
+ baseline = np.median(peak_tmp)
313
320
 
314
- # the resulting peaks should have a height larger than peak_height_tol
315
- peaks = peaks[feature.signals[peaks,1] > peak_height_tol]
321
+ # the resulting peaks should have a height larger than baseline
322
+ peaks = peaks[feature.signals[peaks,1] > baseline]
316
323
 
317
324
  if len(peaks) < 2:
318
325
  return [feature]
@@ -84,7 +84,6 @@ def network_analysis(feature_list, annotation_type="hybrid_and_identity", featur
84
84
  # hide outer frame
85
85
  plt.box(False)
86
86
  plt.rcParams['font.size'] = 12
87
- plt.rcParams['font.family'] = 'Arial'
88
87
  # add legend with arial font
89
88
  plt.legend(handles=[plt.Line2D([0], [0], color="#BC6C25", marker="o", lw=0, markersize=7, label="Identity", markeredgewidth=0.5, markeredgecolor="black", alpha=0.5),
90
89
  plt.Line2D([0], [0], color="#FEFAE0", marker="o", lw=0, markersize=7, label="Hybrid", markeredgewidth=0.5, markeredgecolor="black", alpha=0.5),
@@ -61,7 +61,7 @@ class Params:
61
61
  # feature detection
62
62
  self.mz_tol_ms1 = 0.01 # m/z tolerance for MS1, default is 0.01
63
63
  self.mz_tol_ms2 = 0.015 # m/z tolerance for MS2, default is 0.015
64
- self.feature_gap_tol = 30 # gap tolerance within a feature, default is 30 (i.e. 30 consecutive scans without signal), integer
64
+ self.feature_gap_tol = 10 # gap tolerance within a feature, default is 10 (i.e. 10 consecutive scans without signal), integer
65
65
  self.batch_size = 100 # batch size for parallel processing, default is 100, integer
66
66
  self.percent_cpu_to_use = 0.8 # percentage of CPU to use, default is 0.8, float
67
67
 
@@ -80,8 +80,8 @@ class Params:
80
80
  self.scan_number_cutoff = 5 # feature with non-zero scan number greater than the cutoff will be aligned, default is 5
81
81
  self.detection_rate_cutoff = 0.1 # features detected need to be >rate*(qc+sample), default rate is 0.1
82
82
  self.merge_features = True # whether to merge features with almost the same m/z and RT, default is True
83
- self.mz_tol_merge_features = 0.012 # m/z tolerance for merging features, default is 0.012
84
- self.rt_tol_merge_features = 0.05 # RT tolerance for merging features, default is 0.05
83
+ self.mz_tol_merge_features = 0.01 # m/z tolerance for merging features, default is 0.01
84
+ self.rt_tol_merge_features = 0.02 # RT tolerance for merging features, default is 0.02
85
85
  self.group_features_after_alignment = True # whether to group features after alignment, default is False
86
86
  self.fill_gaps = True # whether to fill the gaps in the aligned features, default is True
87
87
  self.gap_filling_method = "local_maximum" # method for gap filling, default is " local_maximum", string
@@ -5,9 +5,10 @@
5
5
  # imports
6
6
  from pyteomics import mzml, mzxml
7
7
  import numpy as np
8
+ import pandas as pd
8
9
  import os
9
10
  import matplotlib.pyplot as plt
10
- import pandas as pd
11
+ import matplotlib.font_manager as fm
11
12
 
12
13
  from .params import Params, find_ms_info
13
14
  from .feature_detection import detect_features, segment_feature
@@ -142,53 +143,38 @@ class MSData:
142
143
  time_unit = scans[0]['scanList']['scan'][0]['scan start time'].unit_info
143
144
 
144
145
  for idx, spec in enumerate(scans):
145
- # get level of mass spectrum
146
- level = spec['ms level']
147
- if level not in self.params.scan_levels:
148
- continue
149
-
150
- # convert scan time to minute
151
- try:
146
+
147
+ # get time
148
+ if "scan start time" in spec['scanList']['scan'][0]:
152
149
  scan_time = spec['scanList']['scan'][0]['scan start time']
153
- except:
150
+ elif "scan time" in spec['scanList']['scan'][0]:
154
151
  scan_time = spec['scanList']['scan'][0]['scan time'] # not a standard format
152
+
155
153
  if time_unit == 'second':
156
- scan_time /= 60
157
- # skip scans outside the defined retention time range
158
- if scan_time < self.params.rt_lower_limit or scan_time > self.params.rt_upper_limit:
154
+ scan_time /= 60 # convert to minute
155
+
156
+ # get level of mass spectrum
157
+ level = spec['ms level']
158
+
159
+ # skip scans not in the defined scan levels or outside the defined retention time range
160
+ if (level not in self.params.scan_levels) or (scan_time < self.params.rt_lower_limit) or (scan_time > self.params.rt_upper_limit):
161
+ self.scans.append(Scan(level=level, id=idx, scan_time=scan_time, signals=None, precursor_mz=None))
159
162
  continue
160
163
 
161
164
  signals = np.array([spec['m/z array'], spec['intensity array']], dtype=np.float32).T
162
-
163
- # process signals based on parameters and scan level
164
- if level == 1:
165
- signals = clean_signals(signals, intensity_range=[self.params.ms1_abs_int_tol, np.inf])
166
- if self.params.centroid_mz_tol is not None:
167
- signals = centroid_signals(signals, mz_tol=self.params.centroid_mz_tol)
168
- precursor_mz = None
169
- self.ms1_idx.append(idx)
170
- self.ms1_time_arr.append(scan_time)
171
- if len(signals) > 0:
172
- self.base_peak_arr.append(signals[np.argmax(signals[:, 1])])
173
- else:
174
- self.base_peak_arr.append([0, 0])
175
- else:
165
+
166
+ if level == 2:
176
167
  precursor_mz = spec['precursorList']['precursor'][0]['selectedIonList']['selectedIon'][0]['selected ion m/z']
177
- if len(signals) == 0:
178
- int_upper = self.params.ms2_abs_int_tol
179
- else:
180
- int_upper = max(self.params.ms2_abs_int_tol, np.max(signals[:, 1]) * self.params.ms2_rel_int_tol)
181
- signals = clean_signals(signals, mz_range=[0, precursor_mz - self.params.precursor_mz_offset],
182
- intensity_range=[int_upper, np.inf])
183
- if self.params.centroid_mz_tol is not None:
184
- signals = centroid_signals(signals, mz_tol=self.params.centroid_mz_tol)
185
- self.ms2_idx.append(idx)
168
+ else:
169
+ precursor_mz = None
186
170
 
187
- self.scans.append(Scan(level=level, id=idx, scan_time=scan_time, signals=signals,
188
- precursor_mz=precursor_mz))
189
-
190
- self.ms1_time_arr = np.array(self.ms1_time_arr)
191
- self.base_peak_arr = np.array(self.base_peak_arr)
171
+ self.scans.append(_preprocess_signals_to_scan(level=level, id=idx, scan_time=scan_time, signals=signals,
172
+ params=self.params, precursor_mz=precursor_mz))
173
+
174
+ self.ms1_idx = np.array([s.id for s in self.scans if s.level == 1 and s.signals is not None and len(s.signals) > 0])
175
+ self.ms2_idx = np.array([s.id for s in self.scans if s.level == 2 and s.signals is not None and len(s.signals) > 0])
176
+ self.ms1_time_arr = np.array([self.scans[i].time for i in self.ms1_idx])
177
+ self.base_peak_arr = np.array([self.scans[i].signals[np.argmax(self.scans[i].signals[:, 1])] for i in self.ms1_idx])
192
178
 
193
179
 
194
180
  def extract_scan_mzxml(self, scans):
@@ -207,50 +193,35 @@ class MSData:
207
193
  time_unit = scans[0]["retentionTime"].unit_info
208
194
 
209
195
  for idx, spec in enumerate(scans):
210
- # get level of mass spectrum
211
- level = spec['msLevel']
212
- if level not in self.params.scan_levels:
213
- continue
214
196
 
215
- # convert scan time to minute
197
+ # get time
216
198
  scan_time = spec["retentionTime"]
199
+
217
200
  if time_unit == 'second':
218
- scan_time = scan_time / 60
219
- # skip scans outside the defined retention time range
220
- if scan_time < self.params.rt_lower_limit or scan_time > self.params.rt_upper_limit:
201
+ scan_time = scan_time / 60 # convert to minute
202
+
203
+ # get level of mass spectrum
204
+ level = spec['msLevel']
205
+
206
+ # skip scans not in the defined scan levels or outside the defined retention time range
207
+ if (level not in self.params.scan_levels) or (scan_time < self.params.rt_lower_limit) or (scan_time > self.params.rt_upper_limit):
208
+ self.scans.append(Scan(level=level, id=idx, scan_time=scan_time, signals=None, precursor_mz=None))
221
209
  continue
222
210
 
223
211
  signals = np.array([spec['m/z array'], spec['intensity array']], dtype=np.float32).T
224
212
 
225
- # process signals based on parameters and scan level
226
- if level == 1:
227
- signals = clean_signals(signals, intensity_range=[self.params.ms1_abs_int_tol, np.inf])
228
- if self.params.centroid_mz_tol is not None:
229
- signals = centroid_signals(signals, mz_tol=self.params.centroid_mz_tol)
230
- precursor_mz = None
231
- self.ms1_idx.append(idx)
232
- self.ms1_time_arr.append(scan_time)
233
- if len(signals) > 0:
234
- self.base_peak_arr.append(signals[np.argmax(signals[:, 1])])
235
- else:
236
- self.base_peak_arr.append([0, 0])
237
- else:
213
+ if level == 2:
238
214
  precursor_mz = spec['precursorMz'][0]['precursorMz']
239
- if len(signals) == 0:
240
- int_upper = self.params.ms2_abs_int_tol
241
- else:
242
- int_upper = max(self.params.ms2_abs_int_tol, np.max(signals[:, 1]) * self.params.ms2_rel_int_tol)
243
- signals = clean_signals(signals, mz_range=[0, precursor_mz - self.params.precursor_mz_offset],
244
- intensity_range=[int_upper, np.inf])
245
- if self.params.centroid_mz_tol is not None:
246
- signals = centroid_signals(signals, mz_tol=self.params.centroid_mz_tol)
247
- self.ms2_idx.append(idx)
248
-
249
- self.scans.append(Scan(level=level, id=idx, scan_time=scan_time, signals=signals,
250
- precursor_mz=precursor_mz))
215
+ else:
216
+ precursor_mz = None
217
+
218
+ self.scans.append(_preprocess_signals_to_scan(level=level, id=idx, scan_time=scan_time, signals=signals,
219
+ params=self.params, precursor_mz=precursor_mz))
251
220
 
252
- self.ms1_time_arr = np.array(self.ms1_time_arr)
253
- self.base_peak_arr = np.array(self.base_peak_arr)
221
+ self.ms1_idx = np.array([s.id for s in self.scans if s.level == 1 and s.signals is not None and len(s.signals) > 0])
222
+ self.ms2_idx = np.array([s.id for s in self.scans if s.level == 2 and s.signals is not None and len(s.signals) > 0])
223
+ self.ms1_time_arr = np.array([self.scans[i].time for i in self.ms1_idx])
224
+ self.base_peak_arr = np.array([self.scans[i].signals[np.argmax(self.scans[i].signals[:, 1])] for i in self.ms1_idx])
254
225
 
255
226
 
256
227
  def drop_ms1_ions_by_intensity(self, int_tol):
@@ -287,13 +258,10 @@ class MSData:
287
258
  Parameters
288
259
  ----------
289
260
  iteration: int
290
- Number of iterations to segment features.
261
+ Number of iterations to segment features. Increase this number may introduce more false positives.
291
262
  """
292
263
 
293
- distance = 0.05/np.mean(np.diff(self.ms1_time_arr))
294
-
295
- if distance < 1:
296
- distance = 1
264
+ distance = np.clip(0.05 / np.mean(np.diff(self.ms1_time_arr)), 1, 5)
297
265
 
298
266
  for _ in range(iteration):
299
267
  self.features = [segment_feature(feature, peak_height_tol=self.params.ms1_abs_int_tol*3, distance=distance) for feature in self.features]
@@ -415,11 +383,12 @@ class MSData:
415
383
 
416
384
  plt.figure(figsize=(10, 3))
417
385
  plt.rcParams['font.size'] = 14
418
- plt.rcParams['font.family'] = 'Arial'
419
- plt.xlabel("Retention Time (min)", fontsize=18, fontname='Arial')
420
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
421
- plt.xticks(fontsize=14, fontname='Arial')
422
- plt.yticks(fontsize=14, fontname='Arial')
386
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
387
+ plt.rcParams['font.family'] = 'Arial'
388
+ plt.xlabel("Retention Time (min)", fontsize=18)
389
+ plt.ylabel("Intensity", fontsize=18)
390
+ plt.xticks(fontsize=14)
391
+ plt.yticks(fontsize=14)
423
392
 
424
393
  if time_range is None:
425
394
  plt.plot(self.ms1_time_arr, self.base_peak_arr[:, 1], linewidth=1, color="black")
@@ -428,7 +397,7 @@ class MSData:
428
397
  plt.plot(self.ms1_time_arr[v], self.base_peak_arr[v, 1], linewidth=1, color="black")
429
398
 
430
399
  if label_name:
431
- plt.text(self.ms1_time_arr[0], np.max(self.base_peak_arr[:,1])*0.9, self.params.file_name, fontsize=12, fontname='Arial', color="gray")
400
+ plt.text(self.ms1_time_arr[0], np.max(self.base_peak_arr[:,1])*0.9, self.params.file_name, fontsize=12, color="gray")
432
401
 
433
402
  if output_dir is not None:
434
403
  plt.savefig(output_dir, dpi=300, bbox_inches="tight")
@@ -573,9 +542,10 @@ class MSData:
573
542
 
574
543
  plt.figure(figsize=(10, 3))
575
544
  plt.rcParams['font.size'] = 14
576
- plt.rcParams['font.family'] = 'Arial'
577
- plt.xlabel("Retention Time (min)", fontsize=18, fontname='Arial')
578
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
545
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
546
+ plt.rcParams['font.family'] = 'Arial'
547
+ plt.xlabel("Retention Time (min)", fontsize=18)
548
+ plt.ylabel("Intensity", fontsize=18)
579
549
 
580
550
  if ylim is not None:
581
551
  plt.ylim(ylim[0], ylim[1])
@@ -659,6 +629,9 @@ class MSData:
659
629
  Retention time tolerance.
660
630
  """
661
631
 
632
+ self.feature_mz_arr = np.array([feature.mz for feature in self.features])
633
+ self.feature_rt_arr = np.array([feature.rt for feature in self.features])
634
+
662
635
  if rt_target is None:
663
636
  tmp = np.abs(self.feature_mz_arr - mz_target) < mz_tol
664
637
  found_feature = [self.features[i] for i in np.where(tmp)[0]]
@@ -730,13 +703,14 @@ class MSData:
730
703
 
731
704
  plt.figure(figsize=(7, 3))
732
705
  plt.rcParams['font.size'] = 14
733
- plt.rcParams['font.family'] = 'Arial'
706
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
707
+ plt.rcParams['font.family'] = 'Arial'
734
708
  plt.plot(eic_rt, eic_int, linewidth=1, color="black")
735
709
  plt.fill_between(eic_rt[idx_start:idx_end], eic_int[idx_start:idx_end], color="black", alpha=0.4)
736
- plt.xlabel("Retention Time (min)", fontsize=18, fontname='Arial')
737
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
738
- plt.xticks(fontsize=14, fontname='Arial')
739
- plt.yticks(fontsize=14, fontname='Arial')
710
+ plt.xlabel("Retention Time (min)", fontsize=18)
711
+ plt.ylabel("Intensity", fontsize=18)
712
+ plt.xticks(fontsize=14)
713
+ plt.yticks(fontsize=14)
740
714
 
741
715
  if output:
742
716
  plt.savefig(output, dpi=300, bbox_inches="tight")
@@ -860,20 +834,21 @@ class Scan:
860
834
  # plot the scan
861
835
  plt.figure(figsize=(10, 3))
862
836
  plt.rcParams['font.size'] = 14
863
- plt.rcParams['font.family'] = 'Arial'
837
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
838
+ plt.rcParams['font.family'] = 'Arial'
864
839
  plt.ylim(0, max_int*1.2)
865
840
  plt.xlim(mz_range[0], mz_range[1])
866
841
  plt.vlines(x = signals[:,0], ymin = 0, ymax = signals[:,1], color="black", linewidth=1.5)
867
842
  plt.hlines(y = 0, xmin = mz_range[0], xmax = mz_range[1], color="black", linewidth=1.5)
868
- plt.xlabel("m/z, Dalton", fontsize=18, fontname='Arial')
869
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
870
- plt.xticks(fontsize=14, fontname='Arial')
871
- plt.yticks(fontsize=14, fontname='Arial')
843
+ plt.xlabel("m/z, Dalton", fontsize=18)
844
+ plt.ylabel("Intensity", fontsize=18)
845
+ plt.xticks(fontsize=14)
846
+ plt.yticks(fontsize=14)
872
847
  plt.text(mz_range[0]+(mz_range[1]-mz_range[0])*0.4, max_int*1.1,
873
- "Time = {:.3f} min".format(self.time), fontsize=11, fontname='Arial')
848
+ "Time = {:.3f} min".format(self.time), fontsize=11)
874
849
  if self.level == 2:
875
850
  plt.text(mz_range[0]+(mz_range[1]-mz_range[0])*0.05, max_int*1.1,
876
- "Precursor m/z = {:.4f}".format(self.precursor_mz), fontsize=11, fontname='Arial')
851
+ "Precursor m/z = {:.4f}".format(self.precursor_mz), fontsize=11)
877
852
  plt.show()
878
853
 
879
854
  if return_data:
@@ -1015,4 +990,26 @@ def find_best_ms2(ms2_list):
1015
990
  else:
1016
991
  return ms2_list[max(range(len(total_ints)), key=total_ints.__getitem__)]
1017
992
  else:
1018
- return None
993
+ return None
994
+
995
+
996
+ def _preprocess_signals_to_scan(level, id, scan_time, signals, params, precursor_mz=None):
997
+ """
998
+ Function to generate a Scan object from signals.
999
+ """
1000
+
1001
+ if len(signals) == 0:
1002
+ return Scan(level=level, id=id, scan_time=scan_time, signals=signals, precursor_mz=precursor_mz)
1003
+
1004
+ if level == 1:
1005
+ signals = clean_signals(signals, intensity_range=[params.ms1_abs_int_tol, np.inf])
1006
+
1007
+ elif level == 2:
1008
+ int_lower = max(params.ms2_abs_int_tol, np.max(signals[:, 1]) * params.ms2_rel_int_tol)
1009
+ signals = clean_signals(signals, mz_range=[0, precursor_mz - params.precursor_mz_offset],
1010
+ intensity_range=[int_lower, np.inf])
1011
+
1012
+ if params.centroid_mz_tol is not None:
1013
+ signals = centroid_signals(signals, mz_tol=params.centroid_mz_tol)
1014
+
1015
+ return Scan(level=level, id=id, scan_time=scan_time, signals=signals, precursor_mz=precursor_mz)
@@ -11,6 +11,7 @@ from sklearn.decomposition import PCA
11
11
  from umap import UMAP
12
12
  from sklearn.preprocessing import StandardScaler
13
13
  import matplotlib.pyplot as plt
14
+ import matplotlib.font_manager as fm
14
15
  import random
15
16
 
16
17
  from .visualization import plot_pca
@@ -218,7 +219,8 @@ def umap_analysis(feature_table, params):
218
219
  # plot the UMAP
219
220
  plt.figure(figsize=(10, 10))
220
221
  plt.rcParams['font.size'] = 20
221
- plt.rcParams['font.family'] = 'Arial'
222
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
223
+ plt.rcParams['font.family'] = 'Arial'
222
224
  # remove frame, x and y axis
223
225
  plt.box(False)
224
226
  plt.xticks([])
@@ -13,6 +13,7 @@ import matplotlib.pyplot as plt
13
13
  import matplotlib.colors as mcolors
14
14
  import matplotlib.transforms as transforms
15
15
  from matplotlib.patches import Ellipse
16
+ import matplotlib.font_manager as fm
16
17
 
17
18
  from .annotation import extract_signals_from_string
18
19
 
@@ -41,14 +42,16 @@ def plot_bpcs(data_list=None, autocolor=False, show_legend=True, output_path=Non
41
42
 
42
43
  plt.figure(figsize=(10, 4))
43
44
  plt.rcParams['font.size'] = 14
44
- plt.rcParams['font.family'] = 'Arial'
45
+ # check if arial font is available
46
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
47
+ plt.rcParams['font.family'] = 'Arial'
45
48
 
46
49
  for i, d in enumerate(data_list):
47
50
  plt.plot(d.ms1_rt_seq, d.bpc_int, color=color_list[i], linewidth=0.5)
48
- plt.xlabel("Retention Time (min)", fontsize=18, fontname='Arial')
49
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
50
- plt.xticks(fontsize=14, fontname='Arial')
51
- plt.yticks(fontsize=14, fontname='Arial')
51
+ plt.xlabel("Retention Time (min)", fontsize=18)
52
+ plt.ylabel("Intensity", fontsize=18)
53
+ plt.xticks(fontsize=14)
54
+ plt.yticks(fontsize=14)
52
55
 
53
56
  if show_legend:
54
57
  plt.legend([d.params.file_name for d in data_list], fontsize=10)
@@ -100,7 +103,8 @@ def plot_feature(d, feature, mz_tol=0.005, rt_tol=0.3, rt_range=None, output=Fal
100
103
 
101
104
  plt.figure(figsize=(9, 3))
102
105
  plt.rcParams['font.size'] = 14
103
- plt.rcParams['font.family'] = 'Arial'
106
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
107
+ plt.rcParams['font.family'] = 'Arial'
104
108
  plt.plot(eic_rt, eic_int, linewidth=0.5, color="black")
105
109
  plt.ylim(0, max_int*1.2)
106
110
 
@@ -113,13 +117,13 @@ def plot_feature(d, feature, mz_tol=0.005, rt_tol=0.3, rt_range=None, output=Fal
113
117
  # label the left and right of the feature
114
118
  plt.axvline(x = feature.rt_seq[0], color = 'black', linestyle = '--', linewidth=0.5, ymax=0.8)
115
119
  plt.axvline(x = feature.rt_seq[-1], color = 'black', linestyle = '--', linewidth=0.5, ymax=0.8)
116
- plt.xlabel("Retention Time (min)", fontsize=18, fontname='Arial')
117
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
118
- plt.text(eic_rt[0], max_int*1.1, "m/z = {:.4f}".format(feature.mz), fontsize=11, fontname='Arial')
119
- plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.2, max_int*1.1, "G-score = {:.2f}".format(feature.gaussian_similarity), fontsize=11, fontname='Arial', color="blue")
120
- plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.4, max_int*1.1, "N-score = {:.2f}".format(feature.noise_score), fontsize=11, fontname='Arial', color="red")
121
- plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.6, max_int*1.1, "A-score = {:.2f}".format(feature.asymmetry_factor), fontsize=11, fontname='Arial', color="darkgreen")
122
- plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.8,max_int*1.1, d.params.file_name, fontsize=7, fontname='Arial', color="gray")
120
+ plt.xlabel("Retention Time (min)", fontsize=18)
121
+ plt.ylabel("Intensity", fontsize=18)
122
+ plt.text(eic_rt[0], max_int*1.1, "m/z = {:.4f}".format(feature.mz), fontsize=11)
123
+ plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.2, max_int*1.1, "G-score = {:.2f}".format(feature.gaussian_similarity), fontsize=11, color="blue")
124
+ plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.4, max_int*1.1, "N-score = {:.2f}".format(feature.noise_score), fontsize=11, color="red")
125
+ plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.6, max_int*1.1, "A-score = {:.2f}".format(feature.asymmetry_factor), fontsize=11, color="darkgreen")
126
+ plt.text(eic_rt[0]+(eic_rt[-1]-eic_rt[0])*0.8,max_int*1.1, d.params.file_name, fontsize=7, color="gray")
123
127
 
124
128
  if output:
125
129
  plt.savefig(output, dpi=600, bbox_inches="tight")
@@ -170,7 +174,8 @@ def mirror_ms2(precursor_mz1, precursor_mz2, signals1, signals2, annotation=None
170
174
 
171
175
  plt.figure(figsize=(10, 3))
172
176
  plt.rcParams['font.size'] = 14
173
- plt.rcParams['font.family'] = 'Arial'
177
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
178
+ plt.rcParams['font.family'] = 'Arial'
174
179
  # plot precursor
175
180
  plt.vlines(x = precursor_mz1, ymin = 0, ymax = 1, color="cornflowerblue", linewidth=1.5, linestyles='dashed')
176
181
  plt.vlines(x = precursor_mz2, ymin = 0, ymax = -1, color="lightcoral", linewidth=1.5, linestyles='dashed')
@@ -182,18 +187,18 @@ def mirror_ms2(precursor_mz1, precursor_mz2, signals1, signals2, annotation=None
182
187
  xmax = max([precursor_mz1, precursor_mz2])*1.2
183
188
  # plot zero line
184
189
  plt.hlines(y = 0, xmin = 0, xmax = xmax, color="black", linewidth=1.5)
185
- plt.xlabel("m/z, Dalton", fontsize=18, fontname='Arial')
186
- plt.ylabel("Intensity", fontsize=18, fontname='Arial')
187
- plt.xticks(fontsize=14, fontname='Arial')
188
- plt.yticks(fontsize=14, fontname='Arial')
190
+ plt.xlabel("m/z, Dalton", fontsize=18)
191
+ plt.ylabel("Intensity", fontsize=18)
192
+ plt.xticks(fontsize=14)
193
+ plt.yticks(fontsize=14)
189
194
 
190
195
  # note name and similarity score
191
- plt.text(xmax*0.9, 0.9, "Experiment", fontsize=12, fontname='Arial', color="grey")
192
- plt.text(xmax*0.9, -0.9, "Database", fontsize=12, fontname='Arial', color="grey")
196
+ plt.text(xmax*0.9, 0.9, "Experiment", fontsize=12, color="grey")
197
+ plt.text(xmax*0.9, -0.9, "Database", fontsize=12, color="grey")
193
198
  if score is not None:
194
- plt.text(0, 0.9, "similarity = {:.3f}".format(score), fontsize=12, fontname='Arial', color="blue")
199
+ plt.text(0, 0.9, "similarity = {:.3f}".format(score), fontsize=12, color="blue")
195
200
  if annotation is not None:
196
- plt.text(0, -0.95, annotation, fontsize=12, fontname='Arial', color="black")
201
+ plt.text(0, -0.95, annotation, fontsize=12, color="black")
197
202
 
198
203
  if output_path is not None:
199
204
  plt.savefig(output_path, dpi=600, bbox_inches="tight")
@@ -273,12 +278,13 @@ def plot_lowess_normalization(arr, fit_curve, arr_new, sample_idx, qc_idx, n, id
273
278
  v = np.arange(n)
274
279
 
275
280
  plt.rcParams['font.size'] = 20
276
- plt.rcParams['font.family'] = 'Arial'
281
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
282
+ plt.rcParams['font.family'] = 'Arial'
277
283
  plt.figure(figsize=(20,8))
278
284
 
279
285
  plt.subplot(2, 1, 1)
280
286
  plt.title("Before normalization")
281
- plt.ylabel("Intensity", fontname='Arial')
287
+ plt.ylabel("Intensity")
282
288
  plt.plot(v[sample_idx], arr[sample_idx], 'o', markersize=4, color='grey')
283
289
  plt.plot(v[qc_idx], arr[qc_idx], 'o', markersize=6, color='red')
284
290
  plt.plot(v, fit_curve, '--', color='blue', linewidth=2)
@@ -291,8 +297,8 @@ def plot_lowess_normalization(arr, fit_curve, arr_new, sample_idx, qc_idx, n, id
291
297
 
292
298
  plt.subplot(2, 1, 2)
293
299
  plt.title("After normalization")
294
- plt.xlabel("Analytical order", fontname='Arial')
295
- plt.ylabel("Intensity", fontname='Arial')
300
+ plt.xlabel("Analytical order")
301
+ plt.ylabel("Intensity")
296
302
  plt.plot(v[sample_idx], arr_new[sample_idx], 'o', markersize=4, color='grey')
297
303
  plt.plot(v[qc_idx], arr_new[qc_idx], 'o', markersize=6, color='red')
298
304
  plt.ylim(-300, np.max(arr_new[qc_idx]) * 1.1)
@@ -319,7 +325,8 @@ def plot_pca(vecPC1, vecPC2, var_PC1, var_PC2, group_names, colors=None, plot_or
319
325
 
320
326
  fig, ax = plt.subplots(figsize=(10,10))
321
327
  # set font to arial
322
- plt.rcParams['font.family'] = 'Arial'
328
+ if 'Arial' in [f.name for f in fm.fontManager.ttflist]:
329
+ plt.rcParams['font.family'] = 'Arial'
323
330
  groups = np.unique(np.array(group_names))
324
331
  if colors is None:
325
332
  colors = COLORS[:len(groups)]
@@ -340,10 +347,10 @@ def plot_pca(vecPC1, vecPC2, var_PC1, var_PC2, group_names, colors=None, plot_or
340
347
  ax.spines[axis].set_linewidth(2)
341
348
  ax.tick_params(width=2, length=8)
342
349
 
343
- plt.xlabel("PC 1 ({:.1f} %)".format(var_PC1*100), fontname='Arial', fontsize=30, labelpad=25)
344
- plt.ylabel("PC 2 ({:.1f} %)".format(var_PC2*100), fontname='Arial', fontsize=30, labelpad=25)
345
- plt.xticks(fontname='Arial', fontsize=24)
346
- plt.yticks(fontname='Arial', fontsize=24)
350
+ plt.xlabel("PC 1 ({:.1f} %)".format(var_PC1*100), fontsize=30, labelpad=25)
351
+ plt.ylabel("PC 2 ({:.1f} %)".format(var_PC2*100), fontsize=30, labelpad=25)
352
+ plt.xticks(fontsize=24)
353
+ plt.yticks(fontsize=24)
347
354
  plt.grid(linestyle=':')
348
355
  plt.legend(fontsize=20, loc='upper right', frameon=True)
349
356
  plt.rcParams.update({'font.size': 24})
@@ -26,7 +26,7 @@ from .utils_functions import convert_signals_to_string
26
26
 
27
27
  # 1. Untargeted feature detection for a single file
28
28
  def process_single_file(file_name, params=None, segment_feature=True, group_features=False, evaluate_peak_shape=True,
29
- annotate_ms2=False, ms2_library_path=None, output_dir=None):
29
+ annotate_ms2=False, ms2_library_path=None, remove_noise=False, output_dir=None):
30
30
  """
31
31
  Untargeted data processing for a single file (mzML, mzXML, mzjson or compressed mzjson).
32
32
 
@@ -77,6 +77,9 @@ def process_single_file(file_name, params=None, segment_feature=True, group_feat
77
77
  d.summarize_features(cal_g_score=True, cal_a_score=True)
78
78
  else:
79
79
  d.summarize_features(cal_g_score=False, cal_a_score=False)
80
+
81
+ if remove_noise:
82
+ d.remove_noise()
80
83
 
81
84
  # STEP 4. MS2 annotation
82
85
  if annotate_ms2:
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: masscube
3
- Version: 1.2.3
3
+ Version: 1.2.5
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>
@@ -23,6 +23,7 @@ Requires-Dist: ms_entropy==1.3.4
23
23
  Requires-Dist: scikit-learn>=1.3.2
24
24
  Requires-Dist: statsmodels>=0.14.2
25
25
  Requires-Dist: umap-learn>=0.5.7
26
+ Dynamic: license-file
26
27
 
27
28
  # MassCube
28
29
 
File without changes
File without changes
File without changes
File without changes