Quantitative Data#
features#
In OpenMS, information about quantitative data is stored in a so-called
Feature
. Each
Feature
represents a region in RT and m/z space use for quantitative
analysis.
1import pyopenms as oms
2
3feature = oms.Feature()
4feature.setMZ(500.9)
5feature.setCharge(2)
6feature.setRT(1500.1)
7feature.setIntensity(30500)
8feature.setOverallQuality(10)
Usually, the quantitative features would be produced by a so-called
FeatureFinder
algorithm, which we will discuss in the next chapter. The
features can be stored in a FeatureMap
and written to disk.
1fm = oms.FeatureMap()
2fm.push_back(feature)
3feature.setRT(1600.5)
4feature.setCharge(2)
5feature.setMZ(600.0)
6feature.setIntensity(80500.0)
7fm.push_back(feature)
8oms.FeatureXMLFile().store("test.featureXML", fm)
Visualizing the resulting map in TOPPView allows detection of the two
features stored in the FeatureMap
with the visualization indicating charge
state, m/z, RT and other properties:

Note that in this case only two features are present, but in a typical LC-MS/MS experiments, thousands of features are present.
Feature Maps#
The resulting FeatureMap
can be used in various ways to extract
quantitative data directly and it supports direct iteration in Python:
1fmap = oms.FeatureMap()
2oms.FeatureXMLFile().load("test.featureXML", fmap)
3for feature in fmap:
4 print("Feature: ", feature.getIntensity(), feature.getRT(), feature.getMZ())
Consensus Features#
Often LC-MS/MS experiments are run to compare quantitative features across
experiments. In OpenMS, linked features from individual experiments are
represented by a ConsensusFeature
1feature = oms.ConsensusFeature()
2feature.setMZ(500.9)
3feature.setCharge(2)
4feature.setRT(1500.1)
5feature.setIntensity(80500)
6
7# Generate ConsensusFeature and features from two maps (with id 1 and 2)
8### Feature 1
9f_m1 = oms.ConsensusFeature()
10f_m1.setRT(500)
11f_m1.setMZ(300.01)
12f_m1.setIntensity(200)
13f_m1.ensureUniqueId()
14### Feature 2
15f_m2 = oms.ConsensusFeature()
16f_m2.setRT(505)
17f_m2.setMZ(299.99)
18f_m2.setIntensity(600)
19f_m2.ensureUniqueId()
20feature.insert(1, f_m1)
21feature.insert(2, f_m2)
We have thus added two features from two individual maps (which have the unique
identifier 1
and 2
) to the ConsensusFeature
.
Next, we inspect the consensus feature, compute a “consensus” m/z across
the two maps and output the two linked features:
1# The two features in map 1 and map 2 represent the same analyte at
2# slightly different RT and m/z
3for fh in feature.getFeatureList():
4 print(fh.getMapIndex(), fh.getIntensity(), fh.getRT())
5
6print(feature.getMZ())
7feature.computeMonoisotopicConsensus()
8print(feature.getMZ())
9
10# Generate ConsensusMap and add two maps (with id 1 and 2)
11cmap = oms.ConsensusMap()
12fds = {1: oms.ColumnHeader(), 2: oms.ColumnHeader()}
13fds[1].filename = "file1"
14fds[2].filename = "file2"
15cmap.setColumnHeaders(fds)
16
17feature.ensureUniqueId()
18cmap.push_back(feature)
19oms.ConsensusXMLFile().store("test.consensusXML", cmap)
Inspection of the generated test.consensusXML
reveals that it contains
references to two LC-MS/MS runs (file1
and file2
) with their respective
unique identifier. Note how the two features we added before have matching
unique identifiers.
Visualization of the resulting output file reveals a single
ConsensusFeature
of size 2 that links to the two individual features at
their respective positions in RT and m/z:

Consensus Maps#
The resulting ConsensusMap
can be used in various ways to extract
quantitative data directly and it supports direct iteration in Python:
1cmap = oms.ConsensusMap()
2oms.ConsensusXMLFile().load("test.consensusXML", cmap)
3for cfeature in cmap:
4 cfeature.computeConsensus()
5 print(
6 "ConsensusFeature",
7 cfeature.getIntensity(),
8 cfeature.getRT(),
9 cfeature.getMZ(),
10 )
11 # The two features in map 1 and map 2 represent the same analyte at
12 # slightly different RT and m/z
13 for fh in cfeature.getFeatureList():
14 print(" -- Feature", fh.getMapIndex(), fh.getIntensity(), fh.getRT())