Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Peaks2DArray.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "Peaks2DArray.h"
14 
15 #include "Peak2DElement.h"
16 
17 #include <boost/bind.hpp>
18 
19 
20 using namespace kome::objects;
21 
22 
23 #include <crtdbg.h>
24 #ifdef _DEBUG
25  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
26  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
27 #endif // _DEBUG
28 
29 
30 
31 // constructor
33 }
34 
35 // destructor
37 }
38 
39 // get the number of peaks
41  return m_peaks.size();
42 }
43 
44 // get peak element
45 Peak2DElement* Peaks2DArray::getPeak( const unsigned int idx ) {
46  if( idx >= m_peaks.size() ) {
47  return NULL;
48  }
49  return m_peaks[ idx ];
50 }
51 
52 // search peak
54  int idx = -1;
55  for( unsigned int i = 0; i < m_peaks.size() && idx < 0; i++ ) {
56  if( peak == m_peaks[ i ] ) {
57  idx = (int)i;
58  }
59  }
60 
61  return idx;
62 }
63 
64 // sort by RT
65 void Peaks2DArray::sortByRt( const bool desc ) {
66  std::sort(
67  m_peaks.begin(),
68  m_peaks.end(),
69  boost::bind( lessRt, _1, _2, desc )
70  );
71 }
72 
73 // sort by m/z
74 void Peaks2DArray::sortByMz( const bool desc ) {
75  std::sort(
76  m_peaks.begin(),
77  m_peaks.end(),
78  boost::bind( lessMz, _1, _2, desc )
79  );
80 }
81 
82 // sort by intensity
83 void Peaks2DArray::sortByIntensity( const bool desc ) {
84  std::sort(
85  m_peaks.begin(),
86  m_peaks.end(),
87  boost::bind( lessIntensity, _1, _2, desc )
88  );
89 }
90 
91 // compare RT
92 bool Peaks2DArray::lessRt( Peak2DElement* p0, Peak2DElement* p1, bool desc ) {
93  if( desc ) {
94  return ( p0->getRt() > p1->getRt() );
95  }
96  return ( p0->getRt() < p1->getRt() );
97 }
98 
99 // compare m/z
100 bool Peaks2DArray::lessMz( Peak2DElement* p0, Peak2DElement* p1, bool desc ) {
101  if( desc ) {
102  return ( p0->getMz() > p1->getMz() );
103  }
104  return ( p0->getMz() < p1->getMz() );
105 }
106 
107 // compare intensity
109  if( desc ) {
110  return ( p0->getIntensity() > p1->getIntensity() );
111  }
112  return ( p0->getIntensity() < p1->getIntensity() );
113 }
114 
115 
116 // issue peak 2d id
117 int Peaks2DArray::issueId( Peak2DElement* peak2dElement ){
118  if( peak2dElement != NULL && peak2dElement->getId() > 0 ){
119  return peak2dElement->getId()+1;
120  }
121  return 0;
122 }
123 
124 // get peak by peak 2d id
126  for( unsigned int i=0; i < m_peaks.size(); i++ ){
127  if( m_peaks[i]->getId() == id ){
128  return m_peaks[i];
129  }
130  }
131  return NULL;
132 }
static bool lessMz(Peak2DElement *p0, Peak2DElement *p1, bool desc)
compares peaks to sort by m/z
interfaces of Peaks2DArray class
virtual ~Peaks2DArray()
destructor
Peak2DElement * getPeak(const unsigned int idx)
gets peak element
static bool lessRt(Peak2DElement *p0, Peak2DElement *p1, bool desc)
compares peaks to sort by RT
void sortByRt(const bool desc)
sorts peaks by RT
interfaces of Peak2DElement class
void sortByIntensity(const bool desc)
sorts peaks by intensity param desc descending order flag
Peak2DElement * getPeakById(int id)
gets peak element by peak2d id
#define NULL
Definition: CoreMacros.h:18
int searchPeak(Peak2DElement *peak)
searches peak
unsigned int getNumberOfPeaks()
gets the number of peaks
int getId()
gets peak2d id
std::vector< Peak2DElement * > m_peaks
Definition: Peaks2DArray.h:44
int issueId(Peak2DElement *peak2dElement)
to issue the peak2d id
2-dimentional peak element
Definition: Peak2DElement.h:33
static bool lessIntensity(Peak2DElement *p0, Peak2DElement *p1, bool desc)
compares peaks to sort by intensity
double getIntensity()
gets intensity
void sortByMz(const bool desc)
sorts peaks by m/z