Skill Tracer
Skills › Scientific Agent Skills › pyopenms › feature_detection.md

feature_detection.md

134 lines · skills/pyopenms/references/feature_detection.md at 5f2bc03

Open on GitHub

Most marks come from matching words in the file, so treat them as pointers.

1# Feature detection and linking (pyOpenMS 3.6.0)
2

Feature detection and linking (pyOpenMS 3.6.0)

Raw lines 1 to 2
3## Inputs and tolerances
4
5Both bundled detectors select centroided MS1, sort spectra by RT and peaks by
6m/z, and preserve the original experiment. Profile data are rejected; unknown
7type requires independently justified `--assume-centroided`. A sorted spectrum
8is not necessarily centroided. DIA/ion mobility, polarity mixtures and real
9instrument-specific feature performance need separate validation.
11`detect_features_metabo.py` uses `mass_error_ppm`. The peptide detector uses
12`mass_trace:mz_tolerance`, an **absolute m/z** tolerance, exposed as
13`--mz-tol-da`. Do not substitute a ppm conversion at one arbitrary m/z. RT values
14and widths are seconds; feature intensities depend on the generating algorithm,
15so record whether integrated area, fitted area or apex intensity is represented.
16Charge zero is unknown, and quality scores are algorithm-specific, not q-values.

Inputs and tolerances

Both bundled detectors select centroided MS1, sort spectra by RT and peaks by m/z, and preserve the original experiment. Profile data are rejected; unknown type requires independently justified --assume-centroided. A sorted spectrum is not necessarily centroided. DIA/ion mobility, polarity mixtures and real instrument-specific feature performance need separate validation.

detect_features_metabo.py uses mass_error_ppm. The peptide detector uses mass_trace:mz_tolerance, an absolute m/z tolerance, exposed as --mz-tol-da. Do not substitute a ppm conversion at one arbitrary m/z. RT values and widths are seconds; feature intensities depend on the generating algorithm, so record whether integrated area, fitted area or apex intensity is represented. Charge zero is unknown, and quality scores are algorithm-specific, not q-values.

Raw lines 3 to 17
18## Metabolomics bindings
20```python
21import pyopenms as ms
22# exp must already contain sorted centroided MS1 data.
23mtd = ms.MassTraceDetection()
24p = mtd.getDefaults()
25p.setValue("mass_error_ppm", 10.0)
26p.setValue("noise_threshold_int", 1000.0)
27mtd.setParameters(p)
28traces = mtd.run(exp, 0) # 0 means no maximum trace count
30epd = ms.ElutionPeakDetection()
31p = epd.getDefaults()
32p.setValue("width_filtering", "fixed")
33epd.setParameters(p)
34split_traces = epd.detectPeaks(traces)
36ffm = ms.FeatureFindingMetabo()
37p = ffm.getDefaults()
38p.setValue("isotope_filtering_model", "metabolites (5% RMS)")
39p.setValue("remove_single_traces", "true")
40p.setValue("charge_lower_bound", 1)
41p.setValue("charge_upper_bound", 3)
42ffm.setParameters(p)
43features = ms.FeatureMap()
44ffm.run(split_traces, features) # fills features; auxiliary outputs are returned
45features.setUniqueIds()
46ms.FeatureXMLFile().store("features.featureXML", features)
47```
49These are the 3.6 signatures. The older output-list calls to `run`/`detectPeaks`
50raise `TypeError`. A synthetic 41-scan Gaussian isotope envelope yields one
51feature and three mass traces in native regression tests; this confirms data
52flow, not correct isotope grouping for every metabolite. Removing single traces
53can discard valid low-abundance or unusual isotope signals. Select parameters
54using pooled QC, blanks and known compounds rather than maximizing feature count.

Metabolomics bindings

import pyopenms as ms
# exp must already contain sorted centroided MS1 data.
mtd = ms.MassTraceDetection()
p = mtd.getDefaults()
p.setValue("mass_error_ppm", 10.0)
p.setValue("noise_threshold_int", 1000.0)
mtd.setParameters(p)
traces = mtd.run(exp, 0)  # 0 means no maximum trace count

epd = ms.ElutionPeakDetection()
p = epd.getDefaults()
p.setValue("width_filtering", "fixed")
epd.setParameters(p)
split_traces = epd.detectPeaks(traces)

ffm = ms.FeatureFindingMetabo()
p = ffm.getDefaults()
p.setValue("isotope_filtering_model", "metabolites (5% RMS)")
p.setValue("remove_single_traces", "true")
p.setValue("charge_lower_bound", 1)
p.setValue("charge_upper_bound", 3)
ffm.setParameters(p)
features = ms.FeatureMap()
ffm.run(split_traces, features)  # fills features; auxiliary outputs are returned
features.setUniqueIds()
ms.FeatureXMLFile().store("features.featureXML", features)

These are the 3.6 signatures. The older output-list calls to run/detectPeaks raise TypeError. A synthetic 41-scan Gaussian isotope envelope yields one feature and three mass traces in native regression tests; this confirms data flow, not correct isotope grouping for every metabolite. Removing single traces can discard valid low-abundance or unusual isotope signals. Select parameters using pooled QC, blanks and known compounds rather than maximizing feature count.

Raw lines 18 to 55
56## Peptide detector
58```python
59exp.sortSpectra(True)
60exp.updateRanges()
61algo = ms.FeatureFinderAlgorithmPicked()
62p = algo.getDefaults()
63p.setValue("mass_trace:mz_tolerance", 0.004)
64p.setValue("isotopic_pattern:charge_low", 1)
65p.setValue("isotopic_pattern:charge_high", 4)
66features = ms.FeatureMap()
67algo.run(exp, features, p, ms.FeatureMap())
68features.setUniqueIds()
69```
71The synthetic native test produces a feature from a designed isotope envelope.
72Peptide-like isotope distributions and chromatographic shape assumptions are
73not general guarantees for metabolites. Inspect `getDefaults()` separately for
74mass trace, isotope-pattern and seed tolerances; changing one does not set all.

Peptide detector

exp.sortSpectra(True)
exp.updateRanges()
algo = ms.FeatureFinderAlgorithmPicked()
p = algo.getDefaults()
p.setValue("mass_trace:mz_tolerance", 0.004)
p.setValue("isotopic_pattern:charge_low", 1)
p.setValue("isotopic_pattern:charge_high", 4)
features = ms.FeatureMap()
algo.run(exp, features, p, ms.FeatureMap())
features.setUniqueIds()

The synthetic native test produces a feature from a designed isotope envelope. Peptide-like isotope distributions and chromatographic shape assumptions are not general guarantees for metabolites. Inspect getDefaults() separately for mass trace, isotope-pattern and seed tolerances; changing one does not set all.

Raw lines 56 to 75
76## Align, then link
78```bash
79python scripts/align_link_quantify.py one.featureXML two.featureXML --rt-tol 20 --mz-tol 10 --mz-unit ppm --out-prefix study
80python scripts/consensus_to_matrix.py study.consensusXML --out quant.csv --long quant_long.csv
81```
83File-dependent CLI templates: synthetic feature-map tests cover linking,
84alignment selection, table metadata/intensities and median normalization. Choose
85an informative reference map; the script selects the largest map. Alignment
86failure stops processing unless explicitly overridden with `--allow-unaligned`.
87Do not report an unaligned study as aligned. Verify landmarks, residual RT
88errors, retention order, match density and extreme transformations.
90`MapAlignmentAlgorithmPoseClustering.setReference(reference)` and
91`align(sample, trafo)` fit the transform;
92`MapAlignmentTransformer.transformRetentionTimes(sample, trafo, True)` applies
93it. Save raw and aligned coordinates and the fitted transformations in a
94production workflow. The bundled CLI currently exports final consensus/results,
95not standalone transformation files.
97`FeatureGroupingAlgorithmQT` takes a list of feature maps and output
98`ConsensusMap`. `distance_RT:max_difference` is seconds;
99`distance_MZ:max_difference` requires an explicit `ppm`/`Da` unit. Column headers
100must match input map order and carry unique sample names. Linking by m/z and RT
101does not identify a molecule; isobars and incorrect charge assignments can link.

Align, then link

python scripts/align_link_quantify.py one.featureXML two.featureXML --rt-tol 20 --mz-tol 10 --mz-unit ppm --out-prefix study
python scripts/consensus_to_matrix.py study.consensusXML --out quant.csv --long quant_long.csv

File-dependent CLI templates: synthetic feature-map tests cover linking, alignment selection, table metadata/intensities and median normalization. Choose an informative reference map; the script selects the largest map. Alignment failure stops processing unless explicitly overridden with --allow-unaligned. Do not report an unaligned study as aligned. Verify landmarks, residual RT errors, retention order, match density and extreme transformations.

MapAlignmentAlgorithmPoseClustering.setReference(reference) and align(sample, trafo) fit the transform; MapAlignmentTransformer.transformRetentionTimes(sample, trafo, True) applies it. Save raw and aligned coordinates and the fitted transformations in a production workflow. The bundled CLI currently exports final consensus/results, not standalone transformation files.

FeatureGroupingAlgorithmQT takes a list of feature maps and output ConsensusMap. distance_RT:max_difference is seconds; distance_MZ:max_difference requires an explicit ppm/Da unit. Column headers must match input map order and carry unique sample names. Linking by m/z and RT does not identify a molecule; isobars and incorrect charge assignments can link.

Raw lines 76 to 102
Runs code python scripts/align_link_quantify.py :79
Runs code python scripts/consensus_to_matrix.py :80
103## Quantification output
105`ConsensusMap.get_intensity_df()` returns features by samples;
106`get_metadata_df()` returns lowercase `rt`, `mz`, `charge`, `quality`, etc.
107The scripts combine rows positionally and emit a `consensus_id` that is a
108**table row index**, not the stable OpenMS unique feature ID. Keep the consensusXML
109as the provenance artifact. Check unique sample filenames before analysis.
110Missing handles are not measured zero abundance; inspect the exported missing
111value convention and model missingness before imputation.
113Median or quantile normalization assumes comparable distributions and can erase
114true global differences. Use standards, dilution checks, technical QC, blank
115signals and batch metadata to justify it. Within-scan TIC normalization is a
116different operation. These scripts do not provide absolute concentration or
117isobaric reporter-ion quantification.

Quantification output

ConsensusMap.get_intensity_df() returns features by samples; get_metadata_df() returns lowercase rt, mz, charge, quality, etc. The scripts combine rows positionally and emit a consensus_id that is a table row index, not the stable OpenMS unique feature ID. Keep the consensusXML as the provenance artifact. Check unique sample filenames before analysis. Missing handles are not measured zero abundance; inspect the exported missing value convention and model missingness before imputation.

Median or quantile normalization assumes comparable distributions and can erase true global differences. Use standards, dilution checks, technical QC, blank signals and batch metadata to justify it. Within-scan TIC normalization is a different operation. These scripts do not provide absolute concentration or isobaric reporter-ion quantification.

Raw lines 103 to 118
119## Inspect features and annotations
121```python
122for feature in features:
123 print(feature.getRT(), feature.getMZ(), feature.getIntensity(), feature.getCharge())
124 points = feature.getConvexHull().getHullPoints()
125 print(len(points)) # not points.size()
126```
128Subordinates represent algorithm-specific hierarchy; do not assume every
129subordinate is an isotope. `IDMapper` annotates features using existing IDs;
130its presence does not replace identification confidence control.
132Source: [OpenMS 3.6 release changes](https://openms.de/documentation/html/ChangeLog.html),
133[feature tutorial](https://pyopenms.readthedocs.io/en/latest/user_guide/feature_detection.html)
134(check its version banner), and installed 3.6.0 signatures/defaults.

Inspect features and annotations

for feature in features:
    print(feature.getRT(), feature.getMZ(), feature.getIntensity(), feature.getCharge())
    points = feature.getConvexHull().getHullPoints()
    print(len(points))  # not points.size()

Subordinates represent algorithm-specific hierarchy; do not assume every subordinate is an isotope. IDMapper annotates features using existing IDs; its presence does not replace identification confidence control.

Source: OpenMS 3.6 release changes, feature tutorial (check its version banner), and installed 3.6.0 signatures/defaults.

Raw lines 119 to 134