OpenMS  2.6.0
ComparatorUtils.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-2020.
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: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 
36 #pragma once
37 
38 #include <functional>
39 
154 namespace OpenMS
155 {
156 
171  template <class Cmp>
173  public std::binary_function<typename Cmp::first_argument_type *, typename Cmp::second_argument_type *, typename Cmp::result_type>
174  {
176  cmp_(pCmp.cmp_)
177  {}
178  PointerComparator(Cmp const & cmp = Cmp()) :
179  cmp_(cmp)
180  {}
181 
182  template <typename T1, typename T2>
183  typename Cmp::result_type
184  operator()(T1 left, T2 right) const
185  {
186  return cmp_(*left, *right); // T must have operator* defined
187  }
188 
189 protected:
190  Cmp const & cmp_;
191  };
192 
208  template <class Cmp>
210  {
211  return PointerComparator<Cmp>(cmp);
212  }
213 
222  template <class Cmp>
224  std::binary_function<typename Cmp::second_argument_type, typename Cmp::first_argument_type, typename Cmp::result_type>
225  // (Note that here we must reverse the order of template args!)
226  {
228  cmp_(cmp.cmp_) {}
229 
230  ReverseComparator(Cmp const & cmp = Cmp()) :
231  cmp_(cmp) {}
232 
233  template <typename T1, typename T2>
234  typename Cmp::result_type
235  operator()(T1 left, T2 right) const
236  {
237  return cmp_(right, left); // the other way round
238  }
239 
240 protected:
241  Cmp const & cmp_;
242  };
243 
259  template <class Cmp>
261  {
262  return ReverseComparator<Cmp>(cmp);
263  }
264 
274  template <typename Cmp1, typename Cmp2>
276  std::binary_function<typename Cmp1::first_argument_type, typename Cmp1::second_argument_type, bool>
277  {
278  LexicographicComparator(Cmp1 const & cmp1 = Cmp1(), Cmp2 const & cmp2 = Cmp2()) :
279  cmp1_(cmp1), cmp2_(cmp2) {}
280 
281  template <typename T1, typename T2>
282  bool
283  operator()(T1 left, T2 right) const
284  {
285  if (cmp1_(left, right))
286  {
287  return true;
288  }
289  else
290  {
291  if (cmp1_(right, left))
292  {
293  return false;
294  }
295  else
296  {
297  return cmp2_(left, right);
298  }
299  }
300  }
301 
302 protected:
303  Cmp1 const & cmp1_;
304  Cmp2 const & cmp2_;
305  };
306 
315  template <typename Cmp1, typename Cmp2>
316  LexicographicComparator<Cmp1, Cmp2> lexicographicComparator(Cmp1 const & cmp1, Cmp2 const & cmp2)
317  {
318  return LexicographicComparator<Cmp1, Cmp2>(cmp1, cmp2);
319  }
320 
324  template <typename PairType>
326  std::binary_function<PairType, PairType, bool>
327  {
328  bool operator()(const PairType & left, const PairType & right) const
329  {
330  return left.first < right.first;
331  }
332 
333  };
334 
338  template <typename PairType>
340  std::binary_function<PairType, PairType, bool>
341  {
342  bool operator()(const PairType & left, const PairType & right) const
343  {
344  return left.second < right.second;
345  }
346 
347  };
348 
352  template <typename PairType>
354  std::binary_function<PairType, PairType, bool>
355  {
356  bool operator()(const PairType & left, const PairType & right) const
357  {
358  return left.first > right.first;
359  }
360 
361  };
362 
366  template <typename PairType>
368  std::binary_function<PairType, PairType, bool>
369  {
370  bool operator()(const PairType & left, const PairType & right) const
371  {
372  return left.second > right.second;
373  }
374 
375  };
376 
380  template <typename PairType>
382  std::binary_function<PairType, PairType, bool>
383  {
384  bool operator()(const PairType & left, const PairType & right) const
385  {
386  return left.first == right.first;
387  }
388 
389  };
390 
394  template <typename PairType>
396  std::binary_function<PairType, PairType, bool>
397  {
398  bool operator()(const PairType & left, const PairType & right) const
399  {
400  return left.second == right.second;
401  }
402 
403  };
404 
412  template <typename CompareType>
414  public std::binary_function<CompareType, CompareType, bool>
415  {
416  CompareType & tolerance;
417 
418  explicit EqualInTolerance(CompareType & c) :
419  tolerance(c)
420  {}
421 
422  bool operator()(CompareType i, CompareType j)
423  {
424  CompareType diff = fabs(i - j);
425  return diff <= tolerance;
426  }
427 
428  };
429 }
430 
OpenMS::PointerComparator::PointerComparator
PointerComparator(PointerComparator const &pCmp)
Definition: ComparatorUtils.h:175
DefaultParamHandler.h
OpenMS::File::rename
static bool rename(const String &from, const String &to, bool overwrite_existing=true, bool verbose=true)
Rename a file.
OpenMS::EqualInTolerance::EqualInTolerance
EqualInTolerance(CompareType &c)
Definition: ComparatorUtils.h:418
OpenMS::TOPPBase
Base class for TOPP applications.
Definition: TOPPBase.h:144
OpenMS::LexicographicComparator::cmp1_
const Cmp1 & cmp1_
Definition: ComparatorUtils.h:303
OpenMS::PairComparatorFirstElement
Class for comparison of std::pair using first ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:325
OpenMS::Exception::IllegalArgument
A method or algorithm argument contains illegal values.
Definition: Exception.h:648
OpenMS::IdXMLFile::store
void store(const String &filename, const std::vector< ProteinIdentification > &protein_ids, const std::vector< PeptideIdentification > &peptide_ids, const String &document_id="")
Stores the data in an idXML file.
OpenMS::ResidueModification
Representation of a modification.
Definition: ResidueModification.h:76
OpenMS::DigestionEnzymeDB< DigestionEnzymeProtein, ProteaseDB >::getInstance
static ProteaseDB * getInstance()
this member function serves as a replacement of the constructor
Definition: DigestionEnzymeDB.h:69
OpenMS::MzMLFile
File adapter for MzML files.
Definition: MzMLFile.h:55
OpenMS::String
A more convenient string class.
Definition: String.h:59
OpenMS::Residue::getOneLetterCode
const String & getOneLetterCode() const
returns the name as one letter code (String of size 1)
OpenMS::IndexedMzMLDecoder::findIndexListOffset
std::streampos findIndexListOffset(String filename, int buffersize=1023)
Tries to extract the indexList offset from an indexedmzML.
OpenMS::reverseComparator
ReverseComparator< Cmp > reverseComparator(Cmp const &cmp)
Make-function to create a ReverseComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:260
MzMLFile.h
OpenMS::MSExperiment
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:77
OpenMS::LexicographicComparator::operator()
bool operator()(T1 left, T2 right) const
Definition: ComparatorUtils.h:283
OpenMS::Size
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
OpenMS::PointerComparator
Wrapper that takes a comparator for `something' and makes a comparator for pointers to `something' ou...
Definition: ComparatorUtils.h:172
IdXMLFile.h
OpenMS::Constants::c
const double c
OpenMS::ResidueModification::N_TERM
Definition: ResidueModification.h:99
OpenMS::PairComparatorFirstElementMore
Class for comparison of std::pair using first ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:353
OpenMS::PairComparatorSecondElement
Class for comparison of std::pair using second ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:339
OpenMS::PairComparatorSecondElementMore
Class for comparison of std::pair using second ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:367
OpenMS::ReverseComparator::ReverseComparator
ReverseComparator(Cmp const &cmp=Cmp())
Definition: ComparatorUtils.h:230
OpenMS::ResidueDB::getInstance
static ResidueDB * getInstance()
this member function serves as a replacement of the constructor
OpenMS::ProteaseDB::getAllCometNames
void getAllCometNames(std::vector< String > &all_names) const
returns all the enzyme names available for Comet
OpenMS::PairMatcherFirstElement::operator()
bool operator()(const PairType &left, const PairType &right) const
Definition: ComparatorUtils.h:384
OpenMS::ReverseComparator::ReverseComparator
ReverseComparator(ReverseComparator const &cmp)
Definition: ComparatorUtils.h:227
OpenMS::IntList
std::vector< Int > IntList
Vector of signed integers.
Definition: ListUtils.h:55
ResidueDB.h
OPENMS_LOG_WARN
#define OPENMS_LOG_WARN
Macro if a warning, a piece of information which should be read by the user, should be logged.
Definition: LogStream.h:460
OpenMS::ResidueModification::PROTEIN_C_TERM
Definition: ResidueModification.h:100
DCMAKE_PREFIX_PATH
You can set more CMake variables adding< code > linking and adding include directories</td ></tr >< tr >< td valign="top"> c CMAKE_PREFIX_PATH</td >< td > Additional search path for the contrib libraries[MacOSX only] If you want to use libraries installed via Homebrew or MacPorts you might need to provide the corresponding paths< code > DCMAKE_PREFIX_PATH
Definition: common-cmake-parameters.doxygen:19
OpenMS::PairMatcherSecondElement
Struct for comparison of std::pair using second ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:395
OpenMS::ListUtils::concatenate
static String concatenate(const std::vector< T > &container, const String &glue="")
Concatenates all elements of the container and puts the glue string between elements.
Definition: ListUtils.h:193
OpenMS::PointerComparator::operator()
Cmp::result_type operator()(T1 left, T2 right) const
Definition: ComparatorUtils.h:184
OpenMS::ModificationsDB::getInstance
static ModificationsDB * getInstance()
Returns a pointer to the modifications DB (singleton)
OpenMS::MzMLFile::getCentroidInfo
std::map< UInt, std::pair< Size, Size > > getCentroidInfo(const String &filename)
Gets info on centroidedness of spectra based on their metadata.
OpenMS
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
OpenMS::EqualInTolerance::tolerance
CompareType & tolerance
Definition: ComparatorUtils.h:416
OpenMS::ResidueModification::getOrigin
char getOrigin() const
Returns the origin (i.e. modified amino acid)
ProteaseDB.h
OpenMS::Residue
Representation of a residue.
Definition: Residue.h:62
OpenMS::ReverseComparator::cmp_
const Cmp & cmp_
Definition: ComparatorUtils.h:241
Server
You can set more CMake variables adding< code > linking and adding include directories</td ></tr >< tr >< td valign="top"> c CMAKE_PREFIX_PATH</td >< td > Additional search path for the contrib libraries[MacOSX only] If you want to use libraries installed via Homebrew or MacPorts you might need to provide the corresponding paths< code > this flag can be used to disable those parts of the documentation and the tests that need an X Server(Default:On)</td ></tr >< tr >< td valign
OpenMS::PointerComparator::PointerComparator
PointerComparator(Cmp const &cmp=Cmp())
Definition: ComparatorUtils.h:178
OpenMS::ResidueModification::C_TERM
Definition: ResidueModification.h:98
int
DVARIABLE
You can set more CMake variables adding< code > DVARIABLE
Definition: common-cmake-parameters.doxygen:1
OpenMS::ResidueModification::PROTEIN_N_TERM
Definition: ResidueModification.h:101
OpenMS::ResidueModification::getDiffMonoMass
double getDiffMonoMass() const
returns the diff monoisotopic mass, or 0.0 if not set
OpenMS::PairMatcherFirstElement
Class for comparison of std::pair using first ONLY e.g. for use with std::sort.
Definition: ComparatorUtils.h:381
OpenMS::LexicographicComparator::cmp2_
const Cmp2 & cmp2_
Definition: ComparatorUtils.h:304
OpenMS::EqualInTolerance
Struct for binary predicate to consider equality with a certain tolerance.
Definition: ComparatorUtils.h:413
IndexedMzMLDecoder.h
OpenMS::PairMatcherSecondElement::operator()
bool operator()(const PairType &left, const PairType &right) const
Definition: ComparatorUtils.h:398
PepXMLFile.h
OpenMS::String::toQString
QString toQString() const
Conversion to Qt QString.
OpenMS::EqualInTolerance::operator()
bool operator()(CompareType i, CompareType j)
Definition: ComparatorUtils.h:422
seqan::find
bool find(TFinder &finder, const Pattern< TNeedle, FuzzyAC > &me, PatternAuxData< TNeedle > &dh)
Definition: AhoCorasickAmbiguous.h:884
OpenMS::ReverseComparator::operator()
Cmp::result_type operator()(T1 left, T2 right) const
Definition: ComparatorUtils.h:235
OpenMS::StringList
std::vector< String > StringList
Vector of String.
Definition: ListUtils.h:70
OpenMS::PairComparatorSecondElementMore::operator()
bool operator()(const PairType &left, const PairType &right) const
Definition: ComparatorUtils.h:370
ModificationsDB.h
main
int main(int argc, const char **argv)
Definition: INIFileEditor.cpp:73
OpenMS::Constants::UserParam::ISOTOPE_ERROR
const std::string ISOTOPE_ERROR
OpenMS::LexicographicComparator::LexicographicComparator
LexicographicComparator(Cmp1 const &cmp1=Cmp1(), Cmp2 const &cmp2=Cmp2())
Definition: ComparatorUtils.h:278
OPENMS_LOG_ERROR
#define OPENMS_LOG_ERROR
Macro to be used if non-fatal error are reported (processing continues)
Definition: LogStream.h:455
OpenMS::File::TempDir
Class representing a temporary directory.
Definition: File.h:63
OpenMS::File::getTemporaryFile
static const String & getTemporaryFile(const String &alternative_file="")
Obtain a temporary filename, ensuring automatic deletion upon exit.
OpenMS::PlainMSDataWritingConsumer
Consumer class that writes MS data to disk using the mzML format.
Definition: MSDataWritingConsumer.h:240
OpenMS::PairComparatorFirstElementMore::operator()
bool operator()(const PairType &left, const PairType &right) const
Definition: ComparatorUtils.h:356
OpenMS::File::findDatabase
static String findDatabase(const String &db_name)
OpenMS::PepXMLFile::load
void load(const String &filename, std::vector< ProteinIdentification > &proteins, std::vector< PeptideIdentification > &peptides, const String &experiment_name, const SpectrumMetaDataLookup &lookup)
Loads peptide sequences with modifications out of a PepXML file.
OpenMS::PairComparatorSecondElement::operator()
bool operator()(const PairType &left, const PairType &right) const
Definition: ComparatorUtils.h:342
OpenMS::File::readable
static bool readable(const String &file)
Return true if the file exists and is readable.
OpenMS::TOPPBase::ExitCodes
ExitCodes
Exit codes.
Definition: TOPPBase.h:149
OpenMS::FileHandler::stripExtension
static String stripExtension(const String &filename)
If filename contains an extension, it will be removed (including the '.'). Special extensions,...
OpenMS::ModificationsDB::getAllSearchModifications
void getAllSearchModifications(std::vector< String > &modifications) const
Collects all modifications that can be used for identification searches.
OpenMS::PairComparatorFirstElement::operator()
bool operator()(const PairType &left, const PairType &right) const
Definition: ComparatorUtils.h:328
OpenMS::Residue::getName
const String & getName() const
returns the name of the residue
OpenMS::PepXMLFile
Used to load and store PepXML files.
Definition: PepXMLFile.h:63
ResidueModification.h
OpenMS::Map
Map class based on the STL map (containing several convenience functions)
Definition: Map.h:50
OPENMS_LOG_INFO
#define OPENMS_LOG_INFO
Macro if a information, e.g. a status should be reported.
Definition: LogStream.h:465
OpenMS::ResidueDB::getResidue
const Residue * getResidue(const String &name) const
returns a pointer to the residue with name, 3 letter code or 1 letter code name
OpenMS::pointerComparator
PointerComparator< Cmp > pointerComparator(Cmp const &cmp)
Make-function to create a PointerComparator from another comparator without the need to specify the t...
Definition: ComparatorUtils.h:209
MSDataWritingConsumer.h
OpenMS::lexicographicComparator
LexicographicComparator< Cmp1, Cmp2 > lexicographicComparator(Cmp1 const &cmp1, Cmp2 const &cmp2)
Make-function to create a LexicographicComparator from two other comparators without the need to spec...
Definition: ComparatorUtils.h:316
OpenMS::Exception::FileEmpty
File is empty.
Definition: Exception.h:594
OpenMS::IndexedMzMLDecoder
A class to analyze indexedmzML files and extract the offsets of individual tags.
Definition: IndexedMzMLDecoder.h:58
OpenMS::ReverseComparator
Wrapper that reverses (exchanges) the two arguments of a comparator. Normally you should use the make...
Definition: ComparatorUtils.h:223
OpenMS::ResidueModification::getTermSpecificity
TermSpecificity getTermSpecificity() const
returns terminal specificity
OpenMS::LexicographicComparator
A wrapper class that combines two comparators lexicographically. Normally you should use the make-fun...
Definition: ComparatorUtils.h:275
File.h
OpenMS::DefaultParamHandler::writeParametersToMetaValues
static void writeParametersToMetaValues(const Param &write_this, MetaInfoInterface &write_here, const String &prefix="")
Writes all parameters to meta values.
TOPPBase.h
OpenMS::IdXMLFile
Used to load and store idXML files.
Definition: IdXMLFile.h:63
OpenMS::String::toLower
String & toLower()
Converts the string to lowercase.
OpenMS::PointerComparator::cmp_
const Cmp & cmp_
Definition: ComparatorUtils.h:190