Matrix Science header

ms_spectral_lib_file.hpp

00001 /*
00002 ##############################################################################
00003 # File: ms_nist_msp.hpp                                                      #
00004 # Mascot Parser toolkit                                                      #
00005 # Encapsulates spectral library files (e.g. msp, sptext)                     #
00006 #                                                                            #
00007 ##############################################################################
00008 # COPYRIGHT NOTICE                                                           #
00009 # Copyright 2015 Matrix Science Limited  All Rights Reserved.                #
00010 #                                                                            #
00011 ##############################################################################
00012 #    $Source: /vol/cvsroot/parser/inc/ms_spectral_lib_file.hpp,v $
00013 #    $Author: davidc $ 
00014 #      $Date: 2017/05/04 13:34:05 $ 
00015 #  $Revision: 1.19 $
00016 ##############################################################################
00017 */
00018 
00019 #ifndef MS_SPECTRAL_LIB_FILE
00020 #define MS_SPECTRAL_LIB_FILE
00021 
00022 #ifdef _WIN32
00023 #pragma warning(disable:4251)   // Don't want all classes to be exported
00024 #pragma warning(disable:4786)   // Debug symbols too long
00025 #   ifndef _MATRIX_USE_STATIC_LIB
00026 #       ifdef MS_MASCOTRESFILE_EXPORTS
00027 #           define MS_MASCOTRESFILE_API __declspec(dllexport)
00028 #       else
00029 #           define MS_MASCOTRESFILE_API __declspec(dllimport)
00030 #       endif
00031 #   else
00032 #       define MS_MASCOTRESFILE_API
00033 #   endif
00034 #else
00035 #   define MS_MASCOTRESFILE_API
00036 #endif
00037 
00038 // Includes from the standard template library
00039 
00040 #include <map>
00041 #include <set>
00042 #include <string>
00043 
00044 
00045 namespace matrix_science {
00046   
00052 
00053 
00080     class MS_MASCOTRESFILE_API ms_spectral_lib_file : public ms_errors
00081     {
00082     public:
00084         ms_spectral_lib_file(const char * fileName, const char * regexForAccession, const char * cdbFileName = 0);
00085         
00087         ~ms_spectral_lib_file();
00088         
00090         int getNumEntries() const;
00091         
00093         int getNumResidues() const;
00094 
00096         std::vector<int> findEntries(const char * sequence, const char * checksum = 0, const char * accession = 0, const char * mods=0) const;
00097         
00099         ms_spectral_lib_entry getEntryFromNumber(const int number) const;
00100 
00102         std::vector<std::string> getEntryFromNumberAsText(const int number) const;
00103 
00104 
00106         std::string getAccessionFromNumber(const int number) const;
00107 
00109         std::string getChecksumFromNumber(const int number) const;
00110 
00112         std::string getSequenceFromNumber(const int number) const;
00113 
00115         std::string getModsFromNumber(const int number) const;
00116 
00118         double getPrecursorMZFromNumber(const int number) const;
00119 
00121         int getPrecursorChargeFromNumber(const int number) const;
00122 
00124         std::vector<std::string> getAllMods() const;
00125 
00127         ms_spectral_lib::FILE_FORMAT getFormat() const;
00128 
00130         bool saveAs(const char * fileName, 
00131                     const bool   replaceProteinName  = true, 
00132                     ms_spectral_lib::FILE_FORMAT fileFormat = ms_spectral_lib::FORMAT_NIST_MSP,
00133                     const int    startNumber = 1,
00134                     const int    endNumber = -1,
00135                     const ms_spectral_lib_entry::WHAT_TO_ANNOTATE whatToAnnotate = ms_spectral_lib_entry::ANNOTATE_REPLACE_QUESTION_MARKS,
00136                     const double annotateTol = 0.6,
00137                     const char * annotateTolu = "Da",
00138                     const ms_umod_configfile * unimod = 0) const;
00139 
00141         std::string getStatsInformation() const;
00142 
00144         std::string getFileName() const;
00145 
00147         long getQmatch(double minMz, double maxMz) const;
00148 
00149     private:
00150         //Do not copy this object
00151         ms_spectral_lib_file(const ms_spectral_lib_file & src);
00152         ms_spectral_lib_file& operator=(const ms_spectral_lib_file & right);
00153 
00154         struct sequentialIndex_t {
00155             std::string accession;
00156             std::string checksum;
00157             std::string sequence;
00158             std::string mods;
00159             double      precursorMZ;
00160             int         precursorCharge;
00161             OFFSET64_T  fileOffset;
00162         };
00163         bool readFile(int recordNumber) const;
00164         void getline(std::string & str) const;
00165         ms_errs::err getEntryAsText(const int number, std::vector<std::string> & lines, std::string & errorMsg) const;
00166 
00167         void saveIndexes(const  ms_spectral_lib_entry & msp, 
00168                          const  OFFSET64_T          fileOffset);
00169         OFFSET64_T getFileOffsetFromId(int number) const;
00170         const char * getSpectrumDelimiter() const;
00171 
00172         // the following are always valid - with or without a cdb file
00173                 std::string  fileName_;
00174         mutable int          numEntries_;  // May be less than the total in the file if it's being read on demand
00175         mutable int          numResidues_; // May be less than the total in the file if it's being read on demand
00176                 ms_parserule parseRule_;
00177         mutable bool         wholeFileRead_;
00178                 FILE       * ifs_;
00179         mutable ms_spectral_lib::FILE_FORMAT  fileFormat_;
00180 
00181         // the following are valid when creating or using the cdb file
00182         ms_tinycdb * cdb_;
00183 
00184         // the following are only valid when no cdb specified *or* when *first creating* the cdb file
00185         mutable OFFSET64_T offsetToNextRecord_;
00186         typedef std::map<std::string, std::vector<int> > strLookup_t;  // e.g. sequence => vector of spectra
00187         std::vector<strLookup_t> lookup_;
00188         std::vector<sequentialIndex_t> sequentialIndex_;
00189         typedef std::map<std::string, std::size_t> modMap_t;
00190         mutable modMap_t modsMap_;
00191 
00192         typedef std::multiset<double> precursors_t;
00193         mutable precursors_t precursors_;
00194 
00195     }; // class ms_spectral_lib_file
00196  // end of tools_group
00198 } // namespace matrix_science
00199 
00200 #endif // MS_SPECTRAL_LIB_FILE
00201 
00202 /*------------------------------- End of File -------------------------------*/
Copyright © 2016 Matrix Science Ltd.  All Rights Reserved. Generated on Fri Jun 2 2017 01:44:51