Mass++ mzML IO Plugin v2.7.5
 All Classes Namespaces Files Functions Variables Enumerations
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
kome::io::mzml::MzmlSpectrum Class Reference

mzml sample spectrum class More...

#include <MzmlSpectrum.h>

Inheritance diagram for kome::io::mzml::MzmlSpectrum:
Inheritance graph
[legend]
Collaboration diagram for kome::io::mzml::MzmlSpectrum:
Collaboration graph
[legend]

Public Member Functions

 MzmlSpectrum (MzmlSample *file, const char *name)
 constructor More...
 
virtual ~MzmlSpectrum ()
 destructor
 
void setOffset (const long long offset)
 sets data offset More...
 
long long getOffset ()
 gets data offset More...
 

Protected Member Functions

void parse (xercesc::SAX2XMLReader *parser)
 parse XML data More...
 
virtual void onGetXYData (kome::core::XYData *const xyData, const double minX, const double maxX)
 This method is called by getXYData method. (override method) More...
 
virtual void onGetXRange (double *minX, double *maxX)
 This method is called by getMinX or getMaxX method. (override method) More...
 
virtual double onGetTotalIntensity (const double minX, const double maxX)
 This method is called by getTotalIntensity method. (override method) More...
 
virtual double onGetMaxIntensity (const double minX, const double maxX)
 This method is called by getMaxIntensity method. (override method) More...
 
virtual void onSetRequestLoadData (void)
 This method is called by setRequestLoadData method. (abstract method)
 
virtual void onResetRequestLoadData (void)
 This method is called by resetRequestLoadData method. (abstract method)
 
virtual bool onIsRequestLoadData (void)
 This method is called by isRequestLoadData method. (abstract method) More...
 
virtual void onSetFirstAccess (void)
 This method is called by setFirstAccess method. (abstract method)
 
virtual void onResetFirstAccess (void)
 This method is called by resetFirstAccess method. (abstract method)
 
virtual bool onIsFirstAccess (void)
 This method is called by isFirstAccess method. (abstract method) More...
 
virtual bool onLoadData (void)
 This method is called by loadData method. (abstract method) More...
 

Protected Attributes

MzmlSamplem_mzmlSample
 
long long m_offset
 

Detailed Description

mzml sample spectrum class

Definition at line 29 of file MzmlSpectrum.h.

Constructor & Destructor Documentation

kome::io::mzml::MzmlSpectrum::MzmlSpectrum ( MzmlSample file,
const char *  name 
)

constructor

Parameters
filesample file
namespectrum name

Definition at line 37 of file MzmlSpectrum.cpp.

38  : kome::objects::Spectrum( file, name ) {
39  m_mzmlSample = file;
40  m_offset = -1;
41 }

Member Function Documentation

long long kome::io::mzml::MzmlSpectrum::getOffset ( )

gets data offset

Returns
data offset

Definition at line 53 of file MzmlSpectrum.cpp.

53  {
54  return m_offset;
55 }
double kome::io::mzml::MzmlSpectrum::onGetMaxIntensity ( const double  minX,
const double  maxX 
)
protectedvirtual

This method is called by getMaxIntensity method. (override method)

Parameters
minXminimum x of range (If minX is negative number, minimum x value is unbounded.)
maxXmaximum x of range (If maxX is negative number, maximum x value is unbounded.)
Returns
max intensity

Definition at line 225 of file MzmlSpectrum.cpp.

225  {
226  // get data points
227  kome::core::DataPoints pt;
228  onGetXYData( &pt, minX, maxX );
229 
230  // get main intensity
231  double intensity = 0.0;
232  for( unsigned int i = 0; i < pt.getLength(); i++ ) {
233  double y = pt.getY( i );
234  intensity = MAX( y, intensity );
235  }
236 
237  return intensity;
238 }
virtual void onGetXYData(kome::core::XYData *const xyData, const double minX, const double maxX)
This method is called by getXYData method. (override method)

Here is the call graph for this function:

double kome::io::mzml::MzmlSpectrum::onGetTotalIntensity ( const double  minX,
const double  maxX 
)
protectedvirtual

This method is called by getTotalIntensity method. (override method)

Parameters
minXminimum x of range (If minX is negative number, minimum x value is unbounded.)
maxXmaximum x of range (If maxX is negative number, maximum x value is unbounded.)
Returns
total intensity

Definition at line 210 of file MzmlSpectrum.cpp.

210  {
211  // get data points
212  kome::core::DataPoints pt;
213  onGetXYData( &pt, minX, maxX );
214 
215  // get total intensity
216  double intensity = 0.0;
217  for( unsigned int i = 0; i < pt.getLength(); i++ ) {
218  intensity += pt.getY( i );
219  }
220 
221  return intensity;
222 }
virtual void onGetXYData(kome::core::XYData *const xyData, const double minX, const double maxX)
This method is called by getXYData method. (override method)

Here is the call graph for this function:

void kome::io::mzml::MzmlSpectrum::onGetXRange ( double *  minX,
double *  maxX 
)
protectedvirtual

This method is called by getMinX or getMaxX method. (override method)

Parameters
minXthe pointer to store minimum x value
maxXthe pointer to store maximum x value

Definition at line 195 of file MzmlSpectrum.cpp.

195  {
196  // get
197  kome::core::DataPoints dps;
198  onGetXYData( &dps, -1.0, -1.0 );
199 
200  // set
201  if( minX != NULL ) {
202  *minX = dps.getMinX();
203  }
204  if( maxX != NULL ) {
205  *maxX = dps.getMaxX();
206  }
207 }
virtual void onGetXYData(kome::core::XYData *const xyData, const double minX, const double maxX)
This method is called by getXYData method. (override method)

Here is the call graph for this function:

void kome::io::mzml::MzmlSpectrum::onGetXYData ( kome::core::XYData *const  xyData,
const double  minX,
const double  maxX 
)
protectedvirtual

This method is called by getXYData method. (override method)

Parameters
xyDatathe object to store data points
minXminimum x value. (If minX is negative number, minimum x value is not unbounded.)
maxXmaximum x value. (If maxX is negative number, maximum x value is not unbounded.)

Definition at line 129 of file MzmlSpectrum.cpp.

133  {
134 #pragma omp critical ( getMzmlSpectrumData )
135  {
136  // data points
137  kome::core::DataPoints pt;
138 
139  // parser
140  xercesc::SAX2XMLReader* parser = kome::xml::XercesTool::getParser( NULL );
141  parser->setFeature( xercesc::XMLUni::fgXercesSchema, false );
142  parser->setFeature( xercesc::XMLUni::fgXercesSchemaFullChecking, false );
143 
144  // create handler
145  MzmlDataHandler handler( *m_mzmlSample, getName(), pt );
146 
147  parser->setContentHandler( &handler );
148  parser->setErrorHandler( &handler );
149 
150  // parse
151  try {
152  parse( parser );
153  }
154  catch( const xercesc::XMLException& e ) {
155  LOG_ERROR( FMT( "XML Exception: %s", kome::xml::XercesTool::transcode( e.getMessage() ).c_str() ) );
156  handler.setError( true );
157  }
158  catch( const xercesc::SAXParseException& e ) {
159  LOG_ERROR( FMT( "SAX Parse Exception: %s", kome::xml::XercesTool::transcode( e.getMessage() ).c_str() ) );
160  handler.setError( true );
161  }
162  catch( ... ) {
163  LOG_ERROR( FMT( "Unexpected Exception" ) );
164  handler.setError( true );
165  }
166 
167  // get data
168  int startIdx = 0;
169  if( minX >= 0.0 ) {
170  startIdx = pt.searchIndex( minX );
171  if( startIdx < 0 ) {
172  startIdx = - startIdx - 1;
173  }
174  }
175 
176  int endIdx = (int)pt.getLength() - 1;
177  if( maxX >= 0.0 ) {
178  endIdx = pt.searchIndex( maxX );
179  if( endIdx < 0 ) {
180  endIdx = - endIdx - 2;
181  }
182  }
183 
184  int num = endIdx - startIdx + 1;
185  if( num > 0 ) {
186  xyData->reserve( num );
187  for( int i = startIdx; i <= endIdx; i++ ) {
188  xyData->addPoint( pt.getX( i ), pt.getY( i ) );
189  }
190  }
191  }
192 }
XML data handler to get spectrum data points.
void parse(xercesc::SAX2XMLReader *parser)
parse XML data

Here is the call graph for this function:

bool kome::io::mzml::MzmlSpectrum::onIsFirstAccess ( void  )
protectedvirtual

This method is called by isFirstAccess method. (abstract method)

Returns
If true, the first accessing.

Definition at line 273 of file MzmlSpectrum.cpp.

274 {
275  return kome::objects::Spectrum::onIsFirstAccess( );
276 }
bool kome::io::mzml::MzmlSpectrum::onIsRequestLoadData ( void  )
protectedvirtual

This method is called by isRequestLoadData method. (abstract method)

Returns
If true, file read request is valid.

Definition at line 255 of file MzmlSpectrum.cpp.

256 {
257  return kome::objects::Spectrum::onIsRequestLoadData( );
258 }
bool kome::io::mzml::MzmlSpectrum::onLoadData ( void  )
protectedvirtual

This method is called by loadData method. (abstract method)

Returns
If true, file reading success.

Definition at line 279 of file MzmlSpectrum.cpp.

280 {
281  return kome::objects::Spectrum::onLoadData( );
282 }
void kome::io::mzml::MzmlSpectrum::parse ( xercesc::SAX2XMLReader *  parser)
protected

parse XML data

Parameters
parserparser

Definition at line 58 of file MzmlSpectrum.cpp.

58  {
59  // get file
60  MzmlSample* sample = (MzmlSample*)getSample();
61  MzmlSampleSet* sampleSet = sample->getMzmlSampleSet();
62 
63  // parse
64  if( m_offset > 0 ) {
65  // seek
66  FILE* fp = sampleSet->getFile();
67  fileseek( fp, m_offset, SEEK_SET );
68 
69  // read file
70  std::string tag;
71 // >>>>>> @Date:2013/06/03 <Modify> A.Ozaki
72 // 64bit環境で動作させる場合、ポインタアドレスを正しく処理することができなくなります
73 // x86/x64ともに動作させるために、size_tで処理することが勧められているのでいるので、
74 // size_tで処理するように修正します
75  size_t szPos = 0;
76 // <<<<<< @Date:2013/06/03 <Modify> A.Ozaki
77  char buff[ 1024 ];
78  bool loop = true;
79  bool endTag = false;
80  while( loop ) {
81  // read
82  int readSize = fread( buff, 1, 1023, fp );
83 
84  // add to tag
85  if( readSize > 0 ) {
86  buff[ readSize ] = '\0';
87  tag.append( buff );
88  }
89 
90  // check the tag
91 // >>>>>> @Date:2013/06/03 <Modify> A.Ozaki
92  szPos = (size_t)tag.find( "</spectrum>" );
93  if( szPos != (size_t)tag.npos ) {
94  endTag = true;
95  loop = false;
96 
97  tag = tag.substr( 0, szPos );
98  tag.append( "</spectrum>" );
99  }
100 
101  // check the size
102  if( readSize < 1023 ) {
103  loop = false;
104  }
105  }
106 
107  szPos = (size_t)tag.find( "<spectrum" );
108  if( szPos != (size_t)tag.npos ) {
109  tag = tag.substr( szPos );
110  }
111 // <<<<<< @Date:2013/06/03 <Modify> A.Ozaki
112 
113  // parse
114  if( endTag ) {
115  xercesc::MemBufInputSource source( (const XMLByte*)tag.c_str(), tag.size(), "memory_buffer", false );
116  parser->parse( source );
117  }
118  else {
119  LOG_WARN( FMT( "Failed to get the spectrum tag." ) );
120  }
121  }
122  else {
123  // parse file
124  parser->parse( sampleSet->getFilePath() );
125  }
126 }
MzmlSampleSet * getMzmlSampleSet()
gets mzML sample set object
Definition: MzmlSample.cpp:65
mzML sample set class
Definition: MzmlSampleSet.h:24
FILE * getFile()
gets file descriptor
mzML sample class
Definition: MzmlSample.h:26

Here is the call graph for this function:

void kome::io::mzml::MzmlSpectrum::setOffset ( const long long  offset)

sets data offset

Parameters
offsetdata offset

Definition at line 48 of file MzmlSpectrum.cpp.

48  {
49  m_offset = offset;
50 }

Member Data Documentation

MzmlSample* kome::io::mzml::MzmlSpectrum::m_mzmlSample
protected

sample

Definition at line 47 of file MzmlSpectrum.h.

long long kome::io::mzml::MzmlSpectrum::m_offset
protected

data offset

Definition at line 50 of file MzmlSpectrum.h.


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