Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Peak2DElement.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "Peak2DElement.h"
14 
15 #include "Peaks2D.h"
16 #include "PeaksCluster2D.h"
17 #include "PeakElement.h"
18 
19 #include <boost/bind.hpp>
20 
21 
22 using namespace kome::objects;
23 
24 
25 #include <crtdbg.h>
26 #ifdef _DEBUG
27  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
28  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
29 #endif // _DEBUG
30 
31 
32 
33 // constructor
35  // initialize
36  m_peaks = peaks;
37 
38  m_rt = double();
39  m_startRt = double();
40  m_endRt = double();
41 
42  m_mz = double();
43  m_startMz = double();
44  m_endMz = double();
45 
46  m_intensity = -1.0;
47 
48  m_cluster = NULL;
49  m_precursor = -1.0;
50  m_charge = -1;
51  m_fwhm = -1.0;
52  m_area = -1.0;
53 
54  m_elmId = -1;
55 
56  // issue peak2d id
57  if( m_peaks != NULL ){
58  m_peak2dId = m_peaks->issueId( this );
59  }
60 }
61 
62 // destructor
64 }
65 
66 // set RT
67 void Peak2DElement::setRt( const double rt, const double startRt, const double endRt ) {
68  m_rt = rt;
69  m_startRt = startRt;
70  m_endRt = endRt;
71 }
72 
73 // get RT
75  return m_rt;
76 }
77 
78 // get start RT
80  return m_startRt;
81 }
82 
83 // get end RT
85  return m_endRt;
86 }
87 
88 // set m/z
89 void Peak2DElement::setMz( const double mz, const double startMz, const double endMz ) {
90  m_mz = mz;
91  m_startMz = startMz;
92  m_endMz = endMz;
93 }
94 
95 // get m/z
97  return m_mz;
98 }
99 
100 // get start m/z
102  return m_startMz;
103 }
104 
105 // get end m/z
107  return m_endMz;
108 }
109 
110 // set intensity
111 void Peak2DElement::setIntensity( const double intensity ) {
112  m_intensity = intensity;
113 }
114 
115 // get intensity
117  return m_intensity;
118 }
119 
120 // set cluster
122  // check
123  if( m_cluster == cluster ) {
124  return;
125  }
126 
127  // remove
128  if( m_cluster != NULL ) {
129  m_cluster->removePeak( this );
130  }
131 
132  // set
133  m_cluster = cluster;
134 
135  // add
136  if( m_cluster != NULL ) {
137  m_cluster->addPeak( this );
138  }
139 }
140 
141 // get cluster
143  return m_cluster;
144 }
145 
146 // set precursor mass
147 void Peak2DElement::setPrecursorMass( const double precursor ) {
148  m_precursor = precursor;
149 }
150 
151 // get precursor mass
153  return m_precursor;
154 }
155 
156 // set charge
157 void Peak2DElement::setCharge( const int charge ) {
158  m_charge = charge;
159 }
160 
161 // get charge
163  return m_charge;
164 }
165 
166 // set FWHM
167 void Peak2DElement::setFwhm( const double fwhm ) {
168  m_fwhm = fwhm;
169 }
170 
171 // get FWHM
173  return m_fwhm;
174 }
175 
176 // set area
177 void Peak2DElement::setArea( const double area ) {
178  m_area = area;
179 }
180 
181 // get area
183  return m_area;
184 }
185 
186 // get peak2d id
188  return m_peak2dId;
189 }
190 
191 // set peak2d id
192 void Peak2DElement::setId( int id ){
193  m_peak2dId = id;
194 }
195 
196 // clear data
198  m_dataList.clear();
199 }
200 
201 // get the data list size
203  return m_dataList.size();
204 }
205 
206 // add data
207 void Peak2DElement::addData( const int sampleId, const int profileId, const double peakVal, PeakElement* peak ) {
208  m_dataList.resize( m_dataList.size() + 1 );
209  m_dataList.back().peakVal = peakVal;
210  if( peak != NULL ) {
211  m_dataList.back().peak = *peak;
212  }
213  m_dataList.back().sampleId = sampleId;
214  m_dataList.back().profile = profileId;
215 }
216 
217 // set data
218 void Peak2DElement::setData( const int sampleId, const int profileId, const double peakVal, PeakElement* peak ) {
219  clearData();
220  addData( sampleId, profileId, peakVal, peak );
221 
222  // set values
223  setIntensity( peakVal );
224  setArea( peak == NULL ? -1.0 : peak->getArea() );
225  setFwhm( peak == NULL ? -1.0 : peak->getFwhm() );
226 }
227 
228 // get data peak
229 PeakElement* Peak2DElement::getDataPeak( const unsigned int idx ) {
230  if( idx >= m_dataList.size() ) {
231  return NULL;
232  }
233 
234  return &( m_dataList[ idx ].peak );
235 }
236 
237 // get profile ID
238 int Peak2DElement::getDataProfileId( const unsigned int idx ) {
239  if( idx >= m_dataList.size() ) {
240  return -1;
241  }
242 
243  return m_dataList[ idx ].profile;
244 }
245 
246 // get sample ID
247 int Peak2DElement::getDataSampleId( const unsigned int idx ) {
248  if( idx >= m_dataList.size() ) {
249  return -1;
250  }
251 
252  return m_dataList[ idx ].sampleId;
253 }
254 
255 // get peak value
256 double Peak2DElement::getDataPeakValue( const unsigned int idx ) {
257  if( idx >= m_dataList.size() ) {
258  return -1.0;
259  }
260 
261  return m_dataList[ idx ].peakVal;
262 }
263 
264 // clear parameters
266  m_params.clear();
267 }
268 
269 // set parameter
270 void Peak2DElement::setParameter( const char* name, const char* value, const int type ) {
271  // search index
272  int idx = searchParameterIndex( name );
273 
274  // set parametr
275  if( idx < 0 ) { // add
276  m_params.resize( m_params.size() + 1 );
277  m_params.back().name = NVL( name, "" );
278  m_params.back().value = NVL( value, "" );
279  m_params.back().type = type;
280  }
281  else { // update
282  m_params[ idx ].value = NVL( value, "" );
283  if( type > 0 ) {
284  m_params[ idx ].type = type;
285  }
286  }
287 }
288 
289 // get the number of parameters
291  return m_params.size();
292 }
293 
294 // get parameter name
295 const char* Peak2DElement::getParameterName( const int idx ) {
296  if( idx < 0 || idx >= (int)m_params.size() ) {
297  return NULL;
298  }
299 
300  return m_params[ idx ].name.c_str();
301 }
302 
303 // get parameter value
304 const char* Peak2DElement::getParameterValue( const char* name ) {
305  // search index
306  int idx = searchParameterIndex( name );
307 
308  // value
309  return getParameterValue( idx );
310 }
311 
312 // get parameter value
313 const char* Peak2DElement::getParameterValue( const int idx ) {
314  if( idx < 0 || idx >= (int)m_params.size() ) {
315  return NULL;
316  }
317 
318  return m_params[ idx ].value.c_str();
319 }
320 
321 // get parameter type
322 int Peak2DElement::getParameterType( const char* name ) {
323  // search index
324  int idx = searchParameterIndex( name );
325 
326  return getParameterType( idx );
327 }
328 
329 // get parameter type
330 int Peak2DElement::getParameterType( const int idx ) {
331  if( idx < 0 || idx >= (int)m_params.size() ) {
332  return NULL;
333  }
334 
335  return m_params[ idx ].type;
336 }
337 
338 // search parameter index
339 int Peak2DElement::searchParameterIndex( const char* name ) {
340  std::string n = NVL( name, "" );
341 
342  int idx = -1;
343  for( int i = 0; i < (int)m_params.size() && idx < 0; i++ ) {
344  if( n.compare( m_params[ i ].name ) == 0 ) {
345  idx = i;
346  }
347  }
348 
349  return idx;
350 }
double getArea()
gets peak area
int getCharge()
gets the charge state
void setCluster(PeaksCluster2D *cluster)
sets peaks cluster
PeaksCluster2D * m_cluster
Definition: Peak2DElement.h:83
unsigned int getDataListSize()
gets the data list size
void setFwhm(const double fwhm)
sets FWHM
void addPeak(Peak2DElement *peak)
adds peak
unsigned int getNumberOfParameters()
gets the number of parameters
double getPrecursorMass()
gets the precursor mass
double getDataPeakValue(const unsigned int idx=0)
gets the data peak value
std::vector< ParamInfo > m_params
int getParameterType(const char *name)
gets parameter type
void setIntensity(const double intensity)
sets intensity
void clearData()
clears data
void removePeak(Peak2DElement *peak)
removes peak
interfaces of Peaks2D class
void setMz(const double mz, const double startMz, const double endMz)
sets m/z
void setCharge(const int charge)
sets the charge state
void clearParameters()
clears parameters
2-dimentional peaks cluster
void setParameter(const char *name, const char *value, const int type=0)
sets parameters
void setArea(const double area)
sets area
interfaces of Peak2DElement class
Peak2DElement(Peaks2D *peaks)
constructor
interfaces of PeakElement class
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
#define NULL
Definition: CoreMacros.h:18
double getEndRt()
gets end RT
int getId()
gets peak2d id
const char * getParameterValue(const char *name)
gets parameter value
int issueId(Peak2DElement *peak2dElement)
to issue the peak2d id
double getEndMz()
gets end m/z
int getDataProfileId(const unsigned int idx=0)
gets data profile ID
2-dimentional peaks
Definition: Peaks2D.h:32
PeaksCluster2D * getCluster()
gets cluster
int searchParameterIndex(const char *name)
searches parameter index
void addData(const int sampleId, const int profileId, const double peakVal, PeakElement *peak)
adds data
double getStartMz()
gets start m/z
void setId(int id)
sets peak2d id
void setRt(const double rt, const double startRt, const double endRt)
sets RT
double getFwhm()
gets the FWHM
const char * getParameterName(const int idx)
gets parameter name
void setData(const int sampleId, const int profileId, const double peakVal, PeakElement *peak)
sets data
double getStartRt()
gets start RT
PeakElement * getDataPeak(const unsigned int idx=0)
gets data peak
double getIntensity()
gets intensity
int getDataSampleId(const unsigned int idx=0)
gets data sample ID
virtual ~Peak2DElement()
destructor
std::vector< DataInfo > m_dataList
void setPrecursorMass(const double precursor)
sets the precursor mass
interfaces of PeaksCluster2D class