Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Spectrum.cpp
Go to the documentation of this file.
1 
12 #include "stdafx.h"
13 #include "Spectrum.h"
14 
15 #include "DataGroupNode.h"
16 #include "PointsManager.h"
17 #include "PeaksManager.h"
18 #include "Sample.h"
19 #include "SampleSet.h"
20 #include "XYDataOperation.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 #define DEFAULT_RESOLUTION 0.3
35 
36 
37 // static member
38 std::vector< std::string > Spectrum::m_commonProps;
39 
40 
41 // constructor
42 Spectrum::Spectrum( Sample* sample, const char* name ) {
43  // initialize
44  m_sample = sample;
45  m_name = NVL( name, "" );
46 
47  m_rt.start = -1.0;
48  m_rt.end = -1.0;
49 
50  m_bpm = -1.0;
51 
52  m_msStage = 1;
53  m_parentSpec = NULL;
54  m_chrom = false;
55 
56  m_charge = 0;
57 
58  m_group = NULL;
59  m_scanNumber = -1;
60 
61  m_polarity = POLARITY_UNKNOWN;
62  m_centroidMode = false;
63 
64  m_resolution = -1.0;
65 
66  m_orgSpec = NULL;
67  m_op = false;
68 
69  // reserve properties
71 
72  for( unsigned int i = 0; i < m_commonProps.size(); i++ ) {
73  m_props.setValue( m_commonProps[ i ].c_str(), "" );
74  }
75  m_props.setValue( "Name", m_name.c_str() );
76 
77  // issue spectrum id
78  if( sample != NULL ){
79  m_specId = sample->issueSpecId();
80  }
81 
82  // visible flag
83  m_visible = true;
84  m_autoZeroPoints = true;
85 
86  // >>>>>> @Date:2013/07/16 <Add> A.Ozaki
87  m_strSpotId = FMT( "" );
88  // <<<<<< @Date:2013/07/16 <Add> A.Ozaki
89 
90 }
91 
92 // destructor
94  // manager
97 
98  // close
99  DataManager::closeSpectrum( this, true );
100 
101  // delete
102  deleteXYData();
103  ptMgr.clearOperations( this );
104  pkMgr.deletePeaks( this );
105 }
106 
107 // get sample object
109  return m_sample;
110 }
111 
112 // set spectrum name
113 void Spectrum::setName( const char* name ) {
114  m_name = std::string( NVL( name, "" ) ) ;
115  if( m_title.empty() ) {
116  setTitle( name );
117  }
118 
119  m_props.setValue( "Name", m_name.c_str() );
120 }
121 
122 // get spectrum name
123 const char* Spectrum::getName() {
124  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
125  return m_name.c_str();
126 }
127 
128 // set retention time
129 void Spectrum::setRt( const double rt ) {
130  // properties
131  if( rt >= 0.0 ) {
132  m_props.setDoubleValue( "RT", rt );
133  m_props.setDoubleValue( "Start RT", rt );
134  m_props.setDoubleValue( "End RT", rt );
135  }
136  else {
137  m_props.setValue( "RT", "" );
138  m_props.setValue( "Start RT", "" );
139  m_props.setValue( "End RT", "" );
140  }
141 
142  // RT
143  setRt( rt, rt );
144 }
145 
146 // set retention time
147 void Spectrum::setRt( const double startRt, const double endRt ) {
148  if( startRt >= 0.0 && endRt >= 0.0 ) {
149  m_props.setDoubleValue( "RT", ( startRt + endRt ) / 2.0 );
150  }
151  else {
152  m_props.setValue( "RT", "" );
153  }
154 
155  setStartRt( startRt );
156  setEndRt( endRt );
157 }
158 
159 // set start retention time
160 void Spectrum::setStartRt( const double rt ) {
161  if( rt >= 0.0 ) {
162  m_props.setDoubleValue( "Start RT", rt );
163  }
164  else {
165  m_props.setValue( "Start RT", "" );
166  }
167 
168  m_rt.start = rt;
169 }
170 
171 // set end retention time
172 void Spectrum::setEndRt( const double rt ) {
173  if( rt >= 0.0 ) {
174  m_props.setDoubleValue( "End RT", rt );
175  }
176  else {
177  m_props.setValue( "End RT", "" );
178  }
179 
180  m_rt.end = rt;
181 }
182 
183 // get retention time
184 double Spectrum::getRt() {
185  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
186  double rt = ( m_rt.start + m_rt.end ) / 2.0;
187  return rt;
188 }
189 
190 // get start retention time
192  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
193  return m_rt.start;
194 }
195 
196 // get end retention time
198  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
199  return m_rt.end;
200 }
201 
202 // set spectrum type
203 void Spectrum::setSpecType( const char* type ) {
204  m_specType = trimstring( type );
205  m_props.setValue( "Spectrum Type", m_specType.c_str() );
206 }
207 
208 // get spectrum type
209 const char* Spectrum::getSpecType() {
210  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
211  return m_specType.c_str();
212 }
213 
214 // set title
215 void Spectrum::setTitle( const char* title ) {
216  // title
217  m_title = trimstring( title );
218  m_props.setValue( "Title", m_title.c_str() );
219 }
220 
221 // get title
222 const char* Spectrum::getTitle() {
223  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
224 
225  if( m_title.empty() ) {
226  std::string name = m_name;
227  std::string values;
228 
229  int scanNum = getScanNumber();
230  if( scanNum >= 0 ) {
231  if( !values.empty() ) {
232  values.append( "," );
233  }
234  values.append( FMT( "scanNum=%d", scanNum ) );
235  }
236 
237  double rt = getRt();
238  if( rt >= 0.0 ) {
239  if( !values.empty() ) {
240  values.append( "," );
241  }
242  values.append( FMT( "rt=%.2f", rt ) );
243  }
244 
245  double prec = getPrecursor();
246  if( prec >= 0.0 ) {
247  if( !values.empty() ) {
248  values.append( "," );
249  }
250  values.append( FMT( "precursor=%.2f", prec ) );
251  }
252 
253  if( values.empty() ) {
254  m_title = name;
255  }
256  else if( name.empty() ) {
257  m_title = values;
258  }
259  else {
260  m_title = FMT( "%s: %s", name.c_str(), values.c_str() );
261  }
262  }
263 
264  return m_title.c_str();
265 }
266 
267 // set icon name
268 void Spectrum::setIcon( const char* icon ) {
269  m_icon = std::string( NVL( icon, "" ) );
270 }
271 
272 // get icon name
273 const char* Spectrum::getIcon() {
274  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
275  return m_icon.c_str();
276 }
277 
278 // get xy data from data manager
281 
282  return ptMgr.getXYData( this );
283 }
284 
285 // delete xy data of data manager
288 
289  ptMgr.deleteXYData( this );
290 }
291 
292 // get data points
293 void Spectrum::getXYData( kome::core::XYData* const xyData, const bool op ) {
294  // get data points
295  getXYData( xyData, -1.0, -1.0, op );
296 
297  // operation
298  if( op ) {
299  // get operations
301  for( unsigned int i = 0; i < ptMgr.getNumberOfOperations( this ); i++ ) {
302  XYDataOperation* operation = ptMgr.getOperation( this, i );
303 
304  operation->update( *xyData, *xyData, *this );
305  }
306  }
307 }
308 
309 // get data poins
310 void Spectrum::getXYData( kome::core::XYData* const xyData, const double minX, const double maxX, const bool zero ) {
311  // check parameter
312  if( xyData == NULL ) {
313  return;
314  }
315 
316  // gets data points
318  onGetXYData( &dps, minX, maxX );
319 
320  // correct data points
321  if( minX < 0.0 && maxX < 0.0 ) {
322  // get length
323  unsigned int length = dps.getLength();
324 
325  // set x range
326  double minXX = getMinX();
327  double maxXX = getMaxX();
328 
329  // set total and max y
330  if( !m_tic || !m_bpi || m_bpm < 0.0 ) {
331  double tic = 0.0;
332  double bpi = 0.0;
333  double bpm = 0.0;
334 
335  for( unsigned int i = 0; i < length; i++ ) {
336  double x = dps.getX( i );
337  double y = dps.getY( i );
338 
339  tic += y;
340  if( y > bpi ) {
341  bpi = y;
342  bpm = x;
343  }
344  }
345 
346  if( !m_tic ) {
347  setTotalIntensity( tic );
348  }
349  if( !m_bpi ) {
350  setMaxIntensity( bpi );
351  }
352 
353  if( m_bpm < 0.0 ) {
354  setBasePeakMass( bpm );
355  }
356  }
357  }
358 
359  // get precursor intensity
361 
362  // check the points
363  if( dps.getLength() == 0 ) {
364  return;
365  }
366 
367  // zero points
368  if( zero && m_autoZeroPoints ) {
369  double minX = -1.0;
370  if( m_minX ) {
371  minX = m_minX.get();
372  }
373 
374  double maxX = -1.0;
375  if( m_maxX ) {
376  maxX = m_maxX.get();
377  }
378 
379  const double space = DEFAULT_RESOLUTION;
380 
381  // the first point
382  double prevX = dps.getX( 0 );
383  if( prevX > 0.0 && prevX > minX ) {
384  prevX = prevX - space / 3.0;
385  if( prevX < 0.0 ) {
386  prevX = 0.0;
387  }
388  if( prevX < minX ) {
389  prevX = minX;
390  }
391 
392  xyData->addPoint( prevX, 0.0 );
393  }
394 
395  // each points
396  for( unsigned int i = 0; i < dps.getLength(); i++ ) {
397  const double x = dps.getX( i );
398  const double y = dps.getY( i );
399 
400  const double d = x - prevX;
401 
402  if( d > space ) {
403  const double startX = prevX + space / 3.0;
404  const double endX = x - space / 3.0;
405 
406  xyData->addPoint( startX, 0.0 );
407 
408  const int num = (int)( ( endX - startX ) / space );
409 
410  for( int j = 0; j < num; j++ ) {
411  double midX = startX + (double)j * ( endX - startX ) / (double)( num + 2 );
412  if( midX > startX && midX < endX ) {
413  xyData->addPoint( midX, 0.0 );
414  }
415  }
416 
417  xyData->addPoint( endX, 0.0 );
418  }
419 
420  xyData->addPoint( x, y );
421 
422  prevX = x;
423  }
424 
425  // last point
426  if( maxX < 0.0 || prevX < maxX ) {
427  prevX = prevX + space / 3.0;
428  if( maxX >= 0.0 && prevX > maxX ) {
429  prevX = maxX;
430  }
431 
432  xyData->addPoint( prevX, 0.0 );
433  }
434  }
435  else {
436  for( unsigned int i = 0; i < dps.getLength(); i++ ) {
437  xyData->addPoint( dps.getX( i ), dps.getY( i ) );
438  }
439  }
440 }
441 
442 // set x range
443 void Spectrum::setXRange( const double minX, const double maxX ) {
444  setMinX( minX );
445  setMaxX( maxX );
446 }
447 
448 // set min x
449 void Spectrum::setMinX( const double minX ) {
450  if( minX >= 0.0 ) {
451  m_props.setDoubleValue( "Low Mass", minX );
452  }
453  else {
454  m_props.setValue( "Low Mass", "" );
455  }
456 
457  m_minX = minX;
458 }
459 
460 // get min x
462  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
463  // check the member
464  if( !m_minX ) {
465  double minX = double();
466  double maxX = double();
467 
468  onGetXRange( &minX, &maxX );
469 
470  setXRange( minX, maxX );
471  }
472 
473  return m_minX.get();
474 }
475 
476 // set max x
477 void Spectrum::setMaxX( const double maxX ) {
478  if( maxX >= 0.0 ) {
479  m_props.setDoubleValue( "High Mass", maxX );
480  }
481  else {
482  m_props.setValue( "High Mass", "" );
483  }
484 
485  m_maxX = maxX;
486 }
487 
488 // get max x
490  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
491  // check the member
492  if( !m_maxX ) {
493  double minX = double();
494  double maxX = double();
495 
496  onGetXRange( &minX, &maxX );
497 
498  setXRange( minX, maxX );
499  }
500 
501  return m_maxX.get();
502 }
503 
504 // set total intensity
505 void Spectrum::setTotalIntensity( const double intensity ) {
506  if( intensity > 0.0 ) {
507  m_props.setDoubleValue( "TIC", intensity );
508  m_tic = intensity;
509  }
510  else {
511  m_props.setValue( "TIC", "" );
512  }
513 }
514 
515 // get total intensity
516 double Spectrum::getTotalIntensity( const double minX, const double maxX ) {
517  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
518  // check member
519  if( minX < 0.0 && maxX < 0.0 ) {
520  if( m_tic ) {
521  return m_tic.get();
522  }
523  }
524 
525  // get total intensity
526  double intensity = onGetTotalIntensity( minX, maxX );
527 
528  // set tic
529  if( minX < 0.0 && maxX < 0.0 ) {
530  setTotalIntensity( intensity );
531  }
532 
533  return intensity;
534 }
535 
536 // set max intensity
537 void Spectrum::setMaxIntensity( const double intensity ) {
538  if( intensity > 0.0 ) {
539  m_props.setDoubleValue( "BPI", intensity );
540  m_bpi = intensity;
541  }
542  else {
543  m_props.setValue( "BPI", "" );
544  }
545 }
546 
547 // get max intensity
548 double Spectrum::getMaxIntensity( const double minX, const double maxX ) {
549  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
550  // check member
551  if( minX < 0.0 && maxX < 0.0 ) {
552  if( m_bpi ) {
553  return m_bpi.get();
554  }
555  }
556 
557  // get max intensity
558  double intensity = onGetMaxIntensity( minX, maxX );
559 
560  // set bpc
561  if( minX < 0.0 && maxX < 0.0 ) {
562  setMaxIntensity( intensity );
563  }
564 
565  return intensity;
566 }
567 
568 // set base peak mass
569 void Spectrum::setBasePeakMass( const double mass ) {
570  if( mass >= 0.0 ) {
571  m_props.setDoubleValue( "BPM", mass );
572  }
573  else {
574  m_props.setValue( "BPM", "" );
575  }
576 
577  m_bpm = mass;
578 }
579 
580 // get Base Peak Mass
582  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
583  return m_bpm;
584 }
585 
586 // set ms stage
587 void Spectrum::setMsStage( const int stage ) {
588  // properties
589  if( stage > 0 ) {
590  m_props.setIntValue( "Stage", stage );
591  }
592  else {
593  m_props.setValue( "Stage", "" );
594  }
595 
596  for( int i = 1; i < m_msStage; i++ ) {
597  std::string key = FMT( "Precursor%d (Mass)", i );
598  m_props.setValue( key.c_str(), "" );
599 
600  key = FMT( "Precursor%d (Intensity)", i );
601  m_props.setValue( key.c_str(), "" );
602  }
603 
604  // stage
605  m_msStage = stage;
606 
607  // precursor
608  int idx = -1;
609  double prec = -1.0;
610  double intensity = -1.0;
611 
612  for( unsigned int i = 0; i < m_precursor.size() && idx < 0; i++ ) {
613  if( m_precursor[ i ].stage < 0 ) {
614  idx = (int)i;
615  prec = m_precursor[ i ].precursor;
616  intensity = m_precursor[ i ].intensity;
617  }
618  }
619 
620  if( idx >= 0 ) {
621  m_precursor.erase( m_precursor.begin() + idx );
622 
623  if( prec >= 0.0 ) {
624  setPrecursor( stage - 1, prec );
625  }
626 
627  if( intensity >= 0.0 ) {
628  setPrecursorIntensity( stage - 1, intensity );
629  }
630  }
631 }
632 
633 // get ms stage
635  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
636  return m_msStage;
637 }
638 
639 // set precursor
640 void Spectrum::setPrecursor( const int stage, const double precursor ) {
641  // property
642  if( stage >= 1 ) {
643  std::string key = FMT( "Precursor%d (Mass)", stage );
644  m_props.setDoubleValue( key.c_str(), precursor );
645 
646  key = FMT( "Precursor%d (Intensity)", stage );
647  if( !m_props.hasKey( key.c_str() ) ) {
648  m_props.setValue( key.c_str(), "" );
649  }
650  }
651 
652  if( m_msStage > 1 && stage == m_msStage - 1 ) {
653  m_props.setDoubleValue( "Precursor", precursor );
654  }
655 
656  // search
657  for( unsigned int i = 0; i < m_precursor.size(); i++ ) {
658  if( m_precursor[ i ].stage == stage ) {
659  m_precursor[ i ].precursor = precursor;
660  return;
661  }
662  }
663 
664  // add
665  m_precursor.resize( m_precursor.size() + 1 );
666  m_precursor.back().stage = stage;
667  m_precursor.back().intensity = -1.0;
668  m_precursor.back().precursor = precursor;
669 }
670 
671 // set precursor
672 void Spectrum::setPrecursor( const double precursor ) {
673  // stage
674  if( m_msStage > 1 ) {
675  setPrecursor( m_msStage - 1, precursor );
676  }
677  else {
678  setPrecursor( -1, precursor );
679  }
680 }
681 
682 // get precursor
683 double Spectrum::getPrecursor( const int stage ) {
684  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
685  for( unsigned int i = 0; i < m_precursor.size(); i++ ) {
686  if( m_precursor[ i ].stage == stage ) {
687  return m_precursor[ i ].precursor;
688  }
689  }
690 
691  return -1.0;
692 }
693 
694 // get precursor
696  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
697  int stage = ( m_msStage > 1 ? ( m_msStage - 1 ) : -1 );
698  return getPrecursor( stage );
699 }
700 
701 // set precursor intensity
702 void Spectrum::setPrecursorIntensity( const int stage, const double intensity ) {
703  // check parameters
704  if( intensity < 0.0 ) {
705  return;
706  }
707 
708  // property
709  if( stage >= 1 ) {
710  std::string key = FMT( "Precursor%d (Mass)", stage );
711  if( !m_props.hasKey( key.c_str() ) ) {
712  m_props.setValue( key.c_str(), "" );
713  }
714 
715  key = FMT( "Precursor%d (Intensity)", stage );
716  m_props.setDoubleValue( key.c_str(), intensity );
717  }
718 
719  if( m_msStage > 1 && stage == m_msStage - 1 ) {
720  m_props.setDoubleValue( "Precursor Intensity", intensity );
721  }
722 
723  // search
724  for( unsigned int i = 0; i < m_precursor.size(); i++ ) {
725  if( m_precursor[ i ].stage == stage ) {
726  m_precursor[ i ].intensity = intensity;
727  return;
728  }
729  }
730 
731  // add
732  m_precursor.resize( m_precursor.size() + 1 );
733  m_precursor.back().stage = stage;
734  m_precursor.back().precursor = -1.0;
735  m_precursor.back().intensity = intensity;
736 }
737 
738 // set precursor intensity
739 void Spectrum::setPrecursorIntensity( const double intensity ) {
740  if( m_msStage > 1 ) {
741  setPrecursorIntensity( m_msStage - 1, intensity );
742  }
743  else {
744  setPrecursorIntensity( -1, intensity );
745  }
746 }
747 
748 // get precursor intensity
749 double Spectrum::getPrecursorIntensity( const int stage ) {
750  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
751  // get intensity
752  double intensity = -1.0;
753  for( unsigned int i = 0; i < m_precursor.size(); i++ ) {
754  if( m_precursor[ i ].stage == stage ) {
755  intensity = m_precursor[ i ].intensity;
756  }
757  }
758  if( intensity >= 0.0 ) {
759  return intensity;
760  }
761 
762  // get from parent spectrum
763  Spectrum* parent = getParentSpectrum();
764  double precursor = getPrecursor( stage );
765  if( precursor < 0.0 ) {
766  return -1.0;
767  }
768 
769  std::set< Spectrum* > parentSet;
770  parentSet.insert( this );
771  parentSet.insert( parent );
772  while( parent != NULL && parent->getMsStage() != stage ) {
773  parent = parent->getParentSpectrum();
774  if( parentSet.find( parent ) == parentSet.end() ) {
775  parentSet.insert( parent );
776  }
777  else {
778  parent = NULL;
779  }
780  }
781 
782  if( parent != NULL ) {
783  intensity = 0.0;
785  parent->getXYData( &dps, precursor - 0.5, precursor + 0.5, false );
786 
787  for( unsigned int i = 0; i < dps.getLength(); i++ ) {
788  intensity = std::max( intensity, dps.getY( i ) );
789  }
790  setPrecursorIntensity( stage, intensity );
791  }
792 
793  return intensity;
794 }
795 
796 // get precursor intensity
798  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
799  int stage = ( m_msStage > 1 ? ( m_msStage - 1 ) : -1 );
800  return getPrecursorIntensity( stage );
801 }
802 
803 // set precursor charge
804 void Spectrum::setPrecursorCharge( const int charge ) {
805  m_charge = charge;
806 
807  if( charge > 0 ) {
808  m_props.setIntValue( "Precursor Charge", charge );
809  }
810  else {
811  m_props.setValue( "Precursor Charge", "" );
812  }
813 }
814 
815 // get precursor charge
817  return m_charge;
818 }
819 
820 // set parent spectrum
821 void Spectrum::setParentSpectrum( Spectrum* const parent ) {
822  // set parent spectrum
823  m_parentSpec = parent;
824 
825  // precursor
826  std::set< Spectrum* > parentSet;
827  parentSet.insert( this );
828  parentSet.insert( parent );
829  Spectrum* p = parent;
830  while( p != NULL ) {
831  int stage = p->getMsStage() - 1;
832  if( stage > 0 ) {
833  double precursor = getPrecursor( stage );
834  if( precursor < 0.0 ) {
835  precursor = p->getPrecursor();
836  setPrecursor( stage, precursor );
837  }
838  }
839  p = p->getParentSpectrum();
840  if( parentSet.find( p ) == parentSet.end() ) {
841  parentSet.insert( p );
842  }
843  else {
844  p = NULL;
845  }
846  }
847 }
848 
849 // get parent spectrum
851  return m_parentSpec;
852 }
853 
854 // get child spectra
855 void Spectrum::getChildSpectra( std::vector< Spectrum* >& children ) {
856  // sample
857  Sample* smpl = getSample();
858  if( smpl == NULL ) {
859  return;
860  }
861 
862  // get children
863  if( m_children.size() == 0 ) {
864  // spectra
865  for( unsigned int i = 0; i < smpl->getNumberOfGroups(); i++ ) {
866  DataGroupNode* group = smpl->getGroup( i );
867  for( unsigned int j = 0; j < group->getNumberOfSpectra(); j++ ) {
868  Spectrum* spec = group->getSpectrum( j );
869  if( spec->getParentSpectrum() == this ) {
870  m_children.push_back( spec );
871  }
872  }
873  }
874  }
875 
876  // store
877  for( unsigned int i = 0; i < m_children.size(); i++ ) {
878  children.push_back( m_children[ i ] );
879  }
880 }
881 
882 // set whether this spectrum has chromatogram
883 void Spectrum::setHasChromatogram( const bool chromatogram ) {
884  m_chrom = chromatogram;
885 }
886 
887 // judge whether this spectrum has chromatogram
889  return m_chrom;
890 }
891 
892 // set spectrum group
894  m_group = group;
895 }
896 
897 // get spectrum group
899  return m_group;
900 }
901 
902 // set scan number
903 void Spectrum::setScanNumber( const int scan ) {
904  if( scan >= 0 ) {
905  m_props.setIntValue( "Scan Number", scan );
906  }
907  else {
908  m_props.setValue( "Scan Number", "" );
909  }
910 
911  m_scanNumber = scan;
912 }
913 
914 // get scan number
916  return m_scanNumber;
917 }
918 
919 // set polarity
920 void Spectrum::setPolarity( Polarity polarity ) {
921  m_props.setValue(
922  "Polarity",
923  ( polarity == POLARITY_POSITIVE ? "+" : (polarity == POLARITY_NEGATIVE ? "-" : "" ) )
924  );
925 
926  m_polarity = polarity;
927 }
928 
929 // get polarity
931  return m_polarity;
932 }
933 
934 // set centroid mode
935 void Spectrum::setCentroidMode( const bool centroidMode ) {
936  m_props.setBoolValue( "Centroid Mode", centroidMode );
937  m_centroidMode = centroidMode;
938 }
939 
940 // get centroid mode
942  return m_centroidMode;
943 }
944 
945 // set resolution
946 void Spectrum::setResolution( const double resolution ) {
947  m_props.setDoubleValue( "Resolution", resolution );
948  m_resolution = resolution;
949 }
950 
951 // get resolution
953  return m_resolution;
954 }
955 
956 // set collision energy
957 void Spectrum::setCollisionEnergy( const char* collisionEnergy ) {
958  m_props.setValue( "Collision Energy", NVL( collisionEnergy, "" ) );
959  m_collisionEnergy = NVL( collisionEnergy, "" );
960 }
961 
962 // get collision energy
964  return m_collisionEnergy.c_str();
965 }
966 
967 // get properties
969  return m_props;
970 }
971 
972 // set visible flag value
973 void Spectrum::setVisible( const bool visible ) {
974  m_visible = visible;
975 }
976 
977 // get visible flag value
979  return m_visible;
980 }
981 
982 // set auto zero points flag
983 void Spectrum::setAutoZeroPoints( const bool autoZero ) {
984  m_autoZeroPoints = autoZero;
985 }
986 
987 // get auto zero points flag
989  return m_autoZeroPoints;
990 }
991 
992 // get properties
994  return m_userProps;
995 }
996 
997 // set original spectrum
999  m_orgSpec = spec;
1000 }
1001 
1002 // get original spectrum
1004  if( m_orgSpec == NULL ) {
1005  m_orgSpec = this;
1006  }
1007 
1008  return m_orgSpec;
1009 }
1010 
1011 // get properties
1013  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
1014  // get spectrum properties
1015  for( unsigned int i = 0; i < m_props.getNumberOfProperties(); i++ ) {
1016  properties.setValue( m_props.getKey( i ), m_props.getValue( i ) );
1017  }
1018 
1019  // get peak information
1021  Peaks* peaks = pkMgr.getPeaks( this );
1022  if( peaks != NULL ) {
1023  int peakNum = peaks->getLength();
1024  double precursor = peaks->getPrecursor();
1025  std::string chargeStr;
1026  for( unsigned int i = 0; i < peaks->getNumberOfCharges(); i++ ) {
1027  int charge = peaks->getCharge( i );
1028  if( charge > 0 ) {
1029  if( !chargeStr.empty() ) {
1030  chargeStr.append( ", " );
1031  }
1032  }
1033  chargeStr.append( FMT( "%d", charge ) );
1034  }
1035 
1036  properties.setIntValue( "Peaks Count", peakNum );
1037  if( precursor < 0.0 ) {
1038  properties.setValue( "Calculated Precursor", "" );
1039  }
1040  else {
1041  properties.setDoubleValue( "Calculated Precursor", precursor );
1042  }
1043  properties.setValue( "Calculated Precursor Charge", chargeStr.c_str() );
1044  }
1045 
1046  // get group properties
1047  DataGroupNode* group = m_group;
1048 
1049  while( group != NULL ) {
1050  for( unsigned int i = 0; i < group->getProperties().getNumberOfProperties(); i++ ) {
1051  properties.setValue(
1052  group->getProperties().getKey( i ),
1053  group->getProperties().getValue( i )
1054  );
1055  }
1056  group = group->getParentGroup();
1057  }
1058 }
1059 
1060 // get user properties
1062  firstAccessProcess( ); // @Date:2013/07/16 <Add> A.Ozaki
1063  // get spectrum user properties
1064  for( unsigned int i = 0; i < m_userProps.getNumberOfProperties(); i++ ) {
1065  userProperties.setValue( m_userProps.getKey( i ), m_userProps.getValue( i ) );
1066  }
1067 
1068  // get group user properties
1069  DataGroupNode* group = m_group;
1070 
1071  while( group != NULL ) {
1072  for( unsigned int i = 0; i < group->getUserProperties().getNumberOfProperties(); i++ ) {
1073  userProperties.setValue(
1074  group->getUserProperties().getKey( i ),
1075  group->getUserProperties().getValue( i )
1076  );
1077  }
1078  group = group->getParentGroup();
1079  }
1080 }
1081 
1082 // check the property key
1083 bool Spectrum::isCommonProperty( const char* key ) {
1084  // common properties
1085  const char* keys[] = {
1086  "Name",
1087  "RT",
1088  "Start RT",
1089  "End RT",
1090  "Low Mass",
1091  "High Mass",
1092  "TIC",
1093  "BPI",
1094  "BPM",
1095  "Stage",
1096  "Precursor",
1097  "Precursor Intensity",
1098  "Scan Number",
1099  "Polarity",
1100  "Centroid Mode",
1101  "Resolution",
1102  "Collision Energy",
1103  "Spectrum Type",
1104  "Title"
1105  };
1106 
1107  // create array
1108  if( m_commonProps.size() == 0 ) {
1109  const unsigned int num = sizeof( keys ) / sizeof( const char* );
1110 
1111  for( unsigned int i = 0; i < num; i++ ) {
1112  m_commonProps.push_back( keys[ i ] );
1113  }
1114  }
1115 
1116  // check the key
1117  if( key == NULL ) {
1118  return false;
1119  }
1120 
1121  for( unsigned int i = 0; i < m_commonProps.size(); i++ ) {
1122  if( m_commonProps[ i ].compare( key ) == 0 ) {
1123  return true;
1124  }
1125  }
1126 
1127  return false;
1128 }
1129 
1130 // set spectrum id
1131 void Spectrum::setId( int id ){
1132  m_specId = id;
1133 }
1134 
1135 // get spectrum id
1137  return m_specId;
1138 }
1139 
1140 // >>>>>> @Date:2013/07/16 <Add> A.Ozaki
1141 //
1142 
1143 // set spot id
1144 void Spectrum::setSpotId( const char *pcSpotId )
1145 {
1146  m_strSpotId = std::string( NVL( pcSpotId, "" ) );
1147  m_props.setValue( "Spot ID", m_strSpotId.c_str( ) ); // @Date:2013/08/20 <Add> A.Ozaki
1148 
1149  return;
1150 }
1151 
1152 // get spot id
1153 const char *Spectrum::getSpotId( void )
1154 {
1155  firstAccessProcess( );
1156  return m_strSpotId.c_str( );
1157 }
1158 
1159 // set the flag of request load data
1161 {
1163 
1164  return;
1165 }
1166 
1167 // reset the flag of request load data
1168 void Spectrum::resetRequestLoadData( void )
1169 {
1171 
1172  return;
1173 }
1174 
1175 // check the flag of request load data
1177 {
1178  return onIsRequestLoadData( );
1179 }
1180 
1181 // set the flag of first access
1183 {
1184  onSetFirstAccess( );
1185 
1186  return;
1187 }
1188 
1189 // reset the flag of first access
1191 {
1192  onResetFirstAccess( );
1193 
1194  return;
1195 }
1196 
1197 // check the flag of first access
1199 {
1200  return onIsFirstAccess( );
1201 }
1202 
1203 // load data
1205 {
1206  return onLoadData( );
1207 }
1208 
1209 // set the flag of request load data (virtual)
1211 {
1212  return;
1213 }
1214 
1215 // set the flag of request load data (virtual)
1217 {
1218  return;
1219 }
1220 
1221 // check the flag of request load data (virtual)
1223 {
1224  return false;
1225 }
1226 
1227 // set the flag of first access (virtual)
1229 {
1230  return;
1231 }
1232 
1233 // reset the flag of first access (virtual)
1235 {
1236  return;
1237 }
1238 
1239 // check the flag of first access (virtual)
1241 {
1242  return false;
1243 }
1244 
1245 // load data (virtual)
1247 {
1248  return true;
1249 }
1250 
1251 // process of first access
1253 {
1254  bool bRet = true;
1255  if ( isFirstAccess( ) && isRequestLoadData( ) )
1256  {
1257  bRet = loadData( );
1258  resetFirstAccess( );
1259  }
1260 
1261  return bRet;
1262 }
1263 
1264 //
1265 // <<<<<< @Date:2013/07/11 <Add> A.Ozaki
1266 
1267 
1268 
1269 
double getPrecursorIntensity()
gets the precursor intensity of the precursor ion spectrum.
Definition: Spectrum.cpp:797
double getStartRt()
gets the start of retention time
Definition: Spectrum.cpp:191
int issueSpecId()
to issue the spectrum id
Definition: Sample.cpp:462
abstraction class of two dimention coordinate data
Definition: XYData.h:34
unsigned int getNumberOfCharges()
gets the number of charges
Definition: Peaks.cpp:162
void setTotalIntensity(const double intensity)
sets total intensity of spectrum
Definition: Spectrum.cpp:505
void setMaxIntensity(const double intensity)
sets max intensity of spectrum
Definition: Spectrum.cpp:537
kome::core::Properties & getUserProperties()
gets user properties
Definition: Spectrum.cpp:993
Spectrum(Sample *sample, const char *name)
constructor
Definition: Spectrum.cpp:42
void setCollisionEnergy(const char *collisionEnergy)
sets the collision energy
Definition: Spectrum.cpp:957
group of spectrum management class
Definition: DataGroupNode.h:33
virtual bool onIsFirstAccess(void)
This method is called by isFirstAccess method. (abstract method)
Definition: Spectrum.cpp:1240
Sample * getSample()
gets the sample that has this spectrum
Definition: Spectrum.cpp:108
bool firstAccessProcess(void)
method for processing when accessing the first item of this class
Definition: Spectrum.cpp:1252
data points data of profile management class
Definition: DataPoints.h:25
interfaces of PointsManager class
double getPrecursor()
gets precursor
Definition: Peaks.cpp:189
double getPrecursor(const int stage)
gets precursor
Definition: Spectrum.cpp:683
unsigned int getNumberOfOperations(Spectrum *spec)
gets the number of operations of specified spectrum
void setAutoZeroPoints(const bool autoZero)
sets auto zero points flag value
Definition: Spectrum.cpp:983
void setBoolValue(const char *key, bool value)
sets parameter value
Definition: Properties.cpp:67
double getRt()
gets retention time
Definition: Spectrum.cpp:184
bool isFirstAccess(void)
check the flag of first access
Definition: Spectrum.cpp:1198
interfaces of PeaksManager class
double getX(const unsigned int index)
gets x coordinate
Definition: XYData.cpp:224
int getId()
gets spectrum id
Definition: Spectrum.cpp:1136
Peaks * getPeaks(Spectrum *spec)
gets peaks of specified spectrum
void setMinX(const double minX)
sets min x
Definition: Spectrum.cpp:449
const char * getName()
gets spectrum name
Definition: Spectrum.cpp:123
bool isAutoZeroPoints()
gets auto zero points flag value
Definition: Spectrum.cpp:988
void setRt(const double rt)
sets retention time
Definition: Spectrum.cpp:129
const char * getCollisionEnergy()
gets the collision energy
Definition: Spectrum.cpp:963
sample information management class
Definition: Sample.h:34
void setPrecursor(const int stage, const double precursor)
sets precursor
Definition: Spectrum.cpp:640
void setPolarity(Polarity polarity)
sets polarity
Definition: Spectrum.cpp:920
void setPrecursorIntensity(const int stage, const double intensity)
sets precursor intensity
Definition: Spectrum.cpp:702
void setId(int id)
sets spectrum id
Definition: Spectrum.cpp:1131
bool isVisible()
gets the visible flag value
Definition: Spectrum.cpp:978
DataGroupNode * getGroup(const unsigned int index)
gets spectrum group
Definition: Sample.cpp:234
keys and values management class
Definition: Properties.h:29
void setMaxX(const double maxX)
sets max x
Definition: Spectrum.cpp:477
const char * getIcon()
gets icon name
Definition: Spectrum.cpp:273
void setVisible(const bool visible)
sets the visible flag
Definition: Spectrum.cpp:973
void getChildSpectra(std::vector< Spectrum * > &children)
gets child spectra
Definition: Spectrum.cpp:855
void clearOperations(Spectrum *spec)
clears data operation of specified spectrum
void setSpotId(const char *pcSpotId)
set spot id param[in] pcSpotId SpotId information
Definition: Spectrum.cpp:1144
virtual void onResetFirstAccess(void)
This method is called by resetFirstAccess method. (abstract method)
Definition: Spectrum.cpp:1234
void setIcon(const char *icon)
sets icon name
Definition: Spectrum.cpp:268
void setValue(const char *key, const char *value)
sets parameter value
Definition: Properties.cpp:39
void setEndRt(const double rt)
sets end retention time
Definition: Spectrum.cpp:172
void setName(const char *name)
sets spectrum name
Definition: Spectrum.cpp:113
static PointsManager & getInstance()
get data points manager object (This is the only object.)
void setParentSpectrum(Spectrum *const parent)
sets parent spectrum
Definition: Spectrum.cpp:821
const char * getSpotId(void)
get spot id
Definition: Spectrum.cpp:1153
static std::vector< std::string > m_commonProps
Definition: Spectrum.h:169
interfaces of SampleSet class
void setIntValue(const char *key, int value)
sets parameter value
Definition: Properties.cpp:57
data points management class
Definition: PointsManager.h:36
static void closeSpectrum(Spectrum *spec, const bool deleting)
This method is called when a spectrum is closed.
Definition: DataManager.cpp:87
unsigned int getNumberOfSpectra()
gets the number of spectra
Definition: DataSet.cpp:128
virtual double onGetMaxIntensity(const double minX, const double maxX)=0
This method is called by getMaxIntensity method. (abstract method)
short getCharge(const unsigned int index)
gets charge
Definition: Peaks.cpp:167
void setCentroidMode(const bool centroidMode)
sets centroid mode or not
Definition: Spectrum.cpp:935
peaks management class
Definition: PeaksManager.h:41
const char * getValue(const unsigned int index)
gets the parameter value
Definition: Properties.cpp:175
double getY(const unsigned int index)
gets y coordinate
Definition: XYData.cpp:243
std::string trimstring(const char *s)
remove white spaces from both ends of specified string
void update(kome::core::XYData &src, kome::core::XYData &dst, Chromatogram &chrom)
updates xy data
Spectrum * getOrgSpectrum()
gets original spectrum
Definition: Spectrum.cpp:1003
interfaces of Spectrum class
int getPrecursorCharge()
gets the precursor charge
Definition: Spectrum.cpp:816
double getResolution()
gets resolution
Definition: Spectrum.cpp:952
kome::core::Properties & getProperties()
gets properties
static bool isCommonProperty(const char *key)
check whther the specified property key is common property or not
Definition: Spectrum.cpp:1083
interfaces of XYDataOperation class
Spectrum * getSpectrum(const unsigned int index)
gets the number of spectra
Definition: DataSet.cpp:133
interfaces of DataGroupNode class
double getMinX()
gets min x
Definition: Spectrum.cpp:461
int getMsStage()
gets ms stage
Definition: Spectrum.cpp:634
interfaces of Sample class
double getMaxX()
gets max x
Definition: Spectrum.cpp:489
unsigned int getNumberOfProperties()
gets the number of Properties
Definition: Properties.cpp:160
bool loadData(void)
load data
Definition: Spectrum.cpp:1204
void setHasChromatogram(const bool chromatogram)
sets wheher this spectrum has chromatogram
Definition: Spectrum.cpp:883
int getScanNumber()
gets scan number
Definition: Spectrum.cpp:915
DataGroupNode * getParentGroup()
get parent spectrum group
void setRequestLoadData(void)
set the flag of request load data
Definition: Spectrum.cpp:1160
virtual void onResetRequestLoadData(void)
This method is called by resetRequestLoadData method. (abstract method)
Definition: Spectrum.cpp:1216
#define NVL(checkVal, replaceVal)
Definition: CoreMacros.h:99
void setFirstAccess(void)
set the flag of first access
Definition: Spectrum.cpp:1182
void deletePeaks(Spectrum *spec)
deletes peaks of specified spectrum
#define NULL
Definition: CoreMacros.h:18
double getTotalIntensity(const double minX=-1.0, const double maxX=-1.0)
gets total intensity in specified range
Definition: Spectrum.cpp:516
Spectrum * m_orgSpec
Definition: Spectrum.h:162
virtual bool onIsRequestLoadData(void)
This method is called by isRequestLoadData method. (abstract method)
Definition: Spectrum.cpp:1222
kome::core::XYData * getXYData()
gets xy data from data manager
Definition: Spectrum.cpp:279
const char * getKey(const unsigned int index)
gets the name of parameter
Definition: Properties.cpp:165
void resetFirstAccess(void)
reset the flag of first access
Definition: Spectrum.cpp:1190
virtual bool onLoadData(void)
This method is called by loadData method. (abstract method)
Definition: Spectrum.cpp:1246
void setMsStage(const int stage)
sets ms stage
Definition: Spectrum.cpp:587
double getPrecursor()
gets the precursor mass of precursor ion spectrum.
Definition: Spectrum.cpp:695
DataGroupNode * getGroup()
gets spectrum group
Definition: Spectrum.cpp:898
void setStartRt(const double rt)
sets start retention time
Definition: Spectrum.cpp:160
virtual double onGetTotalIntensity(const double minX, const double maxX)=0
This method is called by getTotalIntensity method. (abstract method)
kome::core::Properties & getProperties()
gets properties
Definition: Spectrum.cpp:968
kome::core::Properties & getUserProperties()
gets user properties
void setScanNumber(const int scan)
sets scan number
Definition: Spectrum.cpp:903
void setBasePeakMass(const double mass)
sets base peak mass
Definition: Spectrum.cpp:569
bool hasKey(const char *key)
judges whether this object has specified parameter key
Definition: Properties.cpp:93
const char * getTitle()
gets spectrum title
Definition: Spectrum.cpp:222
unsigned int getNumberOfGroups()
gets the number of spectrum groups
Definition: Sample.cpp:229
void setOrgSpectrum(Spectrum *spec)
sets original spectrum
Definition: Spectrum.cpp:998
kome::core::XYData * getXYData(Spectrum *spec)
gets xy data of specified spectrum
Spectrum * getParentSpectrum()
gets parent spectrum
Definition: Spectrum.cpp:850
spectrum information management class
Definition: Spectrum.h:30
void deleteXYData(Spectrum *spec)
deletes xy data of specified spectrum
virtual void onGetXYData(kome::core::XYData *const xyData, const double minX, const double maxX)=0
This method is called by getXYData method. (abstract method)
double getEndRt()
gets the end of retention time
Definition: Spectrum.cpp:197
void addPoint(const double x, const double y)
adds point
Definition: XYData.cpp:149
void setSpecType(const char *type)
sets spectrum type
Definition: Spectrum.cpp:203
const char * getSpecType()
gets spectrum type
Definition: Spectrum.cpp:209
XYDataOperation * getOperation(Spectrum *spec, const unsigned int index)
gets operation of specified spectrum
peaks information class
Definition: Peaks.h:35
bool isRequestLoadData(void)
check the flag of request load data
Definition: Spectrum.cpp:1176
virtual void onSetRequestLoadData(void)
This method is called by setRequestLoadData method. (abstract method)
Definition: Spectrum.cpp:1210
void deleteXYData()
deletes xy data of data manager
Definition: Spectrum.cpp:286
void setGroup(DataGroupNode *group)
sets spectrum group
Definition: Spectrum.cpp:893
void setTitle(const char *title)
sets spectrum title
Definition: Spectrum.cpp:215
void setPrecursorCharge(const int charge)
sets the precursor charge
Definition: Spectrum.cpp:804
xy data operation class
bool isCentroidMode()
judget wheter this spectrum is centroid mode
Definition: Spectrum.cpp:941
static PeaksManager & getInstance()
get peaks manager object (This is the only object.)
Polarity
polarity definition
Definition: Spectrum.h:51
void setResolution(const double resolution)
sets resolution
Definition: Spectrum.cpp:946
void setXRange(const double minX, const double maxX)
sets x range
Definition: Spectrum.cpp:443
double getMaxIntensity(const double minX=-1.0, const double maxX=-1.0)
gets max intensity in specified range
Definition: Spectrum.cpp:548
virtual void onGetXRange(double *minX, double *maxX)=0
This method is called by getMinX or getMaxX method. (abstract method)
Polarity getPolarity()
gets polarity
Definition: Spectrum.cpp:930
virtual ~Spectrum()
destructor
Definition: Spectrum.cpp:93
double getBasePeakMass()
gets base peak mass
Definition: Spectrum.cpp:581
virtual void onSetFirstAccess(void)
This method is called by setFirstAccess method. (abstract method)
Definition: Spectrum.cpp:1228
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216
bool hasChromatogram()
judges whether this spectrum has chromatogram
Definition: Spectrum.cpp:888
void setDoubleValue(const char *key, double value)
sets parameter value
Definition: Properties.cpp:62