Home  · Classes  · Annotated Classes  · Modules  · Members  · Namespaces  · Related Pages
FeatureFinder_impl.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2013.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Clemens Groepl $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #ifndef OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDER_IMPL_H
36 #define OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDER_IMPL_H
37 
38 #include <OpenMS/CONCEPT/Factory.h>
40 
42 
43 namespace OpenMS
44 {
45  // This is documented in the declaration, see FeatureFinder.h
46  template <class PeakType, class FeatureType>
47  void FeatureFinder::run(const String & algorithm_name, MSExperiment<PeakType> & input_map, FeatureMap<FeatureType> & features, const Param & param, const FeatureMap<FeatureType> & seeds)
48  {
49  // Nothing to do if there is no data
50  if ((algorithm_name != "mrm" && input_map.empty()) || (algorithm_name == "mrm" && input_map.getChromatograms().empty()))
51  {
52  features.clear(true);
53  return;
54  }
55 
56  // check input
57  {
58  // We need updated ranges => check number of peaks
59  if (algorithm_name != "mrm" && input_map.getSize() == 0)
60  {
61  throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "FeatureFinder needs updated ranges on input map. Aborting.");
62  }
63 
64  // We need MS1 data only => check levels
65  if (algorithm_name != "mrm" && (input_map.getMSLevels().size() != 1 || input_map.getMSLevels()[0] != 1))
66  {
67  throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "FeatureFinder can only operate on MS level 1 data. Please do not use MS/MS data. Aborting.");
68  }
69 
70  //Check if the peaks are sorted according to m/z
71  if (!input_map.isSorted(true))
72  {
73  LOG_WARN << "Input map is not sorted by RT and m/z! This is done now, before applying the algorithm!" << std::endl;
74  input_map.sortSpectra(true);
75  input_map.sortChromatograms(true);
76  }
77  for (Size s = 0; s < input_map.size(); ++s)
78  {
79  if (input_map[s].empty())
80  continue;
81  if (input_map[s][0].getMZ() < 0)
82  {
83  throw Exception::IllegalArgument(__FILE__, __LINE__, __PRETTY_FUNCTION__, "FeatureFinder can only operate on spectra that contain peaks with positive m/z values. Filter the data accordingly beforehand! Aborting.");
84  }
85  }
86  }
87 
88  // initialize
89  if (algorithm_name != "mrm" && algorithm_name != "centroided")
90  {
91  // Resize peak flag vector
92  flags_.resize(input_map.size());
93  for (Size i = 0; i < input_map.size(); ++i)
94  {
95  flags_[i].assign(input_map[i].size(), UNUSED);
96  }
97  }
98 
99  // do the work
100  if (algorithm_name != "none")
101  {
103  algorithm->setParameters(param);
104  algorithm->setData(input_map, features, *this);
105  algorithm->setSeeds(seeds);
106  algorithm->run();
107  delete(algorithm);
108  }
109 
110  if (algorithm_name != "mrm") // mrm works on chromatograms; the next section is only for conventional data
111  {
112  //report RT apex spectrum index and native ID for each feature
113  for (Size i = 0; i < features.size(); ++i)
114  {
115  //index
116  Size spectrum_index = input_map.RTBegin(features[i].getRT()) - input_map.begin();
117  features[i].setMetaValue("spectrum_index", spectrum_index);
118  //native id
119  if (spectrum_index < input_map.size())
120  {
121  String native_id = input_map[spectrum_index].getNativeID();
122  features[i].setMetaValue("spectrum_native_id", native_id);
123  }
124  else
125  {
127  std::cerr << "FeatureFinderAlgorithm_impl, line=" << __LINE__ << "; FixMe this cannot be, but happens" << std::endl;
128  }
129  }
130  }
131  }
132 
133 } // namespace OpenMS
134 
135 #endif // OPENMS_TRANSFORMATIONS_FEATUREFINDER_FEATUREFINDER_IMPL_H
A more convenient string class.
Definition: String.h:56
Size size() const
Definition: MSExperiment.h:117
Definition: FeatureFinderDefs.h:63
A container for features.
Definition: FeatureMap.h:111
Abstract base class for FeatureFinder algorithms.
Definition: FeatureFinderAlgorithm.h:74
Returns FactoryProduct* based on the name of the desired concrete FactoryProduct. ...
Definition: Factory.h:62
Iterator begin()
Definition: MSExperiment.h:147
void sortSpectra(bool sort_mz=true)
Sorts the data points by retention time.
Definition: MSExperiment.h:575
void setParameters(const Param &param)
Sets the parameters.
#define LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged...
Definition: LogStream.h:451
ConstIterator RTBegin(CoordinateType rt) const
Fast search for spectrum range begin.
Definition: MSExperiment.h:349
void sortChromatograms(bool sort_rt=true)
Sorts the data points of the chromatograms by m/z.
Definition: MSExperiment.h:594
A method or algorithm argument contains illegal values.
Definition: Exception.h:634
virtual void run()=0
Main method that implements the actual algorithm.
void run(const String &algorithm_name, MSExperiment< PeakType > &input_map, FeatureMap< FeatureType > &features, const Param &param, const FeatureMap< FeatureType > &seeds)
Executes the FeatureFinder using the given algorithm.
Definition: FeatureFinder_impl.h:47
virtual void setSeeds(const FeatureMapType &seeds)
Sets a reference to the calling FeatureFinder.
Definition: FeatureFinderAlgorithm.h:130
const std::vector< UInt > & getMSLevels() const
returns an array of MS levels
Definition: MSExperiment.h:561
Management and storage of parameters / INI files.
Definition: Param.h:69
Representation of a mass spectrometry experiment.
Definition: MSExperiment.h:68
bool isSorted(bool check_mz=true) const
Checks if all spectra are sorted with respect to ascending RT.
Definition: MSExperiment.h:613
UInt64 getSize() const
returns the total number of peaks
Definition: MSExperiment.h:555
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:144
std::vector< std::vector< Flag > > flags_
Container for flags attached to input data.
Definition: FeatureFinder.h:108
bool empty() const
Definition: MSExperiment.h:127
void clear(bool clear_meta_data=true)
Clears all data and meta data.
Definition: FeatureMap.h:468
void setData(const MapType &map, FeatureMapType &features, FeatureFinder &ff)
Sets a reference to the calling FeatureFinder.
Definition: FeatureFinderAlgorithm.h:118
const std::vector< MSChromatogram< ChromatogramPeakType > > & getChromatograms() const
returns the chromatogram list
Definition: MSExperiment.h:768

OpenMS / TOPP release 1.11.1 Documentation generated on Thu Nov 14 2013 11:19:13 using doxygen 1.8.5