Skip to content
Stephan Aiche edited this page Jan 9, 2014 · 2 revisions

This page can be used to collect small code examples that document how to use specific parts of !OpenMS or help people with existing problems/questions

Getting the scan number for the start and end of a Feature

This following question was asked on the OpenMS mailinglist

Dear OpenMS people,

I'm using the FeatureFinder set of functions.

The FeatureFinder reports features in with ranges defined in the ConvexHull2D type with ranges in RT (unit seconds) and m/z value (unit Thompson).

Example of outputting a DBoundingBox, on a FeatureMap<> const_iterator it, with it->getConvexHull().getBoundingBox():

--DBOUNDINGBOX BEGIN-- MIN --> 5341.83 330.995849609375 MAX --> 5990.34 331.020721435547 --DBOUNDINGBOX END--

How would you do to have the scan-number (min and max) corresponding to the RT min and max values?

Is there a MetaValue attribute we can add to the convexhull type, during the featurefinder procedure?

and here is the answer

Use the RT position from the bounding box

// get begin and end rt coordinate
DoubleReal rt_begin = feature_iterator->getConvexHull().getBoundingBox().minPosition()[0];
DoubleReal rt_end = feature_iterator->getConvexHull().getBoundingBox().maxPosition()[0];

and now get an Iterator to the first/last spectrum which has an RT >= / RT <= your desired position

// get iterator to nearest position
MSExperiment<>::ConstIterator rt_begin_spec = ms_exp.RTBegin(rt_begin);
MSExperiment<>::ConstIterator rt_end_spec = ms_exp.RTEnd(rt_end);

if you now substract the begin iterator of your experiment from your rt_begin iterator it should give you the index of the spectrum.

Int begin_scan_index = (rt_begin_spec - ms_exp.begin());
Int end_scan_index = (rt_end_spec - ms_exp.begin());

With these values you can access the original spectra in your experiment and extract all needed information.

std::cout << ms_exp[begin_scan_index].getRT() << std::endl;

Clone this wiki locally