Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
OverlappingChromatogram.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
14 
15 #include "Spectrum.h"
16 #include "DataSet.h"
17 #include "DataGroupNode.h"
18 #include "Spectrum.h"
19 #include "DataSet.h"
20 
21 #include <math.h>
22 
23 
24 using namespace kome::objects;
25 
26 
27 #include <crtdbg.h>
28 #ifdef _DEBUG
29  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
30  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
31 #endif // _DEBUG
32 
33 
34 
35 // constructor
37 
38  m_chroms.clear( );
39  m_dMinX.clear( );
40  m_dMaxX.clear( );
41  m_dMinY.clear( );
42  m_dMaxY.clear( );
43 
44  m_bFlags = NULL;
45  m_dInts = NULL;
46  m_nAllocLen = 0;
47 }
48 
49 // destructor
51 }
52 
53 // add chromatogram
55  // check the chromatogram
56  if( chrom == NULL || searchChromatogram( chrom ) >= 0 ) {
57  return;
58  }
59 
60  // add
61  m_chroms.push_back( chrom );
62 
63  // set group
64  if( m_chroms.size() == 1 ) {
65  setGroup( m_chroms[ 0 ]->getGroup() );
66  }
67  else {
68  setGroup( NULL );
69  }
70 }
71 
72 // clear chromatograms
74  m_chroms.clear();
75 
76  m_dMinX.clear( );
77  m_dMaxX.clear( );
78  m_dMinY.clear( );
79  m_dMaxY.clear( );
80  if ( m_bFlags )
81  {
82  delete[] m_bFlags;
83  m_bFlags = NULL;
84  }
85  if ( m_dInts )
86  {
87  delete[] m_dInts;
88  m_dInts = NULL;
89  }
90  m_nAllocLen = 0;
91 
92  setGroup( NULL );
93 }
94 
95 // remove chromatogram
97  // search
98  int idx = searchChromatogram( chrom );
99  if( idx < 0 ) {
100  return;
101  }
102 
103  // remove
104  m_chroms.erase( m_chroms.begin() + idx );
105 
106  // set group
107  if( m_chroms.size() == 1 ) {
108  setGroup( m_chroms[ 0 ]->getGroup() );
109  }
110  else {
111  setGroup( NULL );
112  }
113 }
114 
115 // search chromatogram
117  // search
118  for( int i = 0; i < (int)m_chroms.size(); i++ ) {
119  if( chrom == m_chroms[ i ] ) {
120  return i;
121  }
122  }
123  return -1;
124 }
125 
126 // get xy data
128  // check the member
129  if( m_chroms.size() == 0 ) {
130  return;
131  }
132 
133  // min, max
134  double minX = 0.0;
135  double maxX = 0.0;
136 
137 #if 0
138  for( unsigned int i = 0; i < m_chroms.size(); i++ ) {
139 
141  // get data points
143  chrom->getXYData( &dps, chrom->getOperationFlag() );
144 
145  double tmpMinX = dps.getMinX();
146  double tmpMaxX = dps.getMaxX();
147 
148  if( i == 0 || tmpMinX < minX ) {
149  minX = tmpMinX;
150  }
151 
152  if( i == 0 || tmpMaxX > maxX ) {
153  maxX = tmpMaxX;
154  }
155  }
156 #else
157  // 新規に登録されたchromatogramの最大最小値をスタックして、
158  // スタックされている情報から最大最小値を求めます
159  // ※chromatogram内の最大最小値を求める時間が省けます
160  //
161  if ( m_chroms.size() > m_dMinX.size() )
162  {
163  kome::objects::Chromatogram* chrom = m_chroms[ m_chroms.size() - 1 ];
164  // get data points
166  chrom->getXYData( &dps, chrom->getOperationFlag() );
167 
168  double tmpMinX = dps.getMinX();
169  double tmpMaxX = dps.getMaxX();
170  double tmpMinY = dps.getMinY();
171  double tmpMaxY = dps.getMaxY();
172 
173  m_dMinX.push_back( tmpMinX );
174  m_dMaxX.push_back( tmpMaxX );
175  m_dMinY.push_back( tmpMinY );
176  m_dMaxY.push_back( tmpMaxY );
177  }
178 
179  for( unsigned int i = 0; i < m_chroms.size(); i++ ) {
180  double tmpMinX = m_dMinX[ i ];
181  double tmpMaxX = m_dMaxX[ i ];
182  double tmpMinY = m_dMinY[ i ];
183  double tmpMaxY = m_dMaxY[ i ];
184 
185  if( i == 0 || tmpMinX < minX ) {
186  minX = tmpMinX;
187  }
188  if( i == 0 || tmpMaxX > maxX ) {
189  maxX = tmpMaxX;
190  }
191  }
192 #endif
193 
194  // index
195  const double spacing = 0.2;
196  const int startIdx = std::max( 0, roundnum( minX / spacing ) );
197  const int endIdx = std::max( 0, roundnum( maxX / spacing ) );
198 
199  // length
200  const int len = endIdx - startIdx + 1;
201  if( len <= 0 ) {
202  return;
203  }
204 
205  // array
206  bool* flags = new bool[ len ];
207  double* ints = new double[ len ];
208 
209  for( int i = 0; i < len; i++ ) {
210  flags[ i ] = false;
211  ints[ i ] = 0.0;
212  }
213 
214  // fill array
215  for( unsigned int i = 0; i < m_chroms.size(); i++ ) {
217  // get data points
219  chrom->getXYData( &dps, chrom->getOperationFlag() );
220 
221  for( unsigned int j = 0; j < dps.getLength(); j++ ){
222 
223  const double x = dps.getX( j );
224  const double y = dps.getY( j );
225 
226  int idx = roundnum( x / spacing );
227  idx = CLAMP( idx, startIdx, endIdx ) - startIdx;
228 
229  flags[ idx ] = true;
230  if( fabs( y ) > fabs( ints[ idx ] ) ) {
231  ints[ idx ] = y;
232  }
233  }
234  }
235 
236  // add array
237  for( int i = 0; i < len; i++ ) {
238  if( flags[ i ] ) {
239  double x = spacing * ( i + startIdx );
240  double y = ints[ i ];
241 
242  xyData->addPoint( x, y );
243  }
244  }
245 
246  delete[] ints;
247  delete[] flags;
248 }
249 
250 // on get spectra
252  DataSet& dataSet,
253  const double startRt,
254  const double endRt,
255  const SearchType startSearch,
256  const SearchType endSearch
257 ) {
258  // chromatograms
259  if( m_chroms.size() == 1 ) {
260  Chromatogram* chrom = m_chroms[ 0 ];
261 
262  chrom->getSpectra( dataSet, startRt, endRt, startSearch, endSearch );
263  }
264 }
265 
266 // on get mass
267 double OverlappingChromatogram::onGetMass( const unsigned int index ) {
268  return -1.0;
269 }
270 
271 // on get MS stage
272 int OverlappingChromatogram::onGetMsStage( const unsigned int index ) {
273  return -1;
274 }
275 
276 // on get precursor
277 double OverlappingChromatogram::onGetPrecursor( const unsigned int index ) {
278  return -1.0;
279 }
280 
abstraction class of two dimention coordinate data
Definition: XYData.h:34
void addChromatogram(Chromatogram *chrom)
adds chromatogram
data points data of profile management class
Definition: DataPoints.h:25
virtual int onGetMsStage(const unsigned int index)
This method is called by getMsStage method (override method)
double getMaxX()
gets maximum x
Definition: XYData.cpp:119
double getX(const unsigned int index)
gets x coordinate
Definition: XYData.cpp:224
void setGroup(DataGroupNode *group)
sets spectrum group
interfaces of Overlapping Chromatogram class
DataGroupNode * getGroup()
gets spectrum group
virtual double onGetMass(const unsigned int index)
This method is called by getMass method (override method)
double getMinY()
gets minimum y
Definition: XYData.cpp:125
double getY(const unsigned int index)
gets y coordinate
Definition: XYData.cpp:243
interfaces of Spectrum class
int roundnum(const double v)
gets the closest integer to the argument
interfaces of DataGroupNode class
interfaces of DataSet class
virtual void onGetXYData(kome::core::XYData *const xyData)
gets chromatogram data points (override method)
kome::core::XYData * getXYData()
gets xy data from data manager
#define NULL
Definition: CoreMacros.h:18
int searchChromatogram(Chromatogram *chrom)
searches chromatogram
double getMinX()
gets minimum x
Definition: XYData.cpp:113
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
virtual void onGetSpectra(DataSet &dataSet, const double startRt, const double endRt, const SearchType startSearch, const SearchType endSearch)
This method is called by searchSpectrum or getSpectra method (override method)
#define CLAMP(x, low, high)
Definition: CoreMacros.h:35
bool getOperationFlag()
gets the operation flag value
Definition: Chromatogram.h:111
virtual double onGetPrecursor(const unsigned int index)
This method is called by getPrecursor method (override method)
one or more spectra management class
Definition: DataSet.h:31
void addPoint(const double x, const double y)
adds point
Definition: XYData.cpp:149
chromatogram information management class
Definition: Chromatogram.h:33
double getMaxY()
gets maximum y
Definition: XYData.cpp:131
void removeChromatogram(Chromatogram *chrom)
removes chromatogram
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216