Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Chromatogram.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "Chromatogram.h"
14 
15 #include "PointsManager.h"
16 #include "PeaksManager.h"
17 #include "Spectrum.h"
18 #include "DataSet.h"
19 #include "DataGroupNode.h"
20 #include "XYDataOperation.h"
21 #include "Spectrum.h"
22 #include "DataSet.h"
23 #include "Sample.h"
24 
25 #include <math.h>
26 #include <set>
27 
28 
29 using namespace kome::objects;
30 
31 
32 #include <crtdbg.h>
33 #ifdef _DEBUG
34  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
35  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
36 #endif // _DEBUG
37 
38 
39 
40 // static member
41 std::vector< std::string > Chromatogram::m_commonProps;
42 
43 
44 // constructor
46  // initialize
47  m_mz = -1.0;
48  m_sample = sample;
49  m_group = NULL;
50  m_icon = "chromatogram";
51 
52  m_autoCreated = false;
53  m_visible = true;
54 
55  m_orgChrom = NULL;
56  m_op = false;
57 
58  m_q1 = -1.0;
59  m_q3 = -1.0;
60 
61  // issue chrom id
62  if( sample != NULL ){
63  m_chromId = sample->issueChromId( sample );
64  }
65 }
66 
67 // destructor
69  // manager
72 
73  // close
74  DataManager::closeChromatogram( this, true );
75 
76  // delete
77  deleteXYData();
78  pkMgr.deletePeaks( this );
79  ptMgr.clearOperations( this );
80 }
81 
82 // get sample
84  return m_sample;
85 }
86 
87 // set name
88 void Chromatogram::setName( const char* name ) {
89  m_name = std::string( NVL( name, "" ) );
90 }
91 
92 // get name
93 const char* Chromatogram::getName() {
94  return m_name.c_str();
95 }
96 
97 // set m/z
98 void Chromatogram::setMz( const double mz ) {
99  m_mz = mz;
100 }
101 
102 // get m/z
104  return m_mz;
105 }
106 
107 // set group
109  m_group = group;
110  m_sample = ( group == NULL ) ? NULL : group->getSample();
111 }
112 
113 // get group
115  return m_group;
116 }
117 
118 // set icon
119 void Chromatogram::setIcon( const char* icon ) {
120  m_icon = NVL( icon, "" );
121 }
122 
123 // get icon
124 const char* Chromatogram::getIcon() {
125  return m_icon.c_str();
126 }
127 
128 // set title
129 void Chromatogram::setTitle( const char* title ) {
130  m_title = NVL( title, "" );
131 }
132 
133 // get title
134 const char* Chromatogram::getTitle() {
135  return m_title.c_str();
136 }
137 
138 // get properties
140  return m_props;
141 }
142 
143 // get user properties
145  return m_userProps;
146 }
147 
148 // set auto created flag
149 void Chromatogram::setAutoCreated( const bool autoCreated ) {
150  m_autoCreated = autoCreated;
151 }
152 
153 // get auto created flag
155  return m_autoCreated;
156 }
157 
158 // set visible flag
159 void Chromatogram::setVisible( const bool visible ) {
160  m_visible = visible;
161 }
162 
163 // get visible flag
165  return m_visible;
166 }
167 
168 // set original chromatogram
170  m_orgChrom = chrom;
171 }
172 
173 // get original chromatogram
175  if( m_orgChrom == NULL ) {
176  m_orgChrom = this;
177  }
178 
179  return m_orgChrom;
180 }
181 
182 // set Q1 Mass
183 void Chromatogram::setQ1( const double q1 ) {
184  m_q1 = q1;
185 
186  if( q1 < 0.0 ) {
187  m_props.setValue( "Q1 Mass", "" );
188  }
189  else {
190  m_props.setDoubleValue( "Q1 Mass", q1 );
191  }
192 }
193 
194 // get Q1 Mass
196  if( m_q1 < 0.0 ) {
197  m_q1 = m_props.getDoubleValue( "Q1 Mass", -1.0 );
198  }
199 
200  return m_q1;
201 }
202 
203 // set Q3 Mass
204 void Chromatogram::setQ3( const double q3 ) {
205  m_q3 = q3;
206 
207  if( q3 < 0.0 ) {
208  m_props.setValue( "Q3 Mass", "" );
209  }
210  else {
211  m_props.setDoubleValue( "Q3 Mass", q3 );
212  }
213 }
214 
215 // get Q3 Mass
217  if( m_q3 < 0.0 ) {
218  m_q3 = m_props.getDoubleValue( "Q3 Mass", -1.0 );
219  }
220 
221  return m_q3;
222 }
223 
224 // get xy data from data manager
227 
228  return ptMgr.getXYData( this );
229 }
230 
231 // delete xy data of data manager
234 
235  ptMgr.deleteXYData( this );
236 }
237 
238 // get data points
239 void Chromatogram::getXYData( kome::core::XYData* const xyData, const bool op ) {
240  // check parameter
241  if( xyData == NULL ) {
242  return;
243  }
244 
245  // get xy data
247  tm.start();
248 
249  onGetXYData( xyData );
250 
251  tm.stop();
252  LOG_DEBUG(
253  FMT(
254  "Getting Chromatogram [%s] ... %.2f sec",
255  m_title.c_str(),
256  tm.getTotalTime()
257  )
258  );
259 
260  // operation
261  if( op ) {
262  // get operations
264 
265  // update
266  for( unsigned int i = 0; i < ptMgr.getNumberOfOperations( this ); i++ ) {
267  XYDataOperation* operation = ptMgr.getOperation( this, i );
268  operation->update( *xyData, *xyData, *this );
269  }
270  }
271 }
272 
273 // search spectrum
274 Spectrum* Chromatogram::searchSpectrum( const double rt, const SearchType search ) {
275  // spectra
276  DataSet dataSet( m_group );
277  getSpectra( dataSet, rt, rt, search, search );
278 
279  // spectrum
280  if( dataSet.getNumberOfSpectra() == 0 ) {
281  return NULL;
282  }
283  return dataSet.getSpectrum( 0 );
284 }
285 
286 // get spectra
288  DataSet& dataSet,
289  const double startRt,
290  const double endRt,
291  const SearchType startSearch,
292  const SearchType endSearch
293 ) {
294  onGetSpectra( dataSet, startRt, endRt, startSearch, endSearch );
295 }
296 
297 // get mass
298 double Chromatogram::getMass( const unsigned int index ) {
299  return onGetMass( index );
300 }
301 
302 // get MS stage
303 int Chromatogram::getMsStage( const unsigned int index ) {
304  return onGetMsStage( index );
305 }
306 
307 // get precursor
308 double Chromatogram::getPrecursor( const unsigned int index ) {
309  return onGetPrecursor( index );
310 }
311 
312 // get properties
314  // get spectrum properties
315  for( unsigned int i = 0; i < m_props.getNumberOfProperties(); i++ ) {
316  properties.setValue( m_props.getKey( i ), m_props.getValue( i ) );
317  }
318 
319  // get peak information
321  Peaks* peaks = pkMgr.getPeaks( this );
322  if( peaks != NULL ) {
323  int peakNum = peaks->getLength();
324  properties.setIntValue( "Peaks Count", peakNum );
325  }
326 
327  // get group properties
328  DataGroupNode* group = m_group;
329 
330  while( group != NULL ) {
331  for( unsigned int i = 0; i < group->getProperties().getNumberOfProperties(); i++ ) {
332  properties.setValue(
333  group->getProperties().getKey( i ),
334  group->getProperties().getValue( i )
335  );
336  }
337  group = group->getParentGroup();
338  }
339 }
340 
341 // get user properties
343  // get spectrum user properties
344  for( unsigned int i = 0; i < m_userProps.getNumberOfProperties(); i++ ) {
345  userProperties.setValue( m_userProps.getKey( i ), m_userProps.getValue( i ) );
346  }
347 
348  // get group user properties
349  DataGroupNode* group = m_group;
350 
351  while( group != NULL ) {
352  for( unsigned int i = 0; i < group->getUserProperties().getNumberOfProperties(); i++ ) {
353  userProperties.setValue(
354  group->getUserProperties().getKey( i ),
355  group->getUserProperties().getValue( i )
356  );
357  }
358  group = group->getParentGroup();
359  }
360 }
361 
362 // check the property key
363 bool Chromatogram::isCommonProperty( const char* key ) {
364  // create array
365  if( m_commonProps.size() == 0 ) {
366  return false;
367  }
368 
369  // check the key
370  if( key == NULL ) {
371  return false;
372  }
373 
374  for( unsigned int i = 0; i < m_commonProps.size(); i++ ) {
375  if( m_commonProps[ i ].compare( key ) == 0 ) {
376  return true;
377  }
378  }
379 
380  return false;
381 }
382 
383 // set chromatogram id
384 void Chromatogram::setId( int id ){
385  m_chromId = id;
386 }
387 
388 // get chromatogram id
390  return m_chromId;
391 }
abstraction class of two dimention coordinate data
Definition: XYData.h:34
double getQ3()
gets the Q3 Mass
virtual int onGetMsStage(const unsigned int index)=0
This method is called by getMsStage method (abstract method)
group of spectrum management class
Definition: DataGroupNode.h:33
interfaces of PointsManager class
unsigned int getNumberOfOperations(Spectrum *spec)
gets the number of operations of specified spectrum
interfaces of Chromatogram class
interfaces of PeaksManager class
static bool isCommonProperty(const char *key)
check whther the specified property key is common property or not
virtual double onGetPrecursor(const unsigned int index)=0
This method is called by getPrecursor method (abstract method)
void setQ1(const double q1)
sets the Q1 Mass
Peaks * getPeaks(Spectrum *spec)
gets peaks of specified spectrum
void setId(int id)
sets chromatogram id
void setGroup(DataGroupNode *group)
sets spectrum group
sample information management class
Definition: Sample.h:34
void setMz(const double mz)
sets m/z
void setOrgChromatogram(Chromatogram *chrom)
sets original chromatogram
keys and values management class
Definition: Properties.h:29
Sample * getSample()
gets sample
DataGroupNode * getGroup()
gets spectrum group
int getId()
gets chromatogram id
void clearOperations(Spectrum *spec)
clears data operation of specified spectrum
void setValue(const char *key, const char *value)
sets parameter value
Definition: Properties.cpp:39
timer class
Definition: Timer.h:26
static PointsManager & getInstance()
get data points manager object (This is the only object.)
void start()
starts timer
Definition: Timer.cpp:46
bool isVisible()
gets the visible flag value
void setIntValue(const char *key, int value)
sets parameter value
Definition: Properties.cpp:57
data points management class
Definition: PointsManager.h:36
unsigned int getNumberOfSpectra()
gets the number of spectra
Definition: DataSet.cpp:128
static std::vector< std::string > m_commonProps
Definition: Chromatogram.h:96
const char * getIcon()
gets icon name
peaks management class
Definition: PeaksManager.h:41
virtual void onGetXYData(kome::core::XYData *const xyData)=0
This method is called by getXYData method (abstract method)
const char * getValue(const unsigned int index)
gets the parameter value
Definition: Properties.cpp:175
void update(kome::core::XYData &src, kome::core::XYData &dst, Chromatogram &chrom)
updates xy data
interfaces of Spectrum class
kome::core::Properties & getProperties()
gets properties
interfaces of XYDataOperation class
void setIcon(const char *icon)
sets icon name
void setName(const char *name)
sets chromatogram name
Spectrum * getSpectrum(const unsigned int index)
gets the number of spectra
Definition: DataSet.cpp:133
interfaces of DataGroupNode class
void setAutoCreated(const bool autoCreated=true)
sets auto created flag
interfaces of Sample class
unsigned int getNumberOfProperties()
gets the number of Properties
Definition: Properties.cpp:160
interfaces of DataSet class
DataGroupNode * getParentGroup()
get parent spectrum group
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
kome::core::XYData * getXYData()
gets xy data from data manager
void deletePeaks(Spectrum *spec)
deletes peaks of specified spectrum
#define NULL
Definition: CoreMacros.h:18
int getMsStage(const unsigned int index)
gets MS stage
virtual ~Chromatogram()
destructor
void setQ3(const double q3)
sets the Q3 Mass
Chromatogram(Sample *sample)
constructor
kome::core::Properties m_userProps
Definition: Chromatogram.h:71
double getQ1()
gets the Q1 Mass
const char * getKey(const unsigned int index)
gets the name of parameter
Definition: Properties.cpp:165
void getSpectra(DataSet &dataSet, const double startRt, const double endRt, const SearchType startSearch=SEARCH_NEAR, const SearchType endSearch=SEARCH_NEAR)
get spectra in specified RT range
SearchType
search type
void setTitle(const char *title)
sets title
bool isAutoCreated()
gets auto created flag value
double getPrecursor(const unsigned int index)
gets precursor mass
double getTotalTime()
gets total time
Definition: Timer.cpp:83
kome::core::Properties & getUserProperties()
gets user properties
kome::core::XYData * getXYData(Spectrum *spec)
gets xy data of specified spectrum
void deleteXYData()
deletes xy data of data manager
spectrum information management class
Definition: Spectrum.h:30
kome::core::Properties & getUserProperties()
gets user properties
Chromatogram * getOrgChromatogram()
gets original chromatogram
const char * getName()
gets chromatogram name
void deleteXYData(Spectrum *spec)
deletes xy data of specified spectrum
one or more spectra management class
Definition: DataSet.h:31
Sample * getSample()
gets sample
Definition: DataSet.cpp:49
const char * getTitle()
gets title
void setVisible(const bool visible)
sets the visible flag
double stop()
stops timer
Definition: Timer.cpp:52
XYDataOperation * getOperation(Spectrum *spec, const unsigned int index)
gets operation of specified spectrum
peaks information class
Definition: Peaks.h:35
int issueChromId(Sample *sample)
to issue the chromatogram id
Definition: Sample.cpp:493
kome::core::Properties m_props
Definition: Chromatogram.h:68
chromatogram information management class
Definition: Chromatogram.h:33
xy data operation class
virtual void onGetSpectra(DataSet &dataSet, const double startRt, const double endRt, const SearchType startSearch, const SearchType endSearch)=0
This method is called by searchSpectrum or getDataSet method (abstract method)
double getMass(const unsigned int index)
gets mass
static PeaksManager & getInstance()
get peaks manager object (This is the only object.)
static void closeChromatogram(Chromatogram *chrom, const bool deleting)
This method is called when a chromatogram is closed.
double getDoubleValue(const char *key, double defaultValue)
gets parameter value converted to double
Definition: Properties.cpp:128
Spectrum * searchSpectrum(const double rt, const SearchType search=SEARCH_NEAR)
searches spectrum
kome::core::Properties & getProperties()
gets properties
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216
virtual double onGetMass(const unsigned int index)=0
This method is called by getMass method (abstract method)
void setDoubleValue(const char *key, double value)
sets parameter value
Definition: Properties.cpp:62