20 #include <boost/function.hpp>
21 #include <boost/bind.hpp>
22 #include <xercesc/framework/MemBufInputSource.hpp>
25 using namespace kome::io::mzml;
30 #define new new( _NORMAL_BLOCK, __FILE__, __LINE__ )
31 #define malloc( s ) _malloc_dbg( s, _NORMAL_BLOCK, __FILE__, __LINE__ )
38 : kome::objects::Spectrum( file, name ) {
66 FILE* fp = sampleSet->
getFile();
82 int readSize = fread( buff, 1, 1023, fp );
86 buff[ readSize ] =
'\0';
92 szPos = (size_t)tag.find(
"</spectrum>" );
93 if( szPos != (
size_t)tag.npos ) {
97 tag = tag.substr( 0, szPos );
98 tag.append(
"</spectrum>" );
102 if( readSize < 1023 ) {
107 szPos = (size_t)tag.find(
"<spectrum" );
108 if( szPos != (
size_t)tag.npos ) {
109 tag = tag.substr( szPos );
115 xercesc::MemBufInputSource source( (
const XMLByte*)tag.c_str(), tag.size(),
"memory_buffer", false );
116 parser->parse( source );
119 LOG_WARN( FMT(
"Failed to get the spectrum tag." ) );
124 parser->parse( sampleSet->getFilePath() );
130 kome::core::XYData*
const xyData,
134 #pragma omp critical ( getMzmlSpectrumData )
137 kome::core::DataPoints pt;
140 xercesc::SAX2XMLReader* parser = kome::xml::XercesTool::getParser( NULL );
141 parser->setFeature( xercesc::XMLUni::fgXercesSchema,
false );
142 parser->setFeature( xercesc::XMLUni::fgXercesSchemaFullChecking,
false );
147 parser->setContentHandler( &handler );
148 parser->setErrorHandler( &handler );
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 );
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 );
163 LOG_ERROR( FMT(
"Unexpected Exception" ) );
164 handler.setError(
true );
170 startIdx = pt.searchIndex( minX );
172 startIdx = - startIdx - 1;
176 int endIdx = (int)pt.getLength() - 1;
178 endIdx = pt.searchIndex( maxX );
180 endIdx = - endIdx - 2;
184 int num = endIdx - startIdx + 1;
186 xyData->reserve( num );
187 for(
int i = startIdx; i <= endIdx; i++ ) {
188 xyData->addPoint( pt.getX( i ), pt.getY( i ) );
197 kome::core::DataPoints dps;
202 *minX = dps.getMinX();
205 *maxX = dps.getMaxX();
212 kome::core::DataPoints pt;
216 double intensity = 0.0;
217 for(
unsigned int i = 0; i < pt.getLength(); i++ ) {
218 intensity += pt.getY( i );
227 kome::core::DataPoints pt;
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 );
257 return kome::objects::Spectrum::onIsRequestLoadData( );
275 return kome::objects::Spectrum::onIsFirstAccess( );
281 return kome::objects::Spectrum::onLoadData( );
MzmlSampleSet * getMzmlSampleSet()
gets mzML sample set object
virtual ~MzmlSpectrum()
destructor
interfaces of MzmlDataHandler class
virtual void onResetFirstAccess(void)
This method is called by resetFirstAccess method. (abstract method)
virtual void onGetXYData(kome::core::XYData *const xyData, const double minX, const double maxX)
This method is called by getXYData method. (override method)
virtual bool onIsFirstAccess(void)
This method is called by isFirstAccess method. (abstract method)
virtual void onResetRequestLoadData(void)
This method is called by resetRequestLoadData method. (abstract method)
virtual void onGetXRange(double *minX, double *maxX)
This method is called by getMinX or getMaxX method. (override method)
interfaces of MzmlSample class
XML data handler to get spectrum data points.
virtual double onGetTotalIntensity(const double minX, const double maxX)
This method is called by getTotalIntensity method. (override method)
virtual void onSetRequestLoadData(void)
This method is called by setRequestLoadData method. (abstract method)
virtual double onGetMaxIntensity(const double minX, const double maxX)
This method is called by getMaxIntensity method. (override method)
virtual bool onLoadData(void)
This method is called by loadData method. (abstract method)
void parse(xercesc::SAX2XMLReader *parser)
parse XML data
interfaces of MzmlSampleSet class
MzmlSpectrum(MzmlSample *file, const char *name)
constructor
virtual void onSetFirstAccess(void)
This method is called by setFirstAccess method. (abstract method)
virtual bool onIsRequestLoadData(void)
This method is called by isRequestLoadData method. (abstract method)
long long getOffset()
gets data offset
interfaces of MzmlSpectrum class
void setOffset(const long long offset)
sets data offset
FILE * getFile()
gets file descriptor
MzmlSample * m_mzmlSample