Skip to content

Commit 9f221e2

Browse files
committed
Merge branch 'asmsbugfixes2024' into 'master'
Asmsbugfixes2024 See merge request mass-spectrometry/corems!108
2 parents 5f8bbc0 + ade01ef commit 9f221e2

13 files changed

Lines changed: 2070 additions & 46 deletions

File tree

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.0.8
2+
current_version = 2.0.9
33
commit = False
44
tag = False
55

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ CoreMS aims to provide
5050

5151
## Current Version
5252

53-
`2.0.8`
53+
`2.0.9`
5454

5555
***
5656

@@ -323,7 +323,7 @@ UML (unified modeling language) diagrams for Direct Infusion FT-MS and GC-MS cla
323323
324324
If you use CoreMS in your work, please use the following citation:
325325
326-
Version [2.0.8 Release on GitHub](https://github.com/EMSL-Computing/CoreMS/releases/tag/v2.0.8), archived on Zenodo:
326+
Version [2.0.9 Release on GitHub](https://github.com/EMSL-Computing/CoreMS/releases/tag/v2.0.9), archived on Zenodo:
327327
328328
[![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.4641552.svg)](https://doi.org/10.5281/zenodo.4641552)
329329

corems/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
__author__ = 'Yuri E. Corilo'
2-
__version__ = '2.0.8'
2+
__version__ = '2.0.9'
33
__doc__ = '''
44
<div align="left">
55

corems/encapsulation/factory/processingSetting.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ def __post_init__(self):
6363
self.header_translate = {'m/z': Labels.mz,
6464
'mOz': Labels.mz,
6565
'Mass': Labels.mz,
66-
'Resolving Power': 'Resolving Power',
66+
'Resolving Power': Labels.rp,
6767
'Res.': Labels.rp,
68+
'resolution': Labels.rp,
6869
'Intensity': Labels.abundance,
6970
'I': Labels.abundance,
7071
'Abundance': Labels.abundance,
72+
'abs_abu': Labels.abundance,
7173
'Signal/Noise': Labels.s2n,
7274
'S/N': Labels.s2n,
73-
'abs_abu': Labels.abundance,
74-
'sn': Labels.s2n,
75-
'resolution': Labels.rp}
75+
'sn': Labels.s2n}
7676

7777
def add_mz_label(self, label):
7878
"""Add a label to the header_translate dictionary to be translated to the corems label for mz."""

corems/mass_spectra/factory/LC_Temp.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ class TIC_Data:
1010
Time: [floats]
1111
list of retention times
1212
TIC: [floats]
13-
total ion chromatogram
13+
total ion current [chromatogram]
14+
BPC: [floats]
15+
base peak [chromatogram]
1416
Apexes: [int]
1517
original thermo apex scan number after peak picking
1618
'''
1719

1820
scans : List[int] = field(default_factory=list)
1921
time : List[float] = field(default_factory=list)
2022
tic : List[float] = field(default_factory=list)
23+
bpc : List[float] = field(default_factory=list)
2124
apexes : List[int] = field(default_factory=list)
2225

2326
@dataclass

corems/mass_spectra/input/rawFileReader.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,15 @@ def func(evt):
503503
# plt.show()
504504

505505
def get_tic(
506-
self, ms_type="MS !d", peak_detection=True, smooth=True, plot=False, ax=None
506+
self, ms_type="MS !d", peak_detection=True, smooth=True, plot=False, ax=None,trace_type='TIC',
507507
) -> Tuple[TIC_Data, axes.Axes]:
508-
"""ms_type: str ('MS', MS2')
508+
"""ms_type: str ('MS !d', 'MS2', None)
509+
if you use None you get all scans.
510+
peak_detection: bool
511+
smooth: bool
512+
plot: bool
513+
ax: matplotlib axis object
514+
trace_type: str ('TIC','BPC')
509515
510516
returns:
511517
chroma: dict
@@ -520,9 +526,16 @@ def get_tic(
520526
original thermo apex scan number after peak picking
521527
}
522528
"""
523-
524-
settings = ChromatogramTraceSettings(TraceType.TIC)
525-
settings.Filter = ms_type
529+
if trace_type == 'TIC':
530+
settings = ChromatogramTraceSettings(TraceType.TIC)
531+
elif trace_type == 'BPC':
532+
settings = ChromatogramTraceSettings(TraceType.BasePeak)
533+
else:
534+
print(f'{trace_type} undefined')
535+
if ms_type == "all":
536+
settings.Filter = None
537+
else:
538+
settings.Filter = ms_type
526539

527540
chroma_settings = IChromatogramSettings(settings)
528541

@@ -532,7 +545,7 @@ def get_tic(
532545

533546
trace = ChromatogramSignal.FromChromatogramData(data)
534547

535-
data = TIC_Data(time=[], scans=[], tic=[], apexes=[])
548+
data = TIC_Data(time=[], scans=[], tic=[], bpc=[], apexes=[])
536549

537550
if trace[0].Length > 0:
538551
for i in range(trace[0].Length):
@@ -564,7 +577,7 @@ def get_tic(
564577
ax = plt.gca()
565578
# fig, ax = plt.subplots(figsize=(6, 3))
566579

567-
ax.plot(data.time, data.tic, label=" TIC")
580+
ax.plot(data.time, data.tic, label=trace_type)
568581
ax.set_xlabel("Time (min)")
569582
ax.set_ylabel("a.u.")
570583
if peak_detection:
@@ -578,8 +591,13 @@ def get_tic(
578591
)
579592

580593
# plt.show()
594+
if trace_type == 'BPC':
595+
data.bpc = data.tic
596+
data.tic = []
581597
return data, ax
582-
598+
if trace_type == 'BPC':
599+
data.bpc = data.tic
600+
data.tic = []
583601
return data, None
584602

585603
else:

corems/mass_spectrum/calc/Calibration.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,13 +381,15 @@ def recalibrate_mass_spectrum(self, cal_peaks_mz : list[float], cal_refs_mz : li
381381
if self.mzsegment:
382382
# Recombine the mass domains
383383
mz_domain = np.concatenate([mz_domain,mz_exp_peaks_unchanged])
384-
mz_profile_calc = np.concatenate([mz_profile_calc,mz_exp_profile_unchanged])
385-
# Sort them
386384
mz_domain.sort()
387-
mz_profile_calc.sort()
385+
if not self.mass_spectrum.is_centroid:
386+
mz_profile_calc = np.concatenate([mz_profile_calc,mz_exp_profile_unchanged])
387+
mz_profile_calc.sort()
388+
# Sort them
388389
if mz_exp_peaks[0] > mz_exp_peaks[1]: #If originally descending mass order
389390
mz_domain = mz_domain[::-1]
390-
mz_profile_calc = mz_profile_calc[::-1]
391+
if not self.mass_spectrum.is_centroid:
392+
mz_profile_calc = mz_profile_calc[::-1]
391393

392394
self.mass_spectrum.mz_cal = mz_domain
393395
if not self.mass_spectrum.is_centroid:

corems/mass_spectrum/calc/PeakPicking.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,10 @@ def get_threshold(self, intes):
453453
elif noise_threshold_method == 'signal_noise':
454454

455455
abundance_threshold = self.settings.noise_threshold_min_s2n
456-
factor = self.baseline_noise_std
456+
if self.is_centroid:
457+
factor = 1
458+
else:
459+
factor = self.baseline_noise_std
457460

458461
elif noise_threshold_method == "relative_abundance":
459462

corems/ms_peak/calc/MSPeakCalc.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ class MSPeakCalculation:
2727
The parent MSParent object associated with the MSPeakCalculation object.
2828
mz_exp : float
2929
The experimental m/z value of the peak.
30-
start_scan : int
30+
peak_left_index : int
3131
The start scan index of the peak.
32-
final_scan : int
32+
peak_right_index : int
3333
The final scan index of the peak.
3434
resolving_power : float
3535
The resolving power of the peak.
@@ -136,11 +136,10 @@ def calc_area(self):
136136
float
137137
peak area
138138
"""
139-
#TODO throughout change final_scan and start_scan when the MSPeakClasses
140-
if self.final_scan > self.start_scan:
139+
if self.peak_right_index > self.peak_left_index:
141140

142-
yy = self._ms_parent.abundance_profile[self.start_scan:self.final_scan]
143-
xx = self._ms_parent.mz_exp_profile[self.start_scan:self.final_scan]
141+
yy = self._ms_parent.abundance_profile[self.peak_left_index:self.peak_right_index]
142+
xx = self._ms_parent.mz_exp_profile[self.peak_left_index:self.peak_right_index]
144143
# check if the axis is high to low m/z or not. if its MSFromFreq its high mz first, if its from Profile, its low mz first
145144
if xx[0] > xx[-1]:
146145
xx = flip(xx)
@@ -182,8 +181,8 @@ def fit_peak(self,mz_extend=6, delta_rp = 0, model='Gaussian'):
182181
mz_extend here extends the x-axis domain so that we have sufficient points either side of the apex to fit.
183182
Takes about 10ms per peak
184183
"""
185-
start_index = self.start_scan - mz_extend if not self.start_scan == 0 else 0
186-
final_index = self.final_scan + mz_extend if not self.final_scan == len(self._ms_parent.mz_exp_profile) else self.final_scan
184+
start_index = self.peak_left_index - mz_extend if not self.peak_left_index == 0 else 0
185+
final_index = self.peak_right_index + mz_extend if not self.peak_right_index == len(self._ms_parent.mz_exp_profile) else self.peak_right_index
187186

188187
# check if MSPeak contains the resolving power info
189188
if self.resolving_power:
@@ -385,8 +384,8 @@ def fit_peak_pso(self, mz_extend : int=6, upsample_multiplier : int=5):
385384
# Thermo data is noise reduced by also noise subtracted, so starts at 0
386385
# Absorption mode/phased data will have positive and negative components and may not be baseline corrected
387386

388-
start_index = self.start_scan - mz_extend if not self.start_scan == 0 else 0
389-
final_index = self.final_scan + mz_extend if not self.final_scan == len(self._ms_parent.mz_exp_profile) else self.final_scan
387+
start_index = self.peak_left_index - mz_extend if not self.peak_left_index == 0 else 0
388+
final_index = self.peak_right_index + mz_extend if not self.peak_right_index == len(self._ms_parent.mz_exp_profile) else self.peak_right_index
390389

391390
# check if MSPeak contains the resolving power info
392391
if self.resolving_power:
@@ -649,8 +648,8 @@ def get_mz_domain(self, oversample_multiplier, mz_overlay):
649648
x-axis domain for fit
650649
651650
"""
652-
start_index = self.start_scan - mz_overlay if not self.start_scan == 0 else 0
653-
final_index = self.final_scan + mz_overlay if not self.final_scan == len(self._ms_parent.mz_exp_profile) else self.final_scan
651+
start_index = self.peak_left_index - mz_overlay if not self.peak_left_index == 0 else 0
652+
final_index = self.peak_right_index + mz_overlay if not self.peak_right_index == len(self._ms_parent.mz_exp_profile) else self.peak_right_index
654653

655654
if oversample_multiplier == 1:
656655

corems/ms_peak/factory/MSPeakClasses.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,9 @@ def __init__(
7979
self.resolving_power = float(resolving_power)
8080
self.signal_to_noise = float(signal_to_noise)
8181
# profile indexes
82-
#TODO fix these names from 'scan' to be more logical about peak indexes.
83-
self.start_scan = int(indexes[0])
84-
self.apex_scan = int(indexes[1])
85-
self.final_scan = int(indexes[2])
82+
self.peak_left_index = int(indexes[0])
83+
self.peak_apex_index = int(indexes[1])
84+
self.peak_right_index = int(indexes[2])
8685

8786
# mass spec obj index
8887
self.index = int(index)
@@ -318,15 +317,15 @@ def plot(
318317

319318
if ax is None:
320319
ax = plt.gca()
321-
x = self._ms_parent.mz_exp_profile[self.start_scan : self.final_scan]
322-
y = self._ms_parent.abundance_profile[self.start_scan : self.final_scan]
320+
x = self._ms_parent.mz_exp_profile[self.peak_left_index : self.peak_right_index]
321+
y = self._ms_parent.abundance_profile[self.peak_left_index : self.peak_right_index]
323322

324323
ax.plot(x, y, color=color, label="Data")
325324
ax.set(xlabel="m/z", ylabel="abundance")
326325
if derivative and not self._ms_parent.is_centroid:
327326
dy = sp.derivate(
328327
self._ms_parent.abundance_profile[
329-
self.start_index : self.final_index + 1
328+
self.peak_left_index : self.peak_right_index + 1
330329
]
331330
)
332331
ax.plot(x, dy, c=deriv_color)

0 commit comments

Comments
 (0)