Mass++ Common Libraries v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations Macros
Classes | Public Member Functions | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
kome::objects::DataMapInfo Class Reference

deta map information More...

#include <DataMapInfo.h>

Collaboration diagram for kome::objects::DataMapInfo:
Collaboration graph
[legend]

Classes

struct  TmpData
 temporary data More...
 

Public Member Functions

 DataMapInfo (DataGroupNode &group, const unsigned int row, const unsigned int col)
 constructor More...
 
virtual ~DataMapInfo ()
 destructor
 
unsigned int getRowSize ()
 gets row size More...
 
unsigned int getColSize ()
 gets column size More...
 
DataGroupNodegetGroup ()
 gets raw data More...
 
SamplegetSample ()
 gets sample More...
 
double getMinMz ()
 gets min m/z More...
 
double getMaxMz ()
 gets max m/z More...
 
double getMinRt ()
 gets min RT More...
 
double getMaxRt ()
 gets max RT More...
 
double getMinIntensity ()
 gets min intensity More...
 
double getMaxIntensity ()
 gets max intensity More...
 
double getIntensity (const unsigned int row, const unsigned int col)
 gets the intensity of the image map More...
 
void setCompleted (const bool completed)
 sets completed flag More...
 
bool isCompleted ()
 gets completed flag More...
 
void setIntensityRange (const double minInt, const double maxInt)
 sets intensity range More...
 
bool setRange (double minMz, double maxMz, double minRt, double maxRt, const char *filterName, kome::core::Progress &progress)
 sets data map range More...
 
void setAutoCommit (const bool autoCommit)
 sets auto commit flag More...
 
bool isAutoCommit ()
 gets auto commit flag More...
 
void commit ()
 commit data
 
void rollback ()
 rollback data
 
bool saveDataMap (const char *path)
 saves data map More...
 
bool loadDataMap (const char *path)
 loads data map More...
 

Protected Member Functions

void createImageMap (std::vector< kome::objects::Spectrum * > &spectra, kome::core::Progress &progress)
 creates image map More...
 
void getSpecIntensities (Spectrum *spec, double *intensities, int size)
 gets intensities of spectrum More...
 
void getSpecArray (const char *filterName, std::vector< kome::objects::Spectrum * > &tmpSpecArray)
 get spectrum array More...
 
void createTmpData ()
 creates temporary data
 
void deleteTmpData ()
 deletes temporary data
 

Static Protected Member Functions

static bool lessSpec (Spectrum *spec0, Spectrum *spec1)
 compare RT of spectrum to sort More...
 

Protected Attributes

unsigned int m_row
 
unsigned int m_col
 
DataGroupNodem_group
 
double * m_map
 
double m_minMz
 
double m_maxMz
 
double m_minRt
 
double m_maxRt
 
double m_minIntensity
 
double m_maxIntensity
 
bool m_completed
 
TmpDatam_tmp
 
bool m_autoCommit
 

Detailed Description

deta map information

Definition at line 31 of file DataMapInfo.h.

Constructor & Destructor Documentation

kome::objects::DataMapInfo::DataMapInfo ( DataGroupNode group,
const unsigned int  row,
const unsigned int  col 
)

constructor

Parameters
[in]groupspectrum group
[in]rowrow size
[in]colcolumn size

Definition at line 39 of file DataMapInfo.cpp.

39  {
40  // initialize
41  m_row = row;
42  m_group = &group;
43  m_col = col;
44 
45  // create map
46  unsigned int size = row * col;
47  if( size == 0 ) {
48  m_map = NULL;
49  }
50  else {
51  m_map = new double[ size ];
52  }
53 
54  // initialize
55  m_minMz = double();
56  m_maxMz = double();
57  m_minRt = double();
58  m_maxRt = double();
59  m_maxIntensity = double();
60  m_minIntensity = double();
61  m_autoCommit = true;
62  m_tmp = NULL;
63  m_completed = false;
64 }
#define NULL
Definition: CoreMacros.h:18
DataGroupNode * m_group
Definition: DataMapInfo.h:54

Member Function Documentation

void kome::objects::DataMapInfo::createImageMap ( std::vector< kome::objects::Spectrum * > &  spectra,
kome::core::Progress progress 
)
protected

creates image map

Parameters
[in]spectraspectrum array
[out]progressthe object to show progress

Definition at line 434 of file DataMapInfo.cpp.

437  {
438  // intensities array
439  double* prevInts = new double[ m_col ];
440  double* nowInts = new double[ m_col ];
441 
442  // initialize
443  m_tmp->minIntensity = 0.0;
444  m_tmp->maxIntensity = 0.1;
445 
446  // unit range (RT)
447  double unitRange = ( m_tmp->maxRt - m_tmp->minRt ) / (double)( m_row - 1 );
448  double rtZeroRange = DEFAULT_RT_ZERO_RANGE;
449  double prevRt = 0.0;
450  if( m_group->getNumberOfSpectra() > 0 ) {
451  prevRt = m_group->getSpectrum( 0 )->getRt() - rtZeroRange;
452  }
453  double prevScan = 0;
454  for( unsigned int i = 0; i < m_group->getNumberOfSpectra(); i++ ) {
456  rtZeroRange = std::max( rtZeroRange, fabs( spec->getRt() - prevRt ) );
457  prevRt = spec->getRt();
458  prevScan = spec->getScanNumber();
459  }
460 
461  // length
462  int length = (int)spectra.size();
463 
464  // create image map
465  int prevIdx = -1;
466  prevRt = -9999999.9;
467  for( unsigned int i = 0; i < spectra.size() && !progress.isStopped() ; i++ ) {
468  // spectrum
469  Spectrum* spec = spectra[ i ];
470 
471  progress.setStatus( FMT( "Getting spectrum data... [%s]", spec->getName() ).c_str() );
472  progress.setPosition( 2 * length + 4 * i );
473 
474  // intensities
475  getSpecIntensities( spec, nowInts, m_row );
476  if( spectra.size() == 1 ) {
477  prevRt = spec->getRt();
478  memcpy( prevInts, nowInts, sizeof( double ) * m_col );
479  }
480 
481  // intensity range
482  for( unsigned int j = 0; j < m_col; j++ ) {
483  if( nowInts[ j ] < m_tmp->minIntensity ) {
484  m_tmp->minIntensity = nowInts[ j ];
485  }
486  if( nowInts[ j ] > m_tmp->maxIntensity ) {
487  m_tmp->maxIntensity = nowInts[ j ];
488  }
489  }
490 
491  // get index
492  int idx = (int)m_row - 1;
493  if( spectra.size() > 1 ) {
494  idx = roundnum( ( spec->getRt() - m_tmp->minRt ) / unitRange );
495  }
496 
497  // set intensities
498  if( idx >= 0 && idx < (int)m_row ) {
499  if( idx == prevIdx ) {
500  for( unsigned int j = 0; j < m_col; j++ ) {
501  int ptIdx = idx * m_col + j;
502  double prevInt = m_tmp->intensities[ ptIdx ];
503  double nowInt = nowInts[ j ];
504 
505  if( fabs( nowInt ) > fabs( prevInt ) ) {
506  m_tmp->intensities[ ptIdx ] = nowInt;
507  }
508  }
509  }
510  else {
511  for( unsigned int j = 0; j < m_col; j++ ) {
512  int ptIdx = idx * m_col + j;
513  m_tmp->intensities[ ptIdx ] = nowInts[ j ];
514  }
515  }
516  }
517 
518  // interpolation
519  int sIdx = prevIdx + 1;
520  sIdx = MAX( 0, sIdx );
521  if( spec->getRt() <= prevRt + rtZeroRange ) { // linear interpolation
522  for( int j = sIdx; j < idx && j < (int)m_row; j++ ) {
523  double rt = m_tmp->minRt + (double)j * unitRange;
524 
525  double d1 = fabs( rt - prevRt );
526  double d2 = fabs( spec->getRt() - rt );
527  if( prevRt == spec->getRt() ) {
528  d1 = 1.0;
529  d2 = 0.0;
530  }
531  for( int k = 0; k < (int)m_col; k++ ) {
532  int ptIdx = j * m_row + k;
533  m_tmp->intensities[ ptIdx ] = ( d2 * prevInts[ k ] + d1 * nowInts[ k ] ) / ( d1 + d2 );
534  }
535  }
536  }
537  else { // insert zero
538  double zeroRange = std::min( ( spec->getRt() - prevRt ) / 2.5, rtZeroRange );
539 
540  for( int j = sIdx; j < idx && j < (int)m_row; j++ ) {
541  double rt = m_tmp->minRt + (double)j * unitRange;
542 
543  if( rt > spec->getRt() - zeroRange ) {
544  double d = rt - ( spec->getRt() - zeroRange );
545 
546  for( int k = 0; k < (int)m_col; k++ ) {
547  int ptIdx = j * m_col + k;
548  m_tmp->intensities[ ptIdx ] = ( d * nowInts[ k ] ) / zeroRange;
549  }
550  }
551  else if( rt < prevRt + zeroRange ) {
552  double d = zeroRange - fabs( rt - prevRt );
553 
554  for( int k = 0; k < (int)m_col; k++ ) {
555  int ptIdx = j * m_col + k;
556  m_tmp->intensities[ ptIdx ] = ( d * prevInts[ k ] ) / zeroRange;
557  }
558  }
559  else {
560  for( int k = 0; k < (int)m_col; k++ ) {
561  int ptIdx = j * m_col + k;
562  m_tmp->intensities[ ptIdx ] = 0.0;
563  }
564  }
565  }
566  }
567 
568  // set previous
569  prevIdx = idx;
570  prevRt = spec->getRt();
571  memcpy( prevInts, nowInts, sizeof( double ) * m_row );
572  }
573 
574  // delete array
575  delete[] prevInts;
576  delete[] nowInts;
577 
578  // check progress
579  if( progress.isStopped() ) {
580  return;
581  }
582 
583  // log
584  LOG_DEBUG(
585  FMT(
586  "Data Map : mz=[%.2f, %.2f] RT=[%.2f, %.2f] Int=[%.2f, %.2f]",
587  m_tmp->minMz,
588  m_tmp->maxMz,
589  m_tmp->minRt,
590  m_tmp->maxRt,
591  m_tmp->minIntensity,
592  m_tmp->maxIntensity
593  )
594  );
595 
596  // progress
597  progress.fill();
598 }
double getRt()
gets retention time
Definition: Spectrum.cpp:184
void fill()
sets end position
Definition: Progress.cpp:206
const char * getName()
gets spectrum name
Definition: Spectrum.cpp:123
unsigned int getNumberOfSpectra()
gets the number of spectra
Definition: DataSet.cpp:128
bool isStopped()
judges whether it has to finish
Definition: Progress.cpp:199
int roundnum(const double v)
gets the closest integer to the argument
Spectrum * getSpectrum(const unsigned int index)
gets the number of spectra
Definition: DataSet.cpp:133
void setPosition(const int pos, const bool bForced=false)
sets progress position
Definition: Progress.cpp:98
int getScanNumber()
gets scan number
Definition: Spectrum.cpp:915
#define MAX(x, y)
Definition: CoreMacros.h:27
DataGroupNode * m_group
Definition: DataMapInfo.h:54
void getSpecIntensities(Spectrum *spec, double *intensities, int size)
gets intensities of spectrum
spectrum information management class
Definition: Spectrum.h:30
void setStatus(const char *status, const bool bForced=false)
sets status
Definition: Progress.cpp:160

Here is the call graph for this function:

unsigned int kome::objects::DataMapInfo::getColSize ( )

gets column size

Returns
column size

Definition at line 86 of file DataMapInfo.cpp.

86  {
87  return m_col;
88 }
DataGroupNode & kome::objects::DataMapInfo::getGroup ( )

gets raw data

Returns
raw data

Definition at line 91 of file DataMapInfo.cpp.

91  {
92  return *m_group;
93 }
DataGroupNode * m_group
Definition: DataMapInfo.h:54
double kome::objects::DataMapInfo::getIntensity ( const unsigned int  row,
const unsigned int  col 
)

gets the intensity of the image map

Parameters
[in]rowrow (RT) index
[in]colcolumn (m/z) index
Returns
the intensity of the image map

Definition at line 131 of file DataMapInfo.cpp.

131  {
132  int idx = row * m_col + col;
133 
134  return m_map[ idx ];
135 }
double kome::objects::DataMapInfo::getMaxIntensity ( )

gets max intensity

Returns
max intensity

Definition at line 126 of file DataMapInfo.cpp.

126  {
127  return m_maxIntensity;
128 }
double kome::objects::DataMapInfo::getMaxMz ( )

gets max m/z

Returns
max m/z

Definition at line 106 of file DataMapInfo.cpp.

106  {
107  return m_maxMz;
108 }
double kome::objects::DataMapInfo::getMaxRt ( )

gets max RT

Returns
max RT

Definition at line 116 of file DataMapInfo.cpp.

116  {
117  return m_maxRt;
118 }
double kome::objects::DataMapInfo::getMinIntensity ( )

gets min intensity

Returns
min intensity

Definition at line 121 of file DataMapInfo.cpp.

121  {
122  return m_minIntensity;
123 }
double kome::objects::DataMapInfo::getMinMz ( )

gets min m/z

Returns
min m/z

Definition at line 101 of file DataMapInfo.cpp.

101  {
102  return m_minMz;
103 }
double kome::objects::DataMapInfo::getMinRt ( )

gets min RT

Returns
min RT

Definition at line 111 of file DataMapInfo.cpp.

111  {
112  return m_minRt;
113 }
unsigned int kome::objects::DataMapInfo::getRowSize ( )

gets row size

Returns
row size

Definition at line 81 of file DataMapInfo.cpp.

81  {
82  return m_row;
83 }
Sample * kome::objects::DataMapInfo::getSample ( )

gets sample

Returns
sample

Definition at line 96 of file DataMapInfo.cpp.

96  {
97  return m_group->getSample();
98 }
DataGroupNode * m_group
Definition: DataMapInfo.h:54
Sample * getSample()
gets sample
Definition: DataSet.cpp:49

Here is the call graph for this function:

void kome::objects::DataMapInfo::getSpecArray ( const char *  filterName,
std::vector< kome::objects::Spectrum * > &  tmpSpecArray 
)
protected

get spectrum array

Parameters
[in]filterNamefilter name
[in]tmpSpecArrayspectrum array

Definition at line 154 of file DataMapInfo.cpp.

154  {
155  // create temporary data
156  createTmpData();
157 
158  // data set
159  kome::objects::DataSet spectra;
160  m_group->getDataSet( &spectra );
161  spectra.sortSpectra();
162 
163  // create array
164  int specNum = (int)spectra.getNumberOfSpectra();
165 
166  // MS
167  if( strcmp( filterName, "ms" ) == 0 ){
168  for( int i = 0; i < specNum; i++ ) {
169  kome::objects::Spectrum* spec = spectra.getSpectrum( i );
170  if( spec->getMsStage() == 1 && spec->hasChromatogram() ) {
171  tmpSpecArray.push_back( spec );
172  }
173  }
174  // MS/MS
175  }else if( strcmp( filterName, "ms2" ) == 0 ){
176  for( int i = 0; i < specNum; i++ ) {
177  kome::objects::Spectrum* spec = spectra.getSpectrum( i );
178  if( spec->getMsStage() >= 2 && spec->hasChromatogram() ) {
179  tmpSpecArray.push_back( spec );
180  }
181  }
182  // All
183  }else if( strcmp( filterName, "all" ) == 0 ){
184  for( int i=0; i< specNum; i++ ){
185  kome::objects::Spectrum* spec = spectra.getSpectrum( i );
186  if( spec->hasChromatogram() ){
187  tmpSpecArray.push_back( spec );
188  }
189  }
190  }
191 }
void getDataSet(DataSet *dataSet)
gets spectra that contains this group. (getSpectrum method cannot get spectra that belong to child gr...
void createTmpData()
creates temporary data
unsigned int getNumberOfSpectra()
gets the number of spectra
Definition: DataSet.cpp:128
Spectrum * getSpectrum(const unsigned int index)
gets the number of spectra
Definition: DataSet.cpp:133
int getMsStage()
gets ms stage
Definition: Spectrum.cpp:634
virtual void sortSpectra()
sorts spectra in retention time order
Definition: DataSet.cpp:155
DataGroupNode * m_group
Definition: DataMapInfo.h:54
spectrum information management class
Definition: Spectrum.h:30
one or more spectra management class
Definition: DataSet.h:31
bool hasChromatogram()
judges whether this spectrum has chromatogram
Definition: Spectrum.cpp:888

Here is the call graph for this function:

void kome::objects::DataMapInfo::getSpecIntensities ( Spectrum spec,
double *  intensities,
int  size 
)
protected

gets intensities of spectrum

Parameters
[in]specspectrum
[out]intensitiesthe array to store intensities
[in]sizearray size

Definition at line 601 of file DataMapInfo.cpp.

605  {
606  // variables
608 
609  // initialize
610  for( int i = 0; i < size; i++ ) {
611  intensities[ i ] = 0.0;
612  }
613 
614  // unit range (m/z)
615  double unitRange = ( m_tmp->maxMz - m_tmp->minMz ) / (double)( size - 1 );
616  double mzZeroRange = std::max( DEFAULT_MZ_ZERO_RANGE, spec->getResolution() );
617 
618  // get point index
619  int mzStartIdx = 0;
620  int mzEndIdx = 0;
621  int length = 0;
622 
623  // get points
624  pt.clearPoints();
625  spec->getXYData( &pt, m_tmp->minMz - mzZeroRange, m_tmp->maxMz + mzZeroRange, false );
626 
627  length = (int)pt.getLength();
628  mzStartIdx = pt.searchIndex( m_tmp->minMz );
629  mzEndIdx = pt.searchIndex( m_tmp->maxMz );
630 
631  if( mzStartIdx < 0 ) {
632  mzStartIdx = - mzStartIdx - 2;
633  mzStartIdx = MAX( 0, mzStartIdx );
634  }
635  if( mzEndIdx < 0 ) {
636  mzEndIdx = - mzEndIdx - 1;
637  mzEndIdx = MIN( length - 1, mzEndIdx );
638  }
639 
640  // get data points
641  int prevIdx = -1;
642  double prevMz = -9999999.9;
643  double prevInt = 0.0;
644  for( int i = mzStartIdx; i <= mzEndIdx + 1; i++ ) {
645  // get point
646  double x = 0.0;
647  double y = 0.0;
648  if( i <= mzEndIdx ) {
649  x = (double)pt.getX( i );
650  y = (double)pt.getY( i );
651  }
652  else {
653  x = std::max( m_tmp->maxMz, prevMz + 1.0 );
654  }
655 
656  // get index
657  int idx = roundnum( (double)( x - m_tmp->minMz ) / unitRange );
658 
659  // set intensity
660  if( idx >= 0 && idx < size ) {
661  if( idx == prevIdx ) {
662  if( fabs( y ) > fabs( intensities[ idx ] ) ) {
663  intensities[ idx ] = y;
664  }
665  }
666  else{
667  intensities[ idx ] = y;
668  }
669  }
670 
671  // interpolation
672  int sIdx = prevIdx + 1;
673  sIdx = MAX( 0, sIdx );
674  if( x <= prevMz + mzZeroRange ) { // linear interpolation
675  for( int j = sIdx; j < idx && j < size; j++ ) {
676  double mz = m_tmp->minMz + (double)j * unitRange;
677 
678  double d1 = fabs( mz - prevMz );
679  double d2 = fabs( x - mz );
680 
681  intensities[ j ] = ( d2 * prevInt + d1 * y ) / ( d1 + d2 );
682  }
683  }
684  else { // insert zero
685  double zeroRange = std::min( ( x - prevMz ) / 2.5, mzZeroRange );
686 
687  for( int j = sIdx; j < idx && j < size; j++ ) {
688  double mz = m_tmp->minMz + (double)j * unitRange;
689 
690  if( mz > x - zeroRange ) {
691  double d = mz - ( x - zeroRange );
692 
693  intensities[ j ] = ( d * y ) / zeroRange;
694  }
695  else if( mz < prevMz + zeroRange ) {
696  double d = zeroRange - fabs( mz - prevMz );
697 
698  intensities[ j ] = ( d * prevInt ) / zeroRange;
699  }
700  else {
701  intensities[ j ] = 0.0;
702  }
703  }
704  }
705 
706  // previous
707  prevIdx = idx;
708  prevMz = x;
709  prevInt = y;
710  }
711 }
data points data of profile management class
Definition: DataPoints.h:25
double getX(const unsigned int index)
gets x coordinate
Definition: XYData.cpp:224
void clearPoints()
clear all data points
Definition: XYData.cpp:137
double getY(const unsigned int index)
gets y coordinate
Definition: XYData.cpp:243
int roundnum(const double v)
gets the closest integer to the argument
double getResolution()
gets resolution
Definition: Spectrum.cpp:952
#define MIN(x, y)
Definition: CoreMacros.h:30
kome::core::XYData * getXYData()
gets xy data from data manager
Definition: Spectrum.cpp:279
#define MAX(x, y)
Definition: CoreMacros.h:27
int searchIndex(const double x)
searches index of specified x value.
Definition: XYData.cpp:276
unsigned int getLength()
gets the number of points @return the number of points
Definition: XYData.cpp:216

Here is the call graph for this function:

bool kome::objects::DataMapInfo::isAutoCommit ( )

gets auto commit flag

Returns
auto commit flag

Definition at line 328 of file DataMapInfo.cpp.

328  {
329  return m_autoCommit;
330 }
bool kome::objects::DataMapInfo::isCompleted ( )

gets completed flag

Returns
completed flag value

Definition at line 143 of file DataMapInfo.cpp.

143  {
144  return m_completed;
145 }
static bool kome::objects::DataMapInfo::lessSpec ( Spectrum spec0,
Spectrum spec1 
)
staticprotected

compare RT of spectrum to sort

Parameters
[in]spec0spectrum to be compared
[in]spec1spectrum to compare
Returns
If spec0 sorts before spec1, this method returns true.

Definition at line 762 of file DataMapInfo.cpp.

762  {
763  return ( spec0->getRt() < spec1->getRt() );
764 }
double getRt()
gets retention time
Definition: Spectrum.cpp:184

Here is the call graph for this function:

bool kome::objects::DataMapInfo::loadDataMap ( const char *  path)

loads data map

Parameters
[in]pathdata map file path to load
Returns
If true, it succeeded to load data map

Definition at line 394 of file DataMapInfo.cpp.

394  {
395  // file open
396  FILE* fp = fileopen( path, "rb" );
397  if( fp == NULL ) {
398  return false;
399  }
400 
401  // array size
402  const unsigned int size = m_row * m_col;
403 
404  // load array size
405  unsigned int row = 0;
406  unsigned int col = 0;
407 
408  fread( &row, sizeof( row ), 1, fp );
409  fread( &col, sizeof( col ), 1, fp );
410 
411  if( row != m_row || col != m_col ) {
412  LOG_WARN( FMT( "Data Map size is different." ) );
413  fclose( fp );
414  return false;
415  }
416 
417  fread( &m_minMz, sizeof( m_minMz ), 1, fp );
418  fread( &m_maxMz, sizeof( m_maxMz ), 1, fp );
419  fread( &m_minRt, sizeof( m_minRt ), 1, fp );
420  fread( &m_maxRt, sizeof( m_maxRt ), 1, fp );
421  fread( &m_minIntensity, sizeof( m_minIntensity ), 1, fp );
422  fread( &m_maxIntensity, sizeof( m_maxIntensity ), 1, fp );
423 
424  if( size > 0 ) {
425  fread( m_map, sizeof( double ), size, fp );
426  }
427 
428  fclose( fp );
429 
430  return true;
431 }
#define NULL
Definition: CoreMacros.h:18
FILE * fileopen(const char *path, const char *mode)
opens file

Here is the call graph for this function:

bool kome::objects::DataMapInfo::saveDataMap ( const char *  path)

saves data map

Parameters
[in]pathdata map file path to save
Returns
If true, it succeeded to save data map

Definition at line 363 of file DataMapInfo.cpp.

363  {
364  // file open
365  FILE* fp = fileopen( path, "wb" );
366  if( fp == NULL ) {
367  return false;
368  }
369 
370  // array size
371  const unsigned int size = m_row * m_col;
372 
373  // save
374  fwrite( &m_row, sizeof( m_row ), 1, fp );
375  fwrite( &m_col, sizeof( m_col ), 1, fp );
376  fwrite( &m_minMz, sizeof( m_minMz ), 1, fp );
377  fwrite( &m_maxMz, sizeof( m_maxMz ), 1, fp );
378  fwrite( &m_minRt, sizeof( m_minRt ), 1, fp );
379  fwrite( &m_maxRt, sizeof( m_maxRt ), 1, fp );
380  fwrite( &m_minIntensity, sizeof( m_minIntensity ), 1, fp );
381  fwrite( &m_maxIntensity, sizeof( m_maxIntensity ), 1, fp );
382 
383  if( size > 0 ) {
384  fwrite( m_map, sizeof( double ), size, fp );
385  }
386 
387  fflush( fp );
388  fclose( fp );
389 
390  return true;
391 }
#define NULL
Definition: CoreMacros.h:18
FILE * fileopen(const char *path, const char *mode)
opens file

Here is the call graph for this function:

void kome::objects::DataMapInfo::setAutoCommit ( const bool  autoCommit)

sets auto commit flag

Parameters
[in]autoCommitauto commit flag

Definition at line 323 of file DataMapInfo.cpp.

323  {
324  m_autoCommit = autoCommit;
325 }
void kome::objects::DataMapInfo::setCompleted ( const bool  completed)

sets completed flag

Parameters
[in]completedcompleted flag value

Definition at line 138 of file DataMapInfo.cpp.

138  {
139  m_completed = completed;
140 }
void kome::objects::DataMapInfo::setIntensityRange ( const double  minInt,
const double  maxInt 
)

sets intensity range

Parameters
[in]minIntmin intensity
[in]maxIntmax intensity

Definition at line 148 of file DataMapInfo.cpp.

148  {
149  m_minIntensity = minInt;
150  m_maxIntensity = maxInt;
151 }
bool kome::objects::DataMapInfo::setRange ( double  minMz,
double  maxMz,
double  minRt,
double  maxRt,
const char *  filterName,
kome::core::Progress progress 
)

sets data map range

Parameters
[in]minMzmin m/z (If negative value, it uses default value instead.)
[in]maxMzmax m/z (If negative value, it uses default value instead.)
[in]minRtmin m/z (If negative value, it uses default value instead.)
[in]maxRtmax m/z (If negative value, it uses default value instead.)
[in]filterNamefilter name
[out]progressthe object to show progress
Returns
If true, map is created completly.

Definition at line 194 of file DataMapInfo.cpp.

201  {
202  // @date 2012.09.07 <Mod> M.Izumi ->
203  std::vector< kome::objects::Spectrum* > tmpSpecArray;
204  getSpecArray( filterName, tmpSpecArray );
205  // @date 2012.09.07 <Mod> M.Izumi <-
206 
207  int specNum = (int)tmpSpecArray.size();
208 
209  // start index
210  int startIdx = 0;
211  if( minRt >= 0.0 ) {
212  for( int i = 0; i < specNum; i++ ) {
213  if( tmpSpecArray[ i ]->getRt() <= minRt ) {
214  startIdx = i;
215  }
216  }
217  }
218 
219  // end index
220  int endIdx = specNum - 1;
221  if( maxRt >= 0.0 ) {
222  for( int i = specNum - 1; i >= 0; i-- ) {
223  if( tmpSpecArray[ i ]->getRt() >= maxRt ) {
224  endIdx = i;
225  }
226  }
227  }
228 
229  int length = endIdx - startIdx + 1;
230 
231  // spectra
232  std::vector< kome::objects::Spectrum* > specArray;
233  for( int i = startIdx; i <= endIdx; i++ ) {
234  specArray.push_back( tmpSpecArray[ i ] );
235  }
236 
237  // check the data
238  if( length <= 0 ) { // There is no spectrum.
239  // set value
240  m_tmp->minMz = MAX( minMz, 0.0 );
241  m_tmp->maxMz = MAX( maxMz, 0.1 );
242  m_tmp->minRt = MAX( minRt, 0.0 );
243  m_tmp->maxRt = MAX( maxRt, 0.1 );
244  m_tmp->minIntensity = 0.0;
245  m_tmp->maxIntensity = 0.0;
246 
247  // progress
248  progress.setRange( 0, 1 );
249  progress.setPosition( 1 );
250 
251  // commit
252  if( m_autoCommit ) {
253  commit();
254  }
255 
256  // flag
257  m_completed = true;
258 
259  return true;
260  }
261 
262  // rt
263  m_tmp->minRt = minRt < 0.0 ? tmpSpecArray[ startIdx ]->getRt() : minRt;
264  m_tmp->maxRt = maxRt < 0.0 ? tmpSpecArray[ endIdx ]->getRt() : maxRt;
265 
266  // progress range
267  progress.setRange( 0, 6 * length );
268  progress.setPosition( 0 );
269 
270  // min m/z
271  if( minMz < 0.0 ) {
272  minMz = tmpSpecArray[ startIdx ]->getMinX();
273 
274  for( int i = startIdx + 1; i <= endIdx && !progress.isStopped(); i++ ) {
275  progress.setPosition( i - startIdx );
276  minMz = MIN( minMz, tmpSpecArray[ i ]->getMinX() );
277  }
278  }
279  progress.setPosition( length );
280 
281  // max m/z
282  if( maxMz < 0.0 ) {
283  maxMz = tmpSpecArray[ startIdx ]->getMaxX();
284 
285  for( int i = startIdx + 1; i < endIdx && !progress.isStopped(); i++ ) {
286  progress.setPosition( length + i - startIdx );
287  maxMz = MAX( maxMz, tmpSpecArray[ i ]->getMaxX() );
288  }
289  }
290 
291  if( !progress.isStopped() ) {
292  progress.setPosition( 2 * length );
293 
294  m_tmp->minMz = MIN( maxMz, minMz );
295  m_tmp->maxMz = MAX( maxMz, minMz );
296  double midMz = ( m_tmp->minMz + m_tmp->maxMz ) / 2.0;
297  m_tmp->minMz = std::min( midMz - 0.01, m_tmp->minMz );
298  m_tmp->maxMz = std::max( midMz + 0.01, m_tmp->maxMz );
299  }
300 
301  // create image map
302  if( !progress.isStopped() ) {
303  createImageMap( specArray, progress );
304  }
305 
306  // restore
307  if( progress.isStopped() ) {
308  rollback();
309  }
310 
311  // commit
312  if( m_autoCommit ) {
313  commit();
314  }
315 
316  // flag
317  m_completed = !progress.isStopped();
318 
319  return m_completed;
320 }
void createImageMap(std::vector< kome::objects::Spectrum * > &spectra, kome::core::Progress &progress)
creates image map
void rollback()
rollback data
bool isStopped()
judges whether it has to finish
Definition: Progress.cpp:199
void getSpecArray(const char *filterName, std::vector< kome::objects::Spectrum * > &tmpSpecArray)
get spectrum array
void setPosition(const int pos, const bool bForced=false)
sets progress position
Definition: Progress.cpp:98
#define MIN(x, y)
Definition: CoreMacros.h:30
#define MAX(x, y)
Definition: CoreMacros.h:27
void commit()
commit data
void setRange(const int start, const int end)
sets progress range
Definition: Progress.cpp:79

Here is the call graph for this function:

Member Data Documentation

bool kome::objects::DataMapInfo::m_autoCommit
protected

auto commit flag

Definition at line 93 of file DataMapInfo.h.

unsigned int kome::objects::DataMapInfo::m_col
protected

column size

Definition at line 52 of file DataMapInfo.h.

bool kome::objects::DataMapInfo::m_completed
protected

completed flag

Definition at line 73 of file DataMapInfo.h.

DataGroupNode* kome::objects::DataMapInfo::m_group
protected

raw data

Definition at line 54 of file DataMapInfo.h.

double* kome::objects::DataMapInfo::m_map
protected

data map

Definition at line 57 of file DataMapInfo.h.

double kome::objects::DataMapInfo::m_maxIntensity
protected

max intensity

Definition at line 70 of file DataMapInfo.h.

double kome::objects::DataMapInfo::m_maxMz
protected

max m/z

Definition at line 62 of file DataMapInfo.h.

double kome::objects::DataMapInfo::m_maxRt
protected

max RT

Definition at line 66 of file DataMapInfo.h.

double kome::objects::DataMapInfo::m_minIntensity
protected

min intensity

Definition at line 68 of file DataMapInfo.h.

double kome::objects::DataMapInfo::m_minMz
protected

min m/z

Definition at line 60 of file DataMapInfo.h.

double kome::objects::DataMapInfo::m_minRt
protected

min RT

Definition at line 64 of file DataMapInfo.h.

unsigned int kome::objects::DataMapInfo::m_row
protected

row size

Definition at line 50 of file DataMapInfo.h.

TmpData* kome::objects::DataMapInfo::m_tmp
protected

temporary data

Definition at line 90 of file DataMapInfo.h.


The documentation for this class was generated from the following files: