Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
DataSet.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "DataSet.h"
14 
15 #include "Spectrum.h"
16 #include "Chromatogram.h"
17 #include "DataGroupNode.h"
18 #include "Sample.h"
19 
20 
21 using namespace kome::objects;
22 
23 
24 #include <crtdbg.h>
25 #ifdef _DEBUG
26  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
27  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
28 #endif // _DEBUG
29 
30 
31 
32 // constructor
34  m_group = NULL;
35  m_sample = NULL;
36 }
37 
38 // constructor
40  m_group = group;
41  m_sample = ( m_group == NULL ) ? NULL : group->getSample();
42 }
43 
44 // destructor
46 }
47 
48 // get sample
50  // check the member
51  if( m_sample != NULL ) {
52  return m_sample;
53  }
54 
55  // group
56  DataGroupNode* group = getGroup();
57  if( group == NULL ) {
58  return NULL;
59  }
60 
61  return group->getSample();
62 }
63 
64 // get spectrum group
66  // check the member
67  if( m_group != NULL ) {
68  return m_group;
69  }
70 
71  // groups
72  std::set< DataGroupNode* > groupSet;
73 
74  for( unsigned int i = 0; i < m_spectra.size(); i++ ) {
75  Spectrum* spec = m_spectra[ i ];
76  DataGroupNode* g = spec->getGroup();
77  if( g == NULL ) {
78  return NULL;
79  }
80  else {
81  groupSet.insert( g );
82  }
83  }
84 
85  for( unsigned int i = 0; i < m_chroms.size(); i++ ) {
86  Chromatogram* chrom = m_chroms[ i ];
87  DataGroupNode* g = chrom->getGroup();
88  if( g == NULL ) {
89  return NULL;
90  }
91  else {
92  groupSet.insert( g );
93  }
94  }
95 
96  // common group
97  DataGroupNode* group = NULL;
98  for( std::set< DataGroupNode* >::iterator it = groupSet.begin();
99  it != groupSet.end(); it++ ) {
100  DataGroupNode* g = *it;
101 
102  if( group == NULL ) {
103  group = g;
104  }
105  else {
106  while( group != NULL && group->getLevel() > g->getLevel() ) {
107  group = group->getParentGroup();
108  }
109  while( g != NULL && g->getLevel() > group->getLevel() ) {
110  g = g->getParentGroup();
111  }
112 
113  while( group != NULL && g != NULL && g != group ) {
114  group = group->getParentGroup();
115  g = g->getParentGroup();
116  }
117 
118  if( group == NULL || g == NULL ) {
119  return NULL;
120  }
121  }
122  }
123 
124  return group;
125 }
126 
127 // get the number of spectra
129  return m_spectra.size();
130 }
131 
132 // get spectrum
133 Spectrum* DataSet::getSpectrum( const unsigned int index ) {
134  if( index >= m_spectra.size() ) {
135  return NULL;
136  }
137  return m_spectra[ index ];
138 }
139 
140 // get the number of chromatograms
142  return m_chroms.size();
143 }
144 
145 // get chromatogram
146 Chromatogram* DataSet::getChromatogram( const unsigned int index ) {
147  // check the index
148  if( index >= m_chroms.size() ) {
149  return NULL;
150  }
151  return m_chroms[ index ];
152 }
153 
154 // sort spectra
156  if( m_spectra.size() > 0 ) {
157  std::sort( m_spectra.begin(), m_spectra.end(), lessSpectrum );
158  }
159 }
160 
161 // clear spectra
163  m_spectra.clear();
164 }
165 
166 // add spectrum
168  insertSpectrum( spec, (int)m_spectra.size() );
169 }
170 
171 // remove spectrum
173  // search
174  int idx = -1;
175  for( unsigned int i = 0; i < m_spectra.size() && idx < 0; i++ ) {
176  Spectrum* tmp = m_spectra[ i ];
177  if( tmp == spec ) {
178  idx = (int)i;
179  }
180  }
181 
182  // remove
183  if( idx >= 0 ) {
184  m_spectra.erase( m_spectra.begin() + idx );
185  }
186 }
187 
188 // insert spectrum
189 void DataSet::insertSpectrum( Spectrum* spec, const int idx ) {
190  // check the parameter
191  if( spec == NULL ) {
192  return;
193  }
194 
195  // check group
196  bool flg = false;
197  DataGroupNode* group = spec->getGroup();
198  while( group != NULL && !flg ) {
199  if( m_group == group ) {
200  flg = true;
201  }
202  group = group->getParentGroup();
203  }
204 
205  // add
206  if( m_group == NULL || flg ) {
207  m_spectra.insert( m_spectra.begin() + idx, spec );
208  }
209 }
210 
211 // clear chromatograms
213  m_chroms.clear();
214 }
215 
216 // add chromatogram
218  insertChromatogram( chrom, (int)m_chroms.size() );
219 }
220 
221 // remove chromatogram
223  // search
224  int idx = -1;
225  for( unsigned int i = 0; i < m_chroms.size() && idx < 0; i++ ) {
227  if( tmp == chrom ) {
228  idx = (int)i;
229  }
230  }
231 
232  // remove
233  if( idx >= 0 ) {
234  m_chroms.erase( m_chroms.begin() + idx );
235  }
236 }
237 
238 // insert chromatogram
239 void DataSet::insertChromatogram( Chromatogram* chrom, const int idx ) {
240  // check the parameter
241  if( chrom == NULL ) {
242  return;
243  }
244 
245  // check group
246  bool flg = false;
247  DataGroupNode* group = chrom->getGroup();
248  while( group != NULL && !flg ) {
249  if( m_group == group ) {
250  flg = true;
251  }
252  group = group->getParentGroup();
253  }
254 
255  // insert
256  if( m_group == NULL || flg ) {
257  m_chroms.insert( m_chroms.begin() + idx, chrom );
258  }
259 }
260 
261 // compare spectra
262 bool DataSet::lessSpectrum( Spectrum* spec0, Spectrum* spec1 ) {
263  // @date 2013.11.11 <Del> M.Izumi ->
265  //const int s0 = spec0->getScanNumber();
266  //const int s1 = spec1->getScanNumber();
267  //if( s0 >= 0 && s1 >= 0 ) {
268  // if( s0 < s1 ) {
269  // return true;
270  // }
271  // return false;
272  //}
273  // @date 2013.11.11 <Del> M.Izumi <-
274 
275  // RT
276  const double rt0 = spec0->getRt();
277  const double rt1 = spec1->getRt();
278 
279  if( rt0 < rt1 ) {
280  return true;
281  }
282  else if( rt0 > rt1 ) {
283  return false;
284  }
285 
286  return false;
287 }
group of spectrum management class
Definition: DataGroupNode.h:33
virtual void clearSpectra()
clears spectra
Definition: DataSet.cpp:162
interfaces of Chromatogram class
double getRt()
gets retention time
Definition: Spectrum.cpp:184
sample information management class
Definition: Sample.h:34
virtual ~DataSet()
destructor
Definition: DataSet.cpp:45
DataGroupNode * getGroup()
gets spectrum group
virtual void addChromatogram(Chromatogram *chrom)
adds chromatogram
Definition: DataSet.cpp:217
virtual void insertChromatogram(Chromatogram *chrom, const int idx)
inserts chromatogram
Definition: DataSet.cpp:239
unsigned int getLevel()
gets group level
virtual void insertSpectrum(Spectrum *spec, const int idx)
inserts spectrum
Definition: DataSet.cpp:189
unsigned int getNumberOfSpectra()
gets the number of spectra
Definition: DataSet.cpp:128
virtual void removeChromatogram(Chromatogram *chrom)
removes chromatogram
Definition: DataSet.cpp:222
interfaces of Spectrum class
static bool lessSpectrum(Spectrum *spec0, Spectrum *spec1)
compare to sort spectra
Definition: DataSet.cpp:262
Spectrum * getSpectrum(const unsigned int index)
gets the number of spectra
Definition: DataSet.cpp:133
interfaces of DataGroupNode class
interfaces of Sample class
DataGroupNode * m_group
Definition: DataSet.h:57
interfaces of DataSet class
Chromatogram * getChromatogram(const unsigned int index)
gets chroamtogram
Definition: DataSet.cpp:146
DataGroupNode * getParentGroup()
get parent spectrum group
#define NULL
Definition: CoreMacros.h:18
virtual void sortSpectra()
sorts spectra in retention time order
Definition: DataSet.cpp:155
unsigned int getNumberOfChromatograms()
gets the number of chromatograms
Definition: DataSet.cpp:141
DataGroupNode * getGroup()
gets spectrum group
Definition: Spectrum.cpp:898
DataGroupNode * getGroup()
gets spectrum group
Definition: DataSet.cpp:65
std::vector< Spectrum * > m_spectra
Definition: DataSet.h:60
virtual void removeSpectrum(Spectrum *spec)
removes spectrum
Definition: DataSet.cpp:172
spectrum information management class
Definition: Spectrum.h:30
virtual void clearChromatograms()
clears chromatograms
Definition: DataSet.cpp:212
Sample * getSample()
gets sample
Definition: DataSet.cpp:49
DataSet()
constructor
Definition: DataSet.cpp:33
chromatogram information management class
Definition: Chromatogram.h:33
std::vector< Chromatogram * > m_chroms
Definition: DataSet.h:63
virtual void addSpectrum(Spectrum *spec)
adds spectrum to group
Definition: DataSet.cpp:167