Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
DataGroupNode.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "DataGroupNode.h"
14 
15 #include "Spectrum.h"
16 #include "Sample.h"
17 #include "Chromatogram.h"
18 
19 #include "SpectraChromatogram.h"
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 #define DEFAULT_SPEC_X_TITLE "m/z"
34 #define DEFAULT_SPEC_Y_TITLE "intensity"
35 #define DEFAULT_CHROM_X_TITLE "RT"
36 #define DEFAULT_CHROM_Y_TITLE "intensity"
37 
38 
39 // cosntructor
40 DataGroupNode::DataGroupNode( Sample* sample, const char* name ) : DataSet( NULL ) {
41  // log
42  LOG_TRACE( FMT( "Creating spectrum group... (%s)", NVL( name, "" ) ) );
43 
44  // initialize
45  m_group = this;
46  m_sample = sample;
47  setName( name );
48  m_index = -1;
49  m_parent = NULL;
50  m_autoScanNumber = true;
51 
52  // axis title
53  m_specXTitle = DEFAULT_SPEC_X_TITLE;
54  m_specYTitle = DEFAULT_SPEC_Y_TITLE;
55  m_chromXTitle = DEFAULT_CHROM_X_TITLE;
56  m_chromYTitle = DEFAULT_CHROM_Y_TITLE;
57 
58  // level
59  m_level = 0;
60 
61  // issue group id
62  if( sample != NULL ){
63  m_groupId = sample->issueGroupId( sample );
64  }
65 }
66 
67 // destructor
69  // delete childrent
70  for( unsigned int i = 0; i < m_children.size(); i++ ) {
71  delete m_children[ i ];
72  }
73  m_children.clear();
74 
75  // delete spectra
76  for( unsigned int i = 0; i < m_spectra.size(); i++ ) {
77  delete m_spectra[ i ];
78  }
79  m_spectra.clear();
80 
81  // delete chromatograms
82  for( unsigned int i = 0; i < m_chroms.size(); i++ ) {
83  delete m_chroms[ i ];
84  }
85  m_chroms.clear();
86 }
87 
88 // set name
89 void DataGroupNode::setName( const char* name ) {
90  m_name = std::string( NVL( name, "" ) );
91 }
92 
93 // get name
94 const char* DataGroupNode::getName() {
95  return m_name.c_str();
96 }
97 
98 // set group index
99 void DataGroupNode::setGroupIndex( const int index ) {
100  m_index = index;
101 }
102 
103 // get group index
105  return m_index;
106 }
107 
108 // get parent spectrum
110  return m_parent;
111 }
112 
113 // create new child group
115  // create child group object
116  DataGroupNode* child = new DataGroupNode( m_sample, name );
117  child->m_level = m_level + 1;
118  child->setParentDataGroupNode( this );
119 
120  // add object to the array
121  m_children.push_back( child );
122 
123  return child;
124 }
125 
126 // remove child group
128  // index
129  int idx = -1;
130  for( int i = 0; i < (int)m_children.size() && idx < 0; i++ ) {
131  DataGroupNode* tmp = m_children[ i ];
132  if( tmp == child ) {
133  idx = i;
134  }
135  }
136 
137  // removee
138  if( idx >= 0 ) {
139  m_children.erase( m_children.begin() + idx );
140  }
141 }
142 
143 // get the number of child groups
145  return m_children.size();
146 }
147 
148 // get child group object
149 DataGroupNode* DataGroupNode::getChild( const unsigned int index ) {
150  // check the index
151  if( index >= m_children.size() ) {
152  return NULL;
153  }
154  return m_children[ index ];
155 }
156 
157 // get spectra
159  // check parameter
160  if( dataSet == NULL ) {
161  return;
162  }
163 
164  // get chromatograms
165  for( unsigned int i = 0; i < m_chroms.size(); i++ ) {
166  dataSet->addChromatogram( m_chroms[ i ] );
167  }
168 
169  // get spectra
170  for( unsigned int i = 0; i < m_spectra.size(); i++ ) {
171  dataSet->addSpectrum( m_spectra[ i ] );
172  }
173 
174  // gets spectra that belong to child group
175  for( unsigned int i = 0; i < m_children.size(); i++ ) {
176  m_children[ i ]->getDataSet( dataSet );
177  }
178 }
179 
180 // set auto scan number flag
181 void DataGroupNode::setAutoScanNumber( const bool autoScanNumber ) {
182  m_autoScanNumber = autoScanNumber;
183 }
184 
185 // get auto scan number flag
187  return m_autoScanNumber;
188 }
189 
190 // set spectrum x axis title
191 void DataGroupNode::setSpecXTitle( const char* title ) {
192  m_specXTitle = std::string( NVL( title, "" ) );
193 }
194 
195 // get spectrum x axis title
197  return m_specXTitle.c_str();
198 }
199 
200 // set spectrum y axis title
201 void DataGroupNode::setSpecYTitle( const char* title ) {
202  m_specYTitle = std::string( NVL( title, "" ) );
203 }
204 
205 // get spectrum y axis title
207  return m_specYTitle.c_str();
208 }
209 
210 // set chromatogram x axis title
211 void DataGroupNode::setChromXTitle( const char* title ) {
212  m_chromXTitle = std::string( NVL( title, "" ) );
213 }
214 
215 // get chromatogram x axis title
217  return m_chromXTitle.c_str();
218 }
219 
220 // set chromatogram y axis title
221 void DataGroupNode::setChromYTitle( const char* title ) {
222  m_chromYTitle = std::string( NVL( title, "" ) );
223 }
224 
225 // get chromatogram y axis title
227  return m_chromYTitle.c_str();
228 }
229 
230 // get group level
231 unsigned int DataGroupNode::getLevel() {
232  return m_level;
233 }
234 
235 // get properties
237  return m_properties;
238 }
239 
240 // get user properties
242  return m_userProperties;
243 }
244 
245 // set parent spectrum group
247  m_parent = parent;
248 }
249 
250 // create default chromatogram
252  // check the member
253  if( m_spectra.size() == 0 || m_chroms.size() > 0 ) {
254  return;
255  }
256 
257  // check spectra
258  int cnt = 0;
259  for( unsigned int i = 0; i < m_spectra.size() && cnt < 2; i++ ) {
260  kome::objects::Spectrum* spec = m_spectra[ i ];
261  if( spec->hasChromatogram() ) {
262  cnt++;
263  }
264  }
265  if( cnt < 2 ) {
266  return;
267  }
268 
269  // TIC
271  tic->setName( "TIC" );
272  tic->setIcon( "TIC" );
273  tic->setAutoCreated( true );
274  m_chroms.push_back( tic );
275 }
276 
277 // sort spectra
279  // sort
281 }
282 
283 // add spectrum
284 void DataGroupNode::insertSpectrum( Spectrum* spectrum, const int idx ) {
285  // check the parameter
286  if( spectrum == NULL ) {
287  return;
288  }
289 
290  // set spectrum properties
291  int scanNum = (int)m_spectra.size();
292 
293  if( spectrum->getScanNumber() < 0 && m_autoScanNumber ) {
294  spectrum->setScanNumber( scanNum );
295  }
296  spectrum->setGroup( this );
297 
298  // insert spectrum
299  m_spectra.insert( m_spectra.begin() + idx, spectrum );
300 
301  // default chromatogram
303 }
304 
305 // add chromatogram
307  // check the object
308  if( chrom == NULL ) {
309  return;
310  }
311 
312  // insert
313  m_chroms.insert( m_chroms.begin() + idx, chrom );
314  chrom->setGroup( this );
315 
316  // delete
317  for( int i = (int)m_chroms.size() - 1; i >= 0; i-- ) {
318  Chromatogram* tmp = m_chroms[ i ];
319  if( tmp->isAutoCreated() ) {
320  m_chroms.erase( m_chroms.begin() + i );
321  delete tmp;
322  }
323  }
324 }
325 
326 // set group id
327 void DataGroupNode::setId( int id ){
328  m_groupId = id;
329 }
330 
331 // get group id
333  return m_groupId;
334 }
void setParentDataGroupNode(DataGroupNode *parent)
sets parent spectrum group
void setAutoScanNumber(const bool autoScanNumber)
sets the auto scan number flag
void setChromXTitle(const char *title)
sets chromatogram x axis title
void setChromYTitle(const char *title)
sets chromatogram y axis title
group of spectrum management class
Definition: DataGroupNode.h:33
void setName(const char *name)
sets group name
void getDataSet(DataSet *dataSet)
gets spectra that contains this group. (getSpectrum method cannot get spectra that belong to child gr...
virtual ~DataGroupNode()
destructor
interfaces of Chromatogram class
DataGroupNode * getChild(const unsigned int index)
gets child group
void setGroup(DataGroupNode *group)
sets spectrum group
void removeChildGroup(DataGroupNode *child)
removes child group
sample information management class
Definition: Sample.h:34
const char * getName()
gets group name
keys and values management class
Definition: Properties.h:29
virtual void addChromatogram(Chromatogram *chrom)
adds chromatogram
Definition: DataSet.cpp:217
void createDefaultChromatogram()
creates default chromatogram
unsigned int getLevel()
gets group level
const char * getChromYTitle()
gets chromatogram y axis title
void setSpecYTitle(const char *title)
sets spectrum y axis title
void setId(int id)
sets group id
DataGroupNode(Sample *sample, const char *name)
constructor
interfaces of Spectrum class
kome::core::Properties & getProperties()
gets properties
void setIcon(const char *icon)
sets icon name
void setName(const char *name)
sets chromatogram name
interfaces of DataGroupNode class
void setAutoCreated(const bool autoCreated=true)
sets auto created flag
interfaces of Sample class
const char * getSpecXTitle()
gets spectrum x axis title
DataGroupNode * m_group
Definition: DataSet.h:57
const char * getSpecYTitle()
gets spectrum y axis title
int getScanNumber()
gets scan number
Definition: Spectrum.cpp:915
DataGroupNode * getParentGroup()
get parent spectrum group
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
interfaces of SpectraChromatogram class
#define NULL
Definition: CoreMacros.h:18
DataGroupNode * createChildGroup(const char *name)
creates new child group object
virtual void sortSpectra()
sorts spectra in retention time order
Definition: DataSet.cpp:155
std::vector< DataGroupNode * > m_children
Definition: DataGroupNode.h:63
bool isAutoCreated()
gets auto created flag value
kome::core::Properties & getUserProperties()
gets user properties
std::vector< Spectrum * > m_spectra
Definition: DataSet.h:60
void setScanNumber(const int scan)
sets scan number
Definition: Spectrum.cpp:903
int getGroupIndex()
gets group index
spectrum information management class
Definition: Spectrum.h:30
virtual void insertSpectrum(Spectrum *spectrum, const int idx)
adds spectrum to group (override method )
one or more spectra management class
Definition: DataSet.h:31
int issueGroupId(Sample *sample)
to issue the group id
Definition: Sample.cpp:526
chromatogram information management class
Definition: Chromatogram.h:33
void setGroup(DataGroupNode *group)
sets spectrum group
Definition: Spectrum.cpp:893
kome::core::Properties m_properties
Definition: DataGroupNode.h:76
std::vector< Chromatogram * > m_chroms
Definition: DataSet.h:63
virtual void insertChromatogram(Chromatogram *chrom, const int idx)
adds chromatogram (override method)
spectrum group chromatogram class
virtual void sortSpectra()
sorts spectra in retention time order (override method)
void setSpecXTitle(const char *title)
sets spectrum x axis title
kome::core::Properties m_userProperties
Definition: DataGroupNode.h:79
unsigned int getNumberOfChildren()
gets the number of children
bool isAutoScanNumber()
gets the auto scan number flag
virtual void addSpectrum(Spectrum *spec)
adds spectrum to group
Definition: DataSet.cpp:167
bool hasChromatogram()
judges whether this spectrum has chromatogram
Definition: Spectrum.cpp:888
const char * getChromXTitle()
gets chromatogram x axis title
void setGroupIndex(const int index)
sets group index