Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
PeaksManager.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "PeaksManager.h"
14 
15 #include "Sample.h"
16 #include "SampleSet.h"
17 #include "Spectrum.h"
18 #include "Chromatogram.h"
19 #include "DataGroupNode.h"
20 #include "DataMapInfo.h"
21 
22 
23 using namespace kome::objects;
24 
25 
26 #include <crtdbg.h>
27 #ifdef _DEBUG
28  #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
29  #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
30 #endif // _DEBUG
31 
32 
33 
34 // constructor
36 }
37 
38 // destructor
40 }
41 
42 // get peaks of specified spectrum
44  // check the parameter
45  if( spec == NULL ) {
46  return NULL;
47  }
48 
49  // get peaks
50  if( m_specPeaksMap.find( spec ) == m_specPeaksMap.end() ) {
51  return NULL;
52  }
53  return &( m_specPeaksMap[ spec ] );
54 }
55 
56 // get peaks of specified chromatogram
58  // check the parameter
59  if( chrom == NULL ) {
60  return NULL;
61  }
62 
63  // get peaks
64  if( m_chromPeaksMap.find( chrom ) == m_chromPeaksMap.end() ) {
65  return NULL;
66  }
67  return &( m_chromPeaksMap[ chrom ] );
68 }
69 
70 // get peaks of specified spectrum group
72  // check the parameter
73  if( group == NULL ) {
74  return NULL;
75  }
76 
77  // get peaks
78  if( m_2dPeaksMap.find( group ) == m_2dPeaksMap.end() ) {
79  return NULL;
80  }
81  return &( m_2dPeaksMap[ group ] );
82 }
83 
84 // create peaks of specified spectrum
86  // check the parameter
87  if( spec == NULL ) {
88  return NULL;
89  }
90 
91  // create peaks
92  Peaks* peaks = getPeaks( spec );
93  if( peaks == NULL ) {
94  peaks = &( m_specPeaksMap[ spec ] );
95  }
96  else {
97  peaks->clearPoints();
98  }
99 
100  // set precursor
101  peaks->setPrecursor( spec->getPrecursor() );
102 
103  return peaks;
104 }
105 
106 // create peaks of specified chromatogram
108  // check the parameter
109  if( chrom == NULL ) {
110  return NULL;
111  }
112 
113  // create peaks
114  Peaks* peaks = getPeaks( chrom );
115  if( peaks == NULL ) {
116  peaks = &( m_chromPeaksMap[ chrom ] );
117  }
118  else {
119  peaks->clearPoints();
120  }
121 
122  return peaks;
123 }
124 
125 // create peaks of specified spectrum group
127  // check the parameter
128  if( group == NULL ) {
129  return NULL;
130  }
131 
132  // create peaks
133  Peaks2D* peaks = getPeaks( group );
134  if( peaks == NULL ) {
135  peaks = &( m_2dPeaksMap[ group ] );
136  }
137  else {
138  peaks->clearClusters();
139  peaks->clearPeaks();
140  }
141 
142  return peaks;
143 }
144 
145 // judge whether peaks of specified spectrum exists
147  return ( m_specPeaksMap.find( spec ) != m_specPeaksMap.end() );
148 }
149 
150 // judge whether peaks of specified chromatogram exists
152  return ( m_chromPeaksMap.find( chrom ) != m_chromPeaksMap.end() );
153 }
154 
155 // judge whether peaks of specified spectrum group exists
157  return ( m_2dPeaksMap.find( group ) != m_2dPeaksMap.end() );
158 }
159 
160 // delete peaks of specified spectrum
162  if( m_specPeaksMap.find( spec ) != m_specPeaksMap.end() ) {
163  m_specPeaksMap.erase( spec );
164  }
165 }
166 
167 // delete peaks of specified chromatogram
169  if( m_chromPeaksMap.find( chrom ) != m_chromPeaksMap.end() ) {
170  m_chromPeaksMap.erase( chrom );
171  }
172 }
173 
174 // delete peaks of specified spectrum group
176  if( m_2dPeaksMap.find( group ) != m_2dPeaksMap.end() ) {
177  m_2dPeaksMap.erase( group );
178  }
179 }
180 
181 // This method is called when a sample is closed
182 void PeaksManager::onCloseSample( Sample* sample, const bool deleting ) {
183  // get spectra
184  std::vector< Spectrum* > spectra;
185  for( std::map< Spectrum*, Peaks >::iterator it = m_specPeaksMap.begin();
186  it != m_specPeaksMap.end(); it++ ) {
187  // spectrum
188  Spectrum* spec = (*it).first;
189  if( spec->getSample() == sample ) {
190  spectra.push_back( spec );
191  }
192  }
193 
194  // erase spectrum peaks
195  for( unsigned int i = 0; i < spectra.size(); i++ ) {
196  Spectrum* spec = spectra[ i ];
197  m_specPeaksMap[ spec ].clearPoints();
198  m_specPeaksMap.erase( spec );
199  }
200 
201  // get chromatograms
202  std::vector< Chromatogram* > chroms;
203  for( std::map< Chromatogram*, Peaks >::iterator it = m_chromPeaksMap.begin();
204  it != m_chromPeaksMap.end(); it++ ) {
205  // chromatogram
206  Chromatogram* chrom = (*it).first;
207  if( chrom->getSample() == sample ) {
208  chroms.push_back( chrom );
209  }
210  }
211 
212  // erase chromatogram peaks
213  for( unsigned int i = 0; i < chroms.size(); i++ ) {
214  Chromatogram* chrom = chroms[ i ];
215  m_chromPeaksMap[ chrom ].clearPoints();
216  m_chromPeaksMap.erase( chrom );
217  }
218 
219  // get spectrum groups
220  std::vector< DataGroupNode* > groups;
221  for( std::map< DataGroupNode*, Peaks2D >::iterator it = m_2dPeaksMap.begin();
222  it != m_2dPeaksMap.end(); it++ ) {
223  // spectrum group
224  DataGroupNode* group = (*it).first;
225  if( group->getSample() == sample ) {
226  groups.push_back( group );
227  }
228  }
229 
230  // erase 2d peaks
231  for( unsigned int i = 0; i < groups.size(); i++ ) {
232  DataGroupNode* group = groups[ i ];
233 
234  Peaks2D& peaks = m_2dPeaksMap[ group ];
235  peaks.clearClusters();
236  peaks.clearPeaks();
237 
238  m_2dPeaksMap.erase( group );
239  }
240 }
241 
242 // update peaks
243 void PeaksManager::updatePeaks( Spectrum& spec, Peaks* peaks, std::vector<PeakElement>& addPeaks ){
244  if( peaks == NULL ) {
245  peaks = createPeaks( &spec );
246  }
247  else {
248  peaks->clearPoints();
249  }
250 
251  for( unsigned int i=0; i < addPeaks.size(); i++ ){
252  PeakElement* peakElement = peaks->createPeak( addPeaks[i].getX(), addPeaks[i].getY() );
253  if( peakElement != NULL ){
254  peakElement->setLeft( addPeaks[i].getLeftX(), addPeaks[i].getLeftY() );
255  peakElement->setRight( addPeaks[i].getRightX(), addPeaks[i].getRightY() );
256  peakElement->setApex( addPeaks[i].getApexX(), addPeaks[i].getApexY() );
257  peakElement->setId( addPeaks[i].getId() );
258  }
259  }
260 }
261 
262 // get peaks manager object
264  // create object (This is the only object.)
265  static PeaksManager mgr;
266 
267  return mgr;
268 }
group of spectrum management class
Definition: DataGroupNode.h:33
Sample * getSample()
gets the sample that has this spectrum
Definition: Spectrum.cpp:108
double getPrecursor(const int stage)
gets precursor
Definition: Spectrum.cpp:683
interfaces of Chromatogram class
interfaces of PeaksManager class
void setPrecursor(const double precursor)
sets precursor
Definition: Peaks.cpp:184
Peaks * getPeaks(Spectrum *spec)
gets peaks of specified spectrum
void setRight(const double x, const double y)
sets peak right
Peaks * createPeaks(Spectrum *spec)
creates peaks of specified spectrum
sample information management class
Definition: Sample.h:34
Sample * getSample()
gets sample
std::map< Chromatogram *, Peaks > m_chromPeaksMap
Definition: PeaksManager.h:60
void clearPoints()
clear all data points
Definition: XYData.cpp:137
void updatePeaks(Spectrum &spec, Peaks *peaks, std::vector< PeakElement > &addPeaks)
update peaks
interfaces of SampleSet class
peaks management class
Definition: PeaksManager.h:41
std::map< DataGroupNode *, Peaks2D > m_2dPeaksMap
Definition: PeaksManager.h:63
interfaces of Spectrum class
interfaces of DataGroupNode class
interfaces of Sample class
interfaces of GraphInfo class
void deletePeaks(Spectrum *spec)
deletes peaks of specified spectrum
#define NULL
Definition: CoreMacros.h:18
std::map< Spectrum *, Peaks > m_specPeaksMap
Definition: PeaksManager.h:57
2-dimentional peaks
Definition: Peaks2D.h:32
bool hasPeaks(Spectrum *spec)
judges whether peaks object of specified spectrum exists
void setId(int id)
sets peak ID
void setApex(const double x, const double y)
sets peak apex
spectrum information management class
Definition: Spectrum.h:30
void setLeft(const double x, const double y)
sets peak left
virtual void onCloseSample(Sample *sample, const bool deleting)
This method is called when a sample is closed. (override method)
Sample * getSample()
gets sample
Definition: DataSet.cpp:49
void clearClusters()
clears clusters
Definition: Peaks2D.cpp:269
void clearPeaks()
clears peaks
Definition: Peaks2D.cpp:207
peaks information class
Definition: Peaks.h:35
chromatogram information management class
Definition: Chromatogram.h:33
virtual ~PeaksManager()
destructor
static PeaksManager & getInstance()
get peaks manager object (This is the only object.)
PeakElement * createPeak(const double x, const double y)
creates peak
Definition: Peaks.cpp:353