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 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)
Opening the resulting feature map in TOPPView allows to visualize the two features (each represented by a black dot in the top right and bottom left, respectively). Hovering over a feature displays m/z, RT and other properties:
In the above example, only two features are present. In a typical LC-MS/MS experiment, you can expect thousands of features.
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.
We will explore how Consensus Maps are created in a process called FeatureLinking in the Feature Linking chapter.
For now, we focus on how to build :term:`consensus feature`s and their container (consensus maps) manually.
1cf = oms.ConsensusFeature()
2cf.setMZ(500.9)
3cf.setCharge(2)
4cf.setRT(1500.1)
5cf.setIntensity(80500)
6
7# Generate ConsensusFeature from features of 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()
20cf.insert(1, f_m1)
21cf.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 cf.getFeatureList():
4 print(fh.getMapIndex(), fh.getIntensity(), fh.getRT())
5
6print(cf.getMZ())
7cf.computeMonoisotopicConsensus()
8print(cf.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
17cf.ensureUniqueId()
18cmap.push_back(cf)
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())