libmstoolkit-cleaned-82/0000755000175000017500000000000013210260002015322 5ustar rusconirusconilibmstoolkit-cleaned-82/README.md0000644000175000017500000000351613210260002016606 0ustar rusconirusconi# MSToolkit The MSToolkit is a light-weight C++ library for reading, writing, and manipulating mass spectrometry data. The MSToolkit is easily linked to virtually any C++ algorithm for simple, fast file reading and analysis. ### Supported File Formats * *mzML* including internal compression (zlib and numpress) and external compression (.mzML.gz) _read/write\*_ * *mzXML* including internal compression (zlib) and external compression (.mzXML.gz) _read-only_ * *mgf* _read/write_ * *ms1* _read/write_ * *ms2* _read/write_ * *bms1* _read/write_ * *bms2* _read/write_ * *cms1* _read/write_ * *cms2* _read/write_ * *RAW* Thermo proprietary file format (Windows only, requires Xcalibur/MSFileReader) _read-only_ _\* Note: .mzML writing produces funtional files, but currently does not export all meta data. Spectral peak data is complete. .mzML.gz files are not produced by the toolkit, and must be gzipped externally._ ### Simple Interface * Open any file format from a single function call. * Store any spectrum in a simple, comprehensive data structure. * Sequential or random-access file reading. ### Easy Integration * All headers included from a single location. * Single library file easily linked by the compiler. ### Compiling A few hints: * Add _NOSQLITE to build smaller library without SQLite. SQLite is only required for special case usage. * Add _NO_THERMORAW to build without Thermo file support in Windows. This is not necessary in Linux, where Thermo support is disabled by default. * Older versions of MSVC may require building with XML_STATIC declared. * Declaring WIN32 may still be required for compiling 64-bit libraries with MSVC. ### License Code written for the MSToolkit uses the Apache License, Version 2.0. All 3rd party software included in the MSToolkit library retains its original license. libmstoolkit-cleaned-82/include/0000755000175000017500000000000013210260002016745 5ustar rusconirusconilibmstoolkit-cleaned-82/include/MSReader.h0000644000175000017500000001264213210260002020565 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _MSREADER_H #define _MSREADER_H #include "Spectrum.h" #include "MSObject.h" #include "mzParser.h" #include #include #include #include //For mzXML Writing //#include "mzXMLWriter.h" //#include "MSToolkitInterface.h" #ifdef _MSC_VER #ifndef _NO_THERMORAW #import "libid:F0C5F3E3-4F2A-443E-A74D-0AABE3237494" rename_namespace("XRawfile") //#import "libid:5FE970A2-29C3-11D3-811D-00104B304896" rename_namespace("XRawfile") using namespace XRawfile; #endif #endif #ifndef _NOSQLITE #include #endif //Macros for 64-bit file support #ifdef _MSC_VER #ifndef _NO_THERMORAW #include "RAWReader.h" #endif typedef __int64 f_off; #define fseek(h,p,o) _fseeki64(h,p,o) #define ftell(h) _ftelli64(h) #else #ifndef _LARGEFILE_SOURCE #error "need to define _LARGEFILE_SOURCE!!" #endif /* end _LARGEFILE_SOURCE */ typedef off_t f_off; #define fseek(h,p,o) fseeko(h,p,o) #define ftell(h) ftello(h) #endif /* end _MSC_VER */ using namespace std; namespace MSToolkit { class MSReader { public: //Constructors & Destructors MSReader(); ~MSReader(); //Functions void addFilter(MSSpectrumType m); void appendFile(char* c, bool text, Spectrum& s); void appendFile(char* c, bool text, MSObject& m); void appendFile(char* c, Spectrum& s); void appendFile(char* c, MSObject& m); MSFileFormat checkFileFormat(const char *fn); string getCurrentFile(); MSSpectrumType getFileType(); MSHeader& getHeader(); void getInstrument(char* str); int getLastScan(); void getManufacturer(char* str); int getPercent(); //get specific header informations void setPrecision(int i, int j); void setPrecisionInt(int i); void setPrecisionMZ(int i); void writeFile(const char* c, bool text, MSObject& m); void writeFile(const char* c, MSFileFormat ff, MSObject& m, const char* sha1Report="\0"); bool readMGFFile(const char* c, Spectrum& s); //Note, no random-access of MGF files. bool readMSTFile(const char* c, bool text, Spectrum& s, int scNum=0); bool readMZPFile(const char* c, Spectrum& s, int scNum=0); bool readFile(const char* c, Spectrum& s, int scNum=0); void setFilter(vector& m); void setFilter(MSSpectrumType m); //For RAW files bool lookupRT(char* c, int scanNum, float& rt); void setAverageRaw(bool b, int width=1, long cutoff=1000); void setLabel(bool b); //label data contains all centroids (including noise and excluded peaks) void setRawFilter(char* c); void setRawFilterExact(bool b); //For MGF files void setHighResMGF(bool b); void setOnePlusMGF(bool b); //File compression void setCompression(bool b); //for Sqlite void createIndex(); protected: private: //Data Members FILE *fileIn; MSHeader header; int headerIndex; MSSpectrumType fileType; f_off lEnd; f_off lPivot; f_off lFWidth; int iIntensityPrecision; int iMZPrecision; int iVersion; int iFType; int lastReadScanNum; MSFileFormat lastFileFormat; string sCurrentFile; string sInstrument; string sManufacturer; //File compression bool compressMe; //mzXML support variables; ramp_fileoffset_t *pScanIndex; RAMPFILE *rampFileIn; bool rampFileOpen; int rampLastScan; int rampIndex; vector filter; //for RAW file support (even if not on windows) bool rawFileOpen; //for mgf support char strMGF[1024]; bool exportMGF; bool highResMGF; bool mgfOnePlus; int mgfIndex; vector mgfGlobalCharge; //Functions void closeFile(); int openFile(const char* c, bool text=false); bool findSpectrum(int i); void readCompressSpec(FILE* fileIn, MSScanInfo& ms, Spectrum& s); void readSpecHeader(FILE* fileIn, MSScanInfo& ms); void writeBinarySpec(FILE* fileOut, Spectrum& s); void writeCompressSpec(FILE* fileOut, Spectrum& s); void writeTextSpec(FILE* fileOut, Spectrum& s); void writeSpecHeader(FILE* fileOut, bool text, Spectrum& s); //support for rawfiles #ifdef _MSC_VER #ifndef _NO_THERMORAW RAWReader cRAW; #endif #endif //support for sqlite #ifndef _NOSQLITE bool readSqlite(const char* c, Spectrum& s, int scNum); void getUncompressedPeaks(Spectrum& s, int& numPeaks, int& mzLen, unsigned char* comprM, int& intensityLen, unsigned char* comprI); int curIndex; //remember where we are int lastScanNumber; int lastIndex; sqlite3* db; void sql_stmt(const char* stmt); bool executeSqlStmt(Spectrum& s, char* zSql); void appendFile(Spectrum& s); void writeSqlite(const char* c, MSObject& m, const char* sha1Report); void readChargeTable(int scanID, Spectrum& s); vector estimateCharge(Spectrum& s); #endif }; } #endif libmstoolkit-cleaned-82/include/MSObject.h0000644000175000017500000000262613210260002020572 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _MSOBJECT_H #define _MSOBJECT_H #include "MSToolkitTypes.h" #include "Spectrum.h" #include using namespace std; namespace MSToolkit { class MSObject { public: //Constructors & Destructors MSObject(); MSObject(const MSObject&); ~MSObject(); //Operator Functions MSObject& operator=(const MSObject&); //Functions void add(Spectrum&); bool addToHeader(char*); bool addToHeader(string); Spectrum& at(unsigned int); Peak_T& at(unsigned int, unsigned int); void clear(); void erase(unsigned int); void erase(unsigned int, unsigned int); MSHeader& getHeader(); void setHeader(const MSHeader& h); int size(); protected: private: vector *vSpectrum; string fileName; MSHeader header; MSSpectrumType fileType; }; } #endif libmstoolkit-cleaned-82/include/MSNumpress.hpp0000644000175000017500000002565713210260002021551 0ustar rusconirusconi/* MSNumpress.hpp johan.teleman@immun.lth.se Copyright 2013 Johan Teleman Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ /* ==================== encodeInt ==================== Some of the encodings described below use a integer compression referred to simply as encodeInt() This encoding works on a 4 byte integer, by truncating initial zeros or ones. If the initial (most significant) half byte is 0x0 or 0xf, the number of such halfbytes starting from the most significant is stored in a halfbyte. This initial count is then followed by the rest of the ints halfbytes, in little-endian order. A count halfbyte c of 0 <= c <= 8 is interpreted as an initial c 0x0 halfbytes 9 <= c <= 15 is interpreted as an initial (c-8) 0xf halfbytes Ex: int c rest 0 => 0x8 -1 => 0xf 0xf 23 => 0x6 0x7 0x1 */ #ifndef _MSNUMPRESS_HPP_ #define _MSNUMPRESS_HPP_ #include #include // defines whether to throw an exception when a number cannot be encoded safely // with the given parameters #ifndef THROW_ON_OVERFLOW #define THROW_ON_OVERFLOW true #endif namespace ms { namespace numpress { namespace MSNumpress { double optimalLinearFixedPoint( const double *data, size_t dataSize); /** * Encodes the doubles in data by first using a * - lossy conversion to a 4 byte 5 decimal fixed point representation * - storing the residuals from a linear prediction after first two values * - encoding by encodeInt (see above) * * The resulting binary is maximally 8 + dataSize * 5 bytes, but much less if the * data is reasonably smooth on the first order. * * This encoding is suitable for typical m/z or retention time binary arrays. * On a test set, the encoding was empirically show to be accurate to at least 0.002 ppm. * * @data pointer to array of double to be encoded (need memorycont. repr.) * @dataSize number of doubles from *data to encode * @result pointer to where resulting bytes should be stored * @fixedPoint the scaling factor used for getting the fixed point repr. * This is stored in the binary and automatically extracted * on decoding. * @return the number of encoded bytes */ size_t encodeLinear( const double *data, const size_t dataSize, unsigned char *result, double fixedPoint); /** * Calls lower level encodeLinear while handling vector sizes appropriately * * @data vector of doubles to be encoded * @result vector of resulting bytes (will be resized to the number of bytes) */ void encodeLinear( const std::vector &data, std::vector &result, double fixedPoint); /** * Decodes data encoded by encodeLinear. * * result vector guaranteed to be shorter or equal to (|data| - 8) * 2 * * Note that this method may throw a const char* if it deems the input data to be corrupt, i.e. * that the last encoded int does not use the last byte in the data. In addition the last encoded * int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte. * * @data pointer to array of bytes to be decoded (need memorycont. repr.) * @dataSize number of bytes from *data to decode * @result pointer to were resulting doubles should be stored * @return the number of decoded doubles, or -1 if dataSize < 4 or 4 < dataSize < 8 */ size_t decodeLinear( const unsigned char *data, const size_t dataSize, double *result); /** * Calls lower level decodeLinear while handling vector sizes appropriately * * Note that this method may throw a const char* if it deems the input data to be corrupt, i.e.. * that the last encoded int does not use the last byte in the data. In addition the last encoded * int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte. * * @data vector of bytes to be decoded * @result vector of resulting double (will be resized to the number of doubles) */ void decodeLinear( const std::vector &data, std::vector &result); ///////////////////////////////////////////////////////////// /** * Encodes the doubles in data by storing the residuals from a linear prediction after first two values. * * The resulting binary is the same size as the input data. * * This encoding is suitable for typical m/z or retention time binary arrays, and is * intended to be used before zlib compression to improve compression. * * @data pointer to array of doubles to be encoded (need memorycont. repr.) * @dataSize number of doubles from *data to encode * @result pointer to were resulting bytes should be stored */ size_t encodeSafe( const double *data, const size_t dataSize, unsigned char *result); /** * Decodes data encoded by encodeSafe. * * result vector is the same size as the input data. * * Might throw const char* is something goes wrong during decoding. * * @data pointer to array of bytes to be decoded (need memorycont. repr.) * @dataSize number of bytes from *data to decode * @result pointer to were resulting doubles should be stored * @return the number of decoded bytes */ size_t decodeSafe( const unsigned char *data, const size_t dataSize, double *result); ///////////////////////////////////////////////////////////// /** * Encodes ion counts by simply rounding to the nearest 4 byte integer, * and compressing each integer with encodeInt. * * The handleable range is therefore 0 -> 4294967294. * The resulting binary is maximally dataSize * 5 bytes, but much less if the * data is close to 0 on average. * * @data pointer to array of double to be encoded (need memorycont. repr.) * @dataSize number of doubles from *data to encode * @result pointer to were resulting bytes should be stored * @return the number of encoded bytes */ size_t encodePic( const double *data, const size_t dataSize, unsigned char *result); /** * Calls lower level encodePic while handling vector sizes appropriately * * @data vector of doubles to be encoded * @result vector of resulting bytes (will be resized to the number of bytes) */ void encodePic( const std::vector &data, std::vector &result); /** * Decodes data encoded by encodePic * * result vector guaranteed to be shorter of equal to |data| * 2 * * Note that this method may throw a const char* if it deems the input data to be corrupt, i.e. * that the last encoded int does not use the last byte in the data. In addition the last encoded * int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte. * * @data pointer to array of bytes to be decoded (need memorycont. repr.) * @dataSize number of bytes from *data to decode * @result pointer to were resulting doubles should be stored * @return the number of decoded doubles */ size_t decodePic( const unsigned char *data, const size_t dataSize, double *result); /** * Calls lower level decodePic while handling vector sizes appropriately * * Note that this method may throw a const char* if it deems the input data to be corrupt, i.e. * that the last encoded int does not use the last byte in the data. In addition the last encoded * int need to use either the last halfbyte, or the second last followed by a 0x0 halfbyte. * * @data vector of bytes to be decoded * @result vector of resulting double (will be resized to the number of doubles) */ void decodePic( const std::vector &data, std::vector &result); ///////////////////////////////////////////////////////////// double optimalSlofFixedPoint( const double *data, size_t dataSize); /** * Encodes ion counts by taking the natural logarithm, and storing a * fixed point representation of this. This is calculated as * * unsigned short fp = log(d + 1) * fixedPoint + 0.5 * * the result vector is exactly |data| * 2 + 8 bytes long * * @data pointer to array of double to be encoded (need memorycont. repr.) * @dataSize number of doubles from *data to encode * @result pointer to were resulting bytes should be stored * @return the number of encoded bytes */ size_t encodeSlof( const double *data, const size_t dataSize, unsigned char *result, double fixedPoint); /** * Calls lower level encodeSlof while handling vector sizes appropriately * * @data vector of doubles to be encoded * @result vector of resulting bytes (will be resized to the number of bytes) */ void encodeSlof( const std::vector &data, std::vector &result, double fixedPoint); /** * Decodes data encoded by encodeSlof * * The return will include exactly (|data| - 8) / 2 doubles. * * Note that this method may throw a const char* if it deems the input data to be corrupt. * * @data pointer to array of bytes to be decoded (need memorycont. repr.) * @dataSize number of bytes from *data to decode * @result pointer to were resulting doubles should be stored * @return the number of decoded doubles */ size_t decodeSlof( const unsigned char *data, const size_t dataSize, double *result); /** * Calls lower level decodeSlof while handling vector sizes appropriately * * Note that this method may throw a const char* if it deems the input data to be corrupt. * * @data vector of bytes to be decoded * @result vector of resulting double (will be resized to the number of doubles) */ void decodeSlof( const std::vector &data, std::vector &result); } // namespace MSNumpress } // namespace msdata } // namespace pwiz #endif // _MSNUMPRESS_HPP_ libmstoolkit-cleaned-82/include/RAWReader.h0000644000175000017500000000555713210260002020706 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _RAWREADER_H #define _RAWREADER_H #ifdef _MSC_VER #ifndef _NO_THERMORAW #include "MSToolkitTypes.h" #include "Spectrum.h" #include #include #include #include #import "libid:F0C5F3E3-4F2A-443E-A74D-0AABE3237494" rename_namespace("XRawfile") //#import "libid:5FE970A2-29C3-11D3-811D-00104B304896" rename_namespace("XRawfile") using namespace XRawfile; using namespace std; namespace MSToolkit { typedef struct rawPrecursorInfo{ double dIsoMZ; double dMonoMZ; long charge; long parScanNum; rawPrecursorInfo(){ dIsoMZ=0; dMonoMZ=0; charge=0; parScanNum=0; } void clear(){ dIsoMZ = 0; dMonoMZ = 0; charge = 0; parScanNum = 0; } } rawPrecursorInfo; class RAWReader { public: //Constructors & Destructors RAWReader(); ~RAWReader(); //Public Functions void getInstrument(char* str); long getLastScanNumber(); void getManufacturer(char* str); long getScanCount(); bool getStatus(); bool lookupRT(char* c, int scanNum, float& rt); bool readRawFile(const char* c, Spectrum& s, int scNum=0); void setAverageRaw(bool b, int width=1, long cutoff=1000); void setLabel(bool b); //label data contains all centroids (including noise and excluded peaks) void setMSLevelFilter(vector* v); void setRawFilter(char* c); void setRawFilterExact(bool b); private: //Data Members bool bRaw; bool rawAvg; bool rawFileOpen; bool rawLabel; bool rawUserFilterExact; char rawCurrentFile[256]; char rawInstrument[256]; char rawManufacturer[256]; char rawUserFilter[256]; int rawAvgWidth; long rawAvgCutoff; long rawCurSpec; long rawTotSpec; IXRawfilePtr m_Raw; vector* msLevelFilter; //Private Functions int calcChargeState(double precursormz, double highmass, VARIANT* varMassList, long nArraySize); double calcPepMass(int chargestate, double precursormz); MSSpectrumType evaluateFilter(long scan, char* chFilter, vector& MZs, bool& bCentroid, double& cv, MSActivation& act); double evaluateTrailerDouble(const char* id); int evaluateTrailerInt(const char* id); bool initRaw(); }; } #endif #endif #endif libmstoolkit-cleaned-82/include/MSToolkitTypes.h0000644000175000017500000000415413210260002022034 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _MSTOOLKITTYPES_H #define _MSTOOLKITTYPES_H #include namespace MSToolkit { enum MSSpectrumType { MS1, MS2, MS3, ZS, UZS, IonSpec, SRM, REFERENCE, Unspecified, MSX }; enum MSFileFormat { bms1, bms2, cms1, cms2, mgf, ms1, ms2, msmat_ff, mzXML, mz5, mzML, raw, sqlite, psm, uzs, zs, mzXMLgz, mzMLgz, dunno }; enum MSTag { no, D, H, I, S, Z }; enum MSActivation { mstCID, mstECD, mstETD, mstETDSA, mstPQD, mstHCD, mstIRMPD, mstNA }; struct MSHeader { char header[16][128]; }; struct MSScanInfo { int scanNumber[2]; int numDataPoints; int numEZStates; int numZStates; float rTime; float IIT; float BPI; double* mz; int mzCount; double convA; double convB; double convC; double convD; double convE; double convI; double TIC; double BPM; MSScanInfo(){ mz=NULL; scanNumber[0]=scanNumber[1]=0; numDataPoints=numEZStates=numZStates=0; rTime=IIT=BPI=0.0f; TIC=BPM=0.0; convA=convB=convC=convD=convE=convI=0.0; mzCount=0; } ~MSScanInfo(){ if(mz!=NULL) delete [] mz; } }; struct DataPeak { double dMass; double dIntensity; }; //For RAW files struct Peak_T { double mz; float intensity; }; struct ZState { int z; double mh; //M+H, not mz }; struct EZState { int z; double mh; //M+H float pRTime; //precursor area float pArea; //precursor retention time }; } #endif libmstoolkit-cleaned-82/include/mzParser.h0000644000175000017500000013346313210260002020733 0ustar rusconirusconi/* mzParser - This distribution contains novel code and publicly available open source utilities. The novel code is open source under the FreeBSD License, please see LICENSE file for detailed information. Copyright (C) 2011, Mike Hoopmann, Institute for Systems Biology Version 1.0, January 4, 2011. Version 1.1, March 14, 2012. Additional code/libraries obtained from: X!Tandem 2010.12.01: http://thegpm.org/ Copyright and license information for these free utilities are provided in the LICENSE file. Note that many changes were made to the code adapted from X!Tandem. */ #ifndef _MZPARSER_H #define _MZPARSER_H //------------------------------------------------ // Standard libraries //------------------------------------------------ #include #include #include #include #include #include #include "expat.h" #include "zlib.h" #include "MSNumpress.hpp" #ifdef MZP_MZ5 #include "hdf5.h" #include "H5Cpp.h" #endif using namespace std; #ifdef MZP_MZ5 using namespace H5; #endif //------------------------------------------------ // MACROS //------------------------------------------------ //#define OSX // to compile with cc on Macintosh OSX //#define OSX_TIGER // use with OSX if OSX Tiger is being used //#define OSX_INTEL // compile with cc on Macintosh OSX on Intel-style processors //#define MINGW // compiling with MinGW gcc toolset // The following should be defined by the compiler already //#define __GNUC__ // compiling with gcc (or g++) //#define _MSC_VER // compiling with Microsoft Studio #define XMLCLASS #ifndef XML_STATIC #define XML_STATIC // to statically link the expat libraries #endif //For Windows #ifdef _MSC_VER #define __inline__ __inline typedef _int64 __int64_t; typedef unsigned _int32 uint32_t; typedef unsigned _int64 uint64_t; typedef __int64 f_off; #define mzpfseek(h,p,o) _fseeki64(h,p,o) #define mzpftell(h) _ftelli64(h) #define mzpatoi64(h) _atoi64(h) #endif //For MinGW toolset, which lacks the ftello, fseeko, etc functions #ifdef MINGW //typedef __int64 f_off; //#define __int64_t int64_t #define mzpfseek(h,p,o) fseeko64(h,p,o) #define mzpftell(h) ftello64(h) #define mzpatoi64(h) _atoi64(h) //#include #endif #if defined(GCC) || defined(__LINUX__) #include #include #ifndef _LARGEFILE_SOURCE #error "need to define _LARGEFILE_SOURCE!!" #endif /* end _LARGEFILE_SOURCE */ #if _FILE_OFFSET_BITS<64 #error "need to define _FILE_OFFSET_BITS=64" #endif typedef off_t f_off; #define mzpfseek(h,p,o) fseeko(h,p,o) #define mzpftell(h) ftello(h) #define mzpatoi64(h) atoll(h) #endif #ifdef OSX #define __inline__ inline #ifndef OSX_TIGER #define __int64_t int64_t #endif #endif // this define for the INTEL-based OSX platform is untested and may not work #ifdef OSX_INTEL #define __inline__ inline #endif // this define should work for most LINUX and UNIX platforms //------------------------------------------------ // mzMLParser structures, definitions, and enums //------------------------------------------------ //specDP (Spectrum Data Point) is the basic content element of a mass spectrum. typedef struct specDP{ double mz; double intensity; } specDP; typedef struct TimeIntensityPair{ double time; double intensity; } TimeIntensityPair; enum enumActivation { none=0, CID=1, HCD=2, ETD=3, ETDSA=4, ECD=5, }; //------------------------------------------------ // mzMLParser classes //------------------------------------------------ //For holding mzML and mzXML indexes class cindex { public: static int compare (const void* a, const void* b) { if( *(int*)a < *(int*)b ) return -1; if( *(int*)a > *(int*)b ) return 1; return 0; } int scanNum; string idRef; f_off offset; }; //For instrument information class instrumentInfo { public: string analyzer; string detector; string id; string ionization; string manufacturer; string model; instrumentInfo(){ analyzer=""; detector=""; id=""; ionization=""; manufacturer=""; model=""; } void clear(){ analyzer=""; detector=""; id=""; ionization=""; manufacturer=""; model=""; } }; typedef struct sPrecursorIon{ double intensity; double isoLowerMZ; //lower offset of the isolation window double isoMZ; //the mz of the isolation window double isoUpperMZ; //upper offset of the isolation window double mz; //is this always redundant with isoMZ? double monoMZ; vector* possibleCharges; int charge; sPrecursorIon(){ intensity=0; isoLowerMZ=0; isoMZ=0; isoUpperMZ=0; mz=0; monoMZ=0; possibleCharges=new vector; charge=0; } sPrecursorIon(const sPrecursorIon& p){ intensity=p.intensity; isoLowerMZ = p.isoLowerMZ; isoMZ = p.isoMZ; isoUpperMZ = p.isoUpperMZ; mz=p.mz; monoMZ=p.monoMZ; possibleCharges=new vector; for(size_t i=0;isize();i++) possibleCharges->push_back(p.possibleCharges->at(i)); charge=p.charge; } ~sPrecursorIon(){ delete possibleCharges; } sPrecursorIon& operator=(const sPrecursorIon& p){ if(this!=&p){ intensity=p.intensity; isoLowerMZ = p.isoLowerMZ; isoMZ = p.isoMZ; isoUpperMZ = p.isoUpperMZ; mz=p.mz; monoMZ=p.monoMZ; delete possibleCharges; possibleCharges=new vector; for(size_t i=0;isize();i++) possibleCharges->push_back(p.possibleCharges->at(i)); charge=p.charge; } return *this; } void clear(){ intensity=0; isoLowerMZ = 0; isoMZ = 0; isoUpperMZ = 0; mz=0; monoMZ=0; possibleCharges->clear(); charge=0; } } sPrecursorIon; class BasicSpectrum { public: //Constructors & Destructors BasicSpectrum(); BasicSpectrum(const BasicSpectrum& s); ~BasicSpectrum(); //Operator overloads BasicSpectrum& operator=(const BasicSpectrum& s); specDP& operator[ ](const unsigned int index); //Modifiers void addDP(specDP dp); void clear(); void setActivation(int a); void setBasePeakIntensity(double d); void setBasePeakMZ(double d); void setCentroid(bool b); void setCollisionEnergy(double d); void setCompensationVoltage(double d); void setFilterLine(char* str); void setHighMZ(double d); void setIDString(char* str); void setIonInjectionTime(double d); void setLowMZ(double d); void setMSLevel(int level); void setPeaksCount(int i); void setPositiveScan(bool b); void setPrecursorIon(sPrecursorIon& pi); void setPrecursorIon(double mz, double monoMZ, double intensity, int charge, int possibleChargeCount, int* possibleCharges); void setPrecursorScanNum(int i); void setRTime(float t); void setScanIndex(int num); void setScanNum(int num); void setTotalIonCurrent(double d); //Accessors int getActivation(); double getBasePeakIntensity(); double getBasePeakMZ(); bool getCentroid(); double getCollisionEnergy(); double getCompensationVoltage(); int getFilterLine(char* str); double getHighMZ(); int getIDString(char* str); double getIonInjectionTime(); double getLowMZ(); int getMSLevel(); int getPeaksCount(); bool getPositiveScan(); sPrecursorIon getPrecursorIon(int i=0); int getPrecursorIonCount(); int getPrecursorCharge(int i=0); int getPrecursorChargeCount(int i=0); double getPrecursorIntensity(int i=0); double getPrecursorMonoMZ(int i=0); double getPrecursorMZ(int i=0); int getPrecursorScanNum(); float getRTime(bool min=true); int getScanIndex(); int getScanNum(); double getTotalIonCurrent(); size_t size(); protected: //Data Members (protected) int activation; double basePeakIntensity; double basePeakMZ; bool centroid; double collisionEnergy; double compensationVoltage; //FAIMS compensation voltage char filterLine[128]; double highMZ; char idString[128]; double ionInjectionTime; double lowMZ; int msLevel; int peaksCount; bool positiveScan; int precursorScanNum; //Precursor scan number; 0 if no precursor or unknown float rTime; //always stored in minutes int scanIndex; //when scan numbers aren't enough, there are indexes (start at 1) int scanNum; //identifying scan number double totalIonCurrent; vector* vData; //Spectrum data points vector* vPrecursor; }; class BasicChromatogram { public: //Constructors & Destructors BasicChromatogram(); BasicChromatogram(const BasicChromatogram& c); ~BasicChromatogram(); //Operator overloads BasicChromatogram& operator=(const BasicChromatogram& c); TimeIntensityPair& operator[ ](const unsigned int index); //Modifiers void addTIP(TimeIntensityPair tip); void clear(); void setIDString(char* str); void setPrecursor(double mz, int z, double offLow, double offHigh); void setProduct(double mz, double offLow, double offHigh); //Accessors int getCharge(); vector& getData(); int getIDString(char* str); double getPreMZ(); double getPreOffsetLower(); double getPreOffsetUpper(); double getProdMZ(); double getProdOffsetLower(); double getProdOffsetUpper(); size_t size(); protected: //Data Members (protected) int charge; char idString[128]; double precursorMZ; double precursorOffsetLower; double precursorOffsetUpper; double productMZ; double productOffsetLower; double productOffsetUpper; vector vData; //Chromatogram data points }; //------------------------------------------------ // Random access gz (zran from zlib source code) //------------------------------------------------ #define SPAN 1048576L // desired distance between access points #define WINSIZE 32768U // sliding window size #define CHUNK 32768 // file input buffer size #define READCHUNK 16384 // access point entry typedef struct point { f_off out; // corresponding offset in uncompressed data f_off in; // offset in input file of first full byte int bits; // number of bits (1-7) from byte at in - 1, or 0 unsigned char window[WINSIZE]; // preceding 32K of uncompressed data } point; // access point list typedef struct gz_access { int have; // number of list entries filled in int size; // number of list entries allocated point *list; // allocated list } gz_access; class Czran{ public: Czran(); ~Czran(); void free_index(); gz_access *addpoint(int bits, f_off in, f_off out, unsigned left, unsigned char *window); int build_index(FILE *in, f_off span); int build_index(FILE *in, f_off span, gz_access **built); int extract(FILE *in, f_off offset, unsigned char *buf, int len); int extract(FILE *in, f_off offset); f_off getfilesize(); protected: private: gz_access* index; unsigned char* buffer; f_off bufferOffset; int bufferLen; unsigned char* lastBuffer; f_off lastBufferOffset; int lastBufferLen; f_off fileSize; }; //------------------------------------------------ // X!Tandem borrowed headers //------------------------------------------------ int b64_decode_mio (char *dest, char *src, size_t size); int b64_encode (char *dest, const char *src, int len); class mzpSAXHandler{ public: // SAXHandler constructors and destructors mzpSAXHandler(); virtual ~mzpSAXHandler(); // SAXHandler eXpat event handlers virtual void startElement(const XML_Char *el, const XML_Char **attr); virtual void endElement(const XML_Char *el); virtual void characters(const XML_Char *s, int len); // SAXHandler Parsing functions. bool open(const char* fileName); bool parse(); bool parseOffset(f_off offset); void setGZCompression(bool b); inline void setFileName(const char* fileName) { m_strFileName = fileName; } // SAXHandler helper functions inline bool isElement(const char *n1, const XML_Char *n2) { return (strcmp(n1, n2) == 0); } inline bool isAttr(const char *n1, const XML_Char *n2) { return (strcmp(n1, n2) == 0); } inline const char* getAttrValue(const char* name, const XML_Char **attr) { for (int i = 0; attr[i]; i += 2) { if (isAttr(name, attr[i])) return attr[i + 1]; } return ""; } protected: XML_Parser m_parser; string m_strFileName; bool m_bStopParse; bool m_bGZCompression; FILE* fptr; Czran gzObj; }; class mzpSAXMzmlHandler : public mzpSAXHandler { public: mzpSAXMzmlHandler(BasicSpectrum* bs); mzpSAXMzmlHandler(BasicSpectrum* bs, BasicChromatogram* bc); ~mzpSAXMzmlHandler(); // Overrides of SAXHandler functions void startElement(const XML_Char *el, const XML_Char **attr); void endElement(const XML_Char *el); void characters(const XML_Char *s, int len); // SAXMzmlHandler public functions vector* getChromatIndex(); f_off getIndexOffset(); vector* getInstrument(); int getPeaksCount(); vector* getSpecIndex(); int highChromat(); int highScan(); bool load(const char* fileName); int lowScan(); bool readChromatogram(int num=-1); bool readHeader(int num=-1); bool readSpectrum(int num=-1); protected: private: // mzpSAXMzmlHandler subclasses class cvParam { public: string refGroupName; string name; string accession; string value; string unitAccession; string unitName; }; // mzpSAXMzmlHandler private functions void processData(); void processCVParam(const char* name, const char* accession, const char* value, const char* unitName="0", const char* unitAccession="0"); void pushChromatogram(); void pushSpectrum(); // Load current data into pvSpec, may have to guess charge f_off readIndexOffset(); void stopParser(); // mzpSAXMzmlHandler Base64 conversion functions void decode(vector& d); //void decode32(vector& d); //void decode64(vector& d); //void decompress32(vector& d); //void decompress64(vector& d); unsigned long dtohl(uint32_t l, bool bNet); uint64_t dtohl(uint64_t l, bool bNet); // mzpSAXMzmlHandler Flags indicating parser is inside a particular tag. bool m_bInIndexedMzML; bool m_bInRefGroup; bool m_bInmzArrayBinary; bool m_bInintenArrayBinary; bool m_bInSpectrumList; bool m_bInChromatogramList; bool m_bInIndexList; bool m_bInProduct; // mzpSAXMzmlHandler procedural flags. bool m_bChromatogramIndex; bool m_bHeaderOnly; bool m_bLowPrecision; bool m_bNetworkData; // i.e. big endian bool m_bNumpressLinear; bool m_bNumpressPic; bool m_bNumpressSlof; bool m_bNoIndex; bool m_bSpectrumIndex; bool m_bZlib; int m_iDataType; //0=unspecified, 1=32-bit float, 2=64-bit float bool m_bIndexSorted; // mzpSAXMzmlHandler index data members. vector m_vIndex; cindex curIndex; int posIndex; f_off indexOffset; vector m_vChromatIndex; cindex curChromatIndex; int posChromatIndex; // mzpSAXMzmlHandler data members. BasicChromatogram* chromat; string m_ccurrentRefGroupName; long m_encodedLen; // For compressed data instrumentInfo m_instrument; sPrecursorIon m_precursorIon; int m_peaksCount; // Count of peaks in spectrum vector m_refGroupCvParams; int m_scanSPECCount; int m_scanIDXCount; int m_scanPRECCount; double m_startTime; //in minutes double m_stopTime; //in minutes string m_strData; // For collecting character data. vector m_vInstrument; BasicSpectrum* spec; vector vdI; vector vdM; // Peak list vectors (masses and charges) }; class mzpSAXMzxmlHandler : public mzpSAXHandler { public: mzpSAXMzxmlHandler(BasicSpectrum* bs); mzpSAXMzxmlHandler(BasicSpectrum* bs, BasicChromatogram* bc); ~mzpSAXMzxmlHandler(); // Overrides of SAXHandler functions void startElement(const XML_Char *el, const XML_Char **attr); void endElement(const XML_Char *el); void characters(const XML_Char *s, int len); // mzpSAXMzxmlHandler public functions vector* getIndex(); f_off getIndexOffset(); instrumentInfo getInstrument(); int getPeaksCount(); int highScan(); bool load(const char* fileName); int lowScan(); bool readChromat(int num=-1); bool readHeader(int num=-1); bool readSpectrum(int num=-1); protected: private: // mzpSAXMzxmlHandler private functions void pushSpectrum(); // Load current data into pvSpec, may have to guess charge f_off readIndexOffset(); void stopParser(); // mzpSAXMzxmlHandler Base64 conversion functions void decode32(); void decode64(); void decompress32(); void decompress64(); unsigned long dtohl(uint32_t l, bool bNet); uint64_t dtohl(uint64_t l, bool bNet); // mzpSAXMzxmlHandler Flags indicating parser is inside a particular tag. bool m_bInDataProcessing; bool m_bInIndex; bool m_bInMsInstrument; bool m_bInMsRun; bool m_bInPeaks; bool m_bInPrecursorMz; bool m_bInScan; // mzpSAXMzxmlHandler procedural flags. bool m_bCompressedData; bool m_bHeaderOnly; bool m_bLowPrecision; bool m_bNetworkData; // i.e. big endian bool m_bNoIndex; bool m_bScanIndex; bool m_bIndexSorted; // mzpSAXMzxmlHandler index data members. vector m_vIndex; cindex curIndex; int posIndex; f_off indexOffset; // mzpSAXMzxmlHandler data members. uLong m_compressLen; // For compressed data instrumentInfo m_instrument; int m_peaksCount; // Count of peaks in spectrum sPrecursorIon m_precursorIon; string m_strData; // For collecting character data. vector m_vInstrument; BasicSpectrum* spec; vector vdI; vector vdM; // Peak list vectors (masses and charges) }; //------------------------------------------------ // mz5 Support //------------------------------------------------ #ifdef MZP_MZ5 //mz5 constants #define CVL 128 #define USRVL 128 #define USRNL 256 #define USRTL 64 static unsigned short MZ5_FILE_MAJOR_VERSION = 0; static unsigned short MZ5_FILE_MINOR_VERSION = 9; //forward declarations class mzpMz5Config; enum MZ5DataSets { ControlledVocabulary, FileContent, Contact, CVReference, CVParam, UserParam, RefParam, ParamGroups, SourceFiles, Samples, Software, ScanSetting, InstrumentConfiguration, DataProcessing, Run, SpectrumMetaData, SpectrumBinaryMetaData, SpectrumIndex, SpectrumMZ, SpectrumIntensity, ChromatogramMetaData, ChromatogramBinaryMetaData, ChromatogramIndex, ChromatogramTime, ChromatogramIntensity, FileInformation }; enum SpectrumLoadPolicy { SLP_InitializeAllOnCreation, SLP_InitializeAllOnFirstCall }; enum ChromatogramLoadPolicy { CLP_InitializeAllOnCreation, CLP_InitializeAllOnFirstCall }; struct FileInformationMZ5Data { unsigned short majorVersion; unsigned short minorVersion; unsigned short didFiltering; unsigned short deltaMZ; unsigned short translateInten; }; struct FileInformationMZ5: public FileInformationMZ5Data { FileInformationMZ5(); FileInformationMZ5(const FileInformationMZ5&); FileInformationMZ5(const mzpMz5Config&); ~FileInformationMZ5(); FileInformationMZ5& operator=(const FileInformationMZ5&); void init(const unsigned short majorVersion, const unsigned short minorVersion, const unsigned didFiltering, const unsigned deltaMZ, const unsigned translateInten); static CompType getType(); }; struct ContVocabMZ5Data { char* uri; char* fullname; char* id; char* version; }; struct ContVocabMZ5: public ContVocabMZ5Data { ContVocabMZ5(); ContVocabMZ5(const string& uri, const string& fullname, const string& id, const string& version); ContVocabMZ5(const char* uri, const char* fullname, const char* id, const char* version); ContVocabMZ5(const ContVocabMZ5&); ContVocabMZ5& operator=(const ContVocabMZ5&); ~ContVocabMZ5(); void init(const string&, const string&, const string&, const string&); static CompType getType(); }; struct CVRefMZ5Data { char* name; char* prefix; unsigned long accession; }; struct CVRefMZ5: public CVRefMZ5Data { CVRefMZ5(); CVRefMZ5(const CVRefMZ5&); CVRefMZ5& operator=(const CVRefMZ5&); ~CVRefMZ5(); void init(const char* name, const char* prefix, const unsigned long accession); static CompType getType(); }; struct UserParamMZ5Data { char name[USRNL]; char value[USRVL]; char type[USRTL]; unsigned long unitCVRefID; }; struct UserParamMZ5: public UserParamMZ5Data { UserParamMZ5(); UserParamMZ5(const UserParamMZ5&); UserParamMZ5& operator=(const UserParamMZ5&); ~UserParamMZ5(); void init(const char* name, const char* value, const char* type, const unsigned long urefid); static CompType getType(); }; struct CVParamMZ5Data { char value[CVL]; unsigned long typeCVRefID; unsigned long unitCVRefID; }; struct CVParamMZ5: public CVParamMZ5Data { CVParamMZ5(); CVParamMZ5(const CVParamMZ5&); CVParamMZ5& operator=(const CVParamMZ5&); ~CVParamMZ5(); void init(const char* value, const unsigned long& cvrefid, const unsigned long& urefid); static CompType getType(); }; struct RefMZ5Data { unsigned long refID; }; struct RefMZ5: public RefMZ5Data { RefMZ5(); RefMZ5(const RefMZ5&); RefMZ5& operator=(const RefMZ5&); ~RefMZ5(); static CompType getType(); }; struct RefListMZ5Data { size_t len; RefMZ5* list; }; struct RefListMZ5: RefListMZ5Data { RefListMZ5(); RefListMZ5(const RefListMZ5&); RefListMZ5& operator=(const RefListMZ5&); ~RefListMZ5(); void init(const RefMZ5* list, const size_t len); static VarLenType getType(); }; struct ParamListMZ5Data { unsigned long cvParamStartID; unsigned long cvParamEndID; unsigned long userParamStartID; unsigned long userParamEndID; unsigned long refParamGroupStartID; unsigned long refParamGroupEndID; }; struct ParamListMZ5: ParamListMZ5Data { ParamListMZ5(); ParamListMZ5(const ParamListMZ5&); ParamListMZ5& operator=(const ParamListMZ5&); ~ParamListMZ5(); void init(const unsigned long cvstart, const unsigned long cvend, const unsigned long usrstart, const unsigned long usrend, const unsigned long refstart, const unsigned long refend); static CompType getType(); }; struct ParamGroupMZ5 { char* id; ParamListMZ5 paramList; ParamGroupMZ5(); ParamGroupMZ5(const ParamGroupMZ5&); ParamGroupMZ5& operator=(const ParamGroupMZ5&); ~ParamGroupMZ5(); void init(const ParamListMZ5& params, const char* id); static CompType getType(); }; struct SourceFileMZ5 { char* id; char* location; char* name; ParamListMZ5 paramList; SourceFileMZ5(); SourceFileMZ5(const SourceFileMZ5&); SourceFileMZ5& operator=(const SourceFileMZ5&); ~SourceFileMZ5(); void init(const ParamListMZ5& params, const char* id, const char* location, const char* name); static CompType getType(); }; struct SampleMZ5 { char* id; char* name; ParamListMZ5 paramList; SampleMZ5(); SampleMZ5(const SampleMZ5&); SampleMZ5& operator=(const SampleMZ5&); ~SampleMZ5(); void init(const ParamListMZ5& params, const char* id, const char* name); static CompType getType(); }; struct SoftwareMZ5 { char* id; char* version; ParamListMZ5 paramList; SoftwareMZ5(); SoftwareMZ5(const SoftwareMZ5&); SoftwareMZ5& operator=(const SoftwareMZ5&); ~SoftwareMZ5(); void init(const ParamListMZ5& params, const char* id, const char* version); static CompType getType(); }; struct ParamListsMZ5 { size_t len; ParamListMZ5* lists; ParamListsMZ5(); ParamListsMZ5(const ParamListsMZ5&); ParamListsMZ5& operator=(const ParamListsMZ5&); ~ParamListsMZ5(); void init(const ParamListMZ5* list, const size_t len); static VarLenType getType(); }; struct ScanSettingMZ5 { char* id; ParamListMZ5 paramList; RefListMZ5 sourceFileIDs; ParamListsMZ5 targetList; ScanSettingMZ5(); ScanSettingMZ5(const ScanSettingMZ5&); ScanSettingMZ5& operator=(const ScanSettingMZ5&); ~ScanSettingMZ5(); void init(const ParamListMZ5& params, const RefListMZ5& refSourceFiles, const ParamListsMZ5 targets, const char* id); static CompType getType(); }; struct ComponentMZ5 { ParamListMZ5 paramList; unsigned long order; ComponentMZ5(); ComponentMZ5(const ComponentMZ5&); ComponentMZ5& operator=(const ComponentMZ5&); ~ComponentMZ5(); void init(const ParamListMZ5&, const unsigned long order); static CompType getType(); }; struct ComponentListMZ5 { size_t len; ComponentMZ5* list; ComponentListMZ5(); ComponentListMZ5(const ComponentListMZ5&); ComponentListMZ5(const vector&); ComponentListMZ5& operator=(const ComponentListMZ5&); ~ComponentListMZ5(); void init(const ComponentMZ5*, const size_t&); static VarLenType getType(); }; struct ComponentsMZ5 { ComponentListMZ5 sources; ComponentListMZ5 analyzers; ComponentListMZ5 detectors; ComponentsMZ5(); ComponentsMZ5(const ComponentsMZ5&); ComponentsMZ5& operator=(const ComponentsMZ5&); ~ComponentsMZ5(); void init(const ComponentListMZ5& sources, const ComponentListMZ5& analyzers, const ComponentListMZ5& detectors); static CompType getType(); }; struct InstrumentConfigurationMZ5 { char* id; ParamListMZ5 paramList; ComponentsMZ5 components; RefMZ5 scanSettingRefID; RefMZ5 softwareRefID; InstrumentConfigurationMZ5(); InstrumentConfigurationMZ5(const InstrumentConfigurationMZ5&); InstrumentConfigurationMZ5& operator=(const InstrumentConfigurationMZ5&); ~InstrumentConfigurationMZ5(); void init(const ParamListMZ5& params, const ComponentsMZ5& components, const RefMZ5& refScanSetting, const RefMZ5& refSoftware, const char* id); static CompType getType(); }; struct ProcessingMethodMZ5 { ParamListMZ5 paramList; RefMZ5 softwareRefID; unsigned long order; ProcessingMethodMZ5(); ProcessingMethodMZ5(const ProcessingMethodMZ5&); ProcessingMethodMZ5& operator=(const ProcessingMethodMZ5&); ~ProcessingMethodMZ5(); void init(const ParamListMZ5& params, const RefMZ5& refSoftware, const unsigned long order); static CompType getType(); }; struct ProcessingMethodListMZ5 { size_t len; ProcessingMethodMZ5* list; ProcessingMethodListMZ5(); ProcessingMethodListMZ5(const ProcessingMethodListMZ5&); ProcessingMethodListMZ5& operator=(const ProcessingMethodListMZ5&); ~ProcessingMethodListMZ5(); void init(const ProcessingMethodMZ5* list, const size_t len); static VarLenType getType(); }; struct DataProcessingMZ5 { char* id; ProcessingMethodListMZ5 processingMethodList; DataProcessingMZ5(); DataProcessingMZ5(const DataProcessingMZ5&); DataProcessingMZ5& operator=(const DataProcessingMZ5&); ~DataProcessingMZ5(); void init(const ProcessingMethodListMZ5&, const char* id); static CompType getType(); }; struct PrecursorMZ5 { char* externalSpectrumId; ParamListMZ5 activation; ParamListMZ5 isolationWindow; ParamListsMZ5 selectedIonList; RefMZ5 spectrumRefID; RefMZ5 sourceFileRefID; PrecursorMZ5(); PrecursorMZ5(const PrecursorMZ5&); PrecursorMZ5& operator=(const PrecursorMZ5&); ~PrecursorMZ5(); void init(const ParamListMZ5& activation, const ParamListMZ5& isolationWindow, const ParamListsMZ5 selectedIonList, const RefMZ5& refSpectrum, const RefMZ5& refSourceFile, const char* externalSpectrumId); static CompType getType(); }; struct PrecursorListMZ5 { size_t len; PrecursorMZ5* list; PrecursorListMZ5(); PrecursorListMZ5(const PrecursorListMZ5&); PrecursorListMZ5& operator=(const PrecursorListMZ5&); ~PrecursorListMZ5(); void init(const PrecursorMZ5*, const size_t len); static VarLenType getType(); }; struct ChromatogramMZ5 { char* id; ParamListMZ5 paramList; PrecursorMZ5 precursor; ParamListMZ5 productIsolationWindow; RefMZ5 dataProcessingRefID; unsigned long index; ChromatogramMZ5(); ChromatogramMZ5(const ChromatogramMZ5&); ChromatogramMZ5& operator=(const ChromatogramMZ5&); ~ChromatogramMZ5(); void init(const ParamListMZ5& params, const PrecursorMZ5& precursor, const ParamListMZ5& productIsolationWindow, const RefMZ5& refDataProcessing, const unsigned long index, const char* id); static CompType getType(); }; struct ScanMZ5 { char* externalSpectrumID; ParamListMZ5 paramList; ParamListsMZ5 scanWindowList; RefMZ5 instrumentConfigurationRefID; RefMZ5 sourceFileRefID; RefMZ5 spectrumRefID; ScanMZ5(); ScanMZ5(const ScanMZ5&); ScanMZ5& operator=(const ScanMZ5&); ~ScanMZ5(); void init(const ParamListMZ5& params, const ParamListsMZ5& scanWindowList, const RefMZ5& refInstrument, const RefMZ5& refSourceFile, const RefMZ5& refSpectrum, const char* externalSpectrumID); static CompType getType(); }; struct ScanListMZ5 { size_t len; ScanMZ5* list; ScanListMZ5(); ScanListMZ5(const ScanListMZ5&); ScanListMZ5(const vector&); ScanListMZ5& operator=(const ScanListMZ5&); ~ScanListMZ5(); void init(const ScanMZ5* list, const size_t len); static VarLenType getType(); }; struct ScansMZ5 { ParamListMZ5 paramList; ScanListMZ5 scanList; ScansMZ5(); ScansMZ5(const ScansMZ5&); ScansMZ5& operator=(const ScansMZ5&); ~ScansMZ5(); void init(const ParamListMZ5& params, const ScanListMZ5& scanList); static CompType getType(); }; struct SpectrumMZ5 { char* id; char* spotID; ParamListMZ5 paramList; ScansMZ5 scanList; PrecursorListMZ5 precursorList; ParamListsMZ5 productList; RefMZ5 dataProcessingRefID; RefMZ5 sourceFileRefID; unsigned int index; SpectrumMZ5(); SpectrumMZ5(const SpectrumMZ5&); SpectrumMZ5& operator=(const SpectrumMZ5&); ~SpectrumMZ5(); void init(const ParamListMZ5& params, const ScansMZ5& scanList, const PrecursorListMZ5& precursors, const ParamListsMZ5& productIonIsolationWindows, const RefMZ5& refDataProcessing, const RefMZ5& refSourceFile, const unsigned long index, const char* id, const char* spotID); static CompType getType(); }; struct RunMZ5 { char* id; char* startTimeStamp; char* fid; char* facc; ParamListMZ5 paramList; RefMZ5 defaultSpectrumDataProcessingRefID; RefMZ5 defaultChromatogramDataProcessingRefID; RefMZ5 defaultInstrumentConfigurationRefID; RefMZ5 sourceFileRefID; RefMZ5 sampleRefID; RunMZ5(); RunMZ5(const RunMZ5&); RunMZ5& operator=(const RunMZ5&); ~RunMZ5(); void init(const ParamListMZ5& params, const RefMZ5& refSpectrumDP, const RefMZ5& refChromatogramDP, const RefMZ5& refDefaultInstrument, const RefMZ5& refSourceFile, const RefMZ5& refSample, const char* id, const char* startTimeStamp, const char* fid, const char* facc); static CompType getType(); }; struct BinaryDataMZ5 { ParamListMZ5 xParamList; ParamListMZ5 yParamList; RefMZ5 xDataProcessingRefID; RefMZ5 yDataProcessingRefID; BinaryDataMZ5(); BinaryDataMZ5(const BinaryDataMZ5&); BinaryDataMZ5& operator=(const BinaryDataMZ5&); ~BinaryDataMZ5(); void init(const ParamListMZ5& xParams, const ParamListMZ5& yParams, const RefMZ5& refDPx, const RefMZ5& refDPy); static CompType getType(); }; struct CVRefItem { int group; //0=MS, 1=UO, don't know what others there are. int ref; }; class mzpMz5Config{ public: mzpMz5Config(); ~mzpMz5Config(); static bool PRINT_HDF5_EXCEPTIONS; const bool doFiltering() const; const bool doTranslating() const; const size_t getBufferInB(); const DataType& getDataTypeFor(const MZ5DataSets v); const string& getNameFor(const MZ5DataSets v); const size_t& getRdccSlots(); MZ5DataSets getVariableFor(const string& name); void setFiltering(const bool flag) const; void setTranslating(const bool flag) const; protected: private: size_t bufferInMB_; ChromatogramLoadPolicy chromatogramLoadPolicy_; int deflateLvl_; mutable bool doFiltering_; mutable bool doTranslating_; size_t rdccSolts_; SpectrumLoadPolicy spectrumLoadPolicy_; map variableBufferSizes_; map variableChunkSizes_; map variableNames_; map variableTypes_; map variableVariables_; //Really? variableVariables? Was this written by Donald Rumsfeld? void init(const bool filter, const bool deltamz, const bool translateinten); }; class cMz5Index : public cindex { public: unsigned long cvStart; unsigned long cvLen; }; class mzpMz5Handler{ public: mzpMz5Handler(mzpMz5Config* c, BasicSpectrum* s); mzpMz5Handler(mzpMz5Config* c, BasicSpectrum* s, BasicChromatogram* bc); ~mzpMz5Handler(); void clean(const MZ5DataSets v, void* data, const size_t dsend); vector* getChromatIndex(); void getData(vector& data, const MZ5DataSets v, const hsize_t start, const hsize_t end); const map& getFields(); vector* getSpecIndex(); int highChromat(); int highScan(); int lowScan(); void processCVParams(unsigned long index); bool readChromatogram(int num=-1); void* readDataSet(const MZ5DataSets v, size_t& dsend, void* ptr=0); bool readFile(const string filename); bool readHeader(int num=-1); bool readSpectrum(int num=-1); protected: private: // mzpMz5Handler index data members. cMz5Index curIndex; f_off indexOffset; int m_scanIDXCount; vector m_vIndex; int posIndex; cMz5Index curChromatIndex; vector m_vChromatIndex; int posChromatIndex; map bufferMap_; BasicChromatogram* chromat; bool closed_; mzpMz5Config* config_; vector cvRef; vector cvParams_; map fields_; H5File* file_; BasicSpectrum* spec; }; #endif //------------------------------------------------ // RAMP API //------------------------------------------------ #define INSTRUMENT_LENGTH 2000 #define SCANTYPE_LENGTH 32 #define CHARGEARRAY_LENGTH 128 #define PRECURSORARRAY_LENGTH 512 typedef double RAMPREAL; typedef f_off ramp_fileoffset_t; typedef struct RAMPFILE{ BasicSpectrum* bs; mzpSAXMzmlHandler* mzML; mzpSAXMzxmlHandler* mzXML; #ifdef MZP_MZ5 mzpMz5Config* mz5Config; mzpMz5Handler* mz5; #endif int fileType; int bIsMzData; RAMPFILE(){ bs=NULL; mzML=NULL; mzXML=NULL; #ifdef MZP_MZ5 mz5=NULL; mz5Config=NULL; #endif fileType=0; bIsMzData=0; } ~RAMPFILE(){ if(bs!=NULL) delete bs; if(mzML!=NULL) delete mzML; if(mzXML!=NULL) delete mzXML; bs=NULL; mzML=NULL; mzXML=NULL; #ifdef MZP_MZ5 if(mz5!=NULL) delete mz5; if(mz5Config!=NULL) delete mz5Config; mz5=NULL; mz5Config=NULL; #endif } } RAMPFILE; static vector data_Ext; struct ScanHeaderStruct { int acquisitionNum; // scan number as declared in File (may be gaps) int mergedScan; // only if MS level > 1 int mergedResultScanNum; // scan number of the resultant merged scan int mergedResultStartScanNum; // smallest scan number of the scanOrigin for merged scan int mergedResultEndScanNum; // largest scan number of the scanOrigin for merged scan int msLevel; int numPossibleCharges; int peaksCount; int precursorCharge; // only if MS level > 1 int precursorCount; int precursorScanNum; // only if MS level > 1 int scanIndex; //a sequential index for non-sequential scan numbers (1-based) int seqNum; //number in sequence observed file (1-based) double basePeakIntensity; double basePeakMZ; double collisionEnergy; double compensationVoltage; // only if MS level > 1 double highMZ; double ionInjectionTime; double ionisationEnergy; double lowMZ; double precursorIntensity; // only if MS level > 1 double precursorMonoMZ; double precursorMZ; //only if MS level > 1 double retentionTime; //in seconds double selectionWindowLower; //the range of ions acquired double selectionWindowUpper; //in DDA, for example, +/-1 Da around precursor double totIonCurrent; char activationMethod[SCANTYPE_LENGTH]; char additionalPrecursors[PRECURSORARRAY_LENGTH]; char filterLine[CHARGEARRAY_LENGTH]; char idString[CHARGEARRAY_LENGTH]; char possibleCharges[SCANTYPE_LENGTH]; char scanType[SCANTYPE_LENGTH]; bool centroid; //true if spectrum is centroided bool possibleChargesArray[CHARGEARRAY_LENGTH]; /* NOTE: does NOT include "precursorCharge" information; only from "possibleCharges" */ ramp_fileoffset_t filePosition; /* where in the file is this header? */ }; struct RunHeaderStruct { int scanCount; double dEndTime; double dStartTime; double endMZ; double highMZ; double lowMZ; double startMZ; }; typedef struct InstrumentStruct { char manufacturer[INSTRUMENT_LENGTH]; char model[INSTRUMENT_LENGTH]; char ionisation[INSTRUMENT_LENGTH]; char analyzer[INSTRUMENT_LENGTH]; char detector[INSTRUMENT_LENGTH]; } InstrumentStruct; struct ScanCacheStruct { int seqNumStart; // scan at which the cache starts int size; // number of scans in the cache struct ScanHeaderStruct *headers; RAMPREAL **peaks; }; int checkFileType(const char* fname); ramp_fileoffset_t getIndexOffset(RAMPFILE *pFI); InstrumentStruct* getInstrumentStruct(RAMPFILE *pFI); void getPrecursor(const struct ScanHeaderStruct *scanHeader, int index, double &mz, double &monoMZ, double &intensity, int &charge, int &possibleCharges, int *&possibleChargeArray); void getScanSpanRange(const struct ScanHeaderStruct *scanHeader, int *startScanNum, int *endScanNum); void rampCloseFile(RAMPFILE *pFI); string rampConstructInputFileName(const string &basename); char* rampConstructInputFileName(char *buf,int buflen,const char *basename); char* rampConstructInputPath(char *buf, int inbuflen, const char *dir_in, const char *basename); const char** rampListSupportedFileTypes(); RAMPFILE* rampOpenFile(const char *filename); char* rampValidFileType(const char *buf); void readHeader(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex, struct ScanHeaderStruct *scanHeader); void readHeader(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex, struct ScanHeaderStruct *scanHeader, unsigned long scanI); ramp_fileoffset_t* readIndex(RAMPFILE *pFI, ramp_fileoffset_t indexOffset, int *iLastScan); int readMsLevel(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex); void readMSRun(RAMPFILE *pFI, struct RunHeaderStruct *runHeader); RAMPREAL* readPeaks(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex); RAMPREAL* readPeaks(RAMPFILE* pFI, ramp_fileoffset_t lScanIndex, unsigned long scanI); int readPeaksCount(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex); int readPeaksCount(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex, unsigned long scanI); void readRunHeader(RAMPFILE *pFI, ramp_fileoffset_t *pScanIndex, struct RunHeaderStruct *runHeader, int iLastScan); //MH:Cached RAMP functions void clearScanCache(struct ScanCacheStruct* cache); void freeScanCache(struct ScanCacheStruct* cache); int getCacheIndex(struct ScanCacheStruct* cache, int seqNum); struct ScanCacheStruct* getScanCache(int size); const struct ScanHeaderStruct* readHeaderCached(struct ScanCacheStruct* cache, int seqNum, RAMPFILE* pFI, ramp_fileoffset_t lScanIndex); int readMsLevelCached(struct ScanCacheStruct* cache, int seqNum, RAMPFILE* pFI, ramp_fileoffset_t lScanIndex); const RAMPREAL* readPeaksCached(struct ScanCacheStruct* cache, int seqNum, RAMPFILE* pFI, ramp_fileoffset_t lScanIndex); void shiftScanCache(struct ScanCacheStruct* cache, int nScans); //MH:Unimplimented functions. These just bark cerr when used. int isScanAveraged(struct ScanHeaderStruct *scanHeader); int isScanMergedResult(struct ScanHeaderStruct *scanHeader); int rampSelfTest(char *filename); char* rampTrimBaseName(char *buf); int rampValidateOrDeriveInputFilename(char *inbuf, int inbuflen, char *spectrumName); double readStartMz(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex); double readEndMz(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex); void setRampOption(long option); //------------------------------------------------ // PWiz API //------------------------------------------------ class Chromatogram{ public: Chromatogram(); ~Chromatogram(); BasicChromatogram* bc; string id; void getTimeIntensityPairs(vector& v); }; typedef class Chromatogram* ChromatogramPtr; class ChromatogramList{ public: ChromatogramList(); ChromatogramList(mzpSAXMzmlHandler* ml, void* m5, BasicChromatogram* bc); ~ChromatogramList(); ChromatogramPtr chromatogram(int index, bool binaryData = false); bool get(); size_t size(); vector* vChromatIndex; #ifdef MZP_MZ5 vector* vMz5Index; #endif private: mzpSAXMzmlHandler* mzML; #ifdef MZP_MZ5 mzpMz5Handler* mz5; #endif ChromatogramPtr chromat; }; typedef class ChromatogramList* ChromatogramListPtr; class PwizRun{ public: PwizRun(); PwizRun(mzpSAXMzmlHandler* ml, void* m5, BasicChromatogram* b); ~PwizRun(); ChromatogramListPtr chromatogramListPtr; void set(mzpSAXMzmlHandler* ml, void* m5, BasicChromatogram* b); private: mzpSAXMzmlHandler* mzML; #ifdef MZP_MZ5 mzpMz5Handler* mz5; #endif BasicChromatogram* bc; }; class MSDataFile{ public: MSDataFile(string s); ~MSDataFile(); PwizRun run; private: BasicSpectrum* bs; BasicChromatogram* bc; mzpSAXMzmlHandler* mzML; #ifdef MZP_MZ5 mzpMz5Config* mz5Config; mzpMz5Handler* mz5; #endif }; //------------------------------------------------ // MzParser Interface //------------------------------------------------ class MzParser { public: //Constructors and Destructors MzParser(BasicSpectrum* s); MzParser(BasicSpectrum* s, BasicChromatogram* c); ~MzParser(); //User functions vector* getChromatIndex(); int highChromat(); int highScan(); bool load(char* fname); int lowScan(); bool readChromatogram(int num=-1); bool readSpectrum(int num=-1); bool readSpectrumHeader(int num=-1); protected: mzpSAXMzmlHandler* mzML; mzpSAXMzxmlHandler* mzXML; #ifdef MZP_MZ5 mzpMz5Handler* mz5; mzpMz5Config* mz5Config; #endif private: //private functions int checkFileType(char* fname); //private data members BasicChromatogram* chromat; int fileType; BasicSpectrum* spec; }; #endif libmstoolkit-cleaned-82/include/Spectrum.h0000644000175000017500000001473313210260002020730 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _SPECTRUM_H #define _SPECTRUM_H #include "MSToolkitTypes.h" #include #include #include #include using namespace std; namespace MSToolkit { class Spectrum { public: //Constructors & Destructors Spectrum(); Spectrum(char*); Spectrum(char, unsigned int); Spectrum(const Spectrum&); ~Spectrum(); //Operator Functions Spectrum& operator=(const Spectrum&); Peak_T& operator[](const int&); //Functions void add(Peak_T&); void add(double,float); void addEZState(int,double,float,float); void addEZState(EZState&); void addMZ(double, double mono=0); void addZState(int,double); void addZState(ZState&); Peak_T& at(const int&); Peak_T& at(const unsigned int&); EZState& atEZ(const int&); EZState& atEZ(const unsigned int&); ZState& atZ(const int&); ZState& atZ(const unsigned int&); void clear(); void clearMZ(); void clearPeaks(); void erase(unsigned int); void erase(unsigned int, unsigned int); void eraseEZ(unsigned int); void eraseEZ(unsigned int, unsigned int); void eraseZ(unsigned int); void eraseZ(unsigned int, unsigned int); MSActivation getActivationMethod(); float getArea(); float getBPI(); double getBPM(); int getCentroidStatus(); int getCharge(); double getCompensationVoltage(); double getConversionA(); double getConversionB(); double getConversionC(); double getConversionD(); double getConversionE(); double getConversionI(); MSSpectrumType getFileType(); float getIonInjectionTime(); double getMonoMZ(int index=0); double getMZ(int index=0); bool getNativeID(char*,int); bool getRawFilter(char*,int,bool bLock=false); float getRTime(); float getRTimeApex(); int getScanNumber(bool second=false); double getScanWindowLower(); double getScanWindowUpper(); double getSelWindowLower(); double getSelWindowUpper(); double getTIC(); int getMsLevel(); void setActivationMethod(MSActivation); void setArea(float); void setBPI(float); void setBPM(double); void setCentroidStatus(int); void setCharge(int); void setCompensationVoltage(double); void setConversionA(double); void setConversionB(double); void setConversionC(double); void setConversionD(double); void setConversionE(double); void setConversionI(double); void setFileType(MSSpectrumType); void setIonInjectionTime(float); void setMZ(double, double mono=0); void setNativeID(char*); void setRawFilter(char*); void setRTime(float); void setRTimeApex(float); void setScanNumber(int, bool second=false); void setScanWindow(double lower, double upper); //the mass range of the spectrum void setSelWindow(double lower, double upper); //the mass range of the selected/acquired ions void setTIC(double); void setMsLevel(int level); int size(); int sizeEZ(); int sizeMZ(); //also returns size of monoMZ int sizeZ(); void sortIntensity(); void sortIntensityRev(); void sortMZ(); void setPeaks( std::vector peaks); void sortMZRev(); //for sqlite format void setScanID(int scanID); int getScanID(); //const vector* getPeaks(); vector* getPeaks(); //void setPeaks(vector peaks); float getTotalIntensity(); //for debugging void printMe(); protected: //Data Members vector *vPeaks; vector *vEZ; //extended z-lines with charge state, M+H, and peak information. vector *vZ; //presumed charge states and M+H; M can be monoisotopic or selected. int charge; float rTime; int scanNumber; int scanNumber2; int msLevel; vector *monoMZ; //the monoisotopic m/z of the selected ion(s) vector *mz; //the selected ion(s) in m/z MSSpectrumType fileType; MSActivation actMethod; int scanID; //index for sqlite float IIT; float BPI; //Base Peak Intensity double compensationVoltage; double convA; double convB; double convC; double convD; double convE; double convI; double selectionWinLower; double selectionWinUpper; double TIC; double BPM; //Base Peak Mass float rTimeApex; //retention time of precursor apex (MS2) float area; //summed peak areas of precursor (MS2) char nativeID[256]; //spectrumNativeID in mzML files char rawFilter[256]; //RAW file header line int centroidStatus; //0=profile, 1=centroid, 2=unknown double scanWinLower; //the instrument spectrum m/z range double scanWinUpper; //the instrument spectrum m/z range //private: //Functions static int compareIntensity(const void *p1,const void *p2); static int compareMZ(const void *p1,const void *p2); static int compareIntensityRev(const void *p1,const void *p2); static int compareMZRev(const void *p1,const void *p2); }; } #endif libmstoolkit-cleaned-82/include/mzMLWriter.h0000644000175000017500000001014113210260002021167 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _MZMLWRITER_H #define _MZMLWRITER_H #include #include #include "MSObject.h" #include "MSReader.h" #include "Spectrum.h" #include "mzParser.h" using namespace std; namespace MSToolkit { typedef struct sMzMLIndex{ string id; f_off offset; } sMzMLIndex; class MzMLWriter { public: MzMLWriter(); ~MzMLWriter(); bool closeList(); //false is chromatogram list bool closeMzML(); bool createList(bool specList=true); //false is chromatogram list bool createMzML(char* fn); int checkState(); void setNumpress(bool b); void setTabs(bool b); void setZlib(bool b); bool writeRunInformation(); bool writeSpectra(MSObject& o); bool writeSpectra(Spectrum& s); bool writeChromatogram(BasicChromatogram& c); bool writeIndex(); private: bool exportActivation(Spectrum& s, int tabs=0); bool exportAnalyzer(); bool exportBinary(char* str, int len, int tabs=0); bool exportBinaryDataArray(BasicChromatogram& c, bool bRT, int tabs = 0); bool exportBinaryDataArray(Spectrum& s, bool bMZ, int tabs=0); bool exportBinaryDataArrayList(BasicChromatogram& c, int tabs = 0); bool exportBinaryDataArrayList(Spectrum& s, int tabs=0); bool exportChromatogram(BasicChromatogram& c, int tabs); bool exportChromatogramList(); bool exportComponentList(); bool exportContact(); bool exportCv(); bool exportCvList(); bool exportCvParam(string ac, string ref, string name, string unitAc="", string unitRef="", string unitName="", string value="", int tabs=0); bool exportDataProcessing(); bool exportDataProcessingList(); bool exportFileContent(); bool exportFileDescription(); bool exportInstrumentConfiguration(); bool exportInstrumentConfigurationList(); bool exportIsolationWindow(BasicChromatogram& c, bool bPre, int tabs = 0); bool exportIsolationWindow(Spectrum& s, int tabs=0); bool exportMzML(); bool exportOffset(string idRef, f_off offset, int tabs=0); bool exportPrecursor(BasicChromatogram& c, int tabs = 0); bool exportPrecursor(Spectrum& s, int tabs=0); bool exportPrecursorList(Spectrum& s, int tabs=0); bool exportProcessingMethod(); bool exportProduct(BasicChromatogram&c, int tabs = 0); bool exportProductList(); bool exportReferencableParamGroup(); bool exportReferenceableParamGroupList(); bool exportReferenceableParamGroupRef(); bool exportRun(); bool exportSample(); bool exportSampleList(); bool exportScan(Spectrum& s, int tabs=0); bool exportScanList(Spectrum& s, int tabs=0); bool exportScanSettings(); bool exportScanSettingsList(); bool exportScanWindow(Spectrum& s, int tabs = 0); bool exportScanWindowList(Spectrum& s, int tabs = 0); bool exportSelectedIon(BasicChromatogram& c, int tabs = 0); bool exportSelectedIon(Spectrum& s, int tabs=0); bool exportSelectedIonList(BasicChromatogram& c, int tabs = 0); bool exportSelectedIonList(Spectrum& s, int tabs=0); bool exportSoftware(); bool exportSoftwareList(); bool exportSoftwareRef(); bool exportSource(); bool exportSouceFile(); bool exportSourceFileList(); bool exportSourceFileRef(); bool exportSourceFileRefList(); bool exportSpectrum(Spectrum& s, int tabs=0); bool exportSpectrumList(); void exportTabs(int tabs); bool exportTarget(); bool exportTargetList(); bool exportDetector(); bool exportUserParam(); int index; int chromIndex; FILE* fptr; f_off fSpecList; f_off fChromList; int iSpecList; int iChromList; bool bTabs; bool bFileOpen; bool bZlib; bool bNumpress; vector vIndex; vector vChromIndex; }; } #endif libmstoolkit-cleaned-82/include/pepXMLWriter.h0000644000175000017500000003100313210260002021455 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #ifndef _PEPXMLWRITER_H #define _PEPXMLWRITER_H #include #include #include #include #include #include using namespace std; //Some simple data structures for PepXMLWriter (pxw) typedef struct pxwBasicXMLTag { string name; string value; } pxwBasicXMLTag; typedef struct pxwModAA{ int position; double mass; } pxwModAA; typedef struct pxwMSMSRunSummary { string base_name; string raw_data_type; string raw_data; string search_engine; } pxwMSMSRunSummary; typedef struct pxwProtein { string protein; char peptide_next_aa; char peptide_prev_aa; } pxwProtein; //Use classes for more complicated structures with dynamic arrays //and additional fuctions. class PXWModInfo{ public: double mod_cterm_mass; double mod_nterm_mass; string modified_peptide; PXWModInfo(){ mod_cterm_mass=0; mod_nterm_mass=0; modified_peptide.clear(); mods=new vector; } PXWModInfo(const PXWModInfo& s){ mod_cterm_mass=s.mod_cterm_mass; mod_nterm_mass=s.mod_nterm_mass; modified_peptide = s.modified_peptide; mods=new vector; for(size_t i=0;isize();i++) mods->push_back(s.mods->at(i)); } ~PXWModInfo(){ delete mods; } PXWModInfo& operator=(const PXWModInfo& s){ if(this!=&s){ mod_cterm_mass = s.mod_cterm_mass; mod_nterm_mass = s.mod_nterm_mass; modified_peptide = s.modified_peptide; delete mods; mods=new vector; for(size_t i=0;isize();i++) mods->push_back(s.mods->at(i)); } return *this; } void addMod(pxwModAA& p){ mods->push_back(p); } void addMod(int pos, double mass){ pxwModAA p; p.position=pos; p.mass=mass; addMod(p); } void clear(){ mod_cterm_mass=0; mod_nterm_mass=0; modified_peptide.clear(); mods->clear(); } pxwModAA& getMod(int index){ return mods->at(index); } pxwModAA& getMod(size_t index){ return mods->at(index); } size_t sizeMods(){ return mods->size(); } private: vector* mods; }; class PXWSearchSummary { public: string base_name; string search_database; string search_engine; string search_engine_version; int precursor_mass_type; //0=monoisotopic, 1=average int fragment_mass_type; //0=monoisotopic, 1=average vector* parameters; PXWSearchSummary(){ base_name.clear(); search_database.clear(); search_engine.clear(); search_engine_version.clear(); precursor_mass_type=0; fragment_mass_type=0; parameters=new vector; } PXWSearchSummary(const PXWSearchSummary& s){ base_name=s.base_name; search_database=s.search_database; search_engine=s.search_engine; search_engine_version=s.search_engine_version; precursor_mass_type=s.precursor_mass_type; fragment_mass_type=s.fragment_mass_type; parameters=new vector; for(size_t i=0;isize();i++) parameters->push_back(s.parameters->at(i)); } ~PXWSearchSummary(){ delete parameters; } PXWSearchSummary& operator=(const PXWSearchSummary& s){ if(this!=&s){ base_name=s.base_name; search_database = s.search_database; search_engine=s.search_engine; search_engine_version=s.search_engine_version; precursor_mass_type=s.precursor_mass_type; fragment_mass_type=s.fragment_mass_type; delete parameters; parameters=new vector; for(size_t i=0;isize();i++) parameters->push_back(s.parameters->at(i)); } return *this; } }; class PXWSearchHit { public: int hit_rank; string peptide; int num_tot_proteins; double calc_neutral_pep_mass; double calc_neutral_xl_mass; double massdiff; double xl_massdiff; PXWModInfo modInfo; string xlink_type; //na,loop,xl PXWSearchHit(){ hit_rank=0; peptide.clear(); num_tot_proteins=0; calc_neutral_pep_mass=0; calc_neutral_xl_mass=0; massdiff=0; xl_massdiff=0; modInfo.clear(); xlink_type="na"; proteins=new vector; searchScores=new vector; xlScores=new vector; } PXWSearchHit(const PXWSearchHit& s){ size_t i; hit_rank=s.hit_rank; peptide=s.peptide; num_tot_proteins=s.num_tot_proteins; calc_neutral_pep_mass=s.calc_neutral_pep_mass; calc_neutral_xl_mass=s.calc_neutral_xl_mass; massdiff=s.massdiff; xl_massdiff=s.xl_massdiff; modInfo=s.modInfo; xlink_type=s.xlink_type; proteins=new vector; searchScores=new vector; xlScores=new vector; for(i=0;isize();i++) proteins->push_back(s.proteins->at(i)); for(i=0;isize();i++) searchScores->push_back(s.searchScores->at(i)); for(i=0;isize();i++) xlScores->push_back(s.xlScores->at(i)); } ~PXWSearchHit(){ delete proteins; delete searchScores; delete xlScores; } PXWSearchHit& operator=(const PXWSearchHit& s){ if(this!=&s){ size_t i; hit_rank=s.hit_rank; peptide=s.peptide; num_tot_proteins=s.num_tot_proteins; calc_neutral_pep_mass=s.calc_neutral_pep_mass; calc_neutral_xl_mass=s.calc_neutral_xl_mass; massdiff=s.massdiff; xl_massdiff=s.xl_massdiff; modInfo=s.modInfo; xlink_type=s.xlink_type; delete proteins; delete searchScores; delete xlScores; proteins=new vector; searchScores=new vector; xlScores=new vector; for(i=0;isize();i++) proteins->push_back(s.proteins->at(i)); for(i=0;isize();i++) searchScores->push_back(s.searchScores->at(i)); for(i=0;isize();i++) xlScores->push_back(s.xlScores->at(i)); } return *this; } void addProtein(pxwProtein& p){ proteins->push_back(p); } void addProtein(char* protein, char peptide_next_aa, char peptide_prev_aa){ pxwProtein p; p.protein=protein; p.peptide_next_aa=peptide_next_aa; p.peptide_prev_aa=peptide_prev_aa; addProtein(p); } void addProtein(string& protein, char peptide_next_aa, char peptide_prev_aa){ pxwProtein p; p.protein=protein; p.peptide_next_aa=peptide_next_aa; p.peptide_prev_aa=peptide_prev_aa; addProtein(p); } void addScore(pxwBasicXMLTag& s){ searchScores->push_back(s); } void addScore(const char* name, const char* value){ pxwBasicXMLTag x; x.name=name; x.value=value; addScore(x); } void addScore(string& name, string& value){ pxwBasicXMLTag x; x.name=name; x.value=value; addScore(x); } void addXLScore(pxwBasicXMLTag& s){ xlScores->push_back(s); } void addXLScore(const char* name, const char* value){ pxwBasicXMLTag x; x.name=name; x.value=value; addXLScore(x); } void addXLScore(string& name, string& value){ pxwBasicXMLTag x; x.name=name; x.value=value; addXLScore(x); } void clear(){ hit_rank=0; peptide.clear(); num_tot_proteins=0; calc_neutral_pep_mass=0; calc_neutral_xl_mass=0; massdiff=0; xl_massdiff=0; xlink_type="na"; modInfo.clear(); proteins->clear(); searchScores->clear(); xlScores->clear(); } pxwProtein& getProtein(int index){ return proteins->at(index); } pxwProtein& getProtein(size_t index){ return proteins->at(index); } pxwBasicXMLTag& getScore(int index){ return searchScores->at(index); } pxwBasicXMLTag& getScore(size_t index){ return searchScores->at(index); } pxwBasicXMLTag& getXLScore(int index){ return xlScores->at(index); } pxwBasicXMLTag& getXLScore(size_t index){ return xlScores->at(index); } size_t sizeProteins(){ return proteins->size(); } size_t sizeScores(){ return searchScores->size(); } size_t sizeXLScores(){ return xlScores->size(); } private: vector* proteins; vector* searchScores; vector* xlScores; }; typedef struct pxwSearchHitPair{ PXWSearchHit* a; PXWSearchHit* b; string identifier; double mass; pxwSearchHitPair(){ a=NULL; b=NULL; identifier.clear(); mass=0; } pxwSearchHitPair(const pxwSearchHitPair& p){ a=NULL; b=NULL; identifier=p.identifier; mass=p.mass; if(p.a!=NULL) { a=new PXWSearchHit(); *a=*p.a; } if(p.b!=NULL){ b=new PXWSearchHit(); *b=*p.b; } } ~pxwSearchHitPair(){ if(a!=NULL) delete a; if(b!=NULL) delete b; } pxwSearchHitPair& operator=(const pxwSearchHitPair& p){ if(this!=&p){ if(a!=NULL) delete a; if(b!=NULL) delete b; a=NULL; b=NULL; identifier=p.identifier; mass=p.mass; if(p.a!=NULL) { a=new PXWSearchHit(); *a=*p.a; } if(p.b!=NULL){ b=new PXWSearchHit(); *b=*p.b; } } return *this; } } pxwSearchHitPair; typedef struct pxwSampleEnzyme{ string name; string cut; string no_cut; string sense; int maxNumInternalCleavages; int minNumTermini; } pxwSampleEnzyme; class PXWSpectrumQuery { public: string spectrum; int start_scan; int end_scan; double retention_time_sec; double precursor_neutral_mass; int assumed_charge; PXWSpectrumQuery(){ spectrum.clear(); start_scan=0; end_scan=0; retention_time_sec=0; precursor_neutral_mass=0; assumed_charge=0; searchHits=new vector; } PXWSpectrumQuery(const PXWSpectrumQuery& s){ spectrum=s.spectrum; start_scan=s.start_scan; end_scan=s.end_scan; retention_time_sec=s.retention_time_sec; precursor_neutral_mass=s.precursor_neutral_mass; assumed_charge=s.assumed_charge; searchHits=new vector; for(size_t i=0;isize();i++) searchHits->push_back(s.searchHits->at(i)); } ~PXWSpectrumQuery(){ delete searchHits; } PXWSpectrumQuery& operator=(const PXWSpectrumQuery& s){ if(this!=&s){ spectrum=s.spectrum; start_scan=s.start_scan; end_scan=s.end_scan; retention_time_sec=s.retention_time_sec; precursor_neutral_mass=s.precursor_neutral_mass; assumed_charge=s.assumed_charge; delete searchHits; searchHits=new vector; for(size_t i=0;isize();i++) searchHits->push_back(s.searchHits->at(i)); } return *this; } void addSearchHit(PXWSearchHit* s, PXWSearchHit* s2=NULL, string* xl=NULL, double* xlMass=NULL){ pxwSearchHitPair p; p.a = new PXWSearchHit(*s); if(s2!=NULL) { if(xl==NULL || xlMass==NULL){ printf("PXWSpectrumQuery.addSearchHit(): cross-linked peptides must contain linker and mass. Exiting.\n"); exit(-4); } p.b = new PXWSearchHit(*s2); } if(xl!=NULL) p.identifier=*xl; if(xlMass!=NULL) p.mass=*xlMass; searchHits->push_back(p); } void clear(){ searchHits->clear(); } pxwSearchHitPair& getSearchHit(int index){ return searchHits->at(index); } pxwSearchHitPair& getSearchHit(size_t index){ return searchHits->at(index); } size_t sizeSearchHits(){ return searchHits->size(); } private: vector* searchHits; }; class PepXMLWriter { public: PepXMLWriter(); ~PepXMLWriter(); void closePepXML (); bool createPepXML (char* fn, pxwMSMSRunSummary& run, pxwSampleEnzyme* enzyme=NULL, PXWSearchSummary* search=NULL); void writeSpectrumQuery (PXWSpectrumQuery& s); private: void addTab (); void deleteTab (); void resetTabs (); void writeAltProtein (pxwProtein& s); void writeModAAMass (pxwModAA& s); void writeModInfo (PXWModInfo& s); void writeLine (const char* str); void writeLinkedPeptide (PXWSearchHit& s, bool alpha=true); void writeSearchHit (pxwSearchHitPair& s); int index; int iTabs; int spQueryIndex; FILE* fptr; bool bTabs; bool bFileOpen; char strTabs[128]; vector vTagState; }; #endif libmstoolkit-cleaned-82/src/0000755000175000017500000000000013210260002016111 5ustar rusconirusconilibmstoolkit-cleaned-82/src/mzParser/0000755000175000017500000000000013210260002017714 5ustar rusconirusconilibmstoolkit-cleaned-82/src/mzParser/BasicChromatogram.cpp0000644000175000017500000000517313210260002024013 0ustar rusconirusconi#include "mzParser.h" BasicChromatogram::BasicChromatogram(){} BasicChromatogram::BasicChromatogram(const BasicChromatogram& c){ vData.clear(); charge=c.charge; precursorMZ=c.precursorMZ; precursorOffsetLower=c.precursorOffsetLower; precursorOffsetUpper=c.precursorOffsetUpper; productMZ=c.productMZ; productOffsetLower=c.productOffsetLower; productOffsetUpper=c.productOffsetUpper; for(unsigned int i=0;i& BasicChromatogram::getData() { return vData; } int BasicChromatogram::getIDString(char* str){ strcpy(str,idString); return (int)strlen(str); } double BasicChromatogram::getPreMZ(){ return precursorMZ;} double BasicChromatogram::getPreOffsetLower(){ return precursorOffsetLower; } double BasicChromatogram::getPreOffsetUpper(){ return precursorOffsetUpper; } double BasicChromatogram::getProdMZ(){ return productMZ; } double BasicChromatogram::getProdOffsetLower(){return productOffsetLower;} double BasicChromatogram::getProdOffsetUpper(){ return productOffsetUpper; } void BasicChromatogram::setIDString(char* str) { strcpy(idString,str); } void BasicChromatogram::setPrecursor(double mz, int z, double offLow, double offHigh){ precursorMZ=mz; charge=z; precursorOffsetLower=offLow; precursorOffsetUpper=offHigh; } void BasicChromatogram::setProduct(double mz, double offLow, double offHigh){ productMZ = mz; productOffsetLower = offLow; productOffsetUpper = offHigh; } size_t BasicChromatogram::size(){ return vData.size(); } libmstoolkit-cleaned-82/src/mzParser/mzParser.cpp0000644000175000017500000001145513210260002022231 0ustar rusconirusconi#include "mzParser.h" MzParser::MzParser(BasicSpectrum* s){ spec=s; fileType=0; mzML=NULL; mzXML=NULL; #ifdef MZP_MZ5 mz5=NULL; mz5Config=NULL; #endif } MzParser::MzParser(BasicSpectrum* s, BasicChromatogram* c){ spec=s; chromat=c; fileType=0; mzML=NULL; mzXML=NULL; #ifdef MZP_MZ5 mz5=NULL; mz5Config=NULL; #endif } MzParser::~MzParser(){ spec=NULL; chromat=NULL; if(mzML!=NULL) delete mzML; if(mzXML!=NULL) delete mzXML; #ifdef MZP_MZ5 if(mz5!=NULL) delete mz5; if(mz5Config!=NULL) delete mz5Config; #endif } vector* MzParser::getChromatIndex(){ switch (fileType){ case 1: case 3: return mzML->getChromatIndex(); break; case 2: case 4: return NULL; break; #ifdef MZP_MZ5 case 5: return NULL; break; #endif default: break; } return NULL; } int MzParser::highChromat(){ switch(fileType){ case 1: case 3: return mzML->highChromat(); break; case 2: case 4: return 0; break; #ifdef MZP_MZ5 case 5: return mz5->highChromat(); break; #endif default: break; } return 0; } int MzParser::highScan(){ switch(fileType){ case 1: case 3: return mzML->highScan(); break; case 2: case 4: return mzXML->highScan(); break; #ifdef MZP_MZ5 case 5: return mz5->highScan(); break; #endif default: break; } return 0; } bool MzParser::load(char* fname){ if(mzML!=NULL) { delete mzML; mzML=NULL; } if(mzXML!=NULL) { delete mzXML; mzXML=NULL; } #ifdef MZP_MZ5 if(mz5!=NULL) { delete mz5; delete mz5Config; mz5=NULL; mz5Config=NULL; } #endif fileType=checkFileType(fname); switch(fileType){ case 1: case 3: mzML = new mzpSAXMzmlHandler(spec,chromat); if(fileType==3) mzML->setGZCompression(true); else mzML->setGZCompression(false); return mzML->load(fname); break; case 2: case 4: mzXML = new mzpSAXMzxmlHandler(spec); if(fileType==4) mzXML->setGZCompression(true); else mzXML->setGZCompression(false); return mzXML->load(fname); break; #ifdef MZP_MZ5 case 5: mz5Config = new mzpMz5Config(); mz5 = new mzpMz5Handler(mz5Config,spec,chromat); return mz5->readFile(fname); break; #endif default: break; } return false; } int MzParser::lowScan(){ switch(fileType){ case 1: case 3: return mzML->lowScan(); break; case 2: case 4: return mzXML->lowScan(); break; #ifdef MZP_MZ5 case 5: return mz5->lowScan(); break; #endif default: break; } return 0; } bool MzParser::readChromatogram(int num){ switch(fileType){ case 1: case 3: return mzML->readChromatogram(num); break; #ifdef MZP_MZ5 case 5: return mz5->readChromatogram(num); break; #endif default: break; } return false; } bool MzParser::readSpectrum(int num){ switch(fileType){ case 1: case 3: return mzML->readSpectrum(num); break; case 2: case 4: return mzXML->readSpectrum(num); break; #ifdef MZP_MZ5 case 5: return mz5->readSpectrum(num); break; #endif default: break; } return false; } bool MzParser::readSpectrumHeader(int num){ switch(fileType){ case 1: case 3: return mzML->readHeader(num); break; case 2: case 4: return mzXML->readHeader(num); break; #ifdef MZP_MZ5 case 5: return mz5->readHeader(num); break; #endif default: break; } return false; } int MzParser::checkFileType(char* fname){ char file[256]; char ext[256]; char *tok; char preExt[256]; unsigned int i; strcpy(ext,""); strcpy(file,fname); tok=strtok(file,".\n"); while(tok!=NULL){ strcpy(preExt,ext); strcpy(ext,tok); tok=strtok(NULL,".\n"); } for(i=0;ilist); free(index); index=NULL; } } /* Add an entry to the access point list. If out of memory, deallocate the existing list and return NULL. */ gz_access * Czran::addpoint(int bits,f_off in, f_off out, unsigned left, unsigned char *window) { point *next; /* if list is empty, create it (start with eight points) */ if (index == NULL) { index = (gz_access*)malloc(sizeof(gz_access)); if (index == NULL) return NULL; index->list = (point*)malloc(sizeof(point) << 3); if (index->list == NULL) { free(index); return NULL; } index->size = 8; index->have = 0; } /* if list is full, make it bigger */ else if (index->have == index->size) { index->size <<= 1; next = (point*)realloc(index->list, sizeof(point) * index->size); if (next == NULL) { free_index(); return NULL; } index->list = next; } /* fill in entry and increment how many we have */ next = index->list + index->have; next->bits = bits; next->in = in; next->out = out; if (left) memcpy(next->window, window + WINSIZE - left, left); if (left < WINSIZE) memcpy(next->window + left, window, WINSIZE - left); index->have++; /* return list, possibly reallocated */ return index; } /* Make one entire pass through the compressed stream and build an index, with access points about every span bytes of uncompressed output -- span is chosen to balance the speed of random access against the memory requirements of the list, about 32K bytes per access point. Note that data after the end of the first zlib or gzip stream in the file is ignored. build_index() returns the number of access points on success (>= 1), Z_MEM_ERROR for out of memory, Z_DATA_ERROR for an error in the input file, or Z_ERRNO for a file read error. On success, *built points to the resulting index. */ int Czran::build_index(FILE *in, f_off span){ return build_index(in,span,&index); } int Czran::build_index(FILE *in, f_off span, gz_access **built){ int ret; f_off totin, totout; /* our own total counters to avoid 4GB limit */ f_off last; /* totout value of last access point */ gz_access *index; /* access points being generated */ z_stream strm; unsigned char input[READCHUNK]; unsigned char window[WINSIZE]; /* initialize inflate */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit2(&strm, 47); /* automatic zlib or gzip decoding */ if (ret != Z_OK) return ret; /* inflate the input, maintain a sliding window, and build an index -- this also validates the integrity of the compressed data using the check information at the end of the gzip or zlib stream */ totin = totout = last = 0; index = NULL; /* will be allocated by first addpoint() */ strm.avail_out = 0; do { /* get some compressed data from input file */ strm.avail_in = fread(input, 1, READCHUNK, in); if (ferror(in)) { ret = Z_ERRNO; goto build_index_error; } if (strm.avail_in == 0) { ret = Z_DATA_ERROR; goto build_index_error; } strm.next_in = input; /* process all of that, or until end of stream */ do { /* reset sliding window if necessary */ if (strm.avail_out == 0) { strm.avail_out = WINSIZE; strm.next_out = window; } /* inflate until out of input, output, or at end of block -- update the total input and output counters */ totin += strm.avail_in; totout += strm.avail_out; ret = inflate(&strm, Z_BLOCK); /* return at end of block */ totin -= strm.avail_in; totout -= strm.avail_out; if (ret == Z_NEED_DICT) ret = Z_DATA_ERROR; if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) goto build_index_error; if (ret == Z_STREAM_END) break; /* if at end of block, consider adding an index entry (note that if data_type indicates an end-of-block, then all of the uncompressed data from that block has been delivered, and none of the compressed data after that block has been consumed, except for up to seven bits) -- the totout == 0 provides an entry point after the zlib or gzip header, and assures that the index always has at least one access point; we avoid creating an access point after the last block by checking bit 6 of data_type */ if ((strm.data_type & 128) && !(strm.data_type & 64) && (totout == 0 || totout - last > span)) { index = addpoint(strm.data_type & 7, totin, totout, strm.avail_out, window); if (index == NULL) { ret = Z_MEM_ERROR; goto build_index_error; } last = totout; } } while (strm.avail_in != 0); } while (ret != Z_STREAM_END); /* clean up and return index (release unused entries in list) */ fileSize=strm.total_out; (void)inflateEnd(&strm); index = (gz_access*)realloc(index, sizeof(point) * index->have); index->size = index->have; *built = index; return index->size; /* return error */ build_index_error: (void)inflateEnd(&strm); fileSize=0; if (index != NULL) free_index(); return ret; } /* Use the index to read len bytes from offset into buf, return bytes read or negative for error (Z_DATA_ERROR or Z_MEM_ERROR). If data is requested past the end of the uncompressed data, then extract() will return a value less than len, indicating how much as actually read into buf. This function should not return a data error unless the file was modified since the index was generated. extract() may also return Z_ERRNO if there is an error on reading or seeking the input file. */ int Czran::extract(FILE *in, f_off offset) { int ret, len; point *here; z_stream strm; unsigned char input[READCHUNK]; f_off marker; /* find where in stream to start */ here = index->list; ret = index->have; while (--ret && here[1].out <= offset) here++; if(ret>0) marker=here[1].out; else marker=0; /* initialize file and inflate state to start there */ strm.zalloc = Z_NULL; strm.zfree = Z_NULL; strm.opaque = Z_NULL; strm.avail_in = 0; strm.next_in = Z_NULL; ret = inflateInit2(&strm, -15); /* raw inflate */ if (ret != Z_OK) return ret; ret = mzpfseek(in, here->in - (here->bits ? 1 : 0), SEEK_SET); if (ret == -1) goto extract_ret; if (here->bits) { ret = getc(in); if (ret == -1) { ret = ferror(in) ? Z_ERRNO : Z_DATA_ERROR; goto extract_ret; } (void)inflatePrime(&strm, here->bits, ret >> (8 - here->bits)); } (void)inflateSetDictionary(&strm, here->window, WINSIZE); if(marker>0) len = (int)(marker-here->out); else len = (int)(fileSize-here->out); if(buffer!=NULL) free(buffer); buffer = (unsigned char*)malloc(len); if(buffer==NULL){ ret = Z_MEM_ERROR; goto extract_ret; } bufferOffset=here->out; strm.avail_in = 0; strm.avail_out = len; strm.next_out = buffer; /* uncompress until avail_out filled, or end of stream */ do { if (strm.avail_in == 0) { strm.avail_in = fread(input, 1, READCHUNK, in); if (ferror(in)) { ret = Z_ERRNO; goto extract_ret; } if (strm.avail_in == 0) { ret = Z_DATA_ERROR; goto extract_ret; } strm.next_in = input; } ret = inflate(&strm, Z_NO_FLUSH); /* normal inflate */ if (ret == Z_NEED_DICT) ret = Z_DATA_ERROR; if (ret == Z_MEM_ERROR || ret == Z_DATA_ERROR) goto extract_ret; if (ret == Z_STREAM_END) break; } while (strm.avail_out != 0); /* compute number of uncompressed bytes read after offset */ ret = len - strm.avail_out; /* clean up and return bytes read or error */ extract_ret: if(ret<0) bufferLen=0; else bufferLen=ret; (void)inflateEnd(&strm); return ret; } int Czran::extract(FILE *in, f_off offset, unsigned char *buf, int len){ int ret, seg; //see if request was to the last buffer //last buffer is only stored when it doesn't reside in large buffer if(lastBuffer!=NULL && offset==lastBufferOffset){ memcpy(buf,lastBuffer,lastBufferLen); return lastBufferLen; } //if we don't have the offset, grab it. if(buffer==NULL || offset=(bufferOffset+bufferLen)){ ret=extract(in,offset); } lastBufferOffset=offset; //check if we have all the requested bytes if( (offset+len) <= (bufferOffset+bufferLen) ){ memcpy(buf,buffer+(offset-bufferOffset),len); if(lastBuffer!=NULL){ free(lastBuffer); lastBuffer=NULL; } return len; } else { if(lastBuffer!=NULL) free(lastBuffer); lastBuffer=(unsigned char*)malloc(len); //otherwise grab what we can and try extending buffer seg=(int)(bufferLen-(offset-bufferOffset)); memcpy(buf,buffer+(offset-bufferOffset),seg); len-=seg; //get next block ret=extract(in,offset+seg); //add remaining bytes if(ret; vPrecursor=new vector; } BasicSpectrum::BasicSpectrum(const BasicSpectrum& s){ vData=new vector; vPrecursor=new vector; unsigned int i; for(i=0;isize();i++) vData->push_back(s.vData->at(i)); for(i=0;isize();i++) vPrecursor->push_back(s.vPrecursor->at(i)); //for(i=0;i<5;i++) precursorCharge[i] = s.precursorCharge[i]; activation=s.activation; basePeakIntensity=s.basePeakIntensity; basePeakMZ=s.basePeakMZ; centroid=s.centroid; highMZ=s.highMZ; ionInjectionTime=s.ionInjectionTime; lowMZ=s.lowMZ; msLevel=s.msLevel; peaksCount=s.peaksCount; positiveScan=s.positiveScan; //precursorChargeCount=s.precursorChargeCount; //precursorIntensity=s.precursorIntensity; compensationVoltage=s.compensationVoltage; //precursorMonoMZ=s.precursorMonoMZ; //precursorMZ=s.precursorMZ; precursorScanNum=s.precursorScanNum; rTime=s.rTime; scanIndex=s.scanIndex; scanNum=s.scanNum; totalIonCurrent=s.totalIonCurrent; strcpy(idString,s.idString); strcpy(filterLine,s.filterLine); } BasicSpectrum::~BasicSpectrum() { delete vData; delete vPrecursor; } //------------------------------------------ // Operator overloads //------------------------------------------ BasicSpectrum& BasicSpectrum::operator=(const BasicSpectrum& s){ if (this != &s) { delete vData; delete vPrecursor; vData=new vector; vPrecursor=new vector; unsigned int i; for(i=0;isize();i++) vData->push_back(s.vData->at(i)); for(i=0;isize();i++) vPrecursor->push_back(s.vPrecursor->at(i)); //for(i=0;i<5;i++) precursorCharge[i] = s.precursorCharge[i]; activation=s.activation; basePeakIntensity=s.basePeakIntensity; basePeakMZ=s.basePeakMZ; centroid=s.centroid; highMZ=s.highMZ; ionInjectionTime=s.ionInjectionTime; lowMZ=s.lowMZ; msLevel=s.msLevel; peaksCount=s.peaksCount; positiveScan=s.positiveScan; //precursorChargeCount=s.precursorChargeCount; //precursorIntensity=s.precursorIntensity; compensationVoltage=s.compensationVoltage; //precursorMonoMZ=s.precursorMonoMZ; //precursorMZ=s.precursorMZ; precursorScanNum=s.precursorScanNum; rTime=s.rTime; scanIndex=s.scanIndex; scanNum=s.scanNum; totalIonCurrent=s.totalIonCurrent; strcpy(filterLine,s.filterLine); strcpy(idString,s.idString); } return *this; } specDP& BasicSpectrum::operator[ ](const unsigned int index) { return vData->at(index); } //------------------------------------------ // Modifiers //------------------------------------------ void BasicSpectrum::addDP(specDP dp) { vData->push_back(dp);} void BasicSpectrum::clear(){ activation=none; basePeakIntensity=0.0; basePeakMZ=0.0; centroid=false; filterLine[0]='\0'; highMZ=0.0; idString[0]='\0'; ionInjectionTime=0.0; lowMZ=0.0; msLevel=1; peaksCount=0; positiveScan=true; //precursorCharge[0]=0; //precursorChargeCount=0; //precursorIntensity=0.0; compensationVoltage=0.0; //precursorMZ=0; precursorScanNum=-1; rTime=0.0f; scanIndex=0; scanNum=-1; totalIonCurrent=0.0; vData->clear(); vPrecursor->clear(); } void BasicSpectrum::setActivation(int a){ activation=a;} void BasicSpectrum::setBasePeakIntensity(double d){ basePeakIntensity=d;} void BasicSpectrum::setBasePeakMZ(double d){ basePeakMZ=d;} void BasicSpectrum::setCentroid(bool b){ centroid=b;} void BasicSpectrum::setCollisionEnergy(double d){ collisionEnergy=d;} void BasicSpectrum::setCompensationVoltage(double d){ compensationVoltage=d; } void BasicSpectrum::setFilterLine(char* str) { strncpy(filterLine,str,127); filterLine[127]='\0'; } void BasicSpectrum::setHighMZ(double d){ highMZ=d;} void BasicSpectrum::setIDString(char* str) { strncpy(idString,str,127); idString[127]='\0'; } void BasicSpectrum::setIonInjectionTime(double d){ ionInjectionTime=d;} void BasicSpectrum::setLowMZ(double d){ lowMZ=d;} void BasicSpectrum::setMSLevel(int level){ msLevel=level;} void BasicSpectrum::setPeaksCount(int i){ peaksCount=i;} void BasicSpectrum::setPositiveScan(bool b){ positiveScan=b;} void BasicSpectrum::setPrecursorIon(sPrecursorIon& p){ vPrecursor->push_back(p);} void BasicSpectrum::setPrecursorScanNum(int i){ precursorScanNum=i;} void BasicSpectrum::setRTime(float f){ rTime=f;} void BasicSpectrum::setScanIndex(int num) { scanIndex=num;} void BasicSpectrum::setScanNum(int num){ scanNum=num;} void BasicSpectrum::setTotalIonCurrent(double d){ totalIonCurrent=d;} //------------------------------------------ // Accessors //------------------------------------------ int BasicSpectrum::getActivation(){ return activation;} double BasicSpectrum::getBasePeakIntensity(){ return basePeakIntensity;} double BasicSpectrum::getBasePeakMZ(){ return basePeakMZ;} bool BasicSpectrum::getCentroid(){ return centroid;} double BasicSpectrum::getCollisionEnergy(){ return collisionEnergy;} double BasicSpectrum::getCompensationVoltage(){ return compensationVoltage;} int BasicSpectrum::getFilterLine(char* str) { strcpy(str,filterLine); return (int)strlen(str); } double BasicSpectrum::getHighMZ(){ return highMZ;} int BasicSpectrum::getIDString(char* str) { strcpy(str,idString); return (int)strlen(str); } double BasicSpectrum::getIonInjectionTime(){return ionInjectionTime;} double BasicSpectrum::getLowMZ(){ return lowMZ;} int BasicSpectrum::getMSLevel(){ return msLevel;} int BasicSpectrum::getPeaksCount(){ return peaksCount;} bool BasicSpectrum::getPositiveScan(){ return positiveScan;} int BasicSpectrum::getPrecursorCharge(int i){ //legacy function. Always returns first charge of requested precursor, or first charge of first precursor if (vPrecursor->size()==0) return 0; if (i>=vPrecursor->size()) return 0; return vPrecursor->at(i).charge; } //int BasicSpectrum::getPrecursorChargeCount(){ return precursorChargeCount;} //double BasicSpectrum::getPrecursorIntensity(){ return precursorIntensity;} //double BasicSpectrum::getPrecursorMonoMZ(){ return precursorMonoMZ;} double BasicSpectrum::getPrecursorMZ(int i){ //legacy function. Always returns first precursor mz if (vPrecursor->size()==0) return 0; if (i >= vPrecursor->size()) return 0; return vPrecursor->at(i).mz; } sPrecursorIon BasicSpectrum::getPrecursorIon(int i){ return vPrecursor->at(i); } int BasicSpectrum::getPrecursorIonCount() { return (int)vPrecursor->size(); } int BasicSpectrum::getPrecursorScanNum(){ return precursorScanNum;} float BasicSpectrum::getRTime(bool min){ if(min) return rTime; else return rTime*60; } int BasicSpectrum::getScanIndex(){ return scanIndex;} int BasicSpectrum::getScanNum(){ return scanNum;} double BasicSpectrum::getTotalIonCurrent(){ return totalIonCurrent;} size_t BasicSpectrum::size(){ return vData->size();} libmstoolkit-cleaned-82/src/mzParser/mzpMz5Structs.cpp0000644000175000017500000003744413210260002023226 0ustar rusconirusconi#include "mzParser.h" #ifdef MZP_MZ5 StrType getStringType() { StrType stringtype(PredType::C_S1, H5T_VARIABLE); return stringtype; } StrType getFStringType(const size_t len) { StrType stringtype(PredType::C_S1, len); return stringtype; } CompType BinaryDataMZ5::getType() { CompType ret(sizeof(BinaryDataMZ5)); size_t offset = 0; ret.insertMember("xParams", offset, ParamListMZ5::getType()); offset += ParamListMZ5::getType().getSize(); ret.insertMember("yParams", offset, ParamListMZ5::getType()); offset += ParamListMZ5::getType().getSize(); ret.insertMember("xrefDataProcessing", offset, RefMZ5::getType()); offset += RefMZ5::getType().getSize(); ret.insertMember("yrefDataProcessing", offset, RefMZ5::getType()); return ret; } CompType ChromatogramMZ5::getType() { CompType ret(sizeof(ChromatogramMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("precursor", offset, PrecursorMZ5::getType()); offset += sizeof(PrecursorMZ5); ret.insertMember("productIsolationWindow", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("refDataProcessing", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("index", offset, PredType::NATIVE_ULONG); offset += sizeof(unsigned long); return ret; } VarLenType ComponentListMZ5::getType() { CompType c = ComponentMZ5::getType(); VarLenType ret(&c); return ret; } CompType ComponentMZ5::getType() { CompType ret(sizeof(ComponentMZ5)); size_t offset = 0; ret.insertMember("paramList", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("order", offset, PredType::NATIVE_ULONG); return ret; } CompType ComponentsMZ5::getType() { CompType ret(sizeof(ComponentsMZ5)); size_t offset = 0; ret.insertMember("sources", offset, ComponentListMZ5::getType()); offset += sizeof(ComponentListMZ5); ret.insertMember("analyzers", offset, ComponentListMZ5::getType()); offset += sizeof(ComponentListMZ5); ret.insertMember("detectors", offset, ComponentListMZ5::getType()); return ret; } CompType ContVocabMZ5::getType() { CompType cvtype(sizeof(ContVocabMZ5Data)); StrType stringtype = getStringType(); cvtype.insertMember("uri", HOFFSET(ContVocabMZ5Data, uri), stringtype); cvtype.insertMember("fullname", HOFFSET(ContVocabMZ5Data, fullname), stringtype); cvtype.insertMember("id", HOFFSET(ContVocabMZ5Data, id), stringtype); cvtype.insertMember("version", HOFFSET(ContVocabMZ5Data, version), stringtype); return cvtype; } CVParamMZ5::CVParamMZ5() { init(0, ULONG_MAX, ULONG_MAX); } CVParamMZ5::CVParamMZ5(const CVParamMZ5& cvparam) { init(cvparam.value, cvparam.typeCVRefID, cvparam.unitCVRefID); } CVParamMZ5& CVParamMZ5::operator=(const CVParamMZ5& rhs) { if (this != &rhs) init(rhs.value, rhs.typeCVRefID, rhs.unitCVRefID); return *this; } CVParamMZ5::~CVParamMZ5(){} CompType CVParamMZ5::getType() { CompType ret(sizeof(CVParamMZ5Data)); StrType stringtype = getFStringType(CVL); ret.insertMember("value", HOFFSET(CVParamMZ5Data, value), stringtype); ret.insertMember("cvRefID", HOFFSET(CVParamMZ5Data, typeCVRefID), PredType::NATIVE_ULONG); ret.insertMember("uRefID", HOFFSET(CVParamMZ5Data, unitCVRefID), PredType::NATIVE_ULONG); return ret; } void CVParamMZ5::init(const char* value, const unsigned long& cvrefid, const unsigned long& urefid) { if (value) strcpy(this->value, value); else this->value[0] = '\0'; this->value[CVL - 1] = '\0'; this->typeCVRefID = cvrefid; this->unitCVRefID = urefid; } CVRefMZ5::CVRefMZ5() { init("","",ULONG_MAX); } CVRefMZ5::CVRefMZ5(const CVRefMZ5& cvref) { init(cvref.name, cvref.prefix, cvref.accession); } CVRefMZ5::~CVRefMZ5() { delete [] name; delete [] prefix; } CVRefMZ5& CVRefMZ5::operator=(const CVRefMZ5& cvp) { if (this != &cvp){ delete [] name; delete [] prefix; init(cvp.name, cvp.prefix, cvp.accession); } return *this; } void CVRefMZ5::init(const char* name, const char* prefix, const unsigned long accession){ if(name) strcpy(this->name,name); strcpy(this->prefix,prefix); this->accession=accession; } CompType CVRefMZ5::getType() { CompType ret(sizeof(CVRefMZ5Data)); StrType stringtype = getStringType(); ret.insertMember("name", HOFFSET(CVRefMZ5Data, name), stringtype); ret.insertMember("prefix", HOFFSET(CVRefMZ5Data, prefix), stringtype); ret.insertMember("accession", HOFFSET(CVRefMZ5Data, accession), PredType::NATIVE_ULONG); return ret; } CompType DataProcessingMZ5::getType() { CompType ret(sizeof(DataProcessingMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("method", offset, ProcessingMethodListMZ5::getType()); offset += sizeof(ProcessingMethodListMZ5); return ret; } FileInformationMZ5::FileInformationMZ5() { this->majorVersion = MZ5_FILE_MAJOR_VERSION; this->minorVersion = MZ5_FILE_MINOR_VERSION; this->didFiltering = 1; this->deltaMZ = 1; this->translateInten = 1; } FileInformationMZ5::FileInformationMZ5(const FileInformationMZ5& rhs) { init(rhs.majorVersion, rhs.minorVersion, rhs.didFiltering, rhs.deltaMZ, rhs.translateInten); } FileInformationMZ5::FileInformationMZ5(const mzpMz5Config& c) { unsigned short didfiltering = c.doFiltering() ? 1 : 0; unsigned short deltamz = c.doTranslating() ? 1 : 0; unsigned short translateinten = c.doTranslating() ? 1 : 0; init(MZ5_FILE_MAJOR_VERSION, MZ5_FILE_MINOR_VERSION, didfiltering, deltamz, translateinten); } FileInformationMZ5::~FileInformationMZ5(){} FileInformationMZ5& FileInformationMZ5::operator=(const FileInformationMZ5& rhs) { if (this != &rhs){ init(rhs.majorVersion, rhs.minorVersion, rhs.didFiltering, rhs.deltaMZ, rhs.translateInten); } return *this; } void FileInformationMZ5::init(const unsigned short majorVersion, const unsigned short minorVersion, const unsigned didFiltering, const unsigned deltaMZ, const unsigned translateInten) { this->majorVersion = majorVersion; this->minorVersion = minorVersion; this->didFiltering = didFiltering; this->deltaMZ = deltaMZ; this->translateInten = translateInten; } CompType FileInformationMZ5::getType() { CompType ret(sizeof(FileInformationMZ5Data)); ret.insertMember("majorVersion", HOFFSET(FileInformationMZ5Data, majorVersion), PredType::NATIVE_USHORT); ret.insertMember("minorVersion", HOFFSET(FileInformationMZ5Data, minorVersion), PredType::NATIVE_USHORT); ret.insertMember("didFiltering", HOFFSET(FileInformationMZ5Data, didFiltering), PredType::NATIVE_USHORT); ret.insertMember("deltaMZ", HOFFSET(FileInformationMZ5Data, deltaMZ), PredType::NATIVE_USHORT); ret.insertMember("translateInten", HOFFSET(FileInformationMZ5Data, translateInten), PredType::NATIVE_USHORT); return ret; } CompType InstrumentConfigurationMZ5::getType() { CompType ret(sizeof(InstrumentConfigurationMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("components", offset, ComponentsMZ5::getType()); offset += sizeof(ComponentsMZ5); ret.insertMember("refScanSetting", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("refSoftware", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); return ret; } CompType ParamGroupMZ5::getType() { CompType ret(sizeof(ParamGroupMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); return ret; } CompType ParamListMZ5::getType() { CompType ret(sizeof(ParamListMZ5Data)); ret.insertMember("cvstart", HOFFSET(ParamListMZ5Data, cvParamStartID), PredType::NATIVE_ULONG); ret.insertMember("cvend", HOFFSET(ParamListMZ5Data, cvParamEndID), PredType::NATIVE_ULONG); ret.insertMember("usrstart", HOFFSET(ParamListMZ5Data, userParamStartID), PredType::NATIVE_ULONG); ret.insertMember("usrend", HOFFSET(ParamListMZ5Data, userParamEndID), PredType::NATIVE_ULONG); ret.insertMember("refstart", HOFFSET(ParamListMZ5Data, refParamGroupStartID), PredType::NATIVE_ULONG); ret.insertMember("refend", HOFFSET(ParamListMZ5Data, refParamGroupEndID), PredType::NATIVE_ULONG); return ret; } VarLenType ParamListsMZ5::getType() { CompType c(ParamListMZ5::getType()); VarLenType ret(&c); return ret; } VarLenType PrecursorListMZ5::getType() { CompType c(PrecursorMZ5::getType()); VarLenType ret(&c); return ret; } CompType PrecursorMZ5::getType() { CompType ret(sizeof(PrecursorMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("externalSpectrumId", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("activation", offset, ParamListMZ5::getType()); offset += ParamListMZ5::getType().getSize(); ret.insertMember("isolationWindow", offset, ParamListMZ5::getType()); offset += ParamListMZ5::getType().getSize(); ret.insertMember("selectedIonList", offset, ParamListsMZ5::getType()); offset += ParamListsMZ5::getType().getSize(); ret.insertMember("refSpectrum", offset, RefMZ5::getType()); offset += RefMZ5::getType().getSize(); ret.insertMember("refSourceFile", offset, RefMZ5::getType()); offset += RefMZ5::getType().getSize(); return ret; } VarLenType ProcessingMethodListMZ5::getType() { CompType c = ProcessingMethodMZ5::getType(); VarLenType ret(&c); return ret; } CompType ProcessingMethodMZ5::getType() { CompType ret(sizeof(ProcessingMethodMZ5)); size_t offset = 0; ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("refSoftware", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("order", offset, PredType::NATIVE_ULONG); return ret; } VarLenType RefListMZ5::getType() { CompType c = RefMZ5::getType(); VarLenType ret(&c); return ret; } CompType RefMZ5::getType() { CompType ret(sizeof(RefMZ5Data)); ret.insertMember("refID", HOFFSET(RefMZ5Data, refID), PredType::NATIVE_ULONG); return ret; } CompType RunMZ5::getType() { CompType ret(sizeof(RunMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("startTimeStamp", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("fid", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("facc", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5); ret.insertMember("refSpectrumDP", offset, RefMZ5::getType()); offset += sizeof(RefMZ5); ret.insertMember("refChromatogramDP", offset, RefMZ5::getType()); offset += sizeof(RefMZ5); ret.insertMember("refDefaultInstrument", offset, RefMZ5::getType()); offset += sizeof(RefMZ5); ret.insertMember("refSourceFile", offset, RefMZ5::getType()); offset += sizeof(RefMZ5); ret.insertMember("refSample", offset, RefMZ5::getType()); offset += sizeof(RefMZ5); return ret; } CompType SampleMZ5::getType() { CompType ret(sizeof(SampleMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("name", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); return ret; } VarLenType ScanListMZ5::getType() { CompType c = ScanMZ5::getType(); VarLenType ret(&c); return ret; } CompType ScanMZ5::getType() { CompType ret(sizeof(ScanMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("externalSpectrumID", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("scanWindowList", offset, ParamListsMZ5::getType()); offset += sizeof(ParamListsMZ5); ret.insertMember("refInstrumentConfiguration", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("refSourceFile", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("refSpectrum", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); return ret; } CompType ScansMZ5::getType() { CompType ret(sizeof(ScansMZ5)); size_t offset = 0; ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5); ret.insertMember("scanList", offset, ScanListMZ5::getType()); return ret; } CompType ScanSettingMZ5::getType() { CompType ret(sizeof(ScanSettingMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("refSourceFiles", offset, RefListMZ5::getType()); offset += sizeof(RefListMZ5Data); ret.insertMember("targets", offset, ParamListsMZ5::getType()); return ret; } CompType SoftwareMZ5::getType() { CompType ret(sizeof(SoftwareMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("version", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); return ret; } CompType SourceFileMZ5::getType() { CompType ret(sizeof(SourceFileMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("location", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("name", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); return ret; } CompType SpectrumMZ5::getType() { CompType ret(sizeof(SpectrumMZ5)); StrType stringtype = getStringType(); size_t offset = 0; ret.insertMember("id", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("spotID", offset, stringtype); offset += stringtype.getSize(); ret.insertMember("params", offset, ParamListMZ5::getType()); offset += sizeof(ParamListMZ5Data); ret.insertMember("scanList", offset, ScansMZ5::getType()); offset += sizeof(ScansMZ5); ret.insertMember("precursors", offset, PrecursorListMZ5::getType()); offset += sizeof(PrecursorListMZ5); ret.insertMember("products", offset, ParamListsMZ5::getType()); offset += sizeof(ParamListsMZ5); ret.insertMember("refDataProcessing", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("refSourceFile", offset, RefMZ5::getType()); offset += sizeof(RefMZ5Data); ret.insertMember("index", offset, PredType::NATIVE_ULONG); offset += PredType::NATIVE_ULONG.getSize(); return ret; } CompType UserParamMZ5::getType() { CompType ret(sizeof(UserParamMZ5Data)); StrType namestringtype = getFStringType(USRNL); StrType valuestringtype = getFStringType(USRVL); StrType typestringtype = getFStringType(USRTL); ret.insertMember("name", HOFFSET(UserParamMZ5Data, name), namestringtype); ret.insertMember("value", HOFFSET(UserParamMZ5Data, value), valuestringtype); ret.insertMember("type", HOFFSET(UserParamMZ5Data, type), typestringtype); ret.insertMember("uRefID", HOFFSET(UserParamMZ5Data, unitCVRefID), PredType::NATIVE_ULONG); return ret; } #endif libmstoolkit-cleaned-82/src/mzParser/mzpMz5Config.cpp0000644000175000017500000002217013210260002022752 0ustar rusconirusconi#include "mzParser.h" #ifdef MZP_MZ5 mzpMz5Config::mzpMz5Config(){ init(false, true, true); } mzpMz5Config::~mzpMz5Config(){} const bool mzpMz5Config::doFiltering() const { return doFiltering_; } const bool mzpMz5Config::doTranslating() const { return doTranslating_; } const size_t mzpMz5Config::getBufferInB() { return (bufferInMB_ * 1024L * 1024L); } const DataType& mzpMz5Config::getDataTypeFor(const MZ5DataSets v) { if (variableTypes_.find(v) != variableTypes_.end()) { return variableTypes_.find(v)->second; } throw out_of_range("[mzpMz5Config::getDataTypeFor]: out of range"); } const string& mzpMz5Config::getNameFor(const MZ5DataSets v) { if (variableNames_.find(v) != variableNames_.end()) { return variableNames_.find(v)->second; } throw out_of_range("[mzpMz5Config::getNameFor]: out of range"); } const size_t& mzpMz5Config::getRdccSlots() { return rdccSolts_; } MZ5DataSets mzpMz5Config::getVariableFor(const std::string& name) { if (variableVariables_.find(name) != variableVariables_.end()) { return variableVariables_.find(name)->second; } throw out_of_range("[mzpMz5Config::getVariableFor]: out of range"); } void mzpMz5Config::init(const bool filter, const bool deltamz, const bool translateinten) { variableNames_.insert(pair(ControlledVocabulary, "ControlledVocabulary")); variableNames_.insert(pair(CVReference, "CVReference")); variableNames_.insert(pair(CVParam, "CVParam")); variableNames_.insert(pair(UserParam, "UserParam")); variableNames_.insert(pair(RefParam, "RefParam")); variableNames_.insert(pair(FileContent, "FileContent")); variableNames_.insert(pair(Contact, "Contact")); variableNames_.insert(pair(ParamGroups, "ParamGroups")); variableNames_.insert(pair(SourceFiles, "SourceFiles")); variableNames_.insert(pair(Samples, "Samples")); variableNames_.insert(pair(Software, "Software")); variableNames_.insert(pair(ScanSetting, "ScanSetting")); variableNames_.insert(pair(InstrumentConfiguration, "InstrumentConfiguration")); variableNames_.insert(pair(DataProcessing, "DataProcessing")); variableNames_.insert(pair(Run, "Run")); variableNames_.insert(pair(SpectrumMetaData, "SpectrumMetaData")); variableNames_.insert(pair(SpectrumBinaryMetaData, "SpectrumListBinaryData")); variableNames_.insert(pair(ChromatogramMetaData, "ChromatogramList")); variableNames_.insert(pair(ChromatogramBinaryMetaData, "ChromatogramListBinaryData")); variableNames_.insert(pair(ChromatogramIndex, "ChromatogramIndex")); variableNames_.insert(pair(SpectrumIndex, "SpectrumIndex")); variableNames_.insert(pair(SpectrumMZ, "SpectrumMZ")); variableNames_.insert(pair(SpectrumIntensity, "SpectrumIntensity")); variableNames_.insert(pair(ChromatogramTime, "ChomatogramTime")); variableNames_.insert(pair(ChromatogramIntensity, "ChromatogramIntensity")); variableNames_.insert(pair(FileInformation, "FileInformation")); for (map::iterator it = variableNames_.begin(); it != variableNames_.end(); ++it) { variableVariables_.insert(pair(it->second, it->first)); } variableTypes_.insert(pair(ControlledVocabulary, ContVocabMZ5::getType())); variableTypes_.insert(pair(FileContent, ParamListMZ5::getType())); variableTypes_.insert(pair(Contact, ParamListMZ5::getType())); variableTypes_.insert(pair(CVReference, CVRefMZ5::getType())); variableTypes_.insert(pair(ParamGroups, ParamGroupMZ5::getType())); variableTypes_.insert(pair(SourceFiles, SourceFileMZ5::getType())); variableTypes_.insert(pair(Samples, SampleMZ5::getType())); variableTypes_.insert(pair(Software, SoftwareMZ5::getType())); variableTypes_.insert(pair(ScanSetting, ScanSettingMZ5::getType())); variableTypes_.insert(pair(InstrumentConfiguration, InstrumentConfigurationMZ5::getType())); variableTypes_.insert(pair(DataProcessing, DataProcessingMZ5::getType())); variableTypes_.insert(pair(Run, RunMZ5::getType())); variableTypes_.insert(pair(SpectrumMetaData, SpectrumMZ5::getType())); variableTypes_.insert(pair(SpectrumBinaryMetaData, BinaryDataMZ5::getType())); variableTypes_.insert(pair(ChromatogramMetaData, ChromatogramMZ5::getType())); variableTypes_.insert(pair(ChromatogramBinaryMetaData, BinaryDataMZ5::getType())); variableTypes_.insert(pair(ChromatogramIndex, PredType::NATIVE_ULONG)); variableTypes_.insert(pair(SpectrumIndex, PredType::NATIVE_ULONG)); variableTypes_.insert(pair(FileInformation, FileInformationMZ5::getType())); variableTypes_.insert(pair(SpectrumMZ, PredType::NATIVE_DOUBLE)); variableTypes_.insert(pair(SpectrumIntensity, PredType::NATIVE_DOUBLE)); variableTypes_.insert(pair(ChromatogramIntensity, PredType::NATIVE_DOUBLE)); variableTypes_.insert(pair(ChromatogramTime, PredType::NATIVE_DOUBLE)); variableTypes_.insert(pair(CVParam, CVParamMZ5::getType())); variableTypes_.insert(pair(UserParam, UserParamMZ5::getType())); variableTypes_.insert(pair(RefParam, RefMZ5::getType())); hsize_t spectrumChunkSize = 5000L; // 1000=faster random read, 10000=better compression hsize_t chromatogramChunkSize = 1000L; hsize_t spectrumMetaChunkSize = 2000L; // should be modified in case of on demand access // hsize_t chromatogramMetaChunkSize = 10L; // usually one experiment does not contain a lot of chromatograms, so this chunk size is small in order to save storage space hsize_t cvparamChunkSize = 5000L; hsize_t userparamChunkSize = 100L; variableChunkSizes_.insert(pair(SpectrumMZ, spectrumChunkSize)); variableChunkSizes_.insert(pair(SpectrumIntensity, spectrumChunkSize)); variableChunkSizes_.insert(pair(ChromatogramTime, chromatogramChunkSize)); variableChunkSizes_.insert(pair(ChromatogramIntensity, chromatogramChunkSize)); bufferInMB_ = 8L; // this affects all datasets. size_t sizeOfDouble = static_cast (sizeof(double)); size_t bufferInByte = bufferInMB_ * 1024L * 1024L; size_t numberOfChunksInBuffer = (bufferInByte / sizeOfDouble) / spectrumChunkSize; rdccSolts_ = 41957L; // for 32 mb, 10000 chunk size hsize_t spectrumBufferSize = spectrumChunkSize * (numberOfChunksInBuffer / 4L); hsize_t chromatogramBufferSize = chromatogramChunkSize * 10L; variableBufferSizes_.insert(pair(SpectrumMZ, spectrumBufferSize)); variableBufferSizes_.insert(pair(SpectrumIntensity, spectrumBufferSize)); variableBufferSizes_.insert(pair(ChromatogramTime, chromatogramBufferSize)); variableBufferSizes_.insert(pair(ChromatogramIntensity, chromatogramBufferSize)); //if (config_.binaryDataEncoderConfig.compression == pwiz::msdata::BinaryDataEncoder::Compression_Zlib) { doTranslating_ = deltamz && translateinten; deflateLvl_ = 1; variableChunkSizes_.insert(pair(SpectrumMetaData, spectrumMetaChunkSize)); variableChunkSizes_.insert(pair(SpectrumBinaryMetaData, spectrumMetaChunkSize)); variableChunkSizes_.insert(pair(SpectrumIndex, spectrumMetaChunkSize)); // should not affect file size to much, if chromatogram information are not compressed // variableChunkSizes_.insert(pair(ChromatogramMetaData, chromatogramMetaChunkSize)); // variableChunkSizes_.insert(pair(ChromatogramBinaryMetaData, chromatogramMetaChunkSize)); // variableChunkSizes_.insert(pair(ChromatogramIndex, chromatogramMetaChunkSize)); variableChunkSizes_.insert(pair(CVParam, cvparamChunkSize)); variableChunkSizes_.insert(pair(UserParam, userparamChunkSize)); //} else { // deflateLvl_ = 0; //} spectrumLoadPolicy_ = SLP_InitializeAllOnFirstCall; chromatogramLoadPolicy_ = CLP_InitializeAllOnFirstCall; doFiltering_ = filter; } void mzpMz5Config::setFiltering(const bool flag) const { doFiltering_ = flag; } void mzpMz5Config::setTranslating(const bool flag) const { doTranslating_ = flag; } #endif libmstoolkit-cleaned-82/src/mzParser/MSNumpress.cpp0000644000175000017500000004764613210260002022515 0ustar rusconirusconi/* MSNumpress.cpp johan.teleman@immun.lth.se Copyright 2013 Johan Teleman Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include #include #include #include #include "MSNumpress.hpp" namespace ms { namespace numpress { namespace MSNumpress { using std::cout; using std::cerr; using std::endl; using std::min; using std::max; using std::abs; // This is only valid on systems were ints use more bytes than chars... const int ONE = 1; static bool is_big_endian() { return *((char*)&(ONE)) == 1; } bool IS_BIG_ENDIAN = is_big_endian(); ///////////////////////////////////////////////////////////// static void encodeFixedPoint( double fixedPoint, unsigned char *result ) { int i; unsigned char *fp = (unsigned char*)&fixedPoint; for (i = 0; i<8; i++) { result[i] = fp[IS_BIG_ENDIAN ? (7 - i) : i]; } } static double decodeFixedPoint( const unsigned char *data ) { int i; double fixedPoint; unsigned char *fp = (unsigned char*)&fixedPoint; for (i = 0; i<8; i++) { fp[i] = data[IS_BIG_ENDIAN ? (7 - i) : i]; } return fixedPoint; } ///////////////////////////////////////////////////////////// /** * Encodes the int x as a number of halfbytes in res. * res_length is incremented by the number of halfbytes, * which will be 1 <= n <= 9 */ static void encodeInt( const unsigned int x, unsigned char* res, size_t *res_length ) { // get the bit pattern of a signed int x_inp unsigned int m; unsigned char i, l; // numbers between 0 and 9 unsigned int mask = 0xf0000000; unsigned int init = x & mask; if (init == 0) { l = 8; for (i = 0; i<8; i++) { m = mask >> (4 * i); if ((x & m) != 0) { l = i; break; } } res[0] = l; for (i = l; i<8; i++) { res[1 + i - l] = static_cast(x >> (4 * (i - l))); } *res_length += 1 + 8 - l; } else if (init == mask) { l = 7; for (i = 0; i<8; i++) { m = mask >> (4 * i); if ((x & m) != m) { l = i; break; } } res[0] = l + 8; for (i = l; i<8; i++) { res[1 + i - l] = static_cast(x >> (4 * (i - l))); } *res_length += 1 + 8 - l; } else { res[0] = 0; for (i = 0; i<8; i++) { res[1 + i] = static_cast(x >> (4 * i)); } *res_length += 9; } } /** * Decodes an int from the half bytes in bp. Lossless reverse of encodeInt */ static void decodeInt( const unsigned char *data, size_t *di, size_t max_di, size_t *half, unsigned int *res ) { size_t n, i; unsigned int mask, m; unsigned char head; unsigned char hb; if (*half == 0) { head = data[*di] >> 4; } else { head = data[*di] & 0xf; (*di)++; } *half = 1 - (*half); *res = 0; if (head <= 8) { n = head; } else { // leading ones, fill n half bytes in res n = head - 8; mask = 0xf0000000; for (i = 0; i> (4 * i); *res = *res | m; } } if (n == 8) { return; } if (*di + ((8 - n) - (1 - *half)) / 2 >= max_di) { throw "[MSNumpress::decodeInt] Corrupt input data! "; } for (i = n; i<8; i++) { if (*half == 0) { hb = data[*di] >> 4; } else { hb = data[*di] & 0xf; (*di)++; } *res = *res | (static_cast(hb) << ((i - n) * 4)); *half = 1 - (*half); } } ///////////////////////////////////////////////////////////// double optimalLinearFixedPoint( const double *data, size_t dataSize ) { /* * safer impl - apparently not needed though * if (dataSize == 0) return 0; double maxDouble = 0; double x; for (size_t i=0; i(data[0] * fixedPoint + 0.5); for (i = 0; i<4; i++) { result[8 + i] = (ints[1] >> (i * 8)) & 0xff; } if (dataSize == 1) return 12; ints[2] = static_cast(data[1] * fixedPoint + 0.5); for (i = 0; i<4; i++) { result[12 + i] = (ints[2] >> (i * 8)) & 0xff; } halfByteCount = 0; ri = 16; for (i = 2; i LLONG_MAX) { throw "[MSNumpress::encodeLinear] Next number overflows LLONG_MAX."; } ints[2] = static_cast(data[i] * fixedPoint + 0.5); extrapol = ints[1] + (ints[1] - ints[0]); if (THROW_ON_OVERFLOW && (ints[2] - extrapol > INT_MAX || ints[2] - extrapol < INT_MIN)) { throw "[MSNumpress::encodeLinear] Cannot encode a number that exceeds the bounds of [-INT_MAX, INT_MAX]."; } diff = static_cast(ints[2] - extrapol); //printf("%lu %lu %lu, extrapol: %ld diff: %d \n", ints[0], ints[1], ints[2], extrapol, diff); encodeInt( static_cast(diff), &halfBytes[halfByteCount], &halfByteCount ); /* printf("%d (%d): ", diff, (int)halfByteCount); for (size_t j=0; j( (halfBytes[hbi - 1] << 4) | (halfBytes[hbi] & 0xf) ); //printf("%x \n", result[ri]); ri++; } if (halfByteCount % 2 != 0) { halfBytes[0] = halfBytes[halfByteCount - 1]; halfByteCount = 1; } else { halfByteCount = 0; } } if (halfByteCount == 1) { result[ri] = static_cast(halfBytes[0] << 4); ri++; } return ri; } size_t decodeLinear( const unsigned char *data, const size_t dataSize, double *result ) { size_t i; size_t ri = 0; unsigned int init, buff; int diff; long long ints[3]; //double d; size_t di; size_t half; long long extrapol; long long y; double fixedPoint; //printf("Decoding %d bytes with fixed point %f\n", (int)dataSize, fixedPoint); if (dataSize == 8) return 0; if (dataSize < 8) throw "[MSNumpress::decodeLinear] Corrupt input data: not enough bytes to read fixed point! "; fixedPoint = decodeFixedPoint(data); if (dataSize < 12) throw "[MSNumpress::decodeLinear] Corrupt input data: not enough bytes to read first value! "; ints[1] = 0; for (i = 0; i<4; i++) { ints[1] = ints[1] | ((0xff & (init = data[8 + i])) << (i * 8)); } result[0] = ints[1] / fixedPoint; if (dataSize == 12) return 1; if (dataSize < 16) throw "[MSNumpress::decodeLinear] Corrupt input data: not enough bytes to read second value! "; ints[2] = 0; for (i = 0; i<4; i++) { ints[2] = ints[2] | ((0xff & (init = data[12 + i])) << (i * 8)); } result[1] = ints[2] / fixedPoint; half = 0; ri = 2; di = 16; //printf(" di ri half int[0] int[1] extrapol diff\n"); while (di < dataSize) { if (di == (dataSize - 1) && half == 1) { if ((data[di] & 0xf) == 0x0) { break; } } //printf("%7d %7d %7d %lu %lu %ld", di, ri, half, ints[0], ints[1], extrapol); ints[0] = ints[1]; ints[1] = ints[2]; decodeInt(data, &di, dataSize, &half, &buff); diff = static_cast(buff); extrapol = ints[1] + (ints[1] - ints[0]); y = extrapol + diff; //printf(" %d \n", diff); result[ri++] = y / fixedPoint; ints[2] = y; } return ri; } void encodeLinear( const std::vector &data, std::vector &result, double fixedPoint ) { size_t dataSize = data.size(); result.resize(dataSize * 5 + 8); size_t encodedLength = encodeLinear(&data[0], dataSize, &result[0], fixedPoint); result.resize(encodedLength); } void decodeLinear( const std::vector &data, std::vector &result ) { size_t dataSize = data.size(); result.resize((dataSize - 8) * 2); size_t decodedLength = decodeLinear(&data[0], dataSize, &result[0]); result.resize(decodedLength); } ///////////////////////////////////////////////////////////// size_t encodeSafe( const double *data, const size_t dataSize, unsigned char *result ) { size_t i, j, ri = 0; double latest[3]; double extrapol, diff; const unsigned char *fp; //printf("d0 d1 d2 extrapol diff\n"); if (dataSize == 0) return ri; latest[1] = data[0]; fp = (unsigned char*)data; for (i = 0; i<8; i++) { result[ri++] = fp[IS_BIG_ENDIAN ? (7 - i) : i]; } if (dataSize == 1) return ri; latest[2] = data[1]; fp = (unsigned char*)&(data[1]); for (i = 0; i<8; i++) { result[ri++] = fp[IS_BIG_ENDIAN ? (7 - i) : i]; } fp = (unsigned char*)&diff; for (i = 2; i INT_MAX || data[i] < -0.5)){ throw "[MSNumpress::encodePic] Cannot use Pic to encode a number larger than INT_MAX or smaller than 0."; } x = static_cast(data[i] + 0.5); //printf("%d %d %d, extrapol: %d diff: %d \n", ints[0], ints[1], ints[2], extrapol, diff); encodeInt(x, &halfBytes[halfByteCount], &halfByteCount); for (hbi = 1; hbi < halfByteCount; hbi += 2) { result[ri] = static_cast( (halfBytes[hbi - 1] << 4) | (halfBytes[hbi] & 0xf) ); //printf("%x \n", result[ri]); ri++; } if (halfByteCount % 2 != 0) { halfBytes[0] = halfBytes[halfByteCount - 1]; halfByteCount = 1; } else { halfByteCount = 0; } } if (halfByteCount == 1) { result[ri] = static_cast(halfBytes[0] << 4); ri++; } return ri; } size_t decodePic( const unsigned char *data, const size_t dataSize, double *result ) { size_t ri; unsigned int x; size_t di; size_t half; //printf("ri di half dSize count\n"); half = 0; ri = 0; di = 0; while (di < dataSize) { if (di == (dataSize - 1) && half == 1) { if ((data[di] & 0xf) == 0x0) { break; } } decodeInt(&data[0], &di, dataSize, &half, &x); //printf("%7d %7d %7d %7d %7d\n", ri, di, half, dataSize, count); //printf("count: %d \n", count); result[ri++] = static_cast(x); } return ri; } void encodePic( const std::vector &data, std::vector &result ) { size_t dataSize = data.size(); result.resize(dataSize * 5); size_t encodedLength = encodePic(&data[0], dataSize, &result[0]); result.resize(encodedLength); } void decodePic( const std::vector &data, std::vector &result ) { size_t dataSize = data.size(); result.resize(dataSize * 2); size_t decodedLength = decodePic(&data[0], dataSize, &result[0]); result.resize(decodedLength); } ///////////////////////////////////////////////////////////// double optimalSlofFixedPoint( const double *data, size_t dataSize ) { if (dataSize == 0) return 0; double maxDouble = 1; double x; double fp; for (size_t i = 0; i USHRT_MAX) { throw "[MSNumpress::encodeSlof] Cannot encode a number that overflows USHRT_MAX."; } x = static_cast(temp + 0.5); result[ri++] = x & 0xff; result[ri++] = (x >> 8) & 0xff; } return ri; } size_t decodeSlof( const unsigned char *data, const size_t dataSize, double *result ) { size_t i, ri; unsigned short x; double fixedPoint; if (dataSize < 8) throw "[MSNumpress::decodeSlof] Corrupt input data: not enough bytes to read fixed point! "; ri = 0; fixedPoint = decodeFixedPoint(data); for (i = 8; i(data[i] | (data[i + 1] << 8)); result[ri++] = exp(x / fixedPoint) - 1; } return ri; } void encodeSlof( const std::vector &data, std::vector &result, double fixedPoint ) { size_t dataSize = data.size(); result.resize(dataSize * 2 + 8); size_t encodedLength = encodeSlof(&data[0], dataSize, &result[0], fixedPoint); result.resize(encodedLength); } void decodeSlof( const std::vector &data, std::vector &result ) { size_t dataSize = data.size(); result.resize((dataSize - 8) / 2); size_t decodedLength = decodeSlof(&data[0], dataSize, &result[0]); result.resize(decodedLength); } } } // namespace numpress } // namespace ms libmstoolkit-cleaned-82/src/mzParser/RAMPface.cpp0000644000175000017500000010125613210260002022003 0ustar rusconirusconi#include "mzParser.h" int checkFileType(const char* fname){ char file[256]; char ext[256]; char *tok; char preExt[256]; unsigned int i; if (strlen(fname) < 4) { cerr << "Incomplete file name. No file loaded: " << fname << endl; return 0; } strcpy(ext,""); strcpy(file,fname); tok=strtok(file,".\n"); while(tok!=NULL){ strcpy(preExt,ext); strcpy(ext,tok); tok=strtok(NULL,".\n"); } for(i=0;iprecursorMZ; d=scanHeader->selectionWindowLower; //these are place holders until the values are actually returned; d=scanHeader->selectionWindowUpper; monoMZ=scanHeader->precursorMonoMZ; intensity=scanHeader->precursorIntensity; charge=scanHeader->precursorCharge; possibleCharges=scanHeader->numPossibleCharges; if(possibleChargeArray!=NULL) delete[] possibleChargeArray; if(possibleCharges>0){ possibleChargeArray = new int[possibleCharges]; for(i=0;ipossibleCharges[i*4],sizeof(int)); } else { possibleChargeArray = NULL; } } else { j=0; for(i=1;iprecursorCount;i++){ memcpy(&mz,&scanHeader->additionalPrecursors[j+=8],sizeof(double)); memcpy(&d, &scanHeader->additionalPrecursors[j += 8], sizeof(double)); //selectionWindowLower memcpy(&d, &scanHeader->additionalPrecursors[j += 8], sizeof(double)); //selectionWindowUpper memcpy(&monoMZ,&scanHeader->additionalPrecursors[j+=8],sizeof(double)); memcpy(&intensity,&scanHeader->additionalPrecursors[j+=8],sizeof(double)); memcpy(&charge,&scanHeader->additionalPrecursors[j+=4],sizeof(int)); memcpy(&possibleCharges,&scanHeader->additionalPrecursors[j+=4],sizeof(int)); if(possibleChargeArray!=NULL) delete[] possibleChargeArray; if(possibleCharges>0){ possibleChargeArray = new int[possibleCharges]; for(k=0;kadditionalPrecursors[j+=4],sizeof(int)); } else { possibleChargeArray = NULL; } if(i==index) break; } } } ramp_fileoffset_t getIndexOffset(RAMPFILE *pFI){ switch(pFI->fileType){ case 1: case 3: return (ramp_fileoffset_t)pFI->mzML->getIndexOffset(); break; case 2: case 4: return (ramp_fileoffset_t)pFI->mzXML->getIndexOffset(); break; default: return -1; } } InstrumentStruct* getInstrumentStruct(RAMPFILE *pFI){ InstrumentStruct* r=(InstrumentStruct *) calloc(1,sizeof(InstrumentStruct)); if(r==NULL) { printf("Cannot allocate memory\n"); return NULL; } else { strcpy(r->analyzer,"UNKNOWN"); strcpy(r->detector,"UNKNOWN"); strcpy(r->ionisation,"UNKNOWN"); strcpy(r->manufacturer,"UNKNOWN"); strcpy(r->model,"UNKNOWN"); } switch(pFI->fileType){ case 1: case 3: if(pFI->mzML->getInstrument()->size()>0){ if(pFI->mzML->getInstrument()->at(0).analyzer.size()>1) strcpy(r->analyzer,&pFI->mzML->getInstrument()->at(0).analyzer[0]); if(pFI->mzML->getInstrument()->at(0).detector.size()>1) strcpy(r->detector,&pFI->mzML->getInstrument()->at(0).detector[0]); if(pFI->mzML->getInstrument()->at(0).ionization.size()>1) strcpy(r->ionisation,&pFI->mzML->getInstrument()->at(0).ionization[0]); if(pFI->mzML->getInstrument()->at(0).manufacturer.size()>1) strcpy(r->manufacturer,&pFI->mzML->getInstrument()->at(0).manufacturer[0]); if(pFI->mzML->getInstrument()->at(0).model.size()>1) strcpy(r->model,&pFI->mzML->getInstrument()->at(0).model[0]); } break; case 2: case 4: if(pFI->mzXML->getInstrument().analyzer.size()>1) strcpy(r->analyzer,&pFI->mzXML->getInstrument().analyzer[0]); if(pFI->mzXML->getInstrument().detector.size()>1) strcpy(r->detector,&pFI->mzXML->getInstrument().detector[0]); if(pFI->mzXML->getInstrument().ionization.size()>1) strcpy(r->ionisation,&pFI->mzXML->getInstrument().ionization[0]); if(pFI->mzXML->getInstrument().manufacturer.size()>1) strcpy(r->manufacturer,&pFI->mzXML->getInstrument().manufacturer[0]); if(pFI->mzXML->getInstrument().model.size()>1) strcpy(r->model,&pFI->mzXML->getInstrument().model[0]); break; case 5: default: break; } return r; } void getScanSpanRange(const struct ScanHeaderStruct *scanHeader, int *startScanNum, int *endScanNum) { if (0 == scanHeader->mergedResultStartScanNum || 0 == scanHeader->mergedResultEndScanNum) { *startScanNum = scanHeader->acquisitionNum; *endScanNum = scanHeader->acquisitionNum; } else { *startScanNum = scanHeader->mergedResultStartScanNum; *endScanNum = scanHeader->mergedResultEndScanNum; } } void rampCloseFile(RAMPFILE *pFI){ if(pFI!=NULL) { delete pFI; pFI=NULL; } } string rampConstructInputFileName(const string &basename){ int len; char *buf = new char[len = (int)(basename.length()+100)]; rampConstructInputPath(buf, len, "", basename.c_str()); string result(buf); delete[] buf; return result; } char* rampConstructInputFileName(char *buf,int buflen,const char *basename){ return rampConstructInputPath(buf, buflen, "", basename); } char* rampConstructInputPath(char *buf, int inbuflen, const char *dir_in, const char *basename){ if( (int)(strlen(dir_in)+strlen(basename)+1) > inbuflen ){ //Can't output error messages in TPP software that use this function //printf("rampConstructInputPath error: buffer too small for file\n"); return NULL; } FILE* f; char* result = NULL; char base[512]; strcpy(base,basename); //Try opening the base name first, then with directory: for(int j=0;j<2;j++){ for(int i=0;i<5;i++){ if(j==1){ strcpy(buf,dir_in); strcat(buf,"/"); strcat(buf,base); } else { strcpy(buf,base); } switch(i){ case 0: strcat(buf,".mzML"); break; case 1: strcat(buf,".mzXML"); break; case 2: strcat(buf,".mzML.gz"); break; case 3: strcat(buf,".mzXML.gz"); break; case 4: strcat(buf,".mz5"); break; default: break; } f=fopen(buf,"r"); if(f==NULL) continue; fclose(f); result=buf; return result; } } //Can't output error messages in TPP software that use this function //printf("rampConstructInputPath: file not found\n"); strcpy(buf,""); result=NULL; return result; } const char** rampListSupportedFileTypes(){ if (!data_Ext.size()) { // needs init data_Ext.push_back(".mzXML"); data_Ext.push_back(".mzML"); data_Ext.push_back(".mzXML.gz"); data_Ext.push_back(".mzML.gz"); data_Ext.push_back(".mz5"); data_Ext.push_back(NULL); // end of list } return &(data_Ext[0]); } RAMPFILE* rampOpenFile(const char* filename){ int i=checkFileType(filename); if(i==0){ return NULL; } else { RAMPFILE* r=new RAMPFILE(); r->bs = new BasicSpectrum(); r->fileType=i; switch(i){ case 1: //mzML case 3: r->mzML=new mzpSAXMzmlHandler(r->bs); if(i==3)r->mzML->setGZCompression(true); else r->mzML->setGZCompression(false); if(!r->mzML->load(filename)){ delete r; return NULL; } else { return r; } case 2: //mzXML case 4: r->mzXML=new mzpSAXMzxmlHandler(r->bs); if(i==4) r->mzXML->setGZCompression(true); else r->mzXML->setGZCompression(false); if(!r->mzXML->load(filename)){ delete r; return NULL; } else { return r; } #ifdef MZP_MZ5 case 5: //mz5 r->mz5Config = new mzpMz5Config(); r->mz5=new mzpMz5Handler(r->mz5Config, r->bs); if(!r->mz5->readFile(filename)){ delete r; return NULL; } else { return r; } #endif default: delete r; return NULL; } } } char* rampValidFileType(const char *buf){ char ext[256]; char preExt[256]; const char* result=NULL; const char* result2=NULL; const char* p; unsigned int i; p=strchr(buf,'.'); while(p!=NULL){ result2=result; result=p; p=strchr(p+1,'.'); } if(result==NULL) return (char*) result; strcpy(ext,result); for(i=0;i* v; sPrecursorIon p; unsigned int i; #ifdef MZP_MZ5 vector* v2; #endif //memset(scanHeader,0,sizeof(struct ScanHeaderStruct)); scanHeader->acquisitionNum=-1; scanHeader->activationMethod[0]='\0'; scanHeader->basePeakIntensity=0.0; scanHeader->basePeakMZ=0.0; scanHeader->centroid=false; scanHeader->collisionEnergy=0.0; scanHeader->compensationVoltage=0.0; scanHeader->filePosition=0; scanHeader->filterLine[0]='\0'; scanHeader->highMZ=0.0; scanHeader->idString[0]='\0'; scanHeader->ionisationEnergy=0.0; scanHeader->lowMZ=0.0; scanHeader->mergedScan=0; scanHeader->mergedResultScanNum=0; scanHeader->mergedResultStartScanNum=0; scanHeader->mergedResultEndScanNum=0; scanHeader->msLevel=0; scanHeader->numPossibleCharges=0; scanHeader->precursorCharge=0; scanHeader->precursorIntensity=0.0; scanHeader->precursorMonoMZ=0.0; scanHeader->precursorMZ=0.0; scanHeader->precursorScanNum=-1; scanHeader->retentionTime=0.0; scanHeader->scanType[0]='\0'; scanHeader->selectionWindowLower=0; scanHeader->selectionWindowUpper=0; scanHeader->totIonCurrent=0.0; scanHeader->scanIndex=0; scanHeader->seqNum=-1; if(lScanIndex<0) return; switch(pFI->fileType){ case 1: case 3: v=pFI->mzML->getSpecIndex(); if(!scanI){ for(i=0;isize();i++) { if(v->at(i).offset==(f_off)lScanIndex) { if(!pFI->mzML->readHeader(v->at(i).scanNum)){ v=NULL; return; } break; } } } else { if(v->at(scanI).offset==(f_off)lScanIndex){ if(!pFI->mzML->readHeader(v->at(scanI).scanNum)){ v=NULL; return; } } } break; case 2: case 4: v=pFI->mzXML->getIndex(); if(!scanI){ for(i=0;isize();i++) { if(v->at(i).offset==(f_off)lScanIndex) { if(!pFI->mzXML->readHeader(v->at(i).scanNum)){ v=NULL; return; } break; } } } else { if(v->at(scanI).offset==(f_off)lScanIndex){ if (!pFI->mzXML->readHeader(v->at(scanI).scanNum)){ v = NULL; return; } } } break; #ifdef MZP_MZ5 case 5: v2=pFI->mz5->getSpecIndex(); if(!scanI){ for(i=0;isize();i++) { if(v2->at(i).offset==(f_off)lScanIndex) { if(!pFI->mz5->readHeader(v2->at(i).scanNum)){ v2=NULL; return; } break; } } } else { if (v2->at(scanI).offset == (f_off)lScanIndex) { if (!pFI->mz5->readHeader(v2->at(scanI).scanNum)){ v2 = NULL; return; } break; } } break; #endif default: pFI->bs->clear(); v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif return; } v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif scanHeader->acquisitionNum=pFI->bs->getScanNum(); scanHeader->basePeakIntensity=pFI->bs->getBasePeakIntensity(); scanHeader->basePeakMZ=pFI->bs->getBasePeakMZ(); scanHeader->centroid=pFI->bs->getCentroid(); scanHeader->collisionEnergy=pFI->bs->getCollisionEnergy(); scanHeader->compensationVoltage=pFI->bs->getCompensationVoltage(); scanHeader->highMZ=pFI->bs->getHighMZ(); scanHeader->ionInjectionTime = pFI->bs->getIonInjectionTime(); scanHeader->lowMZ=pFI->bs->getLowMZ(); scanHeader->msLevel=pFI->bs->getMSLevel(); scanHeader->peaksCount=pFI->bs->getPeaksCount(); scanHeader->precursorScanNum=pFI->bs->getPrecursorScanNum(); scanHeader->retentionTime=(double)pFI->bs->getRTime(false); scanHeader->totIonCurrent=pFI->bs->getTotalIonCurrent(); scanHeader->scanIndex=pFI->bs->getScanIndex(); scanHeader->seqNum=pFI->bs->getScanIndex(); int j=0; int k; double d; scanHeader->precursorCount=pFI->bs->getPrecursorIonCount(); for(i=0;i<(unsigned int)scanHeader->precursorCount;i++){ p=pFI->bs->getPrecursorIon(i); if(i==0){ scanHeader->precursorCharge=p.charge; scanHeader->precursorIntensity=p.intensity; scanHeader->precursorMonoMZ=p.monoMZ; if(p.isoMZ==0) scanHeader->precursorMZ=p.mz; else scanHeader->precursorMZ=p.isoMZ; scanHeader->selectionWindowLower=p.isoMZ-p.isoLowerMZ; scanHeader->selectionWindowUpper=p.isoMZ+p.isoUpperMZ; scanHeader->numPossibleCharges=(int)p.possibleCharges->size(); for(k=0;knumPossibleCharges;k++){ memcpy(&scanHeader->possibleCharges[k*4],&p.possibleCharges->at(k),sizeof(int)); if(k==7){ cout << "Warning: too many possible charges for precursor in scan " << scanHeader->acquisitionNum << endl; break; } } } else { if( (j+32+p.possibleCharges->size()*4) > PRECURSORARRAY_LENGTH-1) { cout << "Warning: too many precursors. Must improve RAMP interface." << endl; break; } if (p.isoMZ == 0) memcpy(&scanHeader->additionalPrecursors[j += 8], &p.mz, sizeof(double)); else memcpy(&scanHeader->additionalPrecursors[j+=8],&p.isoMZ,sizeof(double)); d = p.isoMZ - p.isoLowerMZ; memcpy(&scanHeader->additionalPrecursors[j+=8],&d, sizeof(double)); d = p.isoMZ + p.isoUpperMZ; memcpy(&scanHeader->additionalPrecursors[j+=8],&d, sizeof(double)); memcpy(&scanHeader->additionalPrecursors[j+=8],&p.monoMZ,sizeof(double)); memcpy(&scanHeader->additionalPrecursors[j+=8],&p.intensity,sizeof(double)); memcpy(&scanHeader->additionalPrecursors[j+=4],&p.charge,sizeof(int)); k=(int)p.possibleCharges->size(); memcpy(&scanHeader->additionalPrecursors[j+=4],&k,sizeof(int)); for(k=0;k<(int)p.possibleCharges->size();k++){ memcpy(&scanHeader->additionalPrecursors[j+=k*4],&p.possibleCharges->at(k),sizeof(int)); } } } pFI->bs->getFilterLine(scanHeader->filterLine); pFI->bs->getIDString(scanHeader->idString); switch(pFI->bs->getActivation()){ case 1: strcpy(scanHeader->activationMethod,"CID"); break; case 2: strcpy(scanHeader->activationMethod,"HCD"); break; case 3: strcpy(scanHeader->activationMethod,"ETD"); break; case 4: strcpy(scanHeader->activationMethod,"ETD+SA"); break; case 5: strcpy(scanHeader->activationMethod,"ECD"); break; default: strcpy(scanHeader->activationMethod,""); break; } } //MH: Indexes in RAMP are stored in an array indexed by scan number, with -1 for the offset //if the scan number does not exist. ramp_fileoffset_t* readIndex(RAMPFILE *pFI, ramp_fileoffset_t indexOffset, int *iLastScan){ vector* v; #ifdef MZP_MZ5 vector* v2; #endif ramp_fileoffset_t* rIndex; unsigned int i; switch(pFI->fileType){ case 1: case 3: v=pFI->mzML->getSpecIndex(); rIndex = (ramp_fileoffset_t *) malloc((pFI->mzML->highScan()+2)*sizeof(ramp_fileoffset_t)); memset(rIndex,-1,(pFI->mzML->highScan()+2)*sizeof(ramp_fileoffset_t)); for(i=0;isize();i++) rIndex[v->at(i).scanNum]=(ramp_fileoffset_t)v->at(i).offset; rIndex[v->at(i-1).scanNum+1]=-1; *iLastScan=v->at(i-1).scanNum; break; case 2: case 4: v=pFI->mzXML->getIndex(); rIndex = (ramp_fileoffset_t *) malloc((pFI->mzXML->highScan()+2)*sizeof(ramp_fileoffset_t)); memset(rIndex,-1,(pFI->mzXML->highScan()+2)*sizeof(ramp_fileoffset_t)); for(i=0;isize();i++) rIndex[v->at(i).scanNum]=(ramp_fileoffset_t)v->at(i).offset; rIndex[v->at(i-1).scanNum+1]=-1; *iLastScan=v->at(i-1).scanNum; break; #ifdef MZP_MZ5 case 5: v2=pFI->mz5->getSpecIndex(); rIndex = (ramp_fileoffset_t *) malloc((pFI->mz5->highScan()+2)*sizeof(ramp_fileoffset_t)); memset(rIndex,-1,(pFI->mz5->highScan()+2)*sizeof(ramp_fileoffset_t)); for(i=0;isize();i++) rIndex[v2->at(i).scanNum]=(ramp_fileoffset_t)v2->at(i).offset; rIndex[v2->at(i-1).scanNum+1]=-1; *iLastScan=v2->at(i-1).scanNum; break; #endif default: rIndex=NULL; *iLastScan=0; break; } v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif return rIndex; } int readMsLevel(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex){ vector* v; #ifdef MZP_MZ5 vector* v2; #endif unsigned int i; if(lScanIndex<0) return 0; switch(pFI->fileType){ case 1: case 3: v=pFI->mzML->getSpecIndex(); for(i=0;isize();i++) { if(v->at(i).offset==(f_off)lScanIndex) { pFI->mzML->readSpectrum(v->at(i).scanNum); break; } } break; case 2: case 4: v=pFI->mzXML->getIndex(); for(i=0;isize();i++) { if(v->at(i).offset==(f_off)lScanIndex) { pFI->mzXML->readSpectrum(v->at(i).scanNum); break; } } break; #ifdef MZP_MZ5 case 5: v2=pFI->mz5->getSpecIndex(); for(i=0;isize();i++) { if(v2->at(i).offset==(f_off)lScanIndex) { pFI->mz5->readSpectrum(v2->at(i).scanNum); break; } } break; #endif default: pFI->bs->clear(); break; } v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif return pFI->bs->getMSLevel(); } void readMSRun(RAMPFILE *pFI, struct RunHeaderStruct *runHeader){ vector* v; #ifdef MZP_MZ5 vector* v2; #endif //memset(scanHeader,0,sizeof(struct ScanHeaderStruct)); runHeader->dEndTime=0.0; runHeader->dStartTime=0.0; runHeader->endMZ=0.0; runHeader->highMZ=0.0; runHeader->lowMZ=0.0; runHeader->scanCount=0; runHeader->startMZ=0.0; switch(pFI->fileType){ case 1: case 3: v=pFI->mzML->getSpecIndex(); runHeader->scanCount=(int)v->size(); pFI->mzML->readHeader(v->at(0).scanNum); runHeader->dStartTime=pFI->bs->getRTime(false); pFI->mzML->readHeader(v->at(v->size()-1).scanNum); runHeader->dEndTime=pFI->bs->getRTime(false); pFI->bs->clear(); v=NULL; break; case 2: case 4: v=pFI->mzXML->getIndex(); runHeader->scanCount=(int)v->size(); pFI->mzXML->readHeader(v->at(0).scanNum); runHeader->dStartTime=pFI->bs->getRTime(false); pFI->mzXML->readHeader(v->at(v->size()-1).scanNum); runHeader->dEndTime=pFI->bs->getRTime(false); pFI->bs->clear(); v=NULL; break; #ifdef MZP_MZ5 case 5: v2=pFI->mz5->getSpecIndex(); runHeader->scanCount=v2->size(); pFI->mz5->readHeader(v2->at(0).scanNum); runHeader->dStartTime=pFI->bs->getRTime(false); pFI->mz5->readHeader(v2->at(v2->size()-1).scanNum); runHeader->dEndTime=pFI->bs->getRTime(false); pFI->bs->clear(); v2=NULL; break; #endif default: break; } } //MH: Matching the index is very indirect, but requires less code, //making this wrapper much easier to read RAMPREAL* readPeaks(RAMPFILE* pFI, ramp_fileoffset_t lScanIndex){ return readPeaks(pFI, lScanIndex, 0); } RAMPREAL* readPeaks(RAMPFILE* pFI, ramp_fileoffset_t lScanIndex, unsigned long scanI) { vector* v; #ifdef MZP_MZ5 vector* v2; #endif unsigned int i; RAMPREAL* pPeaks=NULL; if(lScanIndex<0) return pPeaks; switch(pFI->fileType){ case 1: case 3: v=pFI->mzML->getSpecIndex(); if(!scanI){ for(i=0;isize();i++) { if(v->at(i).offset==(f_off)lScanIndex) { pFI->mzML->readSpectrum(v->at(i).scanNum); break; } } } else { if (v->at(scanI).offset == (f_off)lScanIndex) { pFI->mzML->readSpectrum(v->at(scanI).scanNum); break; } } break; case 2: case 4: v=pFI->mzXML->getIndex(); if(!scanI){ for(i=0;isize();i++) { if(v->at(i).offset==(f_off)lScanIndex) { pFI->mzXML->readSpectrum(v->at(i).scanNum); break; } } } else { if (v->at(scanI).offset == (f_off)lScanIndex) { pFI->mzXML->readSpectrum(v->at(scanI).scanNum); break; } } break; #ifdef MZP_MZ5 case 5: v2=pFI->mz5->getSpecIndex(); if(!scanI){ for(i=0;isize();i++) { if(v2->at(i).offset==(f_off)lScanIndex) { pFI->mz5->readSpectrum(v2->at(i).scanNum); break; } } } else { if (v2->at(scanI).offset == (f_off)lScanIndex) { pFI->mz5->readSpectrum(v2->at(scanI).scanNum); break; } } break; #endif default: pFI->bs->clear(); break; } v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif unsigned int j=0; if(pFI->bs->size()>0){ pPeaks = (RAMPREAL *) malloc((pFI->bs->size()+1) * 2 * sizeof(RAMPREAL) + 1); for(i=0;ibs->size();i++){ pPeaks[j++]=pFI->bs->operator [](i).mz; pPeaks[j++]=pFI->bs->operator [](i).intensity; } } else { pPeaks = (RAMPREAL *) malloc(2 * sizeof(RAMPREAL)); } pPeaks[j]=-1; return pPeaks; } int readPeaksCount(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex){ return readPeaksCount(pFI, lScanIndex, 0); } int readPeaksCount(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex, unsigned long scanI){ ScanHeaderStruct s; readHeader(pFI, lScanIndex, &s, scanI); return s.peaksCount; } void readRunHeader(RAMPFILE *pFI, ramp_fileoffset_t *pScanIndex, struct RunHeaderStruct *runHeader, int iLastScan){ vector* v; #ifdef MZP_MZ5 vector* v2; #endif unsigned int i; runHeader->scanCount=0; runHeader->dEndTime=0.0; runHeader->dStartTime=0.0; runHeader->endMZ=0.0; runHeader->highMZ=0.0; runHeader->lowMZ=0.0; runHeader->startMZ=0.0; switch(pFI->fileType){ case 1: case 3: v=pFI->mzML->getSpecIndex(); runHeader->scanCount=(int)v->size(); pFI->mzML->readHeader(v->at(0).scanNum); runHeader->dStartTime=(double)pFI->bs->getRTime(false); runHeader->lowMZ=pFI->bs->getLowMZ(); runHeader->highMZ=pFI->bs->getHighMZ(); runHeader->startMZ=runHeader->lowMZ; runHeader->endMZ=runHeader->highMZ; for(i=1;isize();i++) { pFI->mzML->readHeader(v->at(i).scanNum); if(pFI->bs->getLowMZ()lowMZ) { runHeader->lowMZ=pFI->bs->getLowMZ(); runHeader->startMZ=runHeader->lowMZ; } if(pFI->bs->getHighMZ()>runHeader->highMZ){ runHeader->highMZ=pFI->bs->getHighMZ(); runHeader->endMZ=runHeader->highMZ; } } pFI->mzML->readHeader(v->at(v->size()-1).scanNum); break; case 2: case 4: v=pFI->mzXML->getIndex(); runHeader->scanCount=(int)v->size(); pFI->mzXML->readHeader(v->at(0).scanNum); runHeader->dStartTime=(double)pFI->bs->getRTime(false); runHeader->lowMZ=pFI->bs->getLowMZ(); runHeader->highMZ=pFI->bs->getHighMZ(); runHeader->startMZ=runHeader->lowMZ; runHeader->endMZ=runHeader->highMZ; for(i=1;isize();i++) { pFI->mzXML->readHeader(v->at(i).scanNum); if(pFI->bs->getLowMZ()lowMZ) { runHeader->lowMZ=pFI->bs->getLowMZ(); runHeader->startMZ=runHeader->lowMZ; } if(pFI->bs->getHighMZ()>runHeader->highMZ){ runHeader->highMZ=pFI->bs->getHighMZ(); runHeader->endMZ=runHeader->highMZ; } } pFI->mzXML->readHeader(v->at(v->size()-1).scanNum); break; #ifdef MZP_MZ5 case 5: v2=pFI->mz5->getSpecIndex(); runHeader->scanCount=v2->size(); pFI->mz5->readHeader(v2->at(0).scanNum); runHeader->dStartTime=(double)pFI->bs->getRTime(false); runHeader->lowMZ=pFI->bs->getLowMZ(); runHeader->highMZ=pFI->bs->getHighMZ(); runHeader->startMZ=runHeader->lowMZ; runHeader->endMZ=runHeader->highMZ; for(i=1;isize();i++) { pFI->mz5->readHeader(v2->at(i).scanNum); if(pFI->bs->getLowMZ()lowMZ) { runHeader->lowMZ=pFI->bs->getLowMZ(); runHeader->startMZ=runHeader->lowMZ; } if(pFI->bs->getHighMZ()>runHeader->highMZ){ runHeader->highMZ=pFI->bs->getHighMZ(); runHeader->endMZ=runHeader->highMZ; } } pFI->mz5->readHeader(v2->at(v2->size()-1).scanNum); break; #endif default: pFI->bs->clear(); v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif return; } v=NULL; #ifdef MZP_MZ5 v2=NULL; #endif } //-------------------------------------------------- // CACHED RAMP FUNCTIONS //-------------------------------------------------- void clearScanCache(struct ScanCacheStruct* cache){ for (int i=0; isize; i++) { if (cache->peaks[i] == NULL) continue; free(cache->peaks[i]); cache->peaks[i] = NULL; } memset(cache->headers, 0, cache->size * sizeof(struct ScanHeaderStruct)); } void freeScanCache(struct ScanCacheStruct* cache){ if (cache) { for (int i=0; isize; i++){ if (cache->peaks[i] != NULL) free(cache->peaks[i]); } free(cache->peaks); free(cache->headers); free(cache); } } int getCacheIndex(struct ScanCacheStruct* cache, int seqNum) { int seqNumStart = cache->seqNumStart; int size = cache->size; // First access, just set the start to seqNum. if (seqNumStart == 0) cache->seqNumStart = seqNum; // If requested scan is less than cache start, shift cache window // left to start at requested scan. else if (seqNum < seqNumStart) shiftScanCache(cache, (int) (seqNum - seqNumStart)); // If requested scan is greater than cache end, shift cache window // right so last entry is requested scan. else if (seqNum >= seqNumStart + size) shiftScanCache(cache, (int) (seqNum - (seqNumStart + size - 1))); return (int) (seqNum - cache->seqNumStart); } struct ScanCacheStruct* getScanCache(int size){ struct ScanCacheStruct* cache = (struct ScanCacheStruct*) malloc(sizeof(struct ScanCacheStruct)); cache->seqNumStart = 0; cache->size = size; cache->headers = (struct ScanHeaderStruct*) calloc(size, sizeof(struct ScanHeaderStruct)); cache->peaks = (RAMPREAL**) calloc(size, sizeof(RAMPREAL*)); return cache; } const struct ScanHeaderStruct* readHeaderCached(struct ScanCacheStruct* cache, int seqNum, RAMPFILE* pFI, ramp_fileoffset_t lScanIndex){ int i = getCacheIndex(cache, seqNum); if (cache->headers[i].msLevel == 0) readHeader(pFI, lScanIndex, cache->headers + i); return cache->headers + i; } int readMsLevelCached(struct ScanCacheStruct* cache, int seqNum, RAMPFILE* pFI, ramp_fileoffset_t lScanIndex){ const struct ScanHeaderStruct* header = readHeaderCached(cache, seqNum, pFI, lScanIndex); return header->msLevel; } const RAMPREAL* readPeaksCached(struct ScanCacheStruct* cache, int seqNum, RAMPFILE* pFI, ramp_fileoffset_t lScanIndex){ int i = getCacheIndex(cache, seqNum); if (cache->peaks[i] == NULL) cache->peaks[i] = readPeaks(pFI, lScanIndex); return cache->peaks[i]; } void shiftScanCache(struct ScanCacheStruct* cache, int nScans) { int i; cache->seqNumStart += nScans; if (abs(nScans) > cache->size) { // If the shift is larger than the size of the cache window, // just clear the whole cache. clearScanCache(cache); } else if (nScans > 0) { // Shifting window to the right. Memory moves right, with new // empty scans on the end. // Free the peaks that memmove will overwrite. for (i = 0; i < nScans; i++) { if (cache->peaks[i] != NULL) free(cache->peaks[i]); } memmove(cache->peaks, cache->peaks + nScans, (cache->size - nScans) * sizeof(RAMPREAL*)); memset(cache->peaks + cache->size - nScans, 0, nScans * sizeof(RAMPREAL*)); memmove(cache->headers, cache->headers + nScans,(cache->size - nScans) * sizeof(struct ScanHeaderStruct)); memset(cache->headers + cache->size - nScans, 0, nScans * sizeof(struct ScanHeaderStruct)); } else if (nScans < 0) { // Shifting window to the left. Memory moves right, with new // empty scans at the beginning. nScans = -nScans; // Free the peaks that memmove will overwrite. for (i = 0; i < nScans; i++) { if (cache->peaks[cache->size - 1 - i] != NULL) free(cache->peaks[cache->size - 1 - i]); } memmove(cache->peaks + nScans, cache->peaks, (cache->size - nScans) * sizeof(RAMPREAL*)); memset(cache->peaks, 0, nScans * sizeof(RAMPREAL*)); memmove(cache->headers + nScans, cache->headers, (cache->size - nScans) * sizeof(struct ScanHeaderStruct)); memset(cache->headers, 0, nScans * sizeof(struct ScanHeaderStruct)); } } //-------------------------------------------------- // DEAD FUNCTIONS //-------------------------------------------------- int isScanAveraged(struct ScanHeaderStruct *scanHeader){ cerr << "call to unsupported function: isScanAveraged(struct ScanHeaderStruct *scanHeader)" << endl; return 0; } int isScanMergedResult(struct ScanHeaderStruct *scanHeader){ cerr << "call to unsupported function: isScanMergedResult(struct ScanHeaderStruct *scanHeader)" << endl; return 0; } int rampSelfTest(char *filename){ cerr << "call to unsupported function: rampSelfTest(char *filename)" << endl; return 0; } char* rampTrimBaseName(char *buf){ cerr << "call to unsupported function: rampTrimBaseName(char *buf)" << endl; return buf; } int rampValidateOrDeriveInputFilename(char *inbuf, int inbuflen, char *spectrumName){ cerr << "call to unsupported function: rampValidateOrDeriveInputFilename(char *inbuf, int inbuflen, char *spectrumName)" << endl; return 0; } double readStartMz(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex){ cerr << "call to unsupported function: readStartMz(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex)" << endl; return 0.0; } double readEndMz(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex){ cerr << "call to unsupported function: readEndMz(RAMPFILE *pFI, ramp_fileoffset_t lScanIndex)" << endl; return 0.0; } void setRampOption(long option){ cerr << "call to unsupported function: setRampOption(long option)" << endl; } libmstoolkit-cleaned-82/src/mzParser/saxhandler.cpp0000644000175000017500000002714113210260002022556 0ustar rusconirusconi/* Copyright (C) 2003-2004 Ronald C Beavis, all rights reserved X! tandem This software is a component of the X! proteomics software development project Use of this software governed by the Artistic license, as reproduced here: The Artistic License for all X! software, binaries and documentation Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder as specified below. "Copyright Holder" is whoever is named in the copyright or copyrights for the package. "You" is you, if you're thinking about copying or distributing this Package. "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a. place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as uunet.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b. use the modified Package only within your corporation or organization. c. rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d. make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a. distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b. accompany the distribution with the machine-readable source of the Package with your modifications. c. give non-standard executables non-standard names, and clearly document the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d. make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not a dvertise this Package as a product of your own. You may embed this Package's interpreter within an executable of yours (by linking); this shall be construed as a mere form of aggregation, provided that the complete Standard Version of the interpreter is so embedded. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. If such scripts or library files are aggregated with this Package via the so-called "undump" or "unexec" methods of producing a binary executable image, then distribution of such an image shall neither be construed as a distribution of this Package nor shall it fall under the restrictions of Paragraphs 3 and 4, provided that you do not represent such an executable image as a Standard Version of this Package. 7. C subroutines (or comparably compiled subroutines in other languages) supplied by you and linked into this Package in order to emulate subroutines and variables of the language defined by this Package shall not be considered part of this Package, but are the equivalent of input as in Paragraph 6, provided these subroutines do not change the language in any way that would cause it to fail the regression tests for the language. 8. Aggregation of this Package with a commercial distribution is always permitted provided that the use of this Package is embedded; that is, when no overt attempt is made to make this Package's interfaces visible to the end user of the commercial distribution. Such use shall not be construed as a distribution of this Package. 9. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End */ #include "mzParser.h" // Static callback handlers static void mzp_startElementCallback(void *data, const XML_Char *el, const XML_Char **attr) { ((mzpSAXHandler*) data)->startElement(el, attr); } static void mzp_endElementCallback(void *data, const XML_Char *el) { ((mzpSAXHandler*) data)->endElement(el); } static void mzp_charactersCallback(void *data, const XML_Char *s, int len) { ((mzpSAXHandler*) data)->characters(s, len); } mzpSAXHandler::mzpSAXHandler() { fptr = NULL; m_bGZCompression = false; fptr = NULL; m_parser = XML_ParserCreate(NULL); XML_SetUserData(m_parser, this); XML_SetElementHandler(m_parser, mzp_startElementCallback, mzp_endElementCallback); XML_SetCharacterDataHandler(m_parser, mzp_charactersCallback); } mzpSAXHandler::~mzpSAXHandler() { if(fptr!=NULL) fclose(fptr); fptr = NULL; XML_ParserFree(m_parser); } void mzpSAXHandler::startElement(const XML_Char *el, const XML_Char **attr) { } void mzpSAXHandler::endElement(const XML_Char *el) { } void mzpSAXHandler::characters(const XML_Char *s, int len) { } bool mzpSAXHandler::open(const char* fileName){ if(fptr!=NULL) fclose(fptr); if(m_bGZCompression) fptr=fopen(fileName,"rb"); else fptr=fopen(fileName,"r"); if(fptr==NULL){ //cerr << "Failed to open input file '" << fileName << "'.\n"; return false; } setFileName(fileName); //Build the index if gz compressed if(m_bGZCompression){ gzObj.free_index(); int len; len = gzObj.build_index(fptr, SPAN); if (len < 0) { fclose(fptr); switch (len) { case Z_MEM_ERROR: fprintf(stderr, "Error reading .gz file: out of memory\n"); break; case Z_DATA_ERROR: fprintf(stderr, "Error reading .gz file: compressed data error in %s\n", fileName); break; case Z_ERRNO: fprintf(stderr, "Error reading .gz file: read error on %s\n", fileName); break; default: fprintf(stderr, "Error reading .gz file: error %d while building index\n", len); } fptr=NULL; return false; } } return true; } bool mzpSAXHandler::parse() { if (fptr == NULL){ cerr << "Error parse(): No open file." << endl; return false; } char buffer[CHUNK]; //CHUNK=16384 int readBytes = 0; bool success = true; int chunk=0; if(m_bGZCompression){ while (success && (readBytes = gzObj.extract(fptr, 0+chunk*CHUNK, (unsigned char*)buffer, CHUNK))>0) { success = (XML_Parse(m_parser, buffer, readBytes, false) != 0); chunk++; } } else { while (success && (readBytes = (int) fread(buffer, 1, sizeof(buffer), fptr)) != 0){ success = (XML_Parse(m_parser, buffer, readBytes, false) != 0); } } success = success && (XML_Parse(m_parser, buffer, 0, true) != 0); if (!success) { XML_Error error = XML_GetErrorCode(m_parser); cerr << m_strFileName << "(" << XML_GetCurrentLineNumber(m_parser) << ")" << " : error " << (int) error << ": "; switch (error) { case XML_ERROR_SYNTAX: case XML_ERROR_INVALID_TOKEN: case XML_ERROR_UNCLOSED_TOKEN: cerr << "Syntax error parsing XML."; break; // TODO: Add more descriptive text for interesting errors. default: cerr << "XML Parsing error."; break; } cerr << "\n"; return false; } return true; } //This function operates similarly to the parse() function. //However, it accepts a file offset to begin parsing at a specific point. //The parser will halt file reading when stop flag is triggered. bool mzpSAXHandler::parseOffset(f_off offset){ if (fptr == NULL){ cerr << "Error parseOffset(): No open file." << endl; return false; } char buffer[CHUNK]; //CHUNK=16384 int readBytes = 0; bool success = true; int chunk=0; XML_ParserReset(m_parser,"ISO-8859-1"); XML_SetUserData(m_parser, this); XML_SetElementHandler(m_parser, mzp_startElementCallback, mzp_endElementCallback); XML_SetCharacterDataHandler(m_parser, mzp_charactersCallback); mzpfseek(fptr,offset,SEEK_SET); m_bStopParse=false; if(m_bGZCompression){ while (success && (readBytes = gzObj.extract(fptr, offset+chunk*CHUNK, (unsigned char*)buffer, CHUNK))>0) { success = (XML_Parse(m_parser, buffer, readBytes, false) != 0); chunk++; if(m_bStopParse) break; } } else { while (success && (readBytes = (int) fread(buffer, 1, sizeof(buffer), fptr)) != 0) { success = (XML_Parse(m_parser, buffer, readBytes, false) != 0); if(m_bStopParse) break; } } if (!success && !m_bStopParse) { XML_Error error = XML_GetErrorCode(m_parser); cerr << m_strFileName << "(" << XML_GetCurrentLineNumber(m_parser) << ")" << " : parseOffset() " << (int) error << ": "; switch (error) { case XML_ERROR_SYNTAX: case XML_ERROR_INVALID_TOKEN: case XML_ERROR_UNCLOSED_TOKEN: cerr << "Syntax error parsing XML." << endl; break; // TODO: Add more descriptive text for interesting errors. default: cerr << "Spectrum XML Parsing error:\n"; cerr << XML_ErrorString(error) << endl; break; } exit(-7); return false; } return true; } void mzpSAXHandler::setGZCompression(bool b){ m_bGZCompression=b; } libmstoolkit-cleaned-82/src/mzParser/mzp_base64.cpp0000644000175000017500000001023213210260002022370 0ustar rusconirusconi/* downloaded from web */ //#include //#include //#include "stdafx.h" //#include //#include "base64.h" #include "mzParser.h" inline int getPosition( char buf ); static const unsigned char *b64_tbl = (const unsigned char*) "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; static const unsigned char b64_pad = '='; /* base64 encode a group of between 1 and 3 input chars into a group of 4 output chars */ static void encode_group (unsigned char output[], const unsigned char input[], int n) { unsigned char ingrp[3]; ingrp[0] = n > 0 ? input[0] : 0; ingrp[1] = n > 1 ? input[1] : 0; ingrp[2] = n > 2 ? input[2] : 0; /* upper 6 bits of ingrp[0] */ output[0] = n > 0 ? b64_tbl[ingrp[0] >> 2] : b64_pad; /* lower 2 bits of ingrp[0] | upper 4 bits of ingrp[1] */ output[1] = n > 0 ? b64_tbl[((ingrp[0] & 0x3) << 4) | (ingrp[1] >> 4)] : b64_pad; /* lower 4 bits of ingrp[1] | upper 2 bits of ingrp[2] */ output[2] = n > 1 ? b64_tbl[((ingrp[1] & 0xf) << 2) | (ingrp[2] >> 6)] : b64_pad; /* lower 6 bits of ingrp[2] */ output[3] = n > 2 ? b64_tbl[ingrp[2] & 0x3f] : b64_pad; } int b64_encode (char *dest, const char *src, int len) { int outsz = 0; while (len > 0) { encode_group ( (unsigned char*) dest + outsz, (const unsigned char*) src, len > 3 ? 3 : len); len -= 3; src += 3; outsz += 4; } return outsz; } /* base64 decode a group of 4 input chars into a group of between 0 and * 3 output chars */ static void decode_group (unsigned char output[], const unsigned char input[], int *n) { unsigned char *t1, *t2; *n = 0; if (input[0] == '=') return; t1 = (unsigned char*) strchr ((const char*)b64_tbl, input[0]); t2 = (unsigned char*) strchr ((const char*)b64_tbl, input[1]); output[(*n)++] = (unsigned char)(((t1 - b64_tbl) << 2) | ((t2 - b64_tbl) >> 4)); if (input[2] == '=') return; t1 = (unsigned char*) strchr ((const char*)b64_tbl, input[2]); output[(*n)++] = (unsigned char)(((t2 - b64_tbl) << 4) | ((t1 - b64_tbl) >> 2)); if (input[3] == '=') return; t2 = (unsigned char*) strchr ((const char*)b64_tbl, input[3]); output[(*n)++] = (unsigned char)(((t1 - b64_tbl) << 6) | (t2 - b64_tbl)); return; } inline int getPosition( char buf ) { if( buf > 96 ) // [a-z] return (buf - 71); else if( buf > 64 ) // [A-Z] return (buf - 65); else if( buf > 47 ) // [0-9] return (buf + 4); else if( buf == 43 ) return 63; else // buf == '/' return 64; } // Returns the total number of bytes decoded int b64_decode_mio ( char *dest, char *src, size_t size ) { char *temp = dest; char *end = dest + size; for (;;) { int register a; int register b; int t1,t2,t3,t4; if (!(t1 = *src++) || !(t2 = *src++) || !(t3 = *src++) || !(t4 = *src++)) return (int)(temp-dest); if (t1 == 61 || temp >= end) // if == '=' return(int)(temp-dest); if( t1 > 96 ) // [a-z] a = (t1 - 71); else if( t1 > 64 ) // [A-Z] a = (t1 - 65); else if( t1 > 47 ) // [0-9] a = (t1 + 4); else if( t1 == 43 ) a = 62; else // src[0] == '/' a = 63; if( t2 > 96 ) // [a-z] b = (t2 - 71); else if( t2 > 64 ) // [A-Z] b = (t2 - 65); else if( t2 > 47 ) // [0-9] b = (t2 + 4); else if( t2 == 43 ) b = 62; else // src[0] == '/' b = 63; *temp++ = ( a << 2) | ( b >> 4); if (t3 == 61 || temp >= end) return (int)(temp-dest);; if( t3 > 96 ) // [a-z] a = (t3 - 71); else if( t3 > 64 ) // [A-Z] a = (t3 - 65); else if( t3 > 47 ) // [0-9] a = (t3 + 4); else if( t3 == 43 ) a = 62; else // src[0] == '/' a = 63; *temp++ = ( b << 4) | ( a >> 2); if (t4 == 61 || temp >= end) return (int)(temp-dest);; if( t4 > 96 ) // [a-z] b = (t4 - 71); else if( t4 > 64 ) // [A-Z] b = (t4 - 65); else if( t4 > 47 ) // [0-9] b = (t4 + 4); else if( t4 == 43 ) b = 62; else // src[0] == '/' b = 63; *temp++ = ( a << 6) | ( b ); } } libmstoolkit-cleaned-82/src/mzParser/PWIZface.cpp0000644000175000017500000000724413210260002022037 0ustar rusconirusconi#include "mzParser.h" Chromatogram::Chromatogram(){ bc = NULL; } Chromatogram::~Chromatogram(){ bc = NULL; } void Chromatogram::getTimeIntensityPairs(vector& v){ if(bc==NULL) cerr << "Null chromatogram" << endl; else v=bc->getData(); } ChromatogramList::ChromatogramList(){ } ChromatogramList::ChromatogramList(mzpSAXMzmlHandler* ml, void* m5, BasicChromatogram* bc){ mzML=ml; #ifdef MZP_MZ5 mz5=(mzpMz5Handler*)m5; #endif chromat=new Chromatogram(); chromat->bc=bc; } ChromatogramList::~ChromatogramList(){ mzML=NULL; vChromatIndex=NULL; #ifdef MZP_MZ5 mz5=NULL; vMz5Index=NULL; #endif delete chromat; } ChromatogramPtr ChromatogramList::chromatogram(int index, bool binaryData) { char str[128]; if(mzML!=NULL) { mzML->readChromatogram(index); chromat->bc->getIDString(str); chromat->id=str; return chromat; #ifdef MZP_MZ5 } else if(mz5!=NULL) { mz5->readChromatogram(index); chromat->bc->getIDString(str); chromat->id=str; return chromat; #endif } return NULL; } bool ChromatogramList::get() { if(mzML!=NULL) vChromatIndex = mzML->getChromatIndex(); #ifdef MZP_MZ5 else if(mz5!=NULL) vMz5Index = mz5->getChromatIndex(); #endif else return false; return true; } size_t ChromatogramList::size() { if(vChromatIndex==NULL) { cerr << "Get chromatogram list first." << endl; return 0; } if(mzML!=NULL) return vChromatIndex->size(); #ifdef MZP_MZ5 else if(mz5!=NULL) return vMz5Index->size(); #endif else return 0; } PwizRun::PwizRun(){ chromatogramListPtr = new ChromatogramList(); } PwizRun::PwizRun(mzpSAXMzmlHandler* ml, void* m5, BasicChromatogram* b){ mzML=ml; #ifdef MZP_MZ5 mz5=(mzpMz5Handler*)m5; #endif bc=b; chromatogramListPtr = new ChromatogramList(ml, m5, b); } PwizRun::~PwizRun(){ mzML=NULL; #ifdef MZP_MZ5 mz5=NULL; #endif bc=NULL; delete chromatogramListPtr; } void PwizRun::set(mzpSAXMzmlHandler* ml, void* m5, BasicChromatogram* b){ mzML=ml; #ifdef MZP_MZ5 mz5=(mzpMz5Handler*)m5; #endif bc=b; delete chromatogramListPtr; chromatogramListPtr = new ChromatogramList(ml, m5, b); } MSDataFile::MSDataFile(string s){ int i=checkFileType(&s[0]); if(i==0){ cerr << "Cannot identify file type." << endl; } else { bs = new BasicSpectrum(); bc = new BasicChromatogram(); switch(i){ case 1: //mzML case 3: mzML=new mzpSAXMzmlHandler(bs,bc); if(i==3) mzML->setGZCompression(true); else mzML->setGZCompression(false); if(!mzML->load(&s[0])){ cerr << "Failed to load file." << endl; delete mzML; delete bs; delete bc; } run.chromatogramListPtr->vChromatIndex=mzML->getChromatIndex(); break; case 2: //mzXML case 4: cerr << "mzXML not supported in this interface." << endl; delete bs; delete bc; break; #ifdef MZP_MZ5 case 5: //mz5 mz5Config = new mzpMz5Config(); mz5=new mzpMz5Handler(mz5Config, bs, bc); if(!mz5->readFile(&s[0])){ cerr << "Failed to load file." << endl; delete mz5; delete mz5Config; delete bs; delete bc; } break; #endif default: break; } #ifdef MZP_MZ5 run.set(mzML,mz5,bc); #else run.set(mzML,NULL,bc); #endif } } MSDataFile::~MSDataFile(){ if(mzML!=NULL) delete mzML; #ifdef MZP_MZ5 if(mz5!=NULL){ delete mz5; delete mz5Config; } #endif delete bs; delete bc; } libmstoolkit-cleaned-82/src/mzParser/saxmzmlhandler.cpp0000644000175000017500000007010313210260002023452 0ustar rusconirusconi/************************************************************ * SAXMzmlHandler.cpp * Adapted from SAXMzdataHandler.cpp * August 2008 * Ronald Beavis * * April 2009 - Support for referenceable param groups and mzML 1.1.0 * Fredrik Levander * * December 2010 - Drastically modified and cannibalized to create * robust, yet generic, mzML parser * Mike Hoopmann, Institute for Systems Biology * * Premiere version janvier 2005 * Patrick Lacasse * placasse@mat.ulaval.ca * * 3/11/2005 (Brendan MacLean): Use eXpat SAX parser, and create SAXSpectraHandler * * November 2005 * Fredrik Levander * A few changes to handle MzData 1.05. * * Updated to handle version 1.04 and 1.05. (Rob Craig) * * * See http://psidev.sourceforge.net/ms/#mzdata for * mzData schema information. * * Inspired by DtaSAX2Handler.cpp * copyright : (C) 2002 by Pedrioli Patrick, ISB, Proteomics * email : ppatrick@systemsbiology.org * Artistic License granted 3/11/2005 *******************************************************/ #include "mzParser.h" mzpSAXMzmlHandler::mzpSAXMzmlHandler(BasicSpectrum* bs){ m_bChromatogramIndex = false; m_bInmzArrayBinary = false; m_bInintenArrayBinary = false; m_bInRefGroup = false; m_bNetworkData = false; //always little-endian for mzML m_bNumpressLinear = false; m_bNumpressPic = false; m_bNumpressSlof = false; m_bLowPrecision = false; m_bInSpectrumList=false; m_bInChromatogramList=false; m_bInIndexedMzML=false; m_bInIndexList=false; m_bInProduct=false; m_bHeaderOnly=false; m_bSpectrumIndex=false; m_bNoIndex=true; m_bIndexSorted = true; m_bZlib=false; m_iDataType=0; spec=bs; indexOffset=-1; m_scanPRECCount = 0; m_scanSPECCount = 0; m_scanIDXCount = 0; chromat=NULL; } mzpSAXMzmlHandler::mzpSAXMzmlHandler(BasicSpectrum* bs, BasicChromatogram* cs){ m_bChromatogramIndex = false; m_bInmzArrayBinary = false; m_bInintenArrayBinary = false; m_bInRefGroup = false; m_bNetworkData = false; //always little-endian for mzML m_bNumpressLinear = false; m_bNumpressPic = false; m_bNumpressSlof = false; m_bLowPrecision = false; m_bInSpectrumList=false; m_bInChromatogramList=false; m_bInIndexedMzML=false; m_bInIndexList=false; m_bInProduct=false; m_bHeaderOnly=false; m_bSpectrumIndex=false; m_bNoIndex=true; m_bIndexSorted = true; m_bZlib=false; m_iDataType=0; spec=bs; chromat=cs; indexOffset=-1; m_scanPRECCount = 0; m_scanSPECCount = 0; m_scanIDXCount = 0; } mzpSAXMzmlHandler::~mzpSAXMzmlHandler(){ chromat=NULL; spec=NULL; } void mzpSAXMzmlHandler::startElement(const XML_Char *el, const XML_Char **attr){ if (isElement("binaryDataArray",el)){ m_bNumpressLinear=false; string s=getAttrValue("encodedLength", attr); m_encodedLen=atoi(&s[0]); } else if (isElement("binaryDataArrayList",el)) { if(m_bHeaderOnly) stopParser(); } else if (isElement("chromatogram",el)) { string s=getAttrValue("id", attr); chromat->setIDString(&s[0]); m_peaksCount = atoi(getAttrValue("defaultArrayLength", attr)); } else if (isElement("chromatogramList",el)) { m_bInChromatogramList=true; } else if(isElement("index",el) && m_bInIndexList){ if(!strcmp(getAttrValue("name", attr),"spectrum")) m_bSpectrumIndex=true; if(!strcmp(getAttrValue("name", attr),"chromatogram")) m_bChromatogramIndex=true; } else if (isElement("indexedmzML",el)) { m_vIndex.clear(); m_bInIndexedMzML=true; } else if(isElement("indexList",el)) { m_bInIndexList=true; } else if(isElement("offset",el) && m_bChromatogramIndex){ m_strData.clear(); curChromatIndex.idRef=string(getAttrValue("idRef", attr)); } else if(isElement("offset",el) && m_bSpectrumIndex){ m_strData.clear(); curIndex.idRef=string(getAttrValue("idRef", attr)); if(strstr(&curIndex.idRef[0],"scan=")!=NULL) { curIndex.scanNum=atoi(strstr(&curIndex.idRef[0],"scan=")+5); } else if(strstr(&curIndex.idRef[0],"scanId=")!=NULL) { curIndex.scanNum=atoi(strstr(&curIndex.idRef[0],"scanId=")+7); } else if(strstr(&curIndex.idRef[0],"S")!=NULL) { curIndex.scanNum=atoi(strstr(&curIndex.idRef[0],"S")+1); } else { curIndex.scanNum=++m_scanIDXCount; //Suppressing warning. //cout << "WARNING: Cannot extract scan number in index offset line: " << &curIndex.idRef[0] << "\tDefaulting to " << m_scanIDXCount << endl; } } else if(isElement("precursor",el)) { string s=getAttrValue("spectrumRef", attr); //if spectrumRef is not provided if(s.length()<1){ spec->setPrecursorScanNum(0); } else { if(strstr(&s[0],"scan=")!=NULL) { spec->setPrecursorScanNum(atoi(strstr(&s[0],"scan=")+5)); } else if(strstr(&s[0],"scanId=")!=NULL) { spec->setPrecursorScanNum(atoi(strstr(&s[0],"scanId=")+7)); } else if(strstr(&s[0],"S")!=NULL) { spec->setPrecursorScanNum(atoi(strstr(&s[0],"S")+1)); } else { spec->setPrecursorScanNum(++m_scanPRECCount); //Suppressing warning. //cout << "WARNING: Cannot extract precursor scan number spectrum line: " << &s[0] << "\tDefaulting to " << m_scanPRECCount << endl; } } } else if (isElement("product", el)) { m_bInProduct=true; } else if (isElement("referenceableParamGroup", el)) { const char* groupName = getAttrValue("id", attr); m_ccurrentRefGroupName = string(groupName); m_bInRefGroup = true; } else if (isElement("run", el)){ stopParser(); } else if (isElement("softwareParam", el)) { const char* name = getAttrValue("name", attr); const char* accession = getAttrValue("accession", attr); const char* version = getAttrValue("version", attr); } else if (isElement("spectrum", el)) { string s=getAttrValue("id", attr); spec->setIDString(&s[0]); if(strstr(&s[0],"scan=")!=NULL) { spec->setScanNum(atoi(strstr(&s[0],"scan=")+5)); } else if(strstr(&s[0],"scanId=")!=NULL) { spec->setScanNum(atoi(strstr(&s[0],"scanId=")+7)); } else if(strstr(&s[0],"S")!=NULL) { spec->setScanNum(atoi(strstr(&s[0],"S")+1)); } else { spec->setScanNum(++m_scanSPECCount); //Suppressing warning. //cout << "WARNING: Cannot extract scan number spectrum line: " << &s[0] << "\tDefaulting to " << m_scanSPECCount << endl; } m_peaksCount = atoi(getAttrValue("defaultArrayLength", attr)); spec->setPeaksCount(m_peaksCount); } else if (isElement("spectrumList",el)) { m_bInSpectrumList=true; } else if (isElement("cvParam", el)) { const char* name = getAttrValue("name", attr); const char* accession = getAttrValue("accession", attr); const char* value = getAttrValue("value", attr); const char* unitName = getAttrValue("unitName", attr); const char* unitAccession = getAttrValue("unitAccession", attr); if (m_bInRefGroup) { cvParam m_cvParam; m_cvParam.refGroupName = string(m_ccurrentRefGroupName); m_cvParam.name = string(name); m_cvParam.accession = string(accession); m_cvParam.value = string(value); m_cvParam.unitName = string(unitName); m_cvParam.unitAccession = string(unitAccession); m_refGroupCvParams.push_back(m_cvParam); } else { processCVParam(name,accession,value,unitName,unitAccession); } } else if (isElement("referenceableParamGroupRef", el)) { const char* groupName = getAttrValue("ref", attr); for (unsigned int i=0;isetProduct(m_precursorIon.isoMZ, m_precursorIon.isoLowerMZ, m_precursorIon.isoUpperMZ); } else if(isElement("offset",el) && m_bChromatogramIndex){ curChromatIndex.offset=mzpatoi64(&m_strData[0]); m_vChromatIndex.push_back(curChromatIndex); } else if(isElement("offset",el) && m_bSpectrumIndex){ curIndex.offset=mzpatoi64(&m_strData[0]); m_vIndex.push_back(curIndex); if (m_bIndexSorted && m_vIndex.size() > 1) { if (m_vIndex[m_vIndex.size()-1].scanNum < m_vIndex[m_vIndex.size()-2].scanNum) { m_bIndexSorted = false; } } } else if(isElement("precursorList",el)){ } else if (isElement("product", el)){ m_bInProduct=false; } else if(isElement("referenceableParamGroup", el)) { m_bInRefGroup = false; } else if(isElement("selectedIon",el)) { spec->setPrecursorIon(m_precursorIon); m_precursorIon.clear(); } else if(isElement("spectrum", el)) { pushSpectrum(); stopParser(); } else if(isElement("spectrumList",el)) { m_bInSpectrumList = false; } } void mzpSAXMzmlHandler::characters(const XML_Char *s, int len) { m_strData.append(s, len); } void mzpSAXMzmlHandler::processCVParam(const char* name, const char* accession, const char* value, const char* unitName, const char* unitAccession) { if(!strcmp(name, "32-bit float") || !strcmp(accession,"MS:1000521")) { m_bLowPrecision = true; m_iDataType=1; } else if(!strcmp(name, "64-bit float") || !strcmp(accession,"MS:1000523")) { m_bLowPrecision = false; m_iDataType=2; } else if(!strcmp(name, "base peak intensity") || !strcmp(accession,"MS:1000505")) { spec->setBasePeakIntensity(atof(value)); } else if(!strcmp(name, "base peak m/z") || !strcmp(accession,"MS:1000504")) { spec->setBasePeakMZ(atof(value)); } else if(!strcmp(name, "centroid spectrum") || !strcmp(accession,"MS:1000127")) { spec->setCentroid(true); } else if(!strcmp(name, "charge state") || !strcmp(accession,"MS:1000041")) { m_precursorIon.charge = atoi(value); } else if(!strcmp(name, "collision-induced dissociation") || !strcmp(accession,"MS:1000133")) { if(spec->getActivation()==ETD) spec->setActivation(ETDSA); else spec->setActivation(CID); } else if(!strcmp(name, "collision energy") || !strcmp(accession,"MS:1000045")) { spec->setCollisionEnergy(atof(value)); } else if(!strcmp(name,"electron multiplier") || !strcmp(accession,"MS:1000253")) { m_instrument.detector=name; } else if(!strcmp(name, "electron transfer dissociation") || !strcmp(accession,"MS:1000598")) { if(spec->getActivation()==CID) spec->setActivation(ETDSA); else spec->setActivation(ETD); } else if(!strcmp(name, "FAIMS compensation voltage") || !strcmp(accession,"MS:1001581")) { spec->setCompensationVoltage(atof(value)); } else if(!strcmp(name, "filter string") || !strcmp(accession,"MS:1000512")) { char str[128]; strncpy(str,value,127); str[127]='\0'; spec->setFilterLine(str); } else if(!strcmp(name, "highest observed m/z") || !strcmp(accession,"MS:1000527")) { spec->setHighMZ(atof(value)); } else if(!strcmp(name,"inductive detector") || !strcmp(accession,"MS:1000624")) { m_instrument.detector=name; } else if(!strcmp(name, "intensity array") || !strcmp(accession,"MS:1000515")) { m_bInintenArrayBinary = true; m_bInmzArrayBinary = false; } else if (!strcmp(name, "ion injection time") || !strcmp(accession, "MS:1000927")) { spec->setIonInjectionTime(atof(value)); } else if(!strcmp(name,"isolation window target m/z") || !strcmp(accession,"MS:1000827")) { m_precursorIon.isoMZ=atof(value); } else if (!strcmp(name, "isolation window lower offset") || !strcmp(accession, "MS:1000828")) { m_precursorIon.isoLowerMZ = atof(value); } else if (!strcmp(name, "isolation window upper offset") || !strcmp(accession, "MS:1000829")) { m_precursorIon.isoUpperMZ = atof(value); } else if(!strcmp(name,"LTQ Velos") || !strcmp(accession,"MS:1000855")) { m_instrument.model=name; } else if(!strcmp(name, "lowest observed m/z") || !strcmp(accession,"MS:1000528")) { spec->setLowMZ(atof(value)); } else if( !strcmp(name, "MS1 spectrum") || !strcmp(accession,"MS:1000579") ){ spec->setMSLevel(1); } else if( !strcmp(name, "ms level") || !strcmp(accession,"MS:1000511") ){ spec->setMSLevel(atoi(value)); } else if( !strcmp(name, "MS-Numpress linear prediction compression") || !strcmp(accession,"MS:1002312") ){ m_bNumpressLinear = true; } else if( !strcmp(name, "MS-Numpress positive integer compression") || !strcmp(accession,"MS:1002313") ){ m_bNumpressPic = true; } else if( !strcmp(name, "MS-Numpress short logged float compression") || !strcmp(accession,"MS:1002314") ){ m_bNumpressSlof = true; } else if(!strcmp(name, "m/z array") || !strcmp(accession,"MS:1000514")) { m_bInmzArrayBinary = true; m_bInintenArrayBinary = false; } else if(!strcmp(name,"nanoelectrospray") || !strcmp(accession,"MS:1000398")) { m_instrument.ionization=name; } else if(!strcmp(name,"orbitrap") || !strcmp(accession,"MS:1000484")) { m_instrument.analyzer=name; } else if(!strcmp(name,"peak intensity") || !strcmp(accession,"MS:1000042")) { m_precursorIon.intensity=atof(value); } else if(!strcmp(name,"positive scan") || !strcmp(accession,"MS:1000130")) { spec->setPositiveScan(true); } else if(!strcmp(name,"possible charge state") || !strcmp(accession,"MS:1000633")) { m_precursorIon.possibleCharges->push_back(atoi(value)); } else if(!strcmp(name,"profile spectrum") || !strcmp(accession,"MS:1000128")) { spec->setCentroid(false); } else if(!strcmp(name,"radial ejection linear ion trap") || !strcmp(accession,"MS:1000083")) { m_instrument.analyzer=name; } else if(!strcmp(name, "scan start time") || !strcmp(accession,"MS:1000016")) { if(!strcmp(unitName, "minute") || !strcmp(unitAccession,"UO:0000031")) { spec->setRTime((float)atof(value)); } else { spec->setRTime((float)atof(value)/60.0f); //assume if not minutes, then seconds } } else if(!strcmp(name, "scan window lower limit") || !strcmp(accession,"MS:1000501")) { //TODO: should we also check the units??? spec->setLowMZ(atof(value)); } else if(!strcmp(name, "scan window upper limit") || !strcmp(accession,"MS:1000500")) { //TODO: should we also check the units??? spec->setHighMZ(atof(value)); } else if(!strcmp(name, "selected ion m/z") || !strcmp(accession,"MS:1000744")) { m_precursorIon.mz=atof(value); //in Thermo instruments this is the monoisotopic peak (if known) or the selected ion peak. if(m_precursorIon.monoMZ!=0) m_precursorIon.monoMZ=atof(value); //if the monoisotopic peak was specified earlier, this is a better value to use. else if (m_precursorIon.mzsetTotalIonCurrent(atof(value)); } else if(!strcmp(name,"Thermo RAW file") || !strcmp(accession,"MS:1000563")) { m_instrument.manufacturer="Thermo Scientific"; } else if(!strcmp(name, "zlib compression") || !strcmp(accession,"MS:1000574")) { m_bZlib=true; } } void mzpSAXMzmlHandler::processData() { if(m_bInmzArrayBinary) { decode(vdM); //if(m_bLowPrecision && !m_bCompressedData) decode32(vdM); //else if(m_bLowPrecision && m_bCompressedData) decompress32(vdM); //else if(!m_bLowPrecision && !m_bCompressedData) decode64(vdM); //else decompress64(vdM); } else if(m_bInintenArrayBinary) { decode(vdI); //if(m_bLowPrecision && !m_bCompressedData) decode32(vdI); //else if(m_bLowPrecision && m_bCompressedData) decompress32(vdI); //else if(!m_bLowPrecision && !m_bCompressedData) decode64(vdI); //else decompress64(vdI); } //m_bCompressedData=false; } bool mzpSAXMzmlHandler::readChromatogram(int num){ if(chromat==NULL) return false; chromat->clear(); if(m_bNoIndex){ cout << "Currently only supporting indexed mzML" << endl; return false; } //if no scan was requested, grab the next one if(num<0) posChromatIndex++; else posChromatIndex=num; if(posChromatIndex>=(int)m_vChromatIndex.size()) return false; parseOffset(m_vChromatIndex[posChromatIndex].offset); return true; } bool mzpSAXMzmlHandler::readHeader(int num){ spec->clear(); if(m_bNoIndex){ cout << "Currently only supporting indexed mzML" << endl; return false; } //if no scan was requested, grab the next one if(num<0){ posIndex++; if(posIndex>=(int)m_vIndex.size()) return false; m_bHeaderOnly=true; parseOffset(m_vIndex[posIndex].offset); m_bHeaderOnly=false; return true; } //Assumes scan numbers are in order size_t mid=m_vIndex.size()/2; size_t upper=m_vIndex.size(); size_t lower=0; while(m_vIndex[mid].scanNum!=num){ if(lower==upper) break; if(m_vIndex[mid].scanNum>num){ upper=mid-1; mid=(lower+upper)/2; } else { lower=mid+1; mid=(lower+upper)/2; } } if(m_vIndex[mid].scanNum==num) { m_bHeaderOnly=true; parseOffset(m_vIndex[mid].offset); //force scan number; this was done for files where scan events are not numbered if(spec->getScanNum()!=m_vIndex[mid].scanNum) spec->setScanNum(m_vIndex[mid].scanNum); spec->setScanIndex((int)mid+1); //set the index, which starts from 1, so offset by 1 m_bHeaderOnly=false; posIndex=(int)mid; return true; } return false; } bool mzpSAXMzmlHandler::readSpectrum(int num){ spec->clear(); if(m_bNoIndex){ cout << "Currently only supporting indexed mzML" << endl; return false; } //if no scan was requested, grab the next one if(num<0){ posIndex++; if(posIndex>=(int)m_vIndex.size()) return false; parseOffset(m_vIndex[posIndex].offset); return true; } //Assumes scan numbers are in order size_t mid=m_vIndex.size()/2; size_t upper=m_vIndex.size(); size_t lower=0; while(m_vIndex[mid].scanNum!=num){ if(lower==upper) break; if(m_vIndex[mid].scanNum>num){ upper=mid-1; mid=(lower+upper)/2; } else { lower=mid+1; mid=(lower+upper)/2; } } //need something faster than this perhaps //for(unsigned int i=0;igetScanNum()!=m_vIndex[mid].scanNum) spec->setScanNum(m_vIndex[mid].scanNum); spec->setScanIndex((int)mid+1); //set the index, which starts from 1, so offset by 1 posIndex=(int)mid; return true; } //} return false; } void mzpSAXMzmlHandler::pushChromatogram(){ TimeIntensityPair tip; for(unsigned int i=0;iaddTIP(tip); } } void mzpSAXMzmlHandler::pushSpectrum(){ specDP dp; for(unsigned int i=0;iaddDP(dp); } } void mzpSAXMzmlHandler::decode(vector& d){ //If there is no data, back out now d.clear(); if(m_peaksCount < 1) return; //For byte order correction union udata32 { float d; uint32_t i; } uData32; union udata64 { double d; uint64_t i; } uData64; const char* pData = m_strData.data(); size_t stringSize = m_strData.size(); char* decoded = new char[m_encodedLen]; //array for decoded base64 string int decodeLen; Bytef* unzipped; uLong unzippedLen; int i; //Base64 decoding decodeLen = b64_decode_mio(decoded,(char*)pData,stringSize); //zlib decompression if(m_bZlib) { if(m_iDataType==1) { unzippedLen = m_peaksCount*sizeof(uint32_t); } else if(m_iDataType==2) { unzippedLen = m_peaksCount*sizeof(uint64_t); } else { if(!m_bNumpressLinear && !m_bNumpressSlof && !m_bNumpressPic){ cout << "Unknown data format to unzip. Stopping file read." << endl; exit(EXIT_FAILURE); } //don't know the unzipped size of numpressed data, so assume it to be no larger than unpressed 64-bit data unzippedLen = m_peaksCount*sizeof(uint64_t); } unzipped = new Bytef[unzippedLen]; uncompress((Bytef*)unzipped, &unzippedLen, (const Bytef*)decoded, (uLong)decodeLen); delete [] decoded; } //Numpress decompression if(m_bNumpressLinear || m_bNumpressSlof || m_bNumpressPic){ double* unpressed=new double[m_peaksCount]; try{ if(m_bNumpressLinear){ if(m_bZlib) ms::numpress::MSNumpress::decodeLinear((unsigned char*)unzipped,(const size_t)unzippedLen,unpressed); else ms::numpress::MSNumpress::decodeLinear((unsigned char*)decoded,decodeLen,unpressed); } else if(m_bNumpressSlof){ if(m_bZlib) ms::numpress::MSNumpress::decodeSlof((unsigned char*)unzipped,(const size_t)unzippedLen,unpressed); else ms::numpress::MSNumpress::decodeSlof((unsigned char*)decoded,decodeLen,unpressed); } else if(m_bNumpressPic){ if(m_bZlib) ms::numpress::MSNumpress::decodePic((unsigned char*)unzipped,(const size_t)unzippedLen,unpressed); else ms::numpress::MSNumpress::decodePic((unsigned char*)decoded,decodeLen,unpressed); } } catch (const char* ch){ cout << "Exception: " << ch << endl; exit(EXIT_FAILURE); } if(m_bZlib) delete [] unzipped; else delete [] decoded; for(i=0;i> 24) | ((l >> 8) & 0x00FF00); } #else if (bNet) { l = (l << 24) | ((l << 8) & 0xFF0000) | (l >> 24) | ((l >> 8) & 0x00FF00); } #endif return l; } uint64_t mzpSAXMzmlHandler::dtohl(uint64_t l, bool bNet) { #ifdef OSX if (!bNet) { l = (l << 56) | ((l << 40) & 0xFF000000000000LL) | ((l << 24) & 0x0000FF0000000000LL) | ((l << 8) & 0x000000FF00000000LL) | (l >> 56) | ((l >> 40) & 0x0000000000FF00LL) | ((l >> 24) & 0x0000000000FF0000LL) | ((l >> 8) & 0x00000000FF000000LL) ; } #else if (bNet) { l = (l << 56) | ((l << 40) & 0x00FF000000000000LL) | ((l << 24) & 0x0000FF0000000000LL) | ((l << 8) & 0x000000FF00000000LL) | (l >> 56) | ((l >> 40) & 0x000000000000FF00LL) | ((l >> 24) & 0x0000000000FF0000LL) | ((l >> 8) & 0x00000000FF000000LL) ; } #endif return l; } //Finding the index list offset is done without the xml parser //to speed things along. This can be problematic if the //tag is placed anywhere other than the end of the mzML file. f_off mzpSAXMzmlHandler::readIndexOffset() { char buffer[200]; char chunk[CHUNK]; char* start; char* stop; int readBytes; size_t sz; if(!m_bGZCompression){ FILE* f=fopen(&m_strFileName[0],"r"); mzpfseek(f,-200,SEEK_END); sz = fread(buffer,1,200,f); fclose(f); start=strstr(buffer,""); stop=strstr(buffer,""); } else { readBytes = gzObj.extract(fptr, gzObj.getfilesize()-200, (unsigned char*)chunk, CHUNK); chunk[200]='\0'; start=strstr(chunk,""); stop=strstr(chunk,""); } if(start==NULL || stop==NULL) { cerr << "No index list offset found. File will not be read." << endl; return 0; } char offset[64]; int len=(int)(stop-start-17); strncpy(offset,start+17,len); offset[len]='\0'; return mzpatoi64(offset); } bool mzpSAXMzmlHandler::load(const char* fileName){ if(!open(fileName)) return false; m_vInstrument.clear(); m_vIndex.clear(); m_vChromatIndex.clear(); parseOffset(0); indexOffset = readIndexOffset(); if(indexOffset==0){ m_bNoIndex=true; return false; } else { m_bNoIndex=false; if(!parseOffset(indexOffset)){ cerr << "Cannot parse index. Make sure index offset is correct or rebuild index." << endl; return false; } posIndex=-1; posChromatIndex=-1; } return true; } void mzpSAXMzmlHandler::stopParser(){ m_bStopParse=true; XML_StopParser(m_parser,false); //reset mzML flags m_bInmzArrayBinary = false; m_bInintenArrayBinary = false; m_bInRefGroup = false; m_bInSpectrumList=false; m_bInChromatogramList=false; m_bInIndexedMzML=false; m_bInIndexList=false; //reset other flags m_bSpectrumIndex=false; } int mzpSAXMzmlHandler::highChromat() { return (int)m_vChromatIndex.size(); } int mzpSAXMzmlHandler::highScan() { if(m_vIndex.size()==0) return 0; return m_vIndex[m_vIndex.size()-1].scanNum; } int mzpSAXMzmlHandler::lowScan() { if(m_vIndex.size()==0) return 0; return m_vIndex[0].scanNum; } vector* mzpSAXMzmlHandler::getChromatIndex(){ return &m_vChromatIndex; } f_off mzpSAXMzmlHandler::getIndexOffset(){ return indexOffset; } vector* mzpSAXMzmlHandler::getInstrument(){ return &m_vInstrument; } int mzpSAXMzmlHandler::getPeaksCount(){ return m_peaksCount; } vector* mzpSAXMzmlHandler::getSpecIndex(){ return &m_vIndex; } libmstoolkit-cleaned-82/src/mzParser/mzMLReader.cpp0000644000175000017500000000545613210260002022434 0ustar rusconirusconi#include "mzParser.h" using namespace std; int main(int argc, char* argv[]){ if(argc!=2) { cout << "USAGE: mzMLReader " << endl; exit(0); } MSDataFile* msd; ChromatogramListPtr sl; ChromatogramPtr s2; string st=argv[1]; vector pairs; msd = new MSDataFile(argv[1]); if(!msd->run.chromatogramListPtr->get()) cout << "WTF" << endl; sl = msd->run.chromatogramListPtr; for (int j=1; j<(int)sl->size(); j++) { s2 = sl->chromatogram(j, true); cout << j << "\t" << s2->id << endl; s2->getTimeIntensityPairs(pairs); for(int k=0;k<(int)pairs.size();k++) cout << pairs[k].time << " " << pairs[k].intensity << endl; } exit(1); BasicSpectrum s; BasicChromatogram chromat; MzParser sax(&s,&chromat); sax.load(argv[1]); bool bLastWasSpectrum=true; char c='a'; char str[256]; int num; while(c!='x'){ if(bLastWasSpectrum){ cout << "\nCurrent spectrum:" << endl; cout << "\tScan number: " << s.getScanNum() << endl; cout << "\tRetention Time: " << s.getRTime() << endl; cout << "\tMS Level: " << s.getMSLevel() << endl; cout << "\tNumber of Peaks: " << s.size() << endl; } else { chromat.getIDString(str); cout << "\nCurrent chromatogram:" << endl; cout << "\tID: " << str << endl; cout << "\tNumber of Peaks: " << chromat.size() << endl; } cout << "\nMenu:\n\t'c' to grab a new chromatogram\n\t's' to grab a new spectrum\n\t'p' to show peaks\n\t'x' to exit" << endl; cout << "Please enter your choice: "; cin >> c; switch(c){ case 'c': if(sax.highChromat()==0){ cout << "No chromatograms in the file." << endl; } else { cout << "Enter a number from 0 to " << sax.highChromat()-1 << ": "; cin >> str; num=(int)atoi(str); if(num<0 || num>sax.highChromat()-1) { cout << "Bad number! BOOOOO!" << endl; } else { if(!sax.readChromatogram(num)) cout << "Chromatogram number not in file." << endl; else bLastWasSpectrum=false; } } break; case 'p': if(bLastWasSpectrum){ for(unsigned int i=0;i> str; num=(int)atoi(str); if(numsax.highScan()) { cout << "Bad number! BOOOOO!" << endl; } else { if(!sax.readSpectrum(num)) cout << "Spectrum number not in file." << endl; else bLastWasSpectrum=true; } break; case 'x': break; default: cout << "\nInvalid command!" << endl; break; } } return 0; }libmstoolkit-cleaned-82/src/mzParser/saxmzxmlhandler.cpp0000644000175000017500000004431713210260002023652 0ustar rusconirusconi/************************************************************ * SAXMzxmlHandler.cpp * Adapted from the SAXMzmlHandler.cpp fork at ISB * Originally adapted from SAXMzdataHandler.cpp * August 2008 * Ronald Beavis * * December 2010 - Drastically modified and cannibalized to create * robust, yet generic, mzXML parser * Mike Hoopmann, Institute for Systems Biology * * See http://sashimi.sourceforge.net/schema_revision/mzXML_3.2/ for * mzXML schema information. * * Inspired by DtaSAX2Handler.cpp * copyright : (C) 2002 by Pedrioli Patrick, ISB, Proteomics * email : ppatrick@systemsbiology.org * Artistic License granted 3/11/2005 *******************************************************/ #include "mzParser.h" mzpSAXMzxmlHandler::mzpSAXMzxmlHandler(BasicSpectrum* bs){ m_bInMsInstrument=false; m_bInDataProcessing=false; m_bInScan=false; m_bInPrecursorMz=false; m_bInMsRun=false; m_bInIndex=false; m_bInPeaks=false; m_bCompressedData=false; m_bHeaderOnly=false; m_bLowPrecision=false; m_bNetworkData=true; m_bNoIndex=true; m_bScanIndex=false; m_bIndexSorted = true; spec=bs; indexOffset=-1; } mzpSAXMzxmlHandler::~mzpSAXMzxmlHandler(){ spec=NULL; } void mzpSAXMzxmlHandler::startElement(const XML_Char *el, const XML_Char **attr){ string s; if (isElement("dataProcessing",el)) { m_bInDataProcessing=true; } else if(isElement("index",el)){ if(!strcmp(getAttrValue("name", attr),"scan")) m_bScanIndex=true; m_vIndex.clear(); m_bInIndex=true; } else if(isElement("msDetector",el)){ m_instrument.detector=getAttrValue("value", attr); } else if(isElement("msInstrument",el)){ m_bInMsInstrument=true; m_instrument.clear(); m_instrument.id=getAttrValue("id", attr); } else if(isElement("msIonisation",el)){ m_instrument.ionization=getAttrValue("value", attr); } else if(isElement("msManufacturer",el)){ m_instrument.manufacturer=getAttrValue("value", attr); } else if(isElement("msMassAnalyzer",el)){ m_instrument.analyzer=getAttrValue("value", attr); } else if(isElement("msModel",el)){ m_instrument.model=getAttrValue("value", attr); } else if(isElement("msRun",el)){ m_bInMsRun=true; } else if(isElement("offset",el) && m_bScanIndex){ m_strData.clear(); curIndex.scanNum=atoi(getAttrValue("id", attr)); curIndex.idRef=""; } else if(isElement("peaks",el)){ m_strData.clear(); m_bInPeaks=true; if(!strcmp("network",getAttrValue("byteOrder", attr))) m_bNetworkData=true; else m_bNetworkData=true; //make it true anyway. if(!strcmp("64",getAttrValue("precision", attr))) m_bLowPrecision=false; else m_bLowPrecision=true; m_bCompressedData=false; s=getAttrValue("compressionType", attr); if(!strcmp("zlib",&s[0])) m_bCompressedData=true; else if(!strcmp("none",&s[0])) m_bCompressedData=false; else if(s.length()>0) { cout << "Halting! Unknown compression type: " << &s[0] << endl; exit(-5); } s=getAttrValue("compressedLen", attr); if(s.length()>0) m_compressLen = (uLong)atoi(&s[0]); else m_compressLen=0; if(m_bHeaderOnly) stopParser(); } else if (isElement("precursorMz", el)) { m_strData.clear(); s=getAttrValue("precursorCharge", attr); if(s.length()>0) m_precursorIon.charge=atoi(&s[0]); else m_precursorIon.charge=0; s=getAttrValue("precursorIntensity", attr); if(s.length()>0) m_precursorIon.intensity=atof(&s[0]); else m_precursorIon.intensity=0.0; s=getAttrValue("precursorScanNum", attr); if(s.length()>0) spec->setPrecursorScanNum(atoi(&s[0])); else spec->setPrecursorScanNum(0); m_bInPrecursorMz = true; s=getAttrValue("activationMethod", attr); if(s.length()>0){ if(!strcmp("CID",&s[0])) spec->setActivation(CID); else if(!strcmp("ETD",&s[0])) spec->setActivation(ETD); else if(!strcmp("HCD",&s[0])) spec->setActivation(HCD); else if(!strcmp("ECD",&s[0])) spec->setActivation(ECD); else if(!strcmp("ETD+SA",&s[0])) spec->setActivation(ETDSA); } else { spec->setActivation(none); } } else if (isElement("scan", el)) { if(m_bInScan){ pushSpectrum(); stopParser(); } else { m_bInScan=true; spec->setScanNum(atoi(getAttrValue("num", attr))); spec->setMSLevel(atoi(getAttrValue("msLevel", attr))); spec->setBasePeakIntensity(atof(getAttrValue("basePeakIntensity", attr))); spec->setBasePeakMZ(atof(getAttrValue("basePeakMz", attr))); spec->setCentroid((bool)getAttrValue("centroided",attr)); spec->setCollisionEnergy(atof(getAttrValue("collisionEnergy", attr))); spec->setCompensationVoltage(atof(getAttrValue("CompensationVoltage", attr))); s=getAttrValue("filterLine", attr); spec->setFilterLine(&s[0]); spec->setHighMZ(atof(getAttrValue("highMz", attr))); spec->setLowMZ(atof(getAttrValue("lowMz", attr))); if(spec->getHighMZ()==0) spec->setHighMZ(atof(getAttrValue("endMz", attr))); if(spec->getLowMZ()==0) spec->setLowMZ(atof(getAttrValue("startMz", attr))); spec->setTotalIonCurrent(atof(getAttrValue("totIonCurrent",attr))); m_peaksCount = atoi(getAttrValue("peaksCount", attr)); spec->setPeaksCount(m_peaksCount); s=getAttrValue("retentionTime", attr); if(s.length()>0){ float f=(float)atof(&s[2]); if(s[s.length()-1]=='S') spec->setRTime(f/60.0f); else spec->setRTime(f); } else { spec->setRTime(0.0f); } } } } void mzpSAXMzxmlHandler::endElement(const XML_Char *el) { if(isElement("dataProcessing", el)) { m_bInDataProcessing=false; } else if(isElement("index",el)){ m_bInIndex=false; posIndex=-1; stopParser(); if (!m_bIndexSorted) { qsort(&m_vIndex[0],m_vIndex.size(),sizeof(cindex),cindex::compare); m_bIndexSorted=true; } } else if(isElement("msInstrument",el)){ m_vInstrument.push_back(m_instrument); m_bInMsInstrument=false; } else if(isElement("msRun",el)){ m_bInMsRun=false; } else if(isElement("offset",el) && m_bScanIndex){ if(!m_bInIndex){ //bad index reference cout << "Index offset points to wrong location. Please rebuild index." << endl; m_bNoIndex=true; stopParser(); } curIndex.offset=mzpatoi64(&m_strData[0]); m_vIndex.push_back(curIndex); if (m_bIndexSorted && m_vIndex.size() > 1) { if (m_vIndex[m_vIndex.size()-1].scanNumsetPrecursorIon(m_precursorIon); m_bInPrecursorMz=false; } else if(isElement("scan",el)) { m_bInScan = false; pushSpectrum(); stopParser(); } } void mzpSAXMzxmlHandler::characters(const XML_Char *s, int len) { m_strData.append(s, len); } bool mzpSAXMzxmlHandler::readHeader(int num){ spec->clear(); if(m_bNoIndex){ cout << "Currently only supporting indexed mzXML" << endl; return false; } //if no scan was requested, grab the next one if(num<0){ posIndex++; if(posIndex>=(int)m_vIndex.size()) return false; m_bHeaderOnly=true; parseOffset(m_vIndex[posIndex].offset); m_bHeaderOnly=false; return true; } //Assumes scan numbers are in order size_t mid=m_vIndex.size()/2; size_t upper=m_vIndex.size(); size_t lower=0; while(m_vIndex[mid].scanNum!=num){ if(lower==upper) break; if(m_vIndex[mid].scanNum>num){ upper=mid-1; mid=(lower+upper)/2; } else { lower=mid+1; mid=(lower+upper)/2; } } //need something faster than this, perhaps binary search if(m_vIndex[mid].scanNum==num) { m_bHeaderOnly=true; parseOffset(m_vIndex[mid].offset); //force scan number; this was done for files where scan events are not numbered if(spec->getScanNum()!=m_vIndex[mid].scanNum) spec->setScanNum(m_vIndex[mid].scanNum); spec->setScanIndex((int)mid+1); //set the index, which starts from 1, so offset by 1 m_bHeaderOnly=false; posIndex=(int)mid; return true; } return false; } bool mzpSAXMzxmlHandler::readSpectrum(int num){ spec->clear(); if(m_bNoIndex){ cout << "Currently only supporting indexed mzXML" << endl; return false; } //if no scan was requested, grab the next one if(num<0){ posIndex++; if(posIndex>=(int)m_vIndex.size()) return false; parseOffset(m_vIndex[posIndex].offset); return true; } //Assumes scan numbers are in order size_t mid=m_vIndex.size()/2; size_t upper=m_vIndex.size(); size_t lower=0; while(m_vIndex[mid].scanNum!=num){ if(lower==upper) break; if(m_vIndex[mid].scanNum>num){ upper=mid-1; mid=(lower+upper)/2; } else { lower=mid+1; mid=(lower+upper)/2; } } //need something faster than this perhaps if(m_vIndex[mid].scanNum==num) { parseOffset(m_vIndex[mid].offset); //force scan number; this was done for files where scan events are not numbered if(spec->getScanNum()!=m_vIndex[mid].scanNum) spec->setScanNum(m_vIndex[mid].scanNum); spec->setScanIndex((int)mid+1); //set the index, which starts from 1, so offset by 1 posIndex=(int)mid; return true; } return false; } void mzpSAXMzxmlHandler::pushSpectrum(){ specDP dp; for(unsigned int i=0;iaddDP(dp); } } void mzpSAXMzxmlHandler::decompress32(){ vdM.clear(); vdI.clear(); if(m_peaksCount < 1) return; union udata { float f; uint32_t i; } uData; uLong uncomprLen; uint32_t* data; int length; const char* pData = m_strData.data(); size_t stringSize = m_strData.size(); //Decode base64 char* pDecoded = (char*) new char[m_compressLen]; memset(pDecoded, 0, m_compressLen); length = b64_decode_mio( (char*) pDecoded , (char*) pData, stringSize ); pData=NULL; //zLib decompression data = new uint32_t[m_peaksCount*2]; uncomprLen = m_peaksCount * 2 * sizeof(uint32_t); uncompress((Bytef*)data, &uncomprLen, (const Bytef*)pDecoded, length); delete [] pDecoded; //write data to arrays int n = 0; for(int i=0;i 0) { // Base64 decoding // By comparing the size of the unpacked data and the expected size // an additional check of the data file integrity can be performed int length = b64_decode_mio( (char*) pDecoded , (char*) pData, stringSize ); if(length != size) { cout << " decoded size " << length << " and required size " << (unsigned long)size << " dont match:\n"; cout << " Cause: possible corrupted file.\n"; exit(EXIT_FAILURE); } } // And byte order correction union udata { float fData; uint32_t iData; } uData; vdM.clear(); vdI.clear(); int n = 0; uint32_t* pDecodedInts = (uint32_t*)pDecoded; // cast to uint_32 for reading int sized chunks for(int i = 0; i < m_peaksCount; i++) { uData.iData = dtohl(pDecodedInts[n++], m_bNetworkData); vdM.push_back((double)uData.fData); uData.iData = dtohl(pDecodedInts[n++], m_bNetworkData); vdI.push_back((double)uData.fData); } // Free allocated memory delete[] pDecoded; } void mzpSAXMzxmlHandler::decode64(){ // This code block was revised so that it packs floats correctly // on both 64 and 32 bit machines, by making use of the uint32_t // data type. -S. Wiley const char* pData = m_strData.data(); size_t stringSize = m_strData.size(); size_t size = m_peaksCount * 2 * sizeof(uint64_t); char* pDecoded = (char *) new char[size]; memset(pDecoded, 0, size); if(m_peaksCount > 0) { // Base64 decoding // By comparing the size of the unpacked data and the expected size // an additional check of the data file integrity can be performed int length = b64_decode_mio( (char*) pDecoded , (char*) pData, stringSize ); if(length != size) { cout << " decoded size " << length << " and required size " << (unsigned long)size << " dont match:\n"; cout << " Cause: possible corrupted file.\n"; exit(EXIT_FAILURE); } } // And byte order correction union udata { double fData; uint64_t iData; } uData; vdM.clear(); vdI.clear(); int n = 0; uint64_t* pDecodedInts = (uint64_t*)pDecoded; // cast to uint_64 for reading int sized chunks for(int i = 0; i < m_peaksCount; i++) { uData.iData = dtohl(pDecodedInts[n++], m_bNetworkData); vdM.push_back(uData.fData); uData.iData = dtohl(pDecodedInts[n++], m_bNetworkData); vdI.push_back(uData.fData); } // Free allocated memory delete[] pDecoded; } unsigned long mzpSAXMzxmlHandler::dtohl(uint32_t l, bool bNet) { #ifdef OSX if (!bNet) { l = (l << 24) | ((l << 8) & 0xFF0000) | (l >> 24) | ((l >> 8) & 0x00FF00); } #else if (bNet) { l = (l << 24) | ((l << 8) & 0xFF0000) | (l >> 24) | ((l >> 8) & 0x00FF00); } #endif return l; } uint64_t mzpSAXMzxmlHandler::dtohl(uint64_t l, bool bNet) { #ifdef OSX if (!bNet) { l = (l << 56) | ((l << 40) & 0xFF000000000000LL) | ((l << 24) & 0x0000FF0000000000LL) | ((l << 8) & 0x000000FF00000000LL) | (l >> 56) | ((l >> 40) & 0x0000000000FF00LL) | ((l >> 24) & 0x0000000000FF0000LL) | ((l >> 8) & 0x00000000FF000000LL) ; } #else if (bNet) { l = (l << 56) | ((l << 40) & 0x00FF000000000000LL) | ((l << 24) & 0x0000FF0000000000LL) | ((l << 8) & 0x000000FF00000000LL) | (l >> 56) | ((l >> 40) & 0x000000000000FF00LL) | ((l >> 24) & 0x0000000000FF0000LL) | ((l >> 8) & 0x00000000FF000000LL) ; } #endif return l; } //Finding the index list offset is done without the xml parser //to speed things along. This can be problematic if the //tag is placed anywhere other than the end of the mzML file. f_off mzpSAXMzxmlHandler::readIndexOffset() { char buffer[200]; char chunk[CHUNK]; char* start; char* stop; int readBytes; size_t sz; if(!m_bGZCompression){ FILE* f=fopen(&m_strFileName[0],"r"); mzpfseek(f,-200,SEEK_END); sz = fread(buffer,1,200,f); fclose(f); start=strstr(buffer,""); stop=strstr(buffer,""); } else { readBytes = gzObj.extract(fptr, gzObj.getfilesize()-200, (unsigned char*)chunk, CHUNK); start=strstr(chunk,""); stop=strstr(chunk,""); } if(start==NULL || stop==NULL) { cerr << "No index list offset found. File will not be read." << endl; return 0; } char offset[64]; int len=(int)(stop-start-13); strncpy(offset,start+13,len); offset[len]='\0'; return mzpatoi64(offset); } bool mzpSAXMzxmlHandler::load(const char* fileName){ if(!open(fileName)) return false; indexOffset = readIndexOffset(); if(indexOffset==0){ m_bNoIndex=true; return false; } else { m_bNoIndex=false; if(!parseOffset(indexOffset)){ cerr << "Cannot parse index. Make sure index offset is correct or rebuild index." << endl; return false; } posIndex=-1; } m_vInstrument.clear(); parseOffset(0); return true; } void mzpSAXMzxmlHandler::stopParser(){ m_bStopParse=true; XML_StopParser(m_parser,false); //reset mzML flags m_bInMsInstrument=false; m_bInDataProcessing=false; m_bInScan=false; m_bInPrecursorMz=false; m_bInMsRun=false; m_bInIndex=false; m_bInPeaks=false; m_bLowPrecision=false; //reset other flags m_bScanIndex=false; } int mzpSAXMzxmlHandler::highScan() { if(m_vIndex.size()==0) return 0; return m_vIndex[m_vIndex.size()-1].scanNum; } int mzpSAXMzxmlHandler::lowScan() { if(m_vIndex.size()==0) return 0; return m_vIndex[0].scanNum; } vector* mzpSAXMzxmlHandler::getIndex(){ return &m_vIndex; } f_off mzpSAXMzxmlHandler::getIndexOffset(){ return indexOffset; } instrumentInfo mzpSAXMzxmlHandler::getInstrument(){ return m_instrument; } int mzpSAXMzxmlHandler::getPeaksCount(){ return m_peaksCount; } libmstoolkit-cleaned-82/src/mzParser/mz5handler.cpp0000644000175000017500000003722013210260002022475 0ustar rusconirusconi#include "mzParser.h" #ifdef MZP_MZ5 mzpMz5Handler::mzpMz5Handler(mzpMz5Config* c, BasicSpectrum* s){ config_=c; spec=s; } mzpMz5Handler::mzpMz5Handler(mzpMz5Config* c, BasicSpectrum* s, BasicChromatogram* bc){ config_=c; spec=s; chromat=bc; } mzpMz5Handler::~mzpMz5Handler(){ config_=NULL; spec=NULL; chromat=NULL; } void mzpMz5Handler::clean(const MZ5DataSets v, void* data, const size_t dsend) { hsize_t dim[1] = { static_cast (dsend) }; DataSpace dsp(1, dim); DataSet::vlenReclaim(data, config_->getDataTypeFor(v), dsp); free(data); data = 0; dsp.close(); } vector* mzpMz5Handler::getChromatIndex(){ return &m_vChromatIndex; } void mzpMz5Handler::getData(vector& data, const MZ5DataSets v, const hsize_t start, const hsize_t end) { hsize_t scount = end - start; data.resize(scount); if (scount > 0) { map::iterator it = bufferMap_.find(v); if (it == bufferMap_.end()) { DataSet ds = file_->openDataSet(config_->getNameFor(v)); bufferMap_.insert(pair(v, ds)); it = bufferMap_.find(v); } DataSet dataset = it->second; DataSpace dataspace = dataset.getSpace(); hsize_t offset[1]; offset[0] = start; hsize_t count[1]; count[0] = scount; dataspace.selectHyperslab(H5S_SELECT_SET, count, offset); hsize_t dimsm[1]; dimsm[0] = scount; DataSpace memspace(1, dimsm); dataset.read(&data[0], PredType::NATIVE_DOUBLE, memspace, dataspace); if (v == SpectrumMZ && config_->doTranslating()) { size_t ms = data.size(); double s = 0; for (size_t i = 0; i < ms; ++i) { data[i] = data[i] + s; s = data[i]; } } if (v == SpectrumIntensity && config_->doTranslating()) { //there is no translating to do... //Translator_mz5::reverseTranslateIntensity(data); } memspace.close(); dataspace.close(); } } const map& mzpMz5Handler::getFields() { return fields_; } vector* mzpMz5Handler::getSpecIndex(){ return &m_vIndex; } int mzpMz5Handler::highChromat() { return m_vChromatIndex.size(); } int mzpMz5Handler::highScan() { if(m_vIndex.size()==0) return 0; return m_vIndex[m_vIndex.size()-1].scanNum; } int mzpMz5Handler::lowScan() { if(m_vIndex.size()==0) return 0; return m_vIndex[0].scanNum; } void mzpMz5Handler::processCVParams(unsigned long index){ if(cvRef[cvParams_[index].typeCVRefID].group==0){ //MS: switch(cvRef[cvParams_[index].typeCVRefID].ref) { case 1000016: if(cvRef[cvParams_[index].unitCVRefID].ref==31) spec->setRTime((float)atof(cvParams_[index].value)); else spec->setRTime((float)atof(cvParams_[index].value)/60.0f); //assume seconds if not minutes break; case 1000041: spec->setPrecursorCharge(atoi(cvParams_[index].value)); break; case 1000042: spec->setPrecursorIntensity(atof(cvParams_[index].value)); break; case 1000045: spec->setCollisionEnergy(atof(cvParams_[index].value)); break; case 1000127: spec->setCentroid(true); break; case 1000285: spec->setTotalIonCurrent(atof(cvParams_[index].value)); break; case 1000504: spec->setBasePeakMZ(atof(cvParams_[index].value)); break; case 1000505: spec->setBasePeakIntensity(atof(cvParams_[index].value)); break; case 1000511: spec->setMSLevel(atoi(cvParams_[index].value)); break; case 1000512: spec->setFilterLine(cvParams_[index].value); break; case 1000527: spec->setHighMZ(atof(cvParams_[index].value)); break; case 1000528: spec->setLowMZ(atof(cvParams_[index].value)); break; case 1000744: spec->setPrecursorMZ(atof(cvParams_[index].value)); break; default: //cout << "Unknown/Unparsed CV: " << cvRef[cvParams_[index].typeCVRefID].group << ":" << cvRef[cvParams_[index].typeCVRefID].ref << endl; break; } } else { //unknown: //cout << "Unknown/Unparsed CV: " << cvRef[cvParams_[index].typeCVRefID].group << ":" << cvRef[cvParams_[index].typeCVRefID].ref << endl; } } bool mzpMz5Handler::readChromatogram(int num){ if(chromat==NULL) return false; chromat->clear(); //if no chromatogram was requested, grab the next one if(num<0) posChromatIndex++; else posChromatIndex=num; if(posChromatIndex>=(int)m_vChromatIndex.size()) return false; //Read the chromatogram vector time, inten; TimeIntensityPair tip; if(posChromatIndex==0){ getData(time, ChromatogramTime, 0, (hsize_t)m_vChromatIndex[posChromatIndex].offset); getData(inten, ChromatogramIntensity, 0, (hsize_t)m_vChromatIndex[posChromatIndex].offset); } else { getData(time, ChromatogramTime, (hsize_t)m_vChromatIndex[posChromatIndex-1].offset, (hsize_t)m_vChromatIndex[posChromatIndex].offset); getData(inten, ChromatogramIntensity, (hsize_t)m_vChromatIndex[posChromatIndex-1].offset, (hsize_t)m_vChromatIndex[posChromatIndex].offset); } for(unsigned int i=0;iaddTIP(tip); } //Read the metadata unsigned long start=m_vChromatIndex[posChromatIndex].cvStart; unsigned long stop=start+m_vChromatIndex[posChromatIndex].cvLen; for(size_t i=start;isetIDString(&m_vChromatIndex[posChromatIndex].idRef[0]); return true; } void* mzpMz5Handler::readDataSet(const MZ5DataSets v, size_t& dsend, void* ptr) { DataSet ds = file_->openDataSet(config_->getNameFor(v)); DataSpace dsp = ds.getSpace(); hsize_t start[1], end[1]; dsp.getSelectBounds(start, end); dsend = (static_cast (end[0])) + 1; DataType dt = config_->getDataTypeFor(v); if (ptr == 0) ptr = calloc(dsend, dt.getSize()); ds.read(ptr, dt); dsp.close(); ds.close(); return ptr; } bool mzpMz5Handler::readFile(const string filename){ FileCreatPropList fcparm = FileCreatPropList::DEFAULT; FileAccPropList faparm = FileAccPropList::DEFAULT; int mds_nelemts; size_t rdcc_nelmts, rdcc_nbytes; double rdcc_w0; faparm.getCache(mds_nelemts, rdcc_nelmts, rdcc_nbytes, rdcc_w0); //TODO do not set global buffer size, instead set dataset specific buffer size rdcc_nbytes = config_->getBufferInB(); //TODO can be set to 1 if chunks that have been fully read/written will never be read/written again //rdcc_w0 = 1.0; rdcc_nelmts = config_->getRdccSlots(); faparm.setCache(mds_nelemts, rdcc_nelmts, rdcc_nbytes, rdcc_w0); try { file_ = new H5File(filename, H5F_ACC_RDONLY, fcparm, faparm); } catch (FileIException&){ return false; } closed_ = false; hsize_t start[1], end[1]; size_t dsend = 0; DataSet dataset; DataSpace dataspace; string oname; MZ5DataSets v; for (hsize_t i = 0; i < file_->getNumObjs(); ++i) { oname = file_->getObjnameByIdx(i); dataset = file_->openDataSet(oname); dataspace = dataset.getSpace(); dataspace.getSelectBounds(start, end); dsend = (static_cast (end[0])) + 1; try { v = config_->getVariableFor(oname); fields_.insert(pair(v, dsend)); } catch (out_of_range&) { } dataspace.close(); dataset.close(); } map::const_iterator it; it = fields_.find(FileInformation); if (it != fields_.end()) { DataSet ds = file_->openDataSet(config_->getNameFor(FileInformation)); DataSpace dsp = ds.getSpace(); hsize_t start[1], end[1]; dsp.getSelectBounds(start, end); dsend = (static_cast (end[0])) + 1; DataType dt = config_->getDataTypeFor(FileInformation); FileInformationMZ5* fi = (FileInformationMZ5*) (calloc(dsend, dt.getSize())); ds.read(fi, dt); dsp.close(); ds.close(); if (dsend == 1) { if (fi[0].majorVersion == MZ5_FILE_MAJOR_VERSION && fi[0].minorVersion == MZ5_FILE_MINOR_VERSION) { config_->setFiltering(fi[0].didFiltering > 0 ? true : false); config_->setTranslating(fi[0].deltaMZ && fi[0].translateInten); } } hsize_t dim[1] = { static_cast (dsend) }; DataSpace dspr(1, dim); DataSet::vlenReclaim(fi, config_->getDataTypeFor(FileInformation), dspr); free(fi); fi = 0; dspr.close(); } else { it = fields_.find(Run); if (it == fields_.end()) { throw runtime_error("mzpMz5Handler::readFile(): given file is not mz5."); return false; } } //Read the CV Reference List size_t numberOfRef = fields_.find(CVReference)->second; CVRefMZ5* cvrl = (CVRefMZ5*) readDataSet(CVReference, dsend); cvRef.clear(); CVRefItem cvr; for(int xx=0;xxsecond; cvParams_.resize(numberOfCV); readDataSet(CVParam, dsend, &cvParams_[0]); //Build the index m_vIndex.clear(); m_scanIDXCount=0; size_t numberOfSpectra_ = fields_.find(SpectrumMetaData)->second; vector index; index.resize(numberOfSpectra_); readDataSet(SpectrumIndex,dsend,&index[0]); BinaryDataMZ5* binaryParamsData_ = (BinaryDataMZ5*) calloc(numberOfSpectra_, sizeof(BinaryDataMZ5)); readDataSet(SpectrumBinaryMetaData, dsend, binaryParamsData_); SpectrumMZ5* spectrumData_ = (SpectrumMZ5*) calloc(numberOfSpectra_, sizeof(SpectrumMZ5)); readDataSet(SpectrumMetaData, dsend, spectrumData_); for(size_t i=0;isecond; index.clear(); index.resize(numberOfChromats_); readDataSet(ChromatogramIndex,dsend,&index[0]); free(binaryParamsData_); binaryParamsData_ = (BinaryDataMZ5*) calloc(numberOfChromats_, sizeof(BinaryDataMZ5)); readDataSet(ChromatogramBinaryMetaData, dsend, binaryParamsData_); ChromatogramMZ5* chromatogramData_ = (ChromatogramMZ5*) calloc(numberOfSpectra_, sizeof(ChromatogramMZ5)); readDataSet(ChromatogramMetaData, dsend, chromatogramData_); for(size_t i=0;iclear(); //if no scan was requested, grab the next one if(num<0){ posIndex++; if(posIndex>=(int)m_vIndex.size()) return false; } else { //otherwise do binary search for scan number //Assumes scan numbers are in order int mid=m_vIndex.size()/2; int upper=m_vIndex.size(); int lower=0; while(m_vIndex[mid].scanNum!=num){ if(lower==upper) break; if(m_vIndex[mid].scanNum>num){ upper=mid-1; mid=(lower+upper)/2; } else { lower=mid+1; mid=(lower+upper)/2; } } if(m_vIndex[mid].scanNum==num) posIndex=mid; } //Read the metadata unsigned long start=m_vIndex[posIndex].cvStart; unsigned long stop=start+m_vIndex[posIndex].cvLen; for(size_t i=start;i mz; if(posIndex==0) getData(mz, SpectrumMZ, 0, (hsize_t)m_vIndex[posIndex].offset); else getData(mz, SpectrumMZ, (hsize_t)m_vIndex[posIndex-1].offset, (hsize_t)m_vIndex[posIndex].offset); spec->setPeaksCount((int)mz.size()); if(spec->getScanNum()!=m_vIndex[posIndex].scanNum) spec->setScanNum(m_vIndex[posIndex].scanNum); spec->setScanIndex(posIndex+1); //set the index, which starts from 1, so offset by 1 return true; } bool mzpMz5Handler::readSpectrum(int num){ spec->clear(); //if no scan was requested, grab the next one if(num<0){ posIndex++; if(posIndex>=(int)m_vIndex.size()) return false; } else { //otherwise do binary search for scan number //Assumes scan numbers are in order int mid=m_vIndex.size()/2; int upper=m_vIndex.size(); int lower=0; while(m_vIndex[mid].scanNum!=num){ if(lower==upper) break; if(m_vIndex[mid].scanNum>num){ upper=mid-1; mid=(lower+upper)/2; } else { lower=mid+1; mid=(lower+upper)/2; } } if(m_vIndex[mid].scanNum==num) posIndex=mid; } //Read the peaks vector mz, inten; specDP dp; if(posIndex==0){ getData(mz, SpectrumMZ, 0, (hsize_t)m_vIndex[posIndex].offset); getData(inten, SpectrumIntensity, 0, (hsize_t)m_vIndex[posIndex].offset); } else { getData(mz, SpectrumMZ, (hsize_t)m_vIndex[posIndex-1].offset, (hsize_t)m_vIndex[posIndex].offset); getData(inten, SpectrumIntensity, (hsize_t)m_vIndex[posIndex-1].offset, (hsize_t)m_vIndex[posIndex].offset); } for(unsigned int i=0;iaddDP(dp); } spec->setPeaksCount((int)mz.size()); //Read the metadata unsigned long start=m_vIndex[posIndex].cvStart; unsigned long stop=start+m_vIndex[posIndex].cvLen; for(size_t i=start;igetScanNum()!=m_vIndex[posIndex].scanNum) spec->setScanNum(m_vIndex[posIndex].scanNum); spec->setScanIndex(posIndex+1); //set the index, which starts from 1, so offset by 1 return true; } #endif libmstoolkit-cleaned-82/src/MSToolkit/0000755000175000017500000000000013210260002017776 5ustar rusconirusconilibmstoolkit-cleaned-82/src/MSToolkit/Spectrum.cpp0000644000175000017500000003401713210260002022311 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "Spectrum.h" #include #include using namespace std; using namespace MSToolkit; Spectrum::Spectrum(){ //cout<<"in Spectrum constructor!"<; mz=new vector; TIC=0; IIT=0; compensationVoltage=0; convA=0; convB=0; convC=0; convD=0; convE=0; convI=0; BPI=0; BPM=0; selectionWinLower = 0; selectionWinUpper = 0; centroidStatus=2; fileType=Unspecified; vPeaks = new vector; vEZ = new vector; vZ = new vector; actMethod=mstNA; strcpy(rawFilter,""); strcpy(nativeID,""); } Spectrum::~Spectrum(){ if(vPeaks) delete vPeaks; if(vEZ) delete vEZ; if(vZ) delete vZ; if(mz) delete mz; if(monoMZ) delete monoMZ; } Spectrum::Spectrum(const Spectrum& s){ unsigned int i; rTime = s.rTime; charge = s.charge; scanNumber = s.scanNumber; scanNumber2 = s.scanNumber2; msLevel = s.msLevel; monoMZ = new vector; for(i=0;isize();i++){ monoMZ->push_back(s.monoMZ->at(i)); } mz = new vector; for(i=0;isize();i++){ mz->push_back(s.mz->at(i)); } fileType = s.fileType; IIT = s.IIT; TIC = s.TIC; compensationVoltage = s.compensationVoltage; convA = s.convA; convB = s.convB; convC = s.convC; convD = s.convD; convE = s.convE; convI = s.convI; BPI = s.BPI; BPM = s.BPM; selectionWinLower=s.selectionWinLower; selectionWinUpper=s.selectionWinUpper; centroidStatus = s.centroidStatus; vPeaks = new vector; for(i=0;isize();i++){ vPeaks->push_back(s.vPeaks->at(i)); } vEZ = new vector; for(i=0;isize();i++){ vEZ->push_back(s.vEZ->at(i)); } vZ = new vector; for(i=0;isize();i++){ vZ->push_back(s.vZ->at(i)); } strcpy(rawFilter,s.rawFilter); strcpy(nativeID,s.nativeID); } Spectrum& Spectrum::operator=(const Spectrum& s){ //cout<<"in Spectrum ="<; for(i=0;isize();i++){ monoMZ->push_back(s.monoMZ->at(i)); } mz = new vector; for(i=0;isize();i++){ mz->push_back(s.mz->at(i)); } vPeaks = new vector; for(i=0;isize();i++){ vPeaks->push_back(s.vPeaks->at(i)); } vEZ = new vector; for(i=0;isize();i++){ vEZ->push_back(s.vEZ->at(i)); } vZ = new vector; for(i=0;isize();i++){ vZ->push_back(s.vZ->at(i)); } rTime = s.rTime; charge = s.charge; scanNumber = s.scanNumber; scanNumber2 = s.scanNumber2; msLevel = s.msLevel; BPI = s.BPI; BPM = s.BPM; compensationVoltage = s.compensationVoltage; convA = s.convA; convB = s.convB; convC = s.convC; convD = s.convD; convE = s.convE; convI = s.convI; TIC = s.TIC; IIT = s.IIT; fileType = s.fileType; centroidStatus = s.centroidStatus; selectionWinLower = s.selectionWinLower; selectionWinUpper = s.selectionWinUpper; strcpy(rawFilter,s.rawFilter); strcpy(nativeID,s.nativeID); } return *this; } Peak_T& Spectrum::operator[](const int& i) { return vPeaks->operator[](i); } /* ----- Begin Functions ----- */ /* Adds Result struct to end of spectrum. */ void Spectrum::add(Peak_T& p){ vPeaks->push_back(p); } void Spectrum::add(double d1, float d2){ Peak_T p; p.mz=d1; p.intensity=d2; vPeaks->push_back(p); } void Spectrum::addEZState(EZState& z){ vEZ->push_back(z); } void Spectrum::addEZState(int i, double d, float f1, float f2){ EZState z; z.z=i; z.mh=d; z.pRTime=f1; z.pArea=f2; vEZ->push_back(z); } void Spectrum::addMZ(double d, double mono){ mz->push_back(d); monoMZ->push_back(mono); } void Spectrum::addZState(ZState& z){ vZ->push_back(z); } void Spectrum::addZState(int i, double d){ ZState z; z.z=i; z.mh=d; vZ->push_back(z); } /* Returns Result struct of single element in the spectrum. */ Peak_T& Spectrum::at(const int& i){ return vPeaks->operator [](i); } Peak_T& Spectrum::at(const unsigned int& i){ return vPeaks->operator [](i); } EZState& Spectrum::atEZ(const int& i){ return vEZ->operator [](i); } EZState& Spectrum::atEZ(const unsigned int& i){ return vEZ->operator [](i); } ZState& Spectrum::atZ(const int& i){ return vZ->operator [](i); } ZState& Spectrum::atZ(const unsigned int& i){ return vZ->operator [](i); } /* Clears the spectrum */ void Spectrum::clear(){ delete vPeaks; vPeaks = new vector; delete vEZ; vEZ = new vector; delete vZ; vZ = new vector; delete mz; mz = new vector; delete monoMZ; monoMZ = new vector; scanNumber = 0; scanNumber2 = 0; rTime = 0; charge = 0; msLevel = 0; convA = 0; convB = 0; TIC = 0; IIT = 0; BPI = 0; BPM = 0; selectionWinLower=0; selectionWinUpper=0; fileType = Unspecified; actMethod=mstNA; } void Spectrum::clearMZ(){ delete mz; mz = new vector; delete monoMZ; monoMZ = new vector; } void Spectrum::clearPeaks(){ delete vPeaks; vPeaks = new vector; } /* Erases element i in the spectrum. */ void Spectrum::erase(unsigned int i){ vector::iterator vi; vi=vPeaks->begin()+i; vPeaks->erase(vi); } /* Erases element i to element j, inclusive, in the spectrum. */ void Spectrum::erase(unsigned int i, unsigned int j){ vector::iterator vi1; vector::iterator vi2; vi1=vPeaks->begin()+i; vi2=vPeaks->begin()+j+1; vPeaks->erase(vi1,vi2); } void Spectrum::eraseEZ(unsigned int i){ vector::iterator vi; vi=vEZ->begin()+i; vEZ->erase(vi); } /* Erases element i to element j, inclusive, in the spectrum. */ void Spectrum::eraseEZ(unsigned int i, unsigned int j){ vector::iterator vi1; vector::iterator vi2; vi1=vEZ->begin()+i; vi2=vEZ->begin()+j+1; vEZ->erase(vi1,vi2); } void Spectrum::eraseZ(unsigned int i){ vector::iterator vi; vi=vZ->begin()+i; vZ->erase(vi); } /* Erases element i to element j, inclusive, in the spectrum. */ void Spectrum::eraseZ(unsigned int i, unsigned int j){ vector::iterator vi1; vector::iterator vi2; vi1=vZ->begin()+i; vi2=vZ->begin()+j+1; vZ->erase(vi1,vi2); } MSActivation Spectrum::getActivationMethod(){ return actMethod; } float Spectrum::getBPI(){ return BPI; } double Spectrum::getBPM(){ return BPM; } int Spectrum::getCentroidStatus(){ return centroidStatus; } int Spectrum::getCharge(){ return charge; } double Spectrum::getCompensationVoltage(){ return compensationVoltage; } double Spectrum::getConversionA(){ return convA; } double Spectrum::getConversionB(){ return convB; } double Spectrum::getConversionC(){ return convC; } double Spectrum::getConversionD(){ return convD; } double Spectrum::getConversionE(){ return convE; } double Spectrum::getConversionI(){ return convI; } MSSpectrumType Spectrum::getFileType(){ return fileType; } float Spectrum::getIonInjectionTime(){ return IIT; } double Spectrum::getMonoMZ(int index){ if(index>=(int)monoMZ->size()) return -1.0; return monoMZ->at(index); } double Spectrum::getMZ(int index){ if(index>=(int)mz->size()) return -1.0; return mz->at(index); } bool Spectrum::getNativeID(char* c, int sz){ if(sz<(int)strlen(nativeID)) { cout << "Buffer too small to retrieve spectrumNativeID. " << sizeof(c) << " " << strlen(nativeID) << endl; return false; } else { strcpy(c,nativeID); return true; } } bool Spectrum::getRawFilter(char* c, int sz, bool bLock){ if(sz<(int)strlen(rawFilter)) { cout << "Buffer too small to retrieve RAW filter. " << sizeof(c) << " " << strlen(rawFilter) << endl; return false; } else { strcpy(c,rawFilter); char* chp=strstr(c,"lock"); if(!bLock && chp!=NULL) strcpy(chp,chp+5); return true; } } float Spectrum::getRTime(){ return rTime; } int Spectrum::getScanNumber(bool second){ if(second) return scanNumber2; else return scanNumber; } double Spectrum::getScanWindowLower(){ return scanWinLower; } double Spectrum::getScanWindowUpper(){ return scanWinUpper; } double Spectrum::getSelWindowLower(){ return selectionWinLower; } double Spectrum::getSelWindowUpper(){ return selectionWinUpper; } double Spectrum::getTIC(){ return TIC; } void Spectrum::setBPI(float f){ BPI=f; } void Spectrum::setBPM(double d){ BPM=d; } void Spectrum::setCentroidStatus(int i){ if(i>2) centroidStatus=2; else centroidStatus=i; } void Spectrum::setCharge(int i){ charge=i; } void Spectrum::setCompensationVoltage(double d){ compensationVoltage=d; } void Spectrum::setConversionA(double d){ convA=d; } void Spectrum::setConversionB(double d){ convB=d; } void Spectrum::setConversionC(double d){ convC=d; } void Spectrum::setConversionD(double d){ convD=d; } void Spectrum::setConversionE(double d){ convE=d; } void Spectrum::setConversionI(double d){ convI=d; } void Spectrum::setFileType(MSSpectrumType f){ fileType=f; } void Spectrum::setIonInjectionTime(float f){ IIT=f; } void Spectrum::setMZ(double d, double mono){ clearMZ(); mz->push_back(d); monoMZ->push_back(mono); } void Spectrum::setNativeID(char* c){ if(strlen(c)>256) cout << "Error - spectrumNativeID filter larger than 256 characters." << endl; else strcpy(nativeID,c); } void Spectrum::setRawFilter(char* c){ if(strlen(c)>256) cout << "Error - RAW filter larger than 256 characters." << endl; else strcpy(rawFilter,c); } void Spectrum::setRTime(float d){ rTime=d; } void Spectrum::setScanNumber(int i, bool second){ if(second)scanNumber2=i; else scanNumber=i; } void Spectrum::setScanWindow(double lower, double upper){ scanWinLower = lower; scanWinUpper = upper; } void Spectrum::setSelWindow(double lower, double upper){ selectionWinLower=lower; selectionWinUpper=upper; } void Spectrum::setTIC(double d){ TIC=d; } void Spectrum::setMsLevel(int level) { msLevel = level; } int Spectrum::getMsLevel() { return msLevel; } int Spectrum::getScanID(){ return scanID; } void Spectrum::setScanID(int scanid){ scanID = scanid; } /* Returns the number of elements in the spectrum. */ int Spectrum::size(){ return (int)vPeaks->size(); } int Spectrum::sizeEZ(){ return (int)vEZ->size(); } int Spectrum::sizeMZ(){ return (int)mz->size(); } int Spectrum::sizeZ(){ return (int)vZ->size(); } float Spectrum::getTotalIntensity(){ float totalIntensity = 0; for(unsigned int i=0; isize(); i++) totalIntensity += (vPeaks->at(i)).intensity; return totalIntensity; } /* Sorts the spectrum by Data. */ void Spectrum::sortIntensity(){ qsort(&vPeaks->at(0),vPeaks->size(),sizeof(Peak_T),compareIntensity); } /* Sorts the spectrum by Mass. */ void Spectrum::sortMZ(){ qsort(&vPeaks->at(0),vPeaks->size(),sizeof(Peak_T),compareMZ); } /* Sorts the spectrum by Data. */ void Spectrum::sortIntensityRev(){ qsort(&vPeaks->at(0),vPeaks->size(),sizeof(Peak_T),compareIntensityRev); } /* Sorts the spectrum by Mass. */ void Spectrum::sortMZRev(){ qsort(&vPeaks->at(0),vPeaks->size(),sizeof(Peak_T),compareMZRev); } //const vector* Spectrum::getPeaks(){ // return vPeaks; //}; vector* Spectrum::getPeaks(){ return vPeaks; } void Spectrum::setPeaks(vector peaks) { if(!vPeaks->empty()) vPeaks->clear(); for(unsigned int i=0; ipush_back(peaks.at(i)); } } void Spectrum::setActivationMethod(MSActivation m){ actMethod=m; } void Spectrum::printMe() { cout << "Scan Number: " << getScanNumber() << endl << "Mass to charge: " << getMZ() << endl << "S Charge: " << getCharge() << endl << "RT: " << getRTime() << endl; cout << fixed; for(unsigned int i=0; isize(); i++) { cout << setprecision(10) << vPeaks->at(i).mz << " " << vPeaks->at(i).intensity << endl; } } //Private Functions /* For the qsort */ int Spectrum::compareIntensity(const void *p1, const void *p2){ const Peak_T d1 = *(Peak_T *)p1; const Peak_T d2 = *(Peak_T *)p2; if(d1.intensityd2.intensity) return 1; else return 0; } /* For the qsort */ int Spectrum::compareMZ(const void *p1, const void *p2){ const Peak_T d1 = *(Peak_T *)p1; const Peak_T d2 = *(Peak_T *)p2; if(d1.mzd2.mz) return 1; else return 0; } /* For the qsort */ int Spectrum::compareIntensityRev(const void *p1, const void *p2){ const Peak_T d1 = *(Peak_T *)p1; const Peak_T d2 = *(Peak_T *)p2; if(d1.intensity>d2.intensity) return -1; else if(d1.intensityd2.mz) return -1; else if(d1.mzClose(); m_Raw.Release(); m_Raw=NULL; } msLevelFilter=NULL; } int RAWReader::calcChargeState(double precursormz, double highmass, VARIANT* varMassList, long nArraySize) { // Assumes spectrum is +1 or +2. Figures out charge by // seeing if signal is present above the parent mass // indicating +2 (by taking ratio above/below precursor) bool bFound; long i, iStart; double dLeftSum,dRightSum; double FractionWindow; double CorrectionFactor; dLeftSum = 0.00001; dRightSum = 0.00001; DataPeak* pDataPeaks = NULL; SAFEARRAY FAR* psa = varMassList->parray; SafeArrayAccessData( psa, (void**)(&pDataPeaks) ); //------------- // calc charge //------------- bFound=false; i=0; while(i 0 && (dRightSum / dLeftSum) < (0.2 * CorrectionFactor)){ SafeArrayUnaccessData( psa ); psa=NULL; pDataPeaks=NULL; return 1; } else { SafeArrayUnaccessData( psa ); psa=NULL; pDataPeaks=NULL; return 0; //Set charge to 0 to indicate that both +2 and +3 spectra should be created } //When all else fails, return 0 return 0; } MSSpectrumType RAWReader::evaluateFilter(long scan, char* chFilter, vector& MZs, bool& bCentroid, double& cv, MSActivation& act) { BSTR Filter = NULL; char cStr[256]; string tStr; string mzVal; int stop; bool bSA=false; //For non-ATL and non-MFC conversions int sl; //Initialize raw values to default MZs.clear(); cv=0; m_Raw->GetFilterForScanNum(scan, &Filter); sl = SysStringLen(Filter)+1; WideCharToMultiByte(CP_ACP,0,Filter,-1,chFilter,sl,NULL,NULL); SysFreeString(Filter); strcpy(cStr,chFilter); MSSpectrumType mst=Unspecified; char* tok; tok=strtok(cStr," \n"); while(tok!=NULL){ if(strcmp(tok,"c")==0){ bCentroid=true; } else if(strlen(tok)>2 && tok[0]=='c' && tok[1]=='v'){ cv=atof(tok+3); } else if(strcmp(tok,"d")==0){ } else if(strcmp(tok,"E")==0){ //enhanced } else if(strcmp(tok,"ESI")==0){ } else if(strcmp(tok,"FTMS")==0){ } else if(strcmp(tok,"Full")==0){ } else if(strcmp(tok,"ITMS")==0){ } else if(strcmp(tok,"lock")==0){ } else if(strcmp(tok,"ms")==0){ mst=MS1; } else if(strcmp(tok,"msx")==0){ mst=MSX; } else if(strcmp(tok,"ms2")==0){ if(mst!=MSX) mst=MS2; } else if(strcmp(tok,"ms3")==0){ if(mst!=MSX) mst=MS3; } else if(strcmp(tok,"NSI")==0){ } else if(strcmp(tok,"p")==0){ bCentroid=false; } else if(strcmp(tok,"r")==0){ //appears in fusion data, no documentation } else if(strcmp(tok,"sa")==0){ bSA=true; } else if(strncmp(tok,"sid",3)==0){ } else if(strcmp(tok,"SRM")==0){ mst=SRM; } else if(strcmp(tok,"t")==0){ //turbo scan } else if(strcmp(tok,"u")==0){ mst=UZS; } else if(strcmp(tok,"w")==0){ //wideband activation? } else if(strcmp(tok,"Z")==0){ if(mst!=UZS) mst=ZS; } else if(strcmp(tok,"+")==0){ } else if(strcmp(tok,"-")==0){ } else if(strchr(tok,'@')!=NULL){ tStr=tok; stop=(int)tStr.find("@"); mzVal=tStr.substr(0,stop); MZs.push_back(atof(&mzVal[0])); mzVal=tStr.substr(stop+1,3); if(mzVal.compare("cid")==0){ act=mstCID; } else if(mzVal.compare("etd")==0){ if(bSA) act=mstETDSA; else act=mstETD; } else if(mzVal.compare("hcd")==0){ act=mstHCD; } else { cout << "Unknown activation method: " << &mzVal[0] << endl; act=mstNA; } } else if(strchr(tok,'[')!=NULL){ } else { cout << "Unknown token: " << tok << endl; } tok=strtok(NULL," \n"); } return mst; } double RAWReader::evaluateTrailerDouble(const char* str){ VARIANT v; BSTR bs; int sl; double ret; VariantInit(&v); sl = lstrlenA(str); bs = SysAllocStringLen(NULL, sl); MultiByteToWideChar(CP_ACP, 0, str, sl, bs, sl); m_Raw->GetTrailerExtraValueForScanNum(rawCurSpec, bs, &v); SysFreeString(bs); if (v.vt == VT_R4) ret = (double)v.fltVal; else if (v.vt == VT_R8) ret = (double)v.dblVal; else ret=0; VariantClear(&v); return ret; } int RAWReader::evaluateTrailerInt(const char* str){ VARIANT v; BSTR bs; int sl; int ret; VariantInit(&v); sl = lstrlenA(str); bs = SysAllocStringLen(NULL, sl); MultiByteToWideChar(CP_ACP, 0, str, sl, bs, sl); m_Raw->GetTrailerExtraValueForScanNum(rawCurSpec, bs, &v); SysFreeString(bs); if (v.vt == VT_I2) ret = (int)v.iVal; else if (v.vt == VT_I4) ret = (int)v.lVal; else if (v.vt == VT_I1) ret = (int)v.cVal; else if (v.vt == VT_UI4) ret = (int)v.ulVal; else if (v.vt == VT_UI2) ret = (int)v.uiVal; else if (v.vt == VT_UI1) ret = (int)v.bVal; else if (v.vt == VT_INT) ret = (int)v.intVal; else if (v.vt == VT_UINT) ret = (int)v.uintVal; else ret = 0; VariantClear(&v); return ret; } void RAWReader::getInstrument(char* str){ strcpy(str,rawInstrument); } long RAWReader::getLastScanNumber(){ return rawCurSpec; } void RAWReader::getManufacturer(char* str){ strcpy(str,rawManufacturer); } long RAWReader::getScanCount(){ return rawTotSpec; } bool RAWReader::getStatus(){ return bRaw; } bool RAWReader::initRaw(){ int raw=0; IXRawfile2Ptr m_Raw2; IXRawfile3Ptr m_Raw3; IXRawfile4Ptr m_Raw4; IXRawfile5Ptr m_Raw5; //Example of Xcalibur/Foundation first //if(FAILED(m_Raw5.CreateInstance("XRawfile.XRawfile.1"))){' //Try MSFileReader - using ProteoWizard strategy if(FAILED(m_Raw5.CreateInstance("MSFileReader.XRawfile.1"))){ if(FAILED(m_Raw4.CreateInstance("MSFileReader.XRawfile.1"))){ if(FAILED(m_Raw3.CreateInstance("MSFileReader.XRawfile.1"))){ if(FAILED(m_Raw2.CreateInstance("MSFileReader.XRawfile.1"))){ if(FAILED(m_Raw.CreateInstance("MSFileReader.XRawfile.1"))){ raw=0; //cout << "Cannot load Thermo MSFileReader. Cannot read .RAW files." << endl; } else { raw=1; } } else { m_Raw=m_Raw2; raw=2; } } else { m_Raw=m_Raw3; raw=3; } } else { m_Raw=m_Raw4; raw=4; } } else { m_Raw=m_Raw5; raw=5; } if(raw>0) return true; return false; } bool RAWReader::readRawFile(const char *c, Spectrum &s, int scNum){ //General purpose function members bool bCheckNext; bool bNewFile; char chFilter[256]; char curFilter[256]; double dRTime; double highmass=0.0; double pm1; double pw; long i; long j; long lArraySize=0; long ret; vector MZs; DataPeak* pDataPeaks = NULL; HRESULT lRet; MSSpectrumType MSn; SAFEARRAY FAR* psa; TCHAR pth[MAX_PATH]; VARIANT varMassList; VARIANT varPeakFlags; //Members for gathering averaged scans int charge; int sl; int widthCount; long FirstBkg1=0; long FirstBkg2=0; long LastBkg1=0; long LastBkg2=0; long lowerBound; long upperBound; BSTR rawFilter=NULL; BSTR testStr; //Additional members for Scan Information bool bCentroid; double cv; //Compensation Voltage double BPI; //Base peak intensity double BPM; //Base peak mass double td; //temp double value double TIC; float IIT; //ion injection time long tl; //temp long value MSActivation act; if(!bRaw) return false; //Clear spectrum object s.clear(); if(c==NULL){ //continue reading current file if(!rawFileOpen) return false; if(scNum>0) rawCurSpec=scNum; else rawCurSpec++; if(rawCurSpec>rawTotSpec) return false; bNewFile=false; } else { //check if requested file is already open if(rawFileOpen) { if(strcmp(c,rawCurrentFile)==0){ if(scNum>0) rawCurSpec=scNum; else rawCurSpec++; if(rawCurSpec>rawTotSpec) return false; bNewFile=false; } else { //new file requested, so close the existing one lRet = m_Raw->Close(); rawFileOpen=false; bNewFile=true; } } else { bNewFile=true; } if(bNewFile){ MultiByteToWideChar(CP_ACP,0,c,-1,(LPWSTR)pth,MAX_PATH); lRet = m_Raw->Open((LPWSTR)pth); if(lRet != ERROR_SUCCESS) { cerr << "Cannot open " << c << endl; return false; } else lRet = m_Raw->SetCurrentController(0,1); rawFileOpen=true; m_Raw->GetNumSpectra(&rawTotSpec); testStr=NULL; m_Raw->GetInstModel(&testStr); sl = SysStringLen(testStr)+1; WideCharToMultiByte(CP_ACP,0,testStr,-1,rawInstrument,sl,NULL,NULL); SysFreeString(testStr); strcpy(rawCurrentFile,c); //if scan number is requested, grab it if(scNum>0) rawCurSpec=scNum; else rawCurSpec=1; if(rawCurSpec>rawTotSpec) return false; } } //Initialize members strcpy(chFilter,""); strcpy(curFilter,""); VariantInit(&varMassList); VariantInit(&varPeakFlags); rawPrecursorInfo preInfo; //Rather than grab the next scan number, get the next scan based on a user-filter (if supplied). //if the filter was set, make sure we pass the filter while(true){ MSn = evaluateFilter(rawCurSpec, curFilter, MZs, bCentroid,cv,act); //check for spectrum filter (string) if(strlen(rawUserFilter)>0){ bCheckNext=false; if(rawUserFilterExact) { if(strcmp(curFilter,rawUserFilter)!=0) bCheckNext=true; } else { if(strstr(curFilter,rawUserFilter)==NULL) bCheckNext=true; } //if string doesn't match, get next scan until it does match or EOF if(bCheckNext){ if(scNum>0) return false; rawCurSpec++; if(rawCurSpec>rawTotSpec) return false; continue; } } //check for msLevel filter if(msLevelFilter->size()>0 && find(msLevelFilter->begin(), msLevelFilter->end(), MSn) == msLevelFilter->end()) { if(scNum>0) return false; rawCurSpec++; if(rawCurSpec>rawTotSpec) return false; } else { break; } } //Get basic spectrum metadata. It will be replaced/supplemented later, if available preInfo.clear(); m_Raw->GetScanHeaderInfoForScanNum(rawCurSpec, &tl, &td, &td, &td, &TIC, &BPM, &BPI, &tl, &tl, &td); m_Raw->RTFromScanNum(rawCurSpec, &dRTime); preInfo.charge = evaluateTrailerInt("Charge State:"); preInfo.dMonoMZ = evaluateTrailerDouble("Monoisotopic M/Z:"); IIT = (float)evaluateTrailerDouble("Ion Injection Time (ms):"); //Get more sig digits for isolation mass if (raw > 3 && (MSn==MS2 || MSn==MS3)){ IXRawfile4Ptr raw4 = (IXRawfile4Ptr)m_Raw; if (MSn==MS2) tl=2; else tl=3; ret = raw4->GetPrecursorMassForScanNum(rawCurSpec,tl,&td); if (ret == 0) preInfo.dIsoMZ = td; raw4=NULL; //Correct precursor mono mass if it is more than 5 13C atoms away from isolation mass if (preInfo.dMonoMZ > 0 && preInfo.charge>0){ td = preInfo.dIsoMZ-preInfo.dMonoMZ; if (td>5.01675/preInfo.charge) preInfo.dMonoMZ=preInfo.dIsoMZ; } } //Get the peaks //Average raw files if requested by user if(rawAvg){ widthCount=0; lowerBound=0; upperBound=0; for(i=rawCurSpec-1;i>0;i--){ evaluateFilter(i, chFilter, MZs, bCentroid,cv,act); if(strcmp(curFilter,chFilter)==0){ widthCount++; if(widthCount==rawAvgWidth) { lowerBound=i; break; } } } if(lowerBound==0) lowerBound=rawCurSpec; //this will have "edge" effects widthCount=0; for(i=rawCurSpec+1;iGetFilterForScanNum(i, &rawFilter); j=m_Raw->GetAverageMassList(&lowerBound, &upperBound, &FirstBkg1, &LastBkg1, &FirstBkg2, &LastBkg2, rawFilter, 1, rawAvgCutoff, 0, FALSE, &pw, &varMassList, &varPeakFlags, &lArraySize ); SysFreeString(rawFilter); rawFilter=NULL; } else { //Get regular spectrum data sl=lstrlenA(""); testStr = SysAllocStringLen(NULL,sl); MultiByteToWideChar(CP_ACP,0,"",sl,testStr,sl); j=m_Raw->GetMassListFromScanNum(&rawCurSpec,testStr,0,0,0,FALSE,&pw,&varMassList,&varPeakFlags,&lArraySize); SysFreeString(testStr); } //Handle MS2 and MS3 files differently to create Z-lines if(MSn==MS2 || MSn==MS3){ //if charge state is assigned to spectrum, add Z-lines. if (preInfo.dIsoMZ>0.01) MZs[0]=preInfo.dIsoMZ; //overwrite isolation mass if we have more sig figs. if(preInfo.charge>0){ //if(Charge.iVal>0){ if(preInfo.dMonoMZ>0.01) { //if(MonoMZ.dblVal>0.01) { //pm1 = MonoMZ.dblVal * Charge.iVal - ((Charge.iVal-1)*1.007276466); pm1 = preInfo.dMonoMZ * preInfo.charge - ((preInfo.charge - 1)*1.007276466); s.setMZ(MZs[0], preInfo.dMonoMZ); } else { pm1 = MZs[0] * preInfo.charge - ((preInfo.charge - 1)*1.007276466); s.setMZ(MZs[0]); } s.addZState(preInfo.charge, pm1); s.setCharge(preInfo.charge); } else { s.setMZ(preInfo.dIsoMZ); s.setMZ(MZs[0]); charge = calcChargeState(MZs[0], highmass, &varMassList, lArraySize); //Charge greater than 0 means the charge state is known if(charge>0){ pm1 = MZs[0]*charge - ((charge-1)*1.007276466); s.addZState(charge,pm1); //Charge of 0 means unknown charge state, therefore, compute +2 and +3 states. } else { pm1 = MZs[0]*2 - 1.007276466; s.addZState(2,pm1); pm1 = MZs[0]*3 - 2*1.007276466; s.addZState(3,pm1); } } } //endif MS2 and MS3 if(MSn==MSX){ for(i=0;i<(int)MZs.size();i++){ if(i==0) s.setMZ(MZs[i],0); else s.addMZ(MZs[i],0); } s.setCharge(0); } //Set basic scan info if(bCentroid) s.setCentroidStatus(1); else s.setCentroidStatus(0); s.setRawFilter(curFilter); s.setActivationMethod(act); s.setScanNumber((int)rawCurSpec); s.setScanNumber((int)rawCurSpec,true); s.setRTime((float)dRTime); s.setFileType(MSn); s.setBPI((float)BPI); s.setBPM(BPM); s.setCompensationVoltage(cv); // s.setConversionA(ConversionA.dblVal); //Deprecating Conversion values // s.setConversionB(ConversionB.dblVal); // s.setConversionC(ConversionC.dblVal); // s.setConversionD(ConversionD.dblVal); // s.setConversionE(ConversionE.dblVal); // s.setConversionI(ConversionI.dblVal); s.setTIC(TIC); s.setIonInjectionTime(IIT); if(MSn==SRM) s.setMZ(MZs[0]); switch(MSn){ case MS1: s.setMsLevel(1); break; case MS2: s.setMsLevel(2); break; case MS3: s.setMsLevel(3); break; case MSX: s.setMsLevel(2); break; default: s.setMsLevel(0); break; } psa = varMassList.parray; SafeArrayAccessData( psa, (void**)(&pDataPeaks) ); for(j=0;j* v){ msLevelFilter=v; } void RAWReader::setRawFilter(char *c){ strcpy(rawUserFilter,c); } #endif libmstoolkit-cleaned-82/src/MSToolkit/mzMLWriter.cpp0000644000175000017500000006124413210260002022565 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "mzMLWriter.h" using namespace MSToolkit; using namespace ms::numpress::MSNumpress; MzMLWriter::MzMLWriter(){ iSpecList=0; iChromList=0; bFileOpen=false; bZlib=false; bNumpress=false; bTabs=false; index=0; chromIndex=0; } MzMLWriter::~MzMLWriter(){ if(bFileOpen){ cout << "WARNING: Destroying MzMLWriter before active file was closed. Expect malformed file and/or loss of data." << endl; } } bool MzMLWriter::closeList(){ if (iSpecList==1){ iSpecList = 2; } else if (iChromList == 1){ iChromList=2; } else { cout << "Error: closeList() - no lists are open." << endl; return false; } if (bTabs) fprintf(fptr, " "); fprintf(fptr, "\n"); return true; } bool MzMLWriter::closeMzML(){ if (iSpecList == 1 || iChromList == 1) { cout << "Error: closeMzML() - a spectrumList or chromatogramList is still open." << endl; return false; } if(bTabs) fprintf(fptr," "); fprintf(fptr,"\n"); if(bTabs) fprintf(fptr," "); fprintf(fptr,"\n"); if(!writeIndex()) return false; fprintf(fptr,"\n"); if (iSpecList == 2){ fseek(fptr,fSpecList,0); fprintf(fptr,"%.10d",index); } if (iChromList == 2){ fseek(fptr, fChromList, 0); fprintf(fptr, "%.10d", chromIndex); } fclose(fptr); fptr=NULL; bFileOpen=false; return true; } bool MzMLWriter::createList(bool specList){ if (specList){ if (iSpecList>0){ cout << "Error: createList() - spectrumList already created." << endl; return false; } else if (iChromList == 1){ cout << "Error: createList() - chromatogramList not closed." << endl; return false; } iSpecList=1; if (bTabs)fprintf(fptr, " "); fprintf(fptr, "\n", 0); return true; } if (iChromList>0){ cout << "Error: createList() - chromatogramList already created." << endl; return false; } else if (iSpecList == 1){ cout << "Error: createList() - spectrumList not closed." << endl; return false; } iChromList = 1; if (bTabs)fprintf(fptr, " "); fprintf(fptr, "\n", 0); return true; } bool MzMLWriter::createMzML(char* fn){ if(bFileOpen){ cout << "Error: createMzML() - cannot create new mzML file. Please finalize existing file first." << endl; return false; } fptr = fopen(fn,"wt"); if(!fptr){ cout << "Error: createMzML() - cannot create " << fn << endl; return false; } bFileOpen=true; chromIndex = 0; index=0; vIndex.clear(); vChromIndex.clear(); iSpecList = 0; iChromList = 0; fprintf(fptr,"\n"); fprintf(fptr,"\n"); if(bTabs)fprintf(fptr," "); fprintf(fptr,"\n"); if(bTabs)fprintf(fptr," "); fprintf(fptr,"\n"); return true; } void MzMLWriter::setNumpress(bool b){ if(bFileOpen){ cout << "WARNING: Calling setNumpress before active file was closed. Expect inconsistent data indentation." << endl; } bNumpress=b; } void MzMLWriter::setTabs(bool b){ if(bFileOpen){ cout << "WARNING: Calling setTabs before active file was closed. Expect inconsistent data indentation." << endl; } bTabs=b; } void MzMLWriter::setZlib(bool b){ if(bFileOpen){ cout << "WARNING: Calling setZlib before active file was closed. Expect inconsistent data indentation." << endl; } bZlib=b; } bool MzMLWriter::writeChromatogram(BasicChromatogram& c){ if (!bFileOpen){ cout << "Error: writeChromatogram() - cannot write chromatogram, mzML file not open." << endl; return false; } if (iChromList == 0){ cout << "Error: writeChromatogram() - cannot write chromatogram, chromatogramList not created." << endl; return false; } if (iChromList == 2){ cout << "Error: writeChromatogram() - cannot write chromatogram, chromatogramList closed." << endl; return false; } if (!exportChromatogram(c, 4)) return false; return true; } bool MzMLWriter::writeIndex(){ if(!bFileOpen){ cout << "Error: writeIndex() - cannot write index, mzML file not open." << endl; return false; } unsigned int i; f_off offset; if(bTabs) fprintf(fptr," "); offset=ftell(fptr); int count=0; if (vIndex.size()>0)count++; if (vChromIndex.size()>0)count++; fprintf(fptr,"\n",count); if (vIndex.size()>0){ if(bTabs) { fprintf(fptr," "); fprintf(fptr," "); } fprintf(fptr,"\n"); for(i=0;i\n"); } if (vChromIndex.size()>0){ if (bTabs) { fprintf(fptr, " "); fprintf(fptr, " "); } fprintf(fptr, "\n"); for (i = 0; i\n"); } if(bTabs) fprintf(fptr," "); fprintf(fptr,"\n"); if(bTabs) fprintf(fptr," "); fprintf(fptr,"%lld\n",offset); return true; } bool MzMLWriter::writeSpectra(Spectrum& s){ if(!bFileOpen){ cout << "Error: writeSpectra() - cannot write Spectra, mzML file not open." << endl; return false; } if (iSpecList == 0){ cout << "Error: writeSpectra() - cannot write Spectra, spectrumList not created." << endl; return false; } if (iSpecList == 2){ cout << "Error: writeSpectra() - cannot write Spectra, spectrumList closed." << endl; return false; } if(!exportSpectrum(s,4)) return false; return true; } bool MzMLWriter::writeSpectra(MSObject& o){ for (int i = 0; i < o.size(); i++){ writeSpectra(o.at(i)); } } bool MzMLWriter::exportBinary(char* str, int len, int tabs){ int i; string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,""); for(i=0;i\n"); return true; } bool MzMLWriter::exportBinaryDataArray(BasicChromatogram& c, bool bRT, int tabs){ int i; string tbs = ""; vector d; vector f; //put data in single array if (bRT){ for (i = 0; i0)sz64 += (3 - i); sz64 = sz64 * 4 / 3; arr64 = new char[sz64]; if (bNumpress){ if (bZlib) i = b64_encode(arr64, (char*)zCompr, zLen); else i = b64_encode(arr64, (char*)numpr, numprLen); } else { if (bZlib) i = b64_encode(arr64, (char*)zCompr, zLen); else { if (bRT) i = b64_encode(arr64, (char*)&d[0], d.size()*sizeof(double)); else i = b64_encode(arr64, (char*)&f[0], f.size()*sizeof(float)); } } //write to file if (bTabs) { tbs.append(tabs, ' '); fprintf(fptr, "%s", &tbs[0]); } fprintf(fptr, "\n", i); if (bZlib) exportCvParam("MS:1000574", "MS", "zlib compression", "", "", "", "", tabs + 1); if (bNumpress) { if (bRT) exportCvParam("MS:1002312", "MS", "MS-Numpress linear prediction compression", "", "", "", "", tabs + 1); else exportCvParam("MS:1002314", "MS", "MS-Numpress short logged float compression", "", "", "", "", tabs + 1); } else { if (bRT) exportCvParam("MS:1000523", "MS", "64-bit float", "", "", "", "", tabs + 1); else exportCvParam("MS:1000521", "MS", "32-bit float", "", "", "", "", tabs + 1); } if (bRT) exportCvParam("MS:1000595", "MS", "time array", "UO:0000010", "MS", "second", "", tabs + 1); else exportCvParam("MS:1000515", "MS", "intensity array", "MS:1000131", "MS", "number of detector counts", "", tabs + 1); if (!exportBinary(arr64, i, tabs + 1)) return false; if (bTabs) fprintf(fptr, "%s", &tbs[0]); fprintf(fptr, "\n"); //clean up memory delete[] arr64; if (zCompr != NULL) delete[] zCompr; if (numpr != NULL) delete[] numpr; return true; } bool MzMLWriter::exportBinaryDataArray(Spectrum& s, bool bMZ, int tabs){ int i; string tbs=""; vector d; vector f; //put data in single array if(bMZ){ for(i=0;i0)sz64+=(3-i); sz64=sz64*4/3; arr64=new char[sz64]; if(bNumpress){ if(bZlib) i=b64_encode(arr64,(char*)zCompr,zLen); else i=b64_encode(arr64,(char*)numpr,numprLen); } else { if(bZlib) i=b64_encode(arr64,(char*)zCompr,zLen); else { if(bMZ) i=b64_encode(arr64,(char*)&d[0],d.size()*sizeof(double)); else i=b64_encode(arr64,(char*)&f[0],f.size()*sizeof(float)); } } //write to file if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"\n",i); if(bZlib) exportCvParam("MS:1000574","MS","zlib compression","","","","",tabs+1); if(bNumpress) { if(bMZ) exportCvParam("MS:1002312","MS","MS-Numpress linear prediction compression","","","","",tabs+1); else exportCvParam("MS:1002314","MS","MS-Numpress short logged float compression","","","","",tabs+1); } else { if(bMZ) exportCvParam("MS:1000523","MS","64-bit float","","","","",tabs+1); else exportCvParam("MS:1000521","MS","32-bit float","","","","",tabs+1); } if(bMZ) exportCvParam("MS:1000514","MS","m/z array","MS:1000040","MS","m/z","",tabs+1); else exportCvParam("MS:1000515","MS","intensity array","MS:1000131","MS","number of detector counts","",tabs+1); if(!exportBinary(arr64,i,tabs+1)) return false; if(bTabs) fprintf(fptr,"%s",&tbs[0]); fprintf(fptr,"\n"); //clean up memory delete [] arr64; if(zCompr!=NULL) delete [] zCompr; if(numpr!=NULL) delete [] numpr; return true; } bool MzMLWriter::exportBinaryDataArrayList(BasicChromatogram& c, int tabs){ string tbs = ""; if (bTabs) { tbs.append(tabs, ' '); fprintf(fptr, "%s", &tbs[0]); } fprintf(fptr, "\n"); if (!exportBinaryDataArray(c, true, tabs + 1)) return false; if (!exportBinaryDataArray(c, false, tabs + 1)) return false; if (bTabs) fprintf(fptr, "%s", &tbs[0]); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportBinaryDataArrayList(Spectrum& s, int tabs){ string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"\n"); if(!exportBinaryDataArray(s,true,tabs+1)) return false; if(!exportBinaryDataArray(s,false,tabs+1)) return false; if(bTabs) fprintf(fptr,"%s",&tbs[0]); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportActivation(Spectrum& s, int tabs){ char tmp[128]; string value; string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"\n"); switch(s.getActivationMethod()){ case mstCID: exportCvParam("MS:1000133","MS","collision-induced dissociation","","","","",tabs+1); //TODO: get activation energy //exportCvParam("MS:1000045","MS","collision energy","","","","",tabs+1); break; case mstETD: case mstHCD: break; default: break; } if(bTabs) fprintf(fptr,"%s",&tbs[0]); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportChromatogram(BasicChromatogram& c, int tabs){ char tmp[128]; string value; string tbs = ""; sMzMLIndex x; if (bTabs) { tbs.append(tabs, ' '); fprintf(fptr, "%s", &tbs[0]); } c.getIDString(tmp); x.id = tmp; x.offset = ftell(fptr); vChromIndex.push_back(x); fprintf(fptr, "\n", chromIndex++, tmp, c.size()); if (!exportPrecursor(c, tabs + 1)) return false; if (c.getProdMZ()>0) { if (!exportProduct(c,tabs+1)) return false; } if (!exportBinaryDataArrayList(c, tabs + 1)) return false; if (bTabs) fprintf(fptr, "%s", &tbs[0]); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportCvParam(string ac, string ref, string name, string unitAc, string unitRef, string unitName, string value, int tabs){ string ex=""; if(bTabs) ex.append(tabs,' '); ex+="0) ex+=" value=\"" + value + "\""; if(unitRef.size()>0) ex+=" unitCvRef=\"" + unitRef + "\""; if(unitAc.size()>0) ex+=" unitAccession=\"" + unitAc + "\""; if(unitName.size()>0) ex+=" unitName=\"" + unitName + "\""; ex+="/>"; fprintf(fptr,"%s\n",&ex[0]); return true; } bool MzMLWriter::exportIsolationWindow(BasicChromatogram& c, bool bPre, int tabs){ char tmp[128]; string value; string tbs = ""; if (bTabs) { tbs.append(tabs, ' '); fprintf(fptr, "%s", &tbs[0]); } fprintf(fptr, "\n"); if (bPre) sprintf(tmp, "%.4lf", c.getPreMZ()); else sprintf(tmp, "%.4lf", c.getProdMZ()); value = tmp; exportCvParam("MS:1000827", "MS", "isolation window target m/z", "MS:1000040", "MS", "m/z", value, tabs + 1); if (bPre) sprintf(tmp, "%.4lf", c.getPreOffsetLower()); else sprintf(tmp, "%.4lf", c.getProdOffsetLower()); value = tmp; exportCvParam("MS:1000828", "MS", "isolation window lower offset", "MS:1000040", "MS", "m/z", value, tabs + 1); if (bPre) sprintf(tmp, "%.4lf", c.getPreOffsetUpper()); else sprintf(tmp, "%.4lf", c.getProdOffsetUpper()); value = tmp; exportCvParam("MS:1000829", "MS", "isolation window upper offset", "MS:1000040", "MS", "m/z", value, tabs + 1); if (bTabs) fprintf(fptr, "%s", &tbs[0]); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportIsolationWindow(Spectrum& s, int tabs){ char tmp[128]; string value; string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"\n"); sprintf(tmp,"%.2lf",s.getMZ()); value=tmp; exportCvParam("MS:1000827","MS","isolation window target m/z","MS:1000040","MS","m/z",value,tabs+1); if(bTabs) fprintf(fptr,"%s",&tbs[0]); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportOffset(string idRef, f_off offset, int tabs){ string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"%lld\n",&idRef[0],offset); return true; } bool MzMLWriter::exportPrecursor(BasicChromatogram& c, int tabs){ string tbs = ""; if (bTabs) { tbs.append(tabs, ' '); fprintf(fptr, "%s", &tbs[0]); } fprintf(fptr, "\n"); if (!exportIsolationWindow(c, true, tabs + 1)) return false; if (c.getPreMZ()>0) { if (!exportSelectedIonList(c, tabs + 1)) return false; } //if (!exportActivation(s, tabs + 1)) return false; if (bTabs) fprintf(fptr, "%s", &tbs[0]); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportPrecursor(Spectrum& s, int tabs){ string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"\n"); if(!exportIsolationWindow(s,tabs+1)) return false; //if(s.getMonoMZ()>0) { if(!exportSelectedIonList(s,tabs+1)) return false; //} if(!exportActivation(s,tabs+1)) return false; if(bTabs) fprintf(fptr,"%s",&tbs[0]); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportPrecursorList(Spectrum& s, int tabs){ string tbs=""; if(bTabs) { tbs.append(tabs,' '); fprintf(fptr,"%s",&tbs[0]); } fprintf(fptr,"\n"); if(!exportPrecursor(s,tabs+1)) return false; if(bTabs) fprintf(fptr,"%s",&tbs[0]); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportProduct(BasicChromatogram& c, int tabs){ if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); if (!exportIsolationWindow(c, false, tabs + 1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportScan(Spectrum& s, int tabs){ char tmp[128]; string value; if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); sprintf(tmp,"%f",s.getRTime()); value=tmp; exportCvParam("MS:1000016","MS","scan start time","UO:0000031","UO","minute",value,tabs+1); s.getRawFilter(tmp,128); if (strlen(tmp) > 1){ value=tmp; exportCvParam("MS:1000512", "MS", "filter string", "", "", "",value,tabs+1); } if (!exportScanWindowList(s, tabs + 1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportScanList(Spectrum& s, int tabs){ if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); if(!exportScan(s,tabs+1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportScanWindow(Spectrum& s, int tabs){ char tmp[128]; string value; if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); sprintf(tmp, "%.8lf", s.getScanWindowLower()); value = tmp; exportCvParam("MS:1000501", "MS", "scan window lower limit", "MS:1000040", "MS", "m/z", value, tabs + 1); sprintf(tmp, "%.8lf", s.getScanWindowUpper()); value = tmp; exportCvParam("MS:1000500", "MS", "scan window upper limit", "MS:1000040", "MS", "m/z", value, tabs + 1); if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportScanWindowList(Spectrum& s, int tabs){ if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); if (!exportScanWindow(s, tabs + 1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportSelectedIon(BasicChromatogram& c, int tabs){ char tmp[128]; string value; if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); sprintf(tmp, "%.8lf", c.getPreMZ()); value = tmp; exportCvParam("MS:1000744", "MS", "selected ion m/z", "MS:1000040", "MS", "m/z", value, tabs + 1); sprintf(tmp, "%d", c.getCharge()); value = tmp; exportCvParam("MS:1000041", "MS", "charge state", "", "", "", value, tabs + 1); exportCvParam("MS:1000042", "MS", "peak intensity", "MS:1000132", "MS", "percent of base peak",value,tabs+1); if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportSelectedIon(Spectrum& s, int tabs){ int i; char tmp[128]; string value; if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); if(s.getMonoMZ()>0) sprintf(tmp,"%.12lf",s.getMonoMZ()); else sprintf(tmp, "%.2lf", s.getMZ()); value=tmp; exportCvParam("MS:1000744","MS","selected ion m/z","MS:1000040","MS","m/z",value,tabs+1); if(s.sizeZ()==1) { sprintf(tmp,"%d",s.atZ(0).z); value=tmp; exportCvParam("MS:1000041","MS","charge state","","","",value,tabs+1); } else { for(i=0;i\n"); return true; } bool MzMLWriter::exportSelectedIonList(BasicChromatogram& c, int tabs){ if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); if (!exportSelectedIon(c, tabs + 1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr, "\n"); return true; } bool MzMLWriter::exportSelectedIonList(Spectrum& s, int tabs){ if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); if(!exportSelectedIon(s,tabs+1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); return true; } bool MzMLWriter::exportSpectrum(Spectrum& s, int tabs){ char tmp[128]; string value; sMzMLIndex x; if (bTabs) exportTabs(tabs); sprintf(tmp,"scan=%d",s.getScanNumber()); x.id=tmp; x.offset=ftell(fptr); vIndex.push_back(x); fprintf(fptr,"\n",index++,s.getScanNumber(),s.size()); sprintf(tmp,"%d",s.getMsLevel()); value=tmp; exportCvParam("MS:1000511","MS","ms level","","","",value,tabs+1); sprintf(tmp,"%.12lf",s[0].mz); value=tmp; exportCvParam("MS:1000528","MS","lowest observed m/z","MS:1000040","MS","m/z",value,tabs+1); sprintf(tmp,"%.12lf",s[s.size()-1].mz); value=tmp; exportCvParam("MS:1000527","MS","highest observed m/z","MS:1000040","MS","m/z",value,tabs+1); if(!exportScanList(s,tabs+1)) return false; if(s.getMsLevel()>1){ if(!exportPrecursorList(s,tabs+1)) return false; } if(!exportBinaryDataArrayList(s,tabs+1)) return false; if (bTabs) exportTabs(tabs); fprintf(fptr,"\n"); return true; } void MzMLWriter::exportTabs(int tabs){ string tbs = ""; tbs.append(tabs, ' '); fprintf(fptr, "%s", &tbs[0]); } libmstoolkit-cleaned-82/src/MSToolkit/MSObject.cpp0000644000175000017500000000513513210260002022154 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "MSObject.h" #include using namespace std; using namespace MSToolkit; MSObject::MSObject(){ vSpectrum = new vector; fileName=""; fileType=Unspecified; for(int i=0;i<16;i++) strcpy(header.header[i],"\0"); } MSObject::~MSObject(){ delete vSpectrum; } MSObject::MSObject(const MSObject& m){ unsigned int i; vSpectrum = new vector; for(i=0;isize();i++){ vSpectrum->push_back(m.vSpectrum->at(i)); } fileType = m.fileType; fileName = m.fileName; for(i=0;i<16;i++) strcpy(header.header[i],m.header.header[i]); } MSObject& MSObject::operator=(const MSObject& m){ unsigned int i; if (this!=&m){ delete vSpectrum; vSpectrum = new vector; for(i=0;isize();i++){ vSpectrum->push_back(m.vSpectrum->at(i)); } fileType = m.fileType; fileName = m.fileName; for(i=0;i<16;i++) strcpy(header.header[i],m.header.header[i]); } return *this; } void MSObject::add(Spectrum& s){ vSpectrum->push_back(s); }; bool MSObject::addToHeader(char* c){ if(strlen(c)>127) return false; for(int i=0;i<16;i++){ if(header.header[i][0]=='\0'){ strcpy(header.header[i],c); return true; }; }; return false; }; bool MSObject::addToHeader(string s){ if(s.size()>127) return false; for(int i=0;i<16;i++){ if(header.header[i][0]=='\0'){ strcpy(header.header[i],&s[0]); return true; }; }; return false; }; Spectrum& MSObject::at(unsigned int i){ return vSpectrum->at(i); }; Peak_T& MSObject::at(unsigned int i, unsigned int j){ return vSpectrum->at(i).at(j); }; void MSObject::clear(){ delete vSpectrum; vSpectrum = new vector; for(int i=0;i<16;i++) strcpy(header.header[i],"\0"); }; MSHeader& MSObject::getHeader(){ return header; }; void MSObject::setHeader(const MSHeader& h){ for(int i=0;i<16;i++) strcpy(header.header[i],h.header[i]); }; int MSObject::size(){ return (int)vSpectrum->size(); }; libmstoolkit-cleaned-82/src/MSToolkit/pepXMLWriter.cpp0000644000175000017500000002402513210260002023047 0ustar rusconirusconi/* Copyright 2005-2016, Michael R. Hoopmann Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ #include "pepXMLWriter.h" PepXMLWriter::PepXMLWriter(){ index=0; iTabs=0; bTabs=true; spQueryIndex=0; fptr=NULL; } PepXMLWriter::~PepXMLWriter(){ } void PepXMLWriter::addTab(){ strTabs[iTabs++]=' '; strTabs[iTabs]='\0'; } void PepXMLWriter::closePepXML(){ while(vTagState.size()>0){ deleteTab(); writeLine(&vTagState.back()[0]); vTagState.pop_back(); } fclose(fptr); } bool PepXMLWriter::createPepXML(char* fn, pxwMSMSRunSummary& run, pxwSampleEnzyme* enzyme, PXWSearchSummary* search){ size_t i; time_t timeNow; string st; char str[32]; spQueryIndex=1; if(fptr!=NULL) fclose(fptr); fptr=fopen(fn,"wt"); if(fptr==NULL) return false; char timebuf[80]; time(&timeNow); strftime(timebuf, 80, "%Y-%m-%dT%H:%M:%S", localtime(&timeNow)); resetTabs(); writeLine("\n"); st = "\n"; writeLine(&st[0]); addTab(); st = "\n"; vTagState.push_back(st); st="\n"; writeLine(&st[0]); addTab(); st="\n"; vTagState.push_back(st); if (enzyme != NULL){ st = "name; st += "\">\n"; writeLine(&st[0]); addTab(); st = "cut; st += "\" no_cut=\""; st+=enzyme->no_cut; st += "\" sense=\""; st+=enzyme->sense; st += "\"/>\n"; writeLine(&st[0]); deleteTab(); st = "\n"; writeLine(&st[0]); } if(search!=NULL){ //pass to searchSummary eventually st="base_name; st+="\" search_engine=\""; st+=search->search_engine; if(search->search_engine_version.size()>0){ st += "\" search_engine_version=\""; st += search->search_engine_version; } st+="\" precursor_mass_type=\""; if (search->precursor_mass_type>0) st += "average\""; else st += "monoisotopic\""; st += " fragment_mass_type=\""; if (search->fragment_mass_type>0) st += "average\""; else st += "monoisotopic\""; st += " search_id=\"1\""; st+=">\n"; writeLine(&st[0]); if(search->search_database.size()>1){ st = " search_database; st += "\" type=\"AA\"/>\n"; writeLine(&st[0]); } if (enzyme != NULL){ st = " name; st += "\" max_num_internal_cleavages=\""; sprintf(str,"%d",enzyme->maxNumInternalCleavages); st+=str; st += "\" min_number_termini=\""; sprintf(str, "%d",enzyme->minNumTermini); st+=str; st += "\"/>\n"; writeLine(&st[0]); } for(i=0;iparameters->size();i++){ st=" parameters->at(i).name; st+="\" value=\""; st+=search->parameters->at(i).value; st+="\"/>\n"; writeLine(&st[0]); } st="\n"; writeLine(&st[0]); } return true; } void PepXMLWriter::deleteTab(){ iTabs--; strTabs[iTabs]='\0'; } void PepXMLWriter::resetTabs(){ iTabs=0; strTabs[iTabs]='\0'; } void PepXMLWriter::writeAltProtein(pxwProtein& s){ string st; st="\n"; writeLine(&st[0]); } void PepXMLWriter::writeModAAMass(pxwModAA& s){ string st; char nStr[32]; st="\n"; writeLine(&st[0]); } void PepXMLWriter::writeModInfo(PXWModInfo& s){ string st; char nStr[64]; size_t i; st="0){ st+=" modified_peptide=\""; st+=s.modified_peptide; st+="\""; } if(s.mod_nterm_mass!=0){ sprintf(nStr," mod_nterm_mass=\"%.4lf\"",s.mod_nterm_mass); st+=nStr; } if(s.mod_cterm_mass!=0){ sprintf(nStr," mod_cterm_mass=\"%.4lf\"",s.mod_cterm_mass); st+=nStr; } st+=">\n"; writeLine(&st[0]); addTab(); for(i=0;i0) st+=s.getProtein(0).peptide_prev_aa; else st+="-"; st+="\" peptide_next_aa=\""; if(s.sizeProteins()>0) st+=s.getProtein(0).peptide_next_aa; else st+="-"; st+="\" protein=\""; if(s.sizeProteins()>0) st+=s.getProtein(0).protein; else st+="unknown"; st+="\" num_tot_proteins=\""; sprintf(nStr,"%d",s.num_tot_proteins); st+=nStr; st+="\" calc_neutral_pep_mass=\""; sprintf(nStr,"%.6lf",s.calc_neutral_pep_mass); st+=nStr; st+="\" complement_mass=\""; sprintf(nStr,"%.6lf",s.massdiff); st+=nStr; if(alpha) st+="\" designation=\"alpha\">\n"; else st+="\" designation=\"beta\">\n"; writeLine(&st[0]); addTab(); for(i=1;i0 || s.modInfo.mod_cterm_mass!=0 || s.modInfo.mod_nterm_mass!=0){ writeModInfo(s.modInfo); } for(i=0;i\n"; writeLine(&st[0]); } deleteTab(); writeLine("\n"); } void PepXMLWriter::writeSearchHit(pxwSearchHitPair& s) { string st; char nStr[32]; size_t i; bool bCross=false; if(s.a->xlink_type.compare("xl")==0) bCross=true; st="hit_rank); st+=nStr; st+="\" peptide=\""; if(bCross) st+="-"; else st+=s.a->peptide; st+="\" peptide_prev_aa=\""; if(s.a->sizeProteins()>0 && !bCross) st+=s.a->getProtein(0).peptide_prev_aa; else st+="-"; st+="\" peptide_next_aa=\""; if(s.a->sizeProteins()>0 && !bCross) st+=s.a->getProtein(0).peptide_next_aa; else st+="-"; st+="\" protein=\""; if(s.a->sizeProteins()>0 && !bCross) st+=s.a->getProtein(0).protein; else st+="-"; st+="\" num_tot_proteins=\""; sprintf(nStr,"%d",s.a->num_tot_proteins); st+=nStr; st+="\" calc_neutral_pep_mass=\""; if(bCross) sprintf(nStr,"%.6lf",s.a->calc_neutral_xl_mass); else sprintf(nStr,"%.6lf",s.a->calc_neutral_pep_mass); st+=nStr; st+="\" massdiff=\""; if(bCross) sprintf(nStr,"%.6lf",s.a->xl_massdiff); else sprintf(nStr,"%.6lf",s.a->massdiff); st+=nStr; st+="\" xlink_type=\""; st+=s.a->xlink_type; st+="\">\n"; writeLine(&st[0]); addTab(); if(!bCross){ for(i=1;isizeProteins();i++){ writeAltProtein(s.a->getProtein(i)); } if(s.a->modInfo.sizeMods()>0 || s.a->modInfo.mod_cterm_mass!=0 || s.a->modInfo.mod_nterm_mass!=0){ writeModInfo(s.a->modInfo); } } //loop or cross-link info if(s.a->xlink_type.compare("na")!=0){ st="\n"; writeLine(&st[0]); addTab(); if(bCross) { writeLinkedPeptide(*s.a,true); writeLinkedPeptide(*s.b,false); } else { for(i=0;isizeXLScores();i++){ st="getXLScore(i).name; st+="\" value=\""; st+=s.a->getXLScore(i).value; st+="\"/>\n"; writeLine(&st[0]); } } deleteTab(); writeLine("\n"); } for(i=0;isizeScores();i++){ st="getScore(i).name; st+="\" value=\""; st+=s.a->getScore(i).value; st+="\"/>\n"; writeLine(&st[0]); } deleteTab(); writeLine("\n"); } void PepXMLWriter::writeSpectrumQuery(PXWSpectrumQuery& s){ string st; char nStr[32]; st="0){ //retention time is optional st+="\" retention_time_sec=\""; sprintf(nStr,"%.1lf",s.retention_time_sec); st+=nStr; } st+="\">\n"; writeLine(&st[0]); addTab(); st="\n"; writeLine(&st[0]); addTab(); for(size_t i=0;i using namespace std; using namespace MSToolkit; MSReader::MSReader(){ fileIn=NULL; rampFileIn=NULL; iIntensityPrecision=1; iMZPrecision=4; rampFileOpen=false; compressMe=false; rawFileOpen=false; exportMGF=false; highResMGF=false; mgfOnePlus=false; iFType=0; iVersion=0; for(int i=0;i<16;i++) strcpy(header.header[i],"\0"); headerIndex=0; sCurrentFile.clear(); sInstrument="unknown"; sManufacturer="unknown"; lastReadScanNum=0; #ifndef _NOSQLITE db = NULL; lastIndex=-1; lastScanNumber=-1; #endif } MSReader::~MSReader(){ closeFile(); if(rampFileOpen) { rampCloseFile(rampFileIn); free(pScanIndex); } #ifndef _NOSQLITE if(db != NULL) sqlite3_close(db); #endif } void MSReader::addFilter(MSSpectrumType m){ filter.push_back(m); } void MSReader::appendFile(char* c, bool text, Spectrum& s){ FILE* fileOut; if (c == NULL) return; if (text)fileOut = fopen(c, "at"); else fileOut = fopen(c, "ab"); //output spectrum header writeSpecHeader(fileOut, text, s); //output spectrum if (text){ writeTextSpec(fileOut, s); } else if (compressMe){ writeCompressSpec(fileOut, s); } else { writeBinarySpec(fileOut, s); } fclose(fileOut); } void MSReader::appendFile(char* c, Spectrum& s){ MSFileFormat ff; FILE* fileOut; if (c == NULL) return; ff = checkFileFormat(c); switch (ff){ case mgf: exportMGF = true; fileOut = fopen(c, "at"); writeTextSpec(fileOut, s); fclose(fileOut); exportMGF = false; break; case ms1: case ms2: case zs: case uzs: fileOut = fopen(c, "at"); writeSpecHeader(fileOut, true, s); writeTextSpec(fileOut, s); fclose(fileOut); break; case bms1: case bms2: fileOut = fopen(c, "ab"); writeSpecHeader(fileOut, false, s); writeBinarySpec(fileOut, s); fclose(fileOut); break; case cms1: case cms2: fileOut = fopen(c, "ab"); writeSpecHeader(fileOut, false, s); writeCompressSpec(fileOut, s); fclose(fileOut); break; case psm: #ifndef _NOSQLITE appendFile(s); #endif break; default: cout << "Cannot append file: unknown or unsupported file type." << endl; break; } } void MSReader::appendFile(char* c, bool text, MSObject& m){ FILE* fileOut; int i; //if a filename isn't specified, check to see if the //MSObject has a filename. if (c == NULL) { return; } else { if (text) fileOut = fopen(c, "at"); else fileOut = fopen(c, "ab"); } //output spectra; for (i = 0; i0 && lPivot>0 && lPivot chgs; if(s.getMsLevel() >1) { chgs = estimateCharge(s); } if(s.sizeZ() == 1) charge = s.atZ(0).z; else if(s.sizeZ() > 1) charge = 0; else { if(chgs.size() == 1) charge = chgs.at(0); else charge = 0; } MSActivation act = s.getActivationMethod(); string actMethod; switch(act){ case mstETD: actMethod="ETD"; break; case mstETDSA: actMethod="ETDSA"; break; case mstCID: actMethod="CID"; break; case mstECD: actMethod="ECD"; break; case mstPQD: actMethod = "PQD"; break; case mstHCD: actMethod = "HCD"; break; case mstNA: default: actMethod="UNKNOWN"; break; } sprintf(zSql, "insert into msScan(runID,startScanNumber,endScanNumber,level,precursorMZ, precursorCharge,retentionTime,fragmentationType,peakCount) " "values (1,%d, %d,%d, %f, %d, %f,'%s', %d)", s.getScanNumber(), s.getScanNumber(true), s.getMsLevel(), s.getMZ(), charge, s.getRTime(), actMethod.c_str(), s.size()); sql_stmt(zSql); zSql[0]='\0'; //get scanID strcpy(zSql, "select MAX(id) from msScan"); int rc,iRow, iCol; char** result; int lastScanID; rc = sqlite3_get_table(db, zSql, &result, &iRow, &iCol, 0); if(rc == SQLITE_OK) { lastScanID=atoi(result[1]); } else { cout<<"Can't execute the SQL statement"< 1) { if(s.sizeZ() > 0) { for(int i=0; i MSReader::estimateCharge(Spectrum& s) { vector chgs; float totalIntensity = s.getTotalIntensity(); float beforeMZIntensity=0; double preMZ = s.getMZ(); for(int i=0; i= 0.95) { chgs.push_back(1); } else { chgs.push_back(2); chgs.push_back(3); } return chgs; } void MSReader::createIndex() { //create index for msScan table const char* stmt1 = "create index idxScanNumber on msScan(startScanNumber)"; sql_stmt(stmt1); } #endif void MSReader::setPrecision(int i, int j){ iIntensityPrecision=i; iMZPrecision=j; } void MSReader::setPrecisionInt(int i){ iIntensityPrecision=i; } void MSReader::setPrecisionMZ(int i){ iMZPrecision=i; } bool MSReader::readFile(const char* c, Spectrum& s, int scNum){ if(c!=NULL) { lastFileFormat = checkFileFormat(c); sCurrentFile = c; sInstrument.clear(); sManufacturer.clear(); sInstrument="unknown"; sManufacturer="unknown"; } switch(lastFileFormat){ case ms1: case ms2: case zs: case uzs: return readMSTFile(c,true,s,scNum); break; case bms1: case bms2: setCompression(false); return readMSTFile(c,false,s,scNum); break; case cms1: case cms2: setCompression(true); return readMSTFile(c,false,s,scNum); break; case mz5: case mzXML: case mzML: case mzXMLgz: case mzMLgz: return readMZPFile(c,s,scNum); break; case mgf: if(scNum>0) cout << "Warning: random-access spectrum reads not allowed with MGF format." << endl; return readMGFFile(c,s); break; case raw: #ifdef _MSC_VER #ifndef _NO_THERMORAW //only read the raw file if the dll was present and loaded. if(cRAW.getStatus()) { cRAW.setMSLevelFilter(&filter); bool b=cRAW.readRawFile(c,s,scNum); if(b && c!=NULL) { cRAW.getInstrument(&sInstrument[0]); cRAW.getManufacturer(&sManufacturer[0]); } return b; } else { cerr << "Could not read Thermo RAW file. The Thermo .dll likely was not loaded or out of date." << endl; return false; } #else cerr << "Thermo RAW file format not supported." << endl; return false; #endif #else cerr << "Thermo RAW file format not supported." << endl; return false; #endif break; case sqlite: case psm: #ifndef _NOSQLITE return readSqlite(c,s,scNum); #else //sqlite support disabled cerr << "SQLite support disabled." << endl; return false; #endif break; case dunno: default: cout << "Unknown file format" << endl; return false; break; } return false; } #ifndef _NOSQLITE bool MSReader::readSqlite(const char* c, Spectrum& s, int scNum) { if(c != NULL) { sqlite3_open(c, &db); if(db == 0) { cout<<"Error open database "< lastScanNumber) { cout<<"Specified scan number doesn't exist!"< lastIndex) return false; sprintf(zSql, "select * from msScan, msScanData where id=%d " "AND id=scanID",curIndex); if(executeSqlStmt(s,zSql)) break; } } return true; } bool MSReader::executeSqlStmt(Spectrum& s, char* zSql) { bool isSameLevel=false; sqlite3_stmt *pStmt; int rc; rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); if( rc!=SQLITE_OK ){ cout<<"can't prepare SQL statement!"<(sqlite3_column_text(pStmt,10))); if(strcmp(actMethod,"CID") == 0) s.setActivationMethod(mstCID); if(strcmp(actMethod, "ETD") == 0) s.setActivationMethod(mstETD); if(strcmp(actMethod, "ECD") == 0) s.setActivationMethod(mstECD); if(strcmp(actMethod, "PQD") == 0) s.setActivationMethod(mstPQD); if(strcmp(actMethod, "HCD") == 0) s.setActivationMethod(mstHCD); if(strcmp(actMethod, "UNKNOWN") == 0) s.setActivationMethod(mstNA); int numPeaks = sqlite3_column_int(pStmt,12); int numBytes1=sqlite3_column_bytes(pStmt,14); unsigned char* comprM = (unsigned char*)sqlite3_column_blob(pStmt,14); int numBytes2=sqlite3_column_bytes(pStmt,15); unsigned char* comprI = (unsigned char*)sqlite3_column_blob(pStmt,15); getUncompressedPeaks(s,numPeaks, numBytes1,comprM, numBytes2,comprI); isSameLevel = true; } } rc = sqlite3_finalize(pStmt); return isSameLevel; } void MSReader::readChargeTable(int scanID, Spectrum& s) { char zSql[8192]; sprintf(zSql, "select charge, mass from MS2FileScanCharge where scanID=%d", scanID); sqlite3_stmt *pStmt; int rc; rc = sqlite3_prepare(db, zSql, -1, &pStmt, 0); if( rc!=SQLITE_OK ){ cout<<"can't prepare SQL statement!"< rampLastScan) return false; //clear any spectrum data s.clear(); MSSpectrumType mslevel; //read scan header if(scNum!=0) { rampIndex=scNum; readHeader(rampFileIn, pScanIndex[rampIndex], &scanHeader); if (scanHeader.acquisitionNum != scNum && scanHeader.acquisitionNum != -1) { cerr << "ERROR: Failure reading scan, index corrupted. Line endings may have changed during transfer." << flush; exit(1); } switch(scanHeader.msLevel){ case 1: mslevel = MS1; break; case 2: mslevel = MS2; break; case 3: mslevel = MS3; break; default: break; } if (find(filter.begin(), filter.end(), mslevel) != filter.end()) bFoundSpec=true; } else /* if scnum == 0 */ { if (rampIndex>rampLastScan) return false; //read next index while (true){ rampIndex++; //reached end of file if (rampIndex>rampLastScan) return false; if (pScanIndex[rampIndex]<0) continue; readHeader(rampFileIn, pScanIndex[rampIndex], &scanHeader); switch (scanHeader.msLevel){ case 1: mslevel = MS1; break; case 2: mslevel = MS2; break; case 3: mslevel = MS3; break; default: break; } if (find(filter.begin(), filter.end(), mslevel) != filter.end()) { bFoundSpec = true; break; } } } //if spectrum does not fit filter parameters bail now. if (!bFoundSpec) return false; //set all sorts of meta information about the spectrum if(scanHeader.centroid) s.setCentroidStatus(1); else s.setCentroidStatus(0); s.setNativeID(scanHeader.idString); s.setMsLevel(scanHeader.msLevel); s.setScanNumber(scanHeader.acquisitionNum); s.setScanNumber(scanHeader.acquisitionNum,true); s.setRTime((float)scanHeader.retentionTime/60.0f); s.setCompensationVoltage(scanHeader.compensationVoltage); s.setIonInjectionTime((float)scanHeader.ionInjectionTime); s.setTIC(scanHeader.totIonCurrent); s.setScanWindow(scanHeader.lowMZ,scanHeader.highMZ); s.setBPI(scanHeader.basePeakIntensity); if(strlen(scanHeader.activationMethod)>1){ if(strcmp(scanHeader.activationMethod,"CID")==0) s.setActivationMethod(mstCID); else if(strcmp(scanHeader.activationMethod,"ECD")==0) s.setActivationMethod(mstECD); else if(strcmp(scanHeader.activationMethod,"ETD")==0) s.setActivationMethod(mstETD); else if(strcmp(scanHeader.activationMethod,"ETDSA")==0) s.setActivationMethod(mstETDSA); else if(strcmp(scanHeader.activationMethod,"ETD+SA") == 0) s.setActivationMethod(mstETDSA); else if(strcmp(scanHeader.activationMethod,"PQD")==0) s.setActivationMethod(mstPQD); else if(strcmp(scanHeader.activationMethod,"HCD")==0) s.setActivationMethod(mstHCD); else s.setActivationMethod(mstNA); } if(scanHeader.msLevel>1) { s.setMZ(scanHeader.precursorMZ,scanHeader.precursorMonoMZ); s.setCharge(scanHeader.precursorCharge); s.setSelWindow(scanHeader.selectionWindowLower,scanHeader.selectionWindowUpper); } else { s.setMZ(0); s.setSelWindow(0,0); } if(scanHeader.precursorCharge>0) { if(scanHeader.precursorMonoMZ>0.0001) s.addZState(scanHeader.precursorCharge,scanHeader.precursorMonoMZ*scanHeader.precursorCharge-(scanHeader.precursorCharge-1)*1.007276466); else s.addZState(scanHeader.precursorCharge,scanHeader.precursorMZ*scanHeader.precursorCharge-(scanHeader.precursorCharge-1)*1.007276466); } for(i=0;i& m){ for(unsigned int i=0; i2 && iIntensityPrecision>0){ if(t[0]=='0'){ fprintf(fileOut,"%.*f 0\n",iMZPrecision,s.at(j).mz); } else if(t[k-1]=='0'){ fprintf(fileOut,"%.*f %.*f\n",iMZPrecision,s.at(j).mz,iIntensityPrecision-1,s.at(j).intensity); } else { fprintf(fileOut,"%.*f %.*f\n",iMZPrecision,s.at(j).mz,iIntensityPrecision,s.at(j).intensity); } } else { fprintf(fileOut,"%.*f %.*f\n",iMZPrecision,s.at(j).mz,iIntensityPrecision,s.at(j).intensity); } } fprintf(fileOut,"END IONS\n"); } } else { fprintf(fileOut,"BEGIN IONS\n"); fprintf(fileOut,"PEPMASS=%.*f\n",6,s.getMZ()); fprintf(fileOut,"RTINSECONDS=%d\n",(int)(s.getRTime()*60)); if(s.sizeZ()==1){ if(s.atZ(0).z==1) fprintf(fileOut,"CHARGE=1+\n"); fprintf(fileOut,"TITLE=%s.%d.%d.%d %d %.4f\n","test",s.getScanNumber(),s.getScanNumber(true),s.atZ(0).z,0,s.getRTime()); } else { fprintf(fileOut,"TITLE=%s.%d.%d.%d %d %.4f\n","test",s.getScanNumber(),s.getScanNumber(true),0,0,s.getRTime()); } for(j=0;j2 && iIntensityPrecision>0){ if(t[0]=='0'){ fprintf(fileOut,"%.*f 0\n",iMZPrecision,s.at(j).mz); } else if(t[k-1]=='0'){ fprintf(fileOut,"%.*f %.*f\n",iMZPrecision,s.at(j).mz,iIntensityPrecision-1,s.at(j).intensity); } else { fprintf(fileOut,"%.*f %.*f\n",iMZPrecision,s.at(j).mz,iIntensityPrecision,s.at(j).intensity); } } else { fprintf(fileOut,"%.*f %.*f\n",iMZPrecision,s.at(j).mz,iIntensityPrecision,s.at(j).intensity); } } fprintf(fileOut,"END IONS\n"); } return; } //Only use this code if not writing MGF file for(j=0;j0) fprintf(fileOut,"I\tRTime\t%.*f\n",4,s.getRTime()); if(s.getBPI()>0) fprintf(fileOut,"I\tBPI\t%.*f\n",2,s.getBPI()); if(s.getBPM()>0) fprintf(fileOut,"I\tBPM\t%.*f\n",4,s.getBPM()); if(s.getConversionA()!=0) fprintf(fileOut,"I\tConvA\t%.*f\n",6,s.getConversionA()); if(s.getConversionB()!=0) fprintf(fileOut,"I\tConvB\t%.*f\n",6,s.getConversionB()); if(s.getConversionC()!=0) fprintf(fileOut,"I\tConvC\t%.*f\n",6,s.getConversionC()); if(s.getConversionD()!=0) fprintf(fileOut,"I\tConvD\t%.*f\n",6,s.getConversionD()); if(s.getConversionE()!=0) fprintf(fileOut,"I\tConvE\t%.*f\n",6,s.getConversionE()); if(s.getConversionI()!=0) fprintf(fileOut,"I\tConvI\t%.*f\n",6,s.getConversionI()); if(s.getTIC()>0) fprintf(fileOut,"I\tTIC\t%.*f\n",2,s.getTIC()); if(s.getIonInjectionTime()>0) fprintf(fileOut,"I\tIIT\t%.*f\n",4,s.getIonInjectionTime()); for(j=0;j=5){ fread(&ms.mzCount,4,1,fileIn); if(ms.mz!=NULL) delete [] ms.mz; ms.mz = new double[ms.mzCount]; for(int i=0;i=2){ fread(&ms.BPI,4,1,fileIn); fread(&ms.BPM,8,1,fileIn); fread(&ms.convA,8,1,fileIn); fread(&ms.convB,8,1,fileIn); if(iVersion>=4){ fread(&ms.convC,8,1,fileIn); fread(&ms.convD,8,1,fileIn); fread(&ms.convE,8,1,fileIn); fread(&ms.convI,8,1,fileIn); } fread(&ms.TIC,8,1,fileIn); fread(&ms.IIT,4,1,fileIn); } fread(&ms.numZStates,4,1,fileIn); if(iVersion>=3) fread(&ms.numEZStates,4,1,fileIn); else ms.numEZStates=0; fread(&ms.numDataPoints,4,1,fileIn); } MSFileFormat MSReader::checkFileFormat(const char *fn){ unsigned int i; char ext[32]; char tmp[1024]; char* c; //extract extension & capitalize c=(char*)strrchr(fn,'.'); if(c==NULL) return dunno; strcpy(ext,c); for(i=0;i Uploaders: Filippo Rusconi Build-Depends: debhelper (>= 9.2), dpkg-dev (>= 1.16.1~), zlib1g-dev (>=1:1.2.8), libhdf5-dev (>=1.8.13), libsqlite3-dev (>= 3.8.6), libexpat1-dev (>= 2.1.0), docbook-to-man Standards-Version: 4.1.1 Section: libs Homepage: https://github.com/mhoopmann/mstoolkit Vcs-Git: https://anonscm.debian.org/git/debichem/packages/libmstoolkit.git Vcs-Browser: https://anonscm.debian.org/git/debichem/packages/libmstoolkit.git Package: libmstoolkit-dev Section: libdevel Architecture: any Depends: ${misc:Depends}, libmstoolkit82 (= ${binary:Version}), libzip-dev (>= 0.11.2), libhdf5-dev (>=1.8.13), libsqlite3-dev (>= 3.8.6), libexpat1-dev (>= 2.1.0) Conflicts: libmstoolkit77 Description: libraries for manipulating mass spectrometry data - dev files The MSToolkit is a light-weight C++ library for reading, writing, and manipulating mass spectrometry data. The MSToolkit is easily linked to virtually any C++ algorithm for simple, fast file reading and analysis. . Supported File Formats: ----------------------- - read-only mzML including internal compression (zlib and numpress) and external compression (.mzML.gz) read-only; - read-only mzXML including internal compression (zlib) and external compression (.mzXML.gz) - read/write mgf, ms1, ms2, bms1, bms2, cms1, cms2 . Simple Interface: ------------------ - Open any file format from a single function call; - Store any spectrum in a simple, comprehensive data structure; - Sequential or random-access file reading. Package: libmstoolkit82 Architecture: any Depends: ${shlibs:Depends}, ${misc:Depends} Conflicts: libmstoolkit77 Description: libraries for manipulating mass spectrometry data - runtime The MSToolkit is a light-weight C++ library for reading, writing, and manipulating mass spectrometry data. The MSToolkit is easily linked to virtually any C++ algorithm for simple, fast file reading and analysis. . Supported File Formats: ----------------------- - read-only mzML including internal compression (zlib and numpress) and external compression (.mzML.gz) read-only; - read-only mzXML including internal compression (zlib) and external compression (.mzXML.gz) - read/write mgf, ms1, ms2, bms1, bms2, cms1, cms2 . Simple Interface: ------------------ - Open any file format from a single function call; - Store any spectrum in a simple, comprehensive data structure; - Sequential or random-access file reading. . This package ships these libraries: . - libmstoolkit; - libmstoolkitlite; libmstoolkit-cleaned-82/debian/libmstoolkit82.lintian-overrides0000644000175000017500000000021213210260002025005 0ustar rusconirusconispelling-error-in-binary usr/lib/libmstoolkit.so.82.0.0 dont don't spelling-error-in-binary usr/lib/libmstoolkitlite.so.82.0.0 dont don't libmstoolkit-cleaned-82/debian/libmstoolkit82.links0000644000175000017500000000023313210260002022472 0ustar rusconirusconiusr/lib/libmstoolkit.so.82.0.0 usr/lib/libmstoolkit.so.82 usr/lib/libmstoolkitlite.so.82.0.0 usr/lib/libmstoolkitlite.so.82 libmstoolkit-cleaned-82/debian/libmstoolkit-dev.install0000644000175000017500000000016013210260002023421 0ustar rusconirusconiinclude/* usr/include/libmstoolkit libmstoolkitlite.a usr/lib libmstoolkit.a usr/liblibmstoolkit-cleaned-82/debian/libmstoolkit82.postinst0000644000175000017500000000012313210260002023233 0ustar rusconirusconi#!/bin/sh set -e if [ "$1" = "configure" ]; then ldconfig fi #DEBHELPER# libmstoolkit-cleaned-82/debian/source/0000755000175000017500000000000013210260002020044 5ustar rusconirusconilibmstoolkit-cleaned-82/debian/source/format0000644000175000017500000000001413210260002021252 0ustar rusconirusconi3.0 (quilt) libmstoolkit-cleaned-82/debian/source/lintian-overrides0000644000175000017500000000003513210260002023423 0ustar rusconirusconidebian-watch-file-is-missing libmstoolkit-cleaned-82/debian/libmstoolkit82.install0000644000175000017500000000012013210260002023013 0ustar rusconirusconilibmstoolkit.so.82.0.0 usr/lib libmstoolkitlite.so.82.0.0 usr/lib libmstoolkit-cleaned-82/debian/libmstoolkit-dev.links0000644000175000017500000000032513210260002023076 0ustar rusconirusconiusr/lib/libmstoolkit.so.82.0.0 usr/lib/libmstoolkit.so usr/lib/libmstoolkitlite.so.82.0.0 usr/lib/libmstoolkitlite.so usr/share/man/man3/libmstoolkit.3.gz usr/share/man/man3/libmstoolkit-dev.3.gz libmstoolkit-cleaned-82/debian/copyright0000644000175000017500000004027213210260002020504 0ustar rusconirusconiFormat: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/ Upstream-Name: libmstoolkit Source: https://github.com/mhoopmann/mstoolkit License: Apache . Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at . http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. License: Artistic . Copyright (c) 2000-2006, The Perl Foundation. . Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. . Preamble . This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. . You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. . Definitions . "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. . "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. . "You" and "your" means any person who would like to copy, distribute, or modify the Package. . "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. . "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. . "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. . "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. . "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. . "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. . "Source" form means the source code, documentation source, and configuration files for the Package. . "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. . Permission for Use and Modification Without Distribution . (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. . Permissions for Redistribution of the Standard Version . (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. . (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. . Distribution of Modified Versions of the Package as Source . (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: . (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. . (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under . (i) the Original License or . (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. . Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source . (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. . (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package . (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. . (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. . Items That are Not Considered Part of a Modified Version . (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions . (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. . (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. . (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. . (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. . (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS' AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: BSD-3-Clause . Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: . 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. . 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. . 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. . THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. License: MIT/X . Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: . The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. . THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. License: GPL-3+ This package is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. . This package is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. . You should have received a copy of the GNU General Public License along with this program. If not, see . On Debian systems, the complete text of the GNU General Public License version 3 can be found in "/usr/share/common-licenses/GPL-3". License: Zlib . This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. . Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: . 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. . 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. . 3. This notice may not be removed or altered from any source distribution. . Jean-loup Gailly Mark Adler jloup@gzip.org madler@alumni.caltech.edu . The data format used by the zlib library is described by RFCs (Request for Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt (zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format). Files: * Copyright: 2014 Michael R. Hoopmann, Michael J. MacCoss License: BSD-3-Clause Files: src/mzParser/saxmzxmlhandler.cpp Copyright: 2002 Pedrioli Patrick Institute for Systems Biology 2008 Ronald Beavis 2010 Mike Hoopmann Institute for Systems Biology License: Artistic files: src/mzParser/saxmzmlhandler.cpp Copyright: 2002 Pedrioli Patrick Institute for Systems Biology 2005 Fredrik Levander, Brendan MacLean, Patrick Lacasse 2008 Ronald Beavis 2009 Fredrik Levander 2010 Mike Hoopmann Institute for Systems Biology License: Artistic Files: src/mzParser/saxhandler.cpp Copyright: 2003-2004 Ronald C Beavis License: Artistic Files: src/mzParser/BasicSpectrum.cpp Copyright: 2010-2012, Mike Hoopmann Institute for Systems Biology License: Apache Files: include/MSNumpress.hpp src/mzParser/MSNumpress.cpp Copyright: 2013 Johan Teleman License: Apache Files: include/ascii.h include/iasciitab.h include/expat.h include/expat_external.h include/latin1tab.h include/utf8tab.h include/xmlrole.h include/xmltok.h include/xmltok_impl.h Copyright: 1998, 1999, 2000 Thai Open Source Software Center Ltd and Clark Cooper 2001, 2002, 2003, 2004, 2005, 2006 Expat maintainers License: MIT/X Files: include/zlib.h Copyright: 1995-2010 Jean-loup Gailly and Mark Adler License: Zlib Files: include/deflate.h Copyright: 1995-2002 Jean-loup Gailly and Mark Adler 1995-2010 Jean-loup Gailly License: Zlib Files: include/gzguts.h Copyright: 2004, 2005, 2010 Mark Adler License: Zlib Files: include/inffast.h Copyright: 1995-2003, 2010 Mark Adler License: Zlib Files: include/inftrees.h Copyright: 1995-2005, 2010 Mark Adler License: Zlib Files: include/inflate.h Copyright: 1995-2009 Mark Adler License: Zlib Files: include/zconf.h include/zutil.h Copyright: 1995-2010 Jean-loup Gailly License: Zlib Files: src/mzParser/Czran.cpp Copyright: 2005 Mark Adler License: Zlib Files: include/winconfig.h Copyright: 2000 Clark Cooper License: MIT/X Files: include/sqlite3.h Copyright: public domain License: public-domain . The author disclaims copyright to this source code. In place of a legal notice, here is a blessing: . May you do good and not evil. May you find forgiveness for yourself and forgive others. May you share freely, never taking more than you give. Files: debian/* Copyright: 2014 Filippo Rusconi License: GPL-3+ libmstoolkit-cleaned-82/debian/changelog0000644000175000017500000000322713210260002020422 0ustar rusconirusconilibmstoolkit (82-1) unstable; urgency=medium * New upstream version. Fixes problems I reported on the github site. -- Filippo Rusconi Thu, 14 Sep 2017 17:01:11 +0200 libmstoolkit (77.0.0-1) unstable; urgency=medium * New upstream version; * Fix debian/copyright to reflect source modifications in upstream and to fix lintian-detected glitches; debian/control & debian copyright: change the projet home website url. * Better cleaning up of the source tarball (libs not required, .svn and other cruft); * Still closing the ITP bug (Closes: #763747). -- Filippo Rusconi Tue, 13 Jan 2015 10:25:07 +0100 libmstoolkit (73~svn-3) UNRELEASED; urgency=medium * remove the shlibs.local file. * fix problem with debian/copyright (license ZLib was not detected properly, with a lintian warning) and remove the corresponding lintian override. * Still closing the ITP bug (Closes: #763747); -- Filippo Rusconi Tue, 04 Nov 2014 16:24:42 +0100 libmstoolkit (73~svn-2) unstable; urgency=medium * Fixes to the debian/copyright file so as to document some shipped include files; * Add source lintian overrides file. * Initial packaging (Closes: #763747); -- Filippo Rusconi Tue, 04 Nov 2014 11:27:08 +0100 libmstoolkit (73~svn-1) unstable; urgency=low * Initial packaging (Closes: #763747); * The main modification is related to the Makefile which has been changed so as to produce first-class citizen UNIX/LINUX/POSIX shared object libraries. -- Filippo Rusconi Thu, 02 Oct 2014 12:40:10 +0200 libmstoolkit-cleaned-82/debian/patches/0000755000175000017500000000000013210260002020173 5ustar rusconirusconilibmstoolkit-cleaned-82/debian/patches/series0000644000175000017500000000001713210260002021406 0ustar rusconirusconimakefile.patch libmstoolkit-cleaned-82/debian/patches/makefile.patch0000644000175000017500000001302613210260002022773 0ustar rusconirusconidiff --git a/Makefile b/Makefile index 8f8f087..12724ff 100644 --- a/Makefile +++ b/Makefile @@ -1,79 +1,68 @@ #Set your paths here. -ZLIB_PATH = ./src/zlib-1.2.8 MZPARSER_PATH = ./src/mzParser -EXPAT_PATH = ./src/expat-2.2.0 -SQLITE_PATH = ./src/sqlite-3.7.7.1 MST_PATH = ./src/MSToolkit HEADER_PATH = ./include MZPARSER = mzp.MSNumpress.o mzp.mzp_base64.o mzp.BasicSpectrum.o mzp.mzParser.o mzp.RAMPface.o mzp.saxhandler.o mzp.saxmzmlhandler.o \ mzp.saxmzxmlhandler.o mzp.Czran.o mzp.mz5handler.o mzp.mzpMz5Config.o mzp.mzpMz5Structs.o mzp.BasicChromatogram.o mzp.PWIZface.o + MZPARSERLITE = mzp.MSNumpress.o mzp.mzp_base64_lite.o mzp.BasicSpectrum_lite.o mzp.mzParser_lite.o mzp.RAMPface_lite.o mzp.saxhandler_lite.o mzp.saxmzmlhandler_lite.o \ mzp.saxmzxmlhandler_lite.o mzp.Czran_lite.o mzp.mz5handler_lite.o mzp.mzpMz5Config_lite.o mzp.mzpMz5Structs_lite.o mzp.BasicChromatogram_lite.o mzp.PWIZface_lite.o -EXPAT = xmlparse.o xmlrole.o xmltok.o -ZLIB = adler32.o compress.o crc32.o deflate.o inffast.o inflate.o infback.o inftrees.o trees.o uncompr.o zutil.o + MSTOOLKIT = Spectrum.o MSObject.o mzMLWriter.o pepXMLWriter.o + READER = MSReader.o + READERLITE = MSReaderLite.o -SQLITE = sqlite3.o CC = g++ GCC = gcc NOSQLITE = -D_NOSQLITE -CFLAGS = -O3 -static -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H -LIBS = -lm -lpthread -ldl - -all: $(ZLIB) $(MZPARSER) $(MZPARSERLITE) $(MSTOOLKIT) $(READER) $(READERLITE) $(EXPAT) $(SQLITE) - ar rcs libmstoolkitlite.a $(ZLIB) $(EXPAT) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) - ar rcs libmstoolkit.a $(ZLIB) $(EXPAT) $(MZPARSER) $(MSTOOLKIT) $(READER) $(SQLITE) -# $(CC) $(CFLAGS) MSTDemo.cpp -L. -lmstoolkitlite -o MSTDemo - $(CC) $(CFLAGS) -I./include MSSingleScan/MSSingleScan.cpp -L. -lmstoolkitlite -o msSingleScan -# $(CC) $(CFLAGS) MSConvertFile.cpp -L. -lmstoolkitlite -o MSConvertFile - -lite: $(ZLIB) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) $(EXPAT) - ar rcs libmstoolkitlite.a $(ZLIB) $(EXPAT) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) - $(CC) $(CFLAGS) -I./include MSSingleScan/MSSingleScan.cpp -L. -lmstoolkitlite -o msSingleScan - -clean: - rm -f *.o libmstoolkitlite.a libmstoolkit.a msSingleScan +SOVER = 82 +RELVER = $(SOVER).0.0 -# zLib objects +LIBS = -lm -lpthread -ldl -lz -lsqlite3 -lexpat +LIB_PATH := -L./ -adler32.o : $(ZLIB_PATH)/adler32.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/adler32.c -c +CLEAN_LIBS = libmstoolkitlite.a libmstoolkitlite.so libmstoolkitlite.so.$(SOVER)* libmstoolkit.a libmstoolkit.so libmstoolkit.so.$(SOVER)* -compress.o : $(ZLIB_PATH)/compress.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/compress.c -c +# Original version +# CFLAGS = -O3 -static -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H -crc32.o : $(ZLIB_PATH)/crc32.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/crc32.c -c +.PHONY: objects +objects: CFLAGS += -O3 -static -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H +objects: $(MZPARSER) $(MZPARSERLITE) $(MSTOOLKIT) $(READER) $(READERLITE) -deflate.o : $(ZLIB_PATH)/deflate.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/deflate.c -c +arlib: CFLAGS += -O3 -static -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H +arlib: clean_objects objects -inffast.o : $(ZLIB_PATH)/inffast.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/inffast.c -c + ar rcs libmstoolkitlite.a $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) + ar rcs libmstoolkit.a $(MZPARSER) $(MSTOOLKIT) $(READER) -inflate.o : $(ZLIB_PATH)/inflate.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/inflate.c -c +solib: CFLAGS += -shared -fPIC -g -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H +solib: clean_objects objects -infback.o : $(ZLIB_PATH)/infback.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/infback.c -c + $(CC) $(CFLAGS) -o libmstoolkitlite.so.$(RELVER) -Wl,-z,relro -Wl,-soname,libmstoolkitlite.so.$(SOVER) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) $(LIB_PATH) $(LIBS) + ln -sf libmstoolkitlite.so.$(RELVER) libmstoolkitlite.so.$(SOVER) + ln -sf libmstoolkitlite.so.$(SOVER) libmstoolkitlite.so -inftrees.o : $(ZLIB_PATH)/inftrees.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/inftrees.c -c + $(CC) $(CFLAGS) -o libmstoolkit.so.$(RELVER) -Wl,-z,relro -Wl,-soname,libmstoolkit.so.$(SOVER) $(MZPARSER) $(MSTOOLKIT) $(READER) $(LIB_PATH) $(LIBS) + ln -sf libmstoolkit.so.$(RELVER) libmstoolkit.so.$(SOVER) + ln -sf libmstoolkit.so.$(SOVER) libmstoolkit.so -trees.o : $(ZLIB_PATH)/trees.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/trees.c -c +all: CFLAGS += -shared -fPIC -g -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H +all: solib + $(CC) $(CFLAGS) -I. -I./include MSSingleScan/MSSingleScan.cpp -L. -lmstoolkitlite -o msSingleScan -uncompr.o : $(ZLIB_PATH)/uncompr.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/uncompr.c -c +clean_objects: + rm -f *.o msSingleScan -zutil.o : $(ZLIB_PATH)/zutil.c - $(GCC) $(CFLAGS) $(ZLIB_PATH)/zutil.c -c +clean_libs: + rm -f $(CLEAN_LIBS) +clean: clean_libs clean_objects #mzParser objects @@ -85,23 +74,6 @@ mzp.%_lite.o : $(MZPARSER_PATH)/%.cpp $(CC) $(CFLAGS) $< -c -o $@ -#expat objects -xmlparse.o : $(EXPAT_PATH)/xmlparse.c - $(GCC) $(CFLAGS) $(EXPAT_PATH)/xmlparse.c -c -xmlrole.o : $(EXPAT_PATH)/xmlrole.c - $(GCC) $(CFLAGS) $(EXPAT_PATH)/xmlrole.c -c -xmltok.o : $(EXPAT_PATH)/xmltok.c - $(GCC) $(CFLAGS) $(EXPAT_PATH)/xmltok.c -c - - - -#SQLite object -sqlite3.o : $(SQLITE_PATH)/sqlite3.c - $(GCC) $(CFLAGS) $(SQLITE_PATH)/sqlite3.c -c - - - - #MSToolkit objects Spectrum.o : $(MST_PATH)/Spectrum.cpp libmstoolkit-cleaned-82/debian/libmstoolkit82.manpages0000644000175000017500000000002713210260002023146 0ustar rusconirusconidebian/libmstoolkit.3 libmstoolkit-cleaned-82/debian/libmstoolkit-dev.dirs0000644000175000017500000000005513210260002022717 0ustar rusconirusconiusr/lib usr/include usr/include/libmstoolkit libmstoolkit-cleaned-82/debian/rules0000755000175000017500000000215013210260002017622 0ustar rusconirusconi#!/usr/bin/make -f # -*- makefile -*- # Uncomment this to turn on verbose mode. export DH_VERBOSE=1 DEBIAN_DIR = $(CURDIR)/debian BUILD_DIR = $(CURDIR) LIB_PACKAGE = libmstoolkit82 VERSION = 82.0.0 LIB_VERSION = $(VERSION) # This is the only method that actually worked... # Combined with the CFLAGS += in the Makefile. CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS) CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS) CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS) LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS) %: dh $@ override_dh_auto_clean: make clean rm -f libmstoolkit.3 manpage: docbook-to-man debian/libmstoolkit.sgml > debian/libmstoolkit.3 override_dh_auto_build: manpage make solib make arlib override_dh_makeshlibs: mkdir -p $(DEBIAN_DIR)/$(LIB_PACKAGE)/DEBIAN dpkg-gensymbols -p$(LIB_PACKAGE) \ -v$(LIB_VERSION) \ -c2 -d \ -e$(BUILD_DIR)/libmstoolkitlite.so.$(LIB_VERSION) \ -e$(BUILD_DIR)/libmstoolkit.so.$(LIB_VERSION) \ -O$(DEBIAN_DIR)/$(LIB_PACKAGE)/DEBIAN/symbols dh_makeshlibs -a override_dh_strip: dh_strip --dbg-package=$(LIB_PACKAGE)-dbg -a libmstoolkit-cleaned-82/debian/libmstoolkit.sgml0000644000175000017500000001101513210260002022142 0ustar rusconirusconi manpage.1'. You may view the manual page with: `docbook-to-man manpage.sgml | nroff -man | less'. A typical entry in a Makefile or Makefile.am is: manpage.1: manpage.sgml docbook-to-man $< > $@ The docbook-to-man binary is found in the docbook-to-man package. Please remember that if you create the nroff version in one of the debian/rules file targets (such as build), you will need to include docbook-to-man in your Build-Depends control field. --> Filippo"> Rusconi"> October 2nd, 2014"> 3"> lopippo@debian.org"> LIBMSTOOLKIT"> Debian"> GNU"> GPL"> ]>
&dhemail;
&dhfirstname; &dhsurname; 2014 &dhusername; &dhdate;
&dhucpackage; &dhsection; &dhpackage; The &dhpackage package ships light-weight C++ libraries for reading, writing, and manipulating mass spectrometry data. The &softname libraries are easily linked to virtually any C++ algorithm for simple, fast file reading and analysis. &dhpackage; DESCRIPTION This manual page documents briefly the &dhpackage; source package. This manual page was written for the &debian; distribution because the original program does not have a manual page. The &dhpackage; source package is used to create the following packages: &dhpackage;&LIBVERSION; runtime binary package; &dhpackage;&LIBVERSION;-dbg; runtime binary package (debugging symbols); &dhpackage;-dev development binary package. The &dhpackage;&LIBVERSION; runtime binary package ships the following libraries libmstoolkit.so libmstoolkitlite.so The &dhpackage;-dev development binary package ships the following files: Include files, shipped in /usr/include/&dhpackage; AUTHOR This manual page was written by &dhusername; <&dhemail;> for the &debian; system (and may be used by others). Permission is granted to copy, distribute and/or modify this document under the terms of the &gnu; General Public License, Version 3 or any later version published by the Free Software Foundation. On Debian systems, the complete text of the GNU General Public License can be found in /usr/share/common-licenses/GPL-3.
libmstoolkit-cleaned-82/debian/libmstoolkit82.dirs0000644000175000017500000000001013210260002022304 0ustar rusconirusconiusr/lib libmstoolkit-cleaned-82/debian/source.lintian-overrides0000644000175000017500000000016113210260002023422 0ustar rusconirusconidebian-watch-file-is-missing wildcard-matches-nothing-in-dep5-copyright include/iascii.h (paragraph at line 133) libmstoolkit-cleaned-82/Makefile0000644000175000017500000001000113210260002016752 0ustar rusconirusconi#Set your paths here. ZLIB_PATH = ./src/zlib-1.2.8 MZPARSER_PATH = ./src/mzParser EXPAT_PATH = ./src/expat-2.2.0 SQLITE_PATH = ./src/sqlite-3.7.7.1 MST_PATH = ./src/MSToolkit HEADER_PATH = ./include MZPARSER = mzp.MSNumpress.o mzp.mzp_base64.o mzp.BasicSpectrum.o mzp.mzParser.o mzp.RAMPface.o mzp.saxhandler.o mzp.saxmzmlhandler.o \ mzp.saxmzxmlhandler.o mzp.Czran.o mzp.mz5handler.o mzp.mzpMz5Config.o mzp.mzpMz5Structs.o mzp.BasicChromatogram.o mzp.PWIZface.o MZPARSERLITE = mzp.MSNumpress.o mzp.mzp_base64_lite.o mzp.BasicSpectrum_lite.o mzp.mzParser_lite.o mzp.RAMPface_lite.o mzp.saxhandler_lite.o mzp.saxmzmlhandler_lite.o \ mzp.saxmzxmlhandler_lite.o mzp.Czran_lite.o mzp.mz5handler_lite.o mzp.mzpMz5Config_lite.o mzp.mzpMz5Structs_lite.o mzp.BasicChromatogram_lite.o mzp.PWIZface_lite.o EXPAT = xmlparse.o xmlrole.o xmltok.o ZLIB = adler32.o compress.o crc32.o deflate.o inffast.o inflate.o infback.o inftrees.o trees.o uncompr.o zutil.o MSTOOLKIT = Spectrum.o MSObject.o mzMLWriter.o pepXMLWriter.o READER = MSReader.o READERLITE = MSReaderLite.o SQLITE = sqlite3.o CC = g++ GCC = gcc NOSQLITE = -D_NOSQLITE CFLAGS = -O3 -static -I. -I$(HEADER_PATH) -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -DGCC -DHAVE_EXPAT_CONFIG_H LIBS = -lm -lpthread -ldl all: $(ZLIB) $(MZPARSER) $(MZPARSERLITE) $(MSTOOLKIT) $(READER) $(READERLITE) $(EXPAT) $(SQLITE) ar rcs libmstoolkitlite.a $(ZLIB) $(EXPAT) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) ar rcs libmstoolkit.a $(ZLIB) $(EXPAT) $(MZPARSER) $(MSTOOLKIT) $(READER) $(SQLITE) # $(CC) $(CFLAGS) MSTDemo.cpp -L. -lmstoolkitlite -o MSTDemo $(CC) $(CFLAGS) -I./include MSSingleScan/MSSingleScan.cpp -L. -lmstoolkitlite -o msSingleScan # $(CC) $(CFLAGS) MSConvertFile.cpp -L. -lmstoolkitlite -o MSConvertFile lite: $(ZLIB) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) $(EXPAT) ar rcs libmstoolkitlite.a $(ZLIB) $(EXPAT) $(MZPARSERLITE) $(MSTOOLKIT) $(READERLITE) $(CC) $(CFLAGS) -I./include MSSingleScan/MSSingleScan.cpp -L. -lmstoolkitlite -o msSingleScan clean: rm -f *.o libmstoolkitlite.a libmstoolkit.a msSingleScan # zLib objects adler32.o : $(ZLIB_PATH)/adler32.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/adler32.c -c compress.o : $(ZLIB_PATH)/compress.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/compress.c -c crc32.o : $(ZLIB_PATH)/crc32.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/crc32.c -c deflate.o : $(ZLIB_PATH)/deflate.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/deflate.c -c inffast.o : $(ZLIB_PATH)/inffast.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/inffast.c -c inflate.o : $(ZLIB_PATH)/inflate.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/inflate.c -c infback.o : $(ZLIB_PATH)/infback.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/infback.c -c inftrees.o : $(ZLIB_PATH)/inftrees.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/inftrees.c -c trees.o : $(ZLIB_PATH)/trees.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/trees.c -c uncompr.o : $(ZLIB_PATH)/uncompr.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/uncompr.c -c zutil.o : $(ZLIB_PATH)/zutil.c $(GCC) $(CFLAGS) $(ZLIB_PATH)/zutil.c -c #mzParser objects mzp.%.o : $(MZPARSER_PATH)/%.cpp $(CC) $(CFLAGS) $(MZ5) $< -c -o $@ #mzParserLite objects mzp.%_lite.o : $(MZPARSER_PATH)/%.cpp $(CC) $(CFLAGS) $< -c -o $@ #expat objects xmlparse.o : $(EXPAT_PATH)/xmlparse.c $(GCC) $(CFLAGS) $(EXPAT_PATH)/xmlparse.c -c xmlrole.o : $(EXPAT_PATH)/xmlrole.c $(GCC) $(CFLAGS) $(EXPAT_PATH)/xmlrole.c -c xmltok.o : $(EXPAT_PATH)/xmltok.c $(GCC) $(CFLAGS) $(EXPAT_PATH)/xmltok.c -c #SQLite object sqlite3.o : $(SQLITE_PATH)/sqlite3.c $(GCC) $(CFLAGS) $(SQLITE_PATH)/sqlite3.c -c #MSToolkit objects Spectrum.o : $(MST_PATH)/Spectrum.cpp $(CC) $(CFLAGS) $(MST_PATH)/Spectrum.cpp -c MSReader.o : $(MST_PATH)/MSReader.cpp $(CC) $(CFLAGS) $(MZ5) $(MST_PATH)/MSReader.cpp -c MSReaderLite.o : $(MST_PATH)/MSReader.cpp $(CC) $(CFLAGS) $(NOSQLITE) $(MST_PATH)/MSReader.cpp -c -o MSReaderLite.o MSObject.o : $(MST_PATH)/MSObject.cpp $(CC) $(CFLAGS) $(MST_PATH)/MSObject.cpp -c mzMLWriter.o : $(MST_PATH)/mzMLWriter.cpp $(CC) $(CFLAGS) $(MST_PATH)/mzMLWriter.cpp -c pepXMLWriter.o : $(MST_PATH)/pepXMLWriter.cpp $(CC) $(CFLAGS) $(MST_PATH)/pepXMLWriter.cpp -c libmstoolkit-cleaned-82/MSSingleScan/0000755000175000017500000000000013245065703017633 5ustar rusconirusconilibmstoolkit-cleaned-82/MSSingleScan/MSSingleScan.cpp0000644000175000017500000000340013210260002022577 0ustar rusconirusconi#include #include #include #include "MSToolkitTypes.h" #include "MSReader.h" #include "MSObject.h" #include "Spectrum.h" using namespace std; using namespace MSToolkit; int main(int argc, char *argv[]){ //Here are all the variable we are going to need MSReader r; Spectrum s; int j; if(argc==1){ printf("DESCRIPTION: Reads an MS/MS spectrum from any MSToolkit supported file type and outputs to screen in MS2 format.\n\n"); printf("USAGE: MSSingleScan [scan number] [file]\n"); exit(0); } r.setFilter(MS1); r.addFilter(MS2); r.addFilter(MSX); r.addFilter(SRM); char nativeID[256]; r.readFile(argv[2],s,atoi(argv[1])); if(s.getScanNumber()==0) exit(-1); char szNativeID[128]; if (s.getNativeID(szNativeID, 128)) printf("success: scan %d nativeID: %s\n", s.getScanNumber(), szNativeID); else printf("failure: scan %d\n", s.getScanNumber()); printf("size: %d\n", s.sizeMZ()); s.getNativeID(nativeID, 256); printf("%s\n",nativeID); printf("S\t%d\t%d",s.getScanNumber(),s.getScanNumber()); for(j=0;j0) printf("I\tRTime\t%.*f\n",4,s.getRTime()); //printf("I\tConvA\t%.6lf\n",s.getConversionA()); //printf("I\tConvB\t%.6lf\n",s.getConversionB()); //printf("I\tConvC\t%.6lf\n",s.getConversionC()); //printf("I\tConvD\t%.6lf\n",s.getConversionD()); //printf("I\tConvE\t%.6lf\n",s.getConversionE()); //printf("I\tConvI\t%.6lf\n",s.getConversionI()); for(j=0;j