23 using namespace kome::objects;
28 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
29 #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
34 #define DEFAULT_MZ_ZERO_RANGE 0.2
35 #define DEFAULT_RT_ZERO_RANGE 1.0
46 unsigned int size = row * col;
51 m_map =
new double[ size ];
132 int idx = row *
m_col + col;
167 if( strcmp( filterName,
"ms" ) == 0 ){
168 for(
int i = 0; i < specNum; i++ ) {
171 tmpSpecArray.push_back( spec );
175 }
else if( strcmp( filterName,
"ms2" ) == 0 ){
176 for(
int i = 0; i < specNum; i++ ) {
179 tmpSpecArray.push_back( spec );
183 }
else if( strcmp( filterName,
"all" ) == 0 ){
184 for(
int i=0; i< specNum; i++ ){
187 tmpSpecArray.push_back( spec );
199 const char* filterName,
203 std::vector< kome::objects::Spectrum* > tmpSpecArray;
207 int specNum = (int)tmpSpecArray.size();
212 for(
int i = 0; i < specNum; i++ ) {
213 if( tmpSpecArray[ i ]->getRt() <= minRt ) {
220 int endIdx = specNum - 1;
222 for(
int i = specNum - 1; i >= 0; i-- ) {
223 if( tmpSpecArray[ i ]->getRt() >= maxRt ) {
229 int length = endIdx - startIdx + 1;
232 std::vector< kome::objects::Spectrum* > specArray;
233 for(
int i = startIdx; i <= endIdx; i++ ) {
234 specArray.push_back( tmpSpecArray[ i ] );
244 m_tmp->minIntensity = 0.0;
245 m_tmp->maxIntensity = 0.0;
263 m_tmp->minRt = minRt < 0.0 ? tmpSpecArray[ startIdx ]->getRt() : minRt;
264 m_tmp->maxRt = maxRt < 0.0 ? tmpSpecArray[ endIdx ]->getRt() : maxRt;
272 minMz = tmpSpecArray[ startIdx ]->getMinX();
274 for(
int i = startIdx + 1; i <= endIdx && !progress.
isStopped(); i++ ) {
276 minMz =
MIN( minMz, tmpSpecArray[ i ]->getMinX() );
283 maxMz = tmpSpecArray[ startIdx ]->getMaxX();
285 for(
int i = startIdx + 1; i < endIdx && !progress.
isStopped(); i++ ) {
287 maxMz =
MAX( maxMz, tmpSpecArray[ i ]->getMaxX() );
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 );
350 memcpy(
m_map,
m_tmp->intensities,
sizeof(
double ) * size );
375 fwrite( &m_col,
sizeof( m_col ), 1, fp );
384 fwrite(
m_map,
sizeof(
double ), size, fp );
405 unsigned int row = 0;
406 unsigned int col = 0;
408 fread( &row,
sizeof( row ), 1, fp );
409 fread( &col,
sizeof( col ), 1, fp );
411 if( row !=
m_row || col != m_col ) {
412 LOG_WARN( FMT(
"Data Map size is different." ) );
425 fread(
m_map,
sizeof(
double ), size, fp );
435 std::vector< kome::objects::Spectrum* >& spectra,
439 double* prevInts =
new double[
m_col ];
440 double* nowInts =
new double[
m_col ];
443 m_tmp->minIntensity = 0.0;
444 m_tmp->maxIntensity = 0.1;
447 double unitRange = (
m_tmp->maxRt -
m_tmp->minRt ) / (
double)(
m_row - 1 );
448 double rtZeroRange = DEFAULT_RT_ZERO_RANGE;
456 rtZeroRange = std::max( rtZeroRange, fabs( spec->
getRt() - prevRt ) );
457 prevRt = spec->
getRt();
462 int length = (int)spectra.size();
467 for(
unsigned int i = 0; i < spectra.size() && !progress.
isStopped() ; i++ ) {
471 progress.
setStatus( FMT(
"Getting spectrum data... [%s]", spec->
getName() ).c_str() );
476 if( spectra.size() == 1 ) {
477 prevRt = spec->
getRt();
478 memcpy( prevInts, nowInts,
sizeof(
double ) *
m_col );
482 for(
unsigned int j = 0; j <
m_col; j++ ) {
483 if( nowInts[ j ] <
m_tmp->minIntensity ) {
484 m_tmp->minIntensity = nowInts[ j ];
486 if( nowInts[ j ] >
m_tmp->maxIntensity ) {
487 m_tmp->maxIntensity = nowInts[ j ];
492 int idx = (int)
m_row - 1;
493 if( spectra.size() > 1 ) {
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 ];
505 if( fabs( nowInt ) > fabs( prevInt ) ) {
506 m_tmp->intensities[ ptIdx ] = nowInt;
511 for(
unsigned int j = 0; j <
m_col; j++ ) {
512 int ptIdx = idx * m_col + j;
513 m_tmp->intensities[ ptIdx ] = nowInts[ j ];
519 int sIdx = prevIdx + 1;
520 sIdx =
MAX( 0, sIdx );
521 if( spec->
getRt() <= prevRt + rtZeroRange ) {
522 for(
int j = sIdx; j < idx && j < (int)m_row; j++ ) {
523 double rt =
m_tmp->minRt + (double)j * unitRange;
525 double d1 = fabs( rt - prevRt );
526 double d2 = fabs( spec->
getRt() - rt );
527 if( prevRt == spec->
getRt() ) {
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 );
538 double zeroRange = std::min( ( spec->
getRt() - prevRt ) / 2.5, rtZeroRange );
540 for(
int j = sIdx; j < idx && j < (int)m_row; j++ ) {
541 double rt =
m_tmp->minRt + (double)j * unitRange;
543 if( rt > spec->
getRt() - zeroRange ) {
544 double d = rt - ( spec->
getRt() - zeroRange );
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;
551 else if( rt < prevRt + zeroRange ) {
552 double d = zeroRange - fabs( rt - prevRt );
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;
560 for(
int k = 0; k < (int)m_col; k++ ) {
561 int ptIdx = j * m_col + k;
562 m_tmp->intensities[ ptIdx ] = 0.0;
570 prevRt = spec->
getRt();
571 memcpy( prevInts, nowInts,
sizeof(
double ) * m_row );
586 "Data Map : mz=[%.2f, %.2f] RT=[%.2f, %.2f] Int=[%.2f, %.2f]",
610 for(
int i = 0; i < size; i++ ) {
611 intensities[ i ] = 0.0;
615 double unitRange = (
m_tmp->maxMz -
m_tmp->minMz ) / (
double)( size - 1 );
616 double mzZeroRange = std::max( DEFAULT_MZ_ZERO_RANGE, spec->
getResolution() );
631 if( mzStartIdx < 0 ) {
632 mzStartIdx = - mzStartIdx - 2;
633 mzStartIdx =
MAX( 0, mzStartIdx );
636 mzEndIdx = - mzEndIdx - 1;
637 mzEndIdx =
MIN( length - 1, mzEndIdx );
642 double prevMz = -9999999.9;
643 double prevInt = 0.0;
644 for(
int i = mzStartIdx; i <= mzEndIdx + 1; i++ ) {
648 if( i <= mzEndIdx ) {
649 x = (double)pt.
getX( i );
650 y = (double)pt.
getY( i );
653 x = std::max(
m_tmp->maxMz, prevMz + 1.0 );
657 int idx =
roundnum( (
double)( x -
m_tmp->minMz ) / unitRange );
660 if( idx >= 0 && idx < size ) {
661 if( idx == prevIdx ) {
662 if( fabs( y ) > fabs( intensities[ idx ] ) ) {
663 intensities[ idx ] = y;
667 intensities[ idx ] = y;
672 int sIdx = prevIdx + 1;
673 sIdx =
MAX( 0, sIdx );
674 if( x <= prevMz + mzZeroRange ) {
675 for(
int j = sIdx; j < idx && j < size; j++ ) {
676 double mz =
m_tmp->minMz + (double)j * unitRange;
678 double d1 = fabs( mz - prevMz );
679 double d2 = fabs( x - mz );
681 intensities[ j ] = ( d2 * prevInt + d1 * y ) / ( d1 + d2 );
685 double zeroRange = std::min( ( x - prevMz ) / 2.5, mzZeroRange );
687 for(
int j = sIdx; j < idx && j < size; j++ ) {
688 double mz =
m_tmp->minMz + (double)j * unitRange;
690 if( mz > x - zeroRange ) {
691 double d = mz - ( x - zeroRange );
693 intensities[ j ] = ( d * y ) / zeroRange;
695 else if( mz < prevMz + zeroRange ) {
696 double d = zeroRange - fabs( mz - prevMz );
698 intensities[ j ] = ( d * prevInt ) / zeroRange;
701 intensities[ j ] = 0.0;
722 m_tmp->minMz = double();
723 m_tmp->maxMz = double();
724 m_tmp->minRt = double();
725 m_tmp->maxRt = double();
726 m_tmp->minIntensity = double();
727 m_tmp->maxIntensity = double();
732 m_tmp->intensities =
new double[ size ];
733 for(
unsigned int i = 0; i < size; i++ ) {
734 m_tmp->intensities[ i ] = 0.0;
751 delete[]
m_tmp->intensities;
static void closeDataMap(DataMapInfo *dataMap, const bool deleting)
This method is called when a data map is closed.
group of spectrum management class
data points data of profile management class
DataMapInfo(DataGroupNode &group, const unsigned int row, const unsigned int col)
constructor
virtual ~DataMapInfo()
destructor
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
double getRt()
gets retention time
void fill()
sets end position
double getX(const unsigned int index)
gets x coordinate
const char * getName()
gets spectrum name
double getMinMz()
gets min m/z
sample information management class
double getMaxIntensity()
gets max intensity
Sample * getSample()
gets sample
void createImageMap(std::vector< kome::objects::Spectrum * > &spectra, kome::core::Progress &progress)
creates image map
void setCompleted(const bool completed)
sets completed flag
bool loadDataMap(const char *path)
loads data map
void clearPoints()
clear all data points
void rollback()
rollback data
unsigned int getNumberOfSpectra()
gets the number of spectra
double getMinIntensity()
gets min intensity
bool isStopped()
judges whether it has to finish
double getY(const unsigned int index)
gets y coordinate
interfaces of Spectrum class
int roundnum(const double v)
gets the closest integer to the argument
double getMaxRt()
gets max RT
double getResolution()
gets resolution
progress display abstract class
void getSpecArray(const char *filterName, std::vector< kome::objects::Spectrum * > &tmpSpecArray)
get spectrum array
Spectrum * getSpectrum(const unsigned int index)
gets the number of spectra
interfaces of DataGroupNode class
int getMsStage()
gets ms stage
void setPosition(const int pos, const bool bForced=false)
sets progress position
interfaces of DataSet class
static bool lessSpec(Spectrum *spec0, Spectrum *spec1)
compare RT of spectrum to sort
int getScanNumber()
gets scan number
double getMaxMz()
gets max m/z
void deleteTmpData()
deletes temporary data
interfaces of GraphInfo class
DataGroupNode & getGroup()
gets raw data
double getIntensity(const unsigned int row, const unsigned int col)
gets the intensity of the image map
kome::core::XYData * getXYData()
gets xy data from data manager
FILE * fileopen(const char *path, const char *mode)
opens file
virtual void sortSpectra()
sorts spectra in retention time order
void setIntensityRange(const double minInt, const double maxInt)
sets intensity range
void setAutoCommit(const bool autoCommit)
sets auto commit flag
bool setRange(double minMz, double maxMz, double minRt, double maxRt, const char *filterName, kome::core::Progress &progress)
sets data map range
void getSpecIntensities(Spectrum *spec, double *intensities, int size)
gets intensities of spectrum
spectrum information management class
one or more spectra management class
Sample * getSample()
gets sample
unsigned int getRowSize()
gets row size
unsigned int getColSize()
gets column size
bool isAutoCommit()
gets auto commit flag
void setStatus(const char *status, const bool bForced=false)
sets status
bool isCompleted()
gets completed flag
interfaces of DataManager class
void setRange(const int start, const int end)
sets progress range
int searchIndex(const double x)
searches index of specified x value.
double getMinRt()
gets min RT
unsigned int getLength()
gets the number of points @return the number of points
bool saveDataMap(const char *path)
saves data map
bool hasChromatogram()
judges whether this spectrum has chromatogram