Skills › Scientific Agent Skills › pyopenms › _common.py
_common.py
24 lines · skills/pyopenms/scripts/_common.py at 5f2bc03
1"""Input checks shared by the two centroided feature detectors."""
2import pyopenms as ms
5def centroided_ms1(exp, assume_centroided=False):
6 """Copy only MS1 scans, require centroid metadata, and sort RT/m/z."""
7 selected = []
8 for spec in exp:
9 if spec.getMSLevel() != 1:
10 continue
11 kind = spec.getType()
12 if kind == ms.SpectrumSettings.SpectrumType.PROFILE:
13 raise ValueError("Feature detection requires centroided MS1; peak-pick profile data first.")
14 if kind == ms.SpectrumSettings.SpectrumType.UNKNOWN and not assume_centroided:
15 raise ValueError("MS1 spectrum type is unknown; verify acquisition/conversion and use --assume-centroided only when justified.")
16 selected.append(spec)
17 if not selected:
18 raise ValueError("No MS1 spectra available for feature detection.")
19 result = ms.MSExperiment(exp)
20 result.setSpectra(selected)
21 result.setChromatograms([])
22 result.sortSpectra(True)
23 result.updateRanges()
24 return result