00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef MS_MS2QUANTITATION_HPP
00019 #define MS_MS2QUANTITATION_HPP
00020
00021
00022
00023 #include <string>
00024 #include <vector>
00025 #include <list>
00026 #include <utility>
00027
00028 namespace msparser_internal {
00029 class ms_ms2ratiocalculator;
00030 class ms_XMLElement;
00031 class ms_XMLHelper;
00032 }
00033
00034 namespace matrix_science {
00035 class ms_quant_ratio;
00036 class ms_quantitation;
00037 class ms_peptidesummary;
00038 class ms_peptide_quant_key;
00039 class ms_peptide_quant_key_vector;
00040 class ms_quant_helper;
00041 class ms_protein;
00042
00048
00049
00125 class MS_MASCOTRESFILE_API ms_ms2quantitation: public ms_quantitation
00126 {
00127 friend class ms_customquantitation;
00128 public:
00130 explicit ms_ms2quantitation(const ms_peptidesummary& pepsum);
00131
00133 ms_ms2quantitation(const ms_peptidesummary& pepsum, const ms_quant_method &qm);
00134
00136 virtual ~ms_ms2quantitation();
00137
00138 virtual bool hasPeptideRatio(const ms_peptide_quant_key &key, const std::string &ratioName) const;
00139 virtual ms_peptide_quant_ratio getPeptideRatio(const ms_peptide_quant_key &key, const std::string &ratioName) const;
00140
00141 virtual void setPeptideRatioIncluded(const ms_peptide_quant_key &key, const std::string &ratioName);
00142 virtual void setPeptideRatioExcluded(const ms_peptide_quant_key &key, const std::string &ratioName);
00143 virtual bool isPeptideRatioExcluded(const ms_peptide_quant_key &key, const std::string &ratioName) const;
00144
00145 virtual void setProteinRatioType(const char *value);
00146
00147 virtual void setQuantOutliers(const ms_quant_outliers *);
00148
00149 virtual ms_protein_quant_ratio getProteinRatio(const std::string &accession, int dbIdx, const std::string &ratioName) const;
00150
00151 virtual ms_protein_quant_ratio getProteinRatio(const std::string &accession, int dbIdx, const std::string &ratioName, const ms_peptide_quant_key_vector &includeKeys, const ms_peptide_quant_key_vector &excludeKeys) const;
00152
00154 bool getAllProteinRatios(const std::string & accession, const int dbIdx,
00155 const std::string & ratioName,
00156 std::vector<double> & ratios,
00157 std::vector<std::vector<bool> > & flags,
00158 ms_peptide_quant_key_vector & keys) const;
00159
00161 std::vector<double> getAllProteinRatios(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
00162
00164 std::vector<std::vector<bool> > getAllProteinRatioFlags(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
00165
00167 void setQuantNormalisation(const ms_quant_normalisation *norm);
00168
00170 bool hasPeptideRatioNormalisation() const;
00171
00173 void normalisePeptideRatios();
00174
00176 std::vector<double> getComponentIntensities(const ms_peptide_quant_key &key, bool raw = false) const;
00177
00179 void includeProteinPeptideRatioKeys(const std::string &accession, int dbIdx, const std::string &ratioName, const ms_peptide_quant_key_vector &includeKeys);
00180
00182 void excludeProteinPeptideRatioKeys(const std::string &accession, int dbIdx, const std::string &ratioName, const ms_peptide_quant_key_vector &excludeKeys);
00183
00185 std::vector<std::string> getReportRatioNamesInFile(unsigned int fileNum) const;
00186
00188 const ms_quant_ratio* getReportRatioFromFile(unsigned int fileNum, const std::string &ratioName) const;
00189
00191 void setReportRatioInFile(unsigned int fileNum, const std::string &ratioName, const ms_quant_ratio &ratioDef);
00192
00194 void removeReportRatioInFile(unsigned int fileNum, const std::string &ratioName);
00195
00196
00198 std::vector<std::string> getCombinedReportRatioNames() const;
00199
00201 const ms_quant_ratio* getCombinedReportRatio(const std::string &ratioName) const;
00202
00204 void removeCombinedReportRatio(const std::string &ratioName);
00205
00207 void setCombinedReportRatio(const std::string &ratioName, const ms_quant_ratio &ratioDef);
00208
00210 double getIntensityNormalisationBase(const std::string &componentName) const;
00211
00213 void setIntensityNormalisationBase(const std::string &componentName, double b);
00214
00216 void removeIntensityNormalisationBase(const std::string &componentName);
00217
00219 void removeIntensityNormalisationBases();
00220
00222 bool hasIntensityNormalisation() const;
00223
00225 void normaliseIntensities();
00226
00228 bool loadCdbFile(const char* path);
00229
00231 bool loadCdbFiles(const std::vector<std::string> & cdbFiles);
00232
00234 bool saveXmlFile(const std::string & xmlFilename, bool completeReport);
00235
00237 bool saveCdbFile(const std::string & cdbFilename);
00238
00240 using ms_quantitation::countDistinctPeptides;
00241
00242 #ifndef SWIG
00243
00244 virtual int countDistinctPeptides(const std::vector<ms_peptide_quant_key> & activeKeys) const;
00245 #endif
00246 protected:
00247 virtual void getSortedFinitePeptideRatioValues(const std::string &ratioName, const std::set<ms_peptide_quant_key> &keys, const std::set<ms_peptide_quant_key> &includeKeys, const std::set<ms_peptide_quant_key> &excludeKEys, std::vector<double> &values, std::vector<double> &weights, std::vector<ms_peptide_quant_key> &activeKeys, std::map<ms_peptide_quant_key, int> &inactiveKeys) const;
00248
00249
00250 private:
00251
00252 ms_ms2quantitation(const ms_ms2quantitation ©From);
00253 ms_ms2quantitation& operator=(const ms_ms2quantitation &right);
00254
00255 enum SUPPORTED_PROTEIN_RATIO_TYPE {
00256 PROTEIN_RATIO_TYPE_MEDIAN = 0,
00257 PROTEIN_RATIO_TYPE_AVERAGE,
00258 PROTEIN_RATIO_TYPE_WEIGHTED
00259 };
00260
00261 int proteinRatioType_;
00262
00263 const ms_peptidesummary &pepsum_;
00264 const unsigned int numResfiles_;
00265
00266 std::vector<std::string> componentNames_;
00267 std::vector<double>::size_type numComponents_;
00268
00269 std::vector<double> componentIntensityNormalisationBase_;
00270 bool normaliseComponentIntensities_;
00271
00272 bool renormaliseOnDemand_;
00273
00274 std::map<ms_peptide_quant_key, bool> peptideQuantKeyQualityTest_;
00275 bool testPeptideQuantKeyUniqueness_;
00276 bool testedAllKeysForNormalisation_;
00277 ms_quant_helper *quantHelper_;
00278
00279 typedef std::map< std::string, std::set<ms_peptide_quant_key> > ratio_name_to_peptide_quant_key_exclusion_t;
00280 std::vector< ratio_name_to_peptide_quant_key_exclusion_t > isPeptideQuantKeyExcluded_;
00281
00282 bool useCanonicalQPvalues_;
00283
00284 typedef std::pair<int, int> qp_t;
00285 qp_t keyToCanonicalQP(const ms_peptide_quant_key &key) const;
00286 int rankToCanonicalRank(int p) const;
00287
00288 std::vector<double> loadIntensities(const ms_peptide_quant_key &key) const;
00289 std::vector<double> loadIntensities(int q, int p) const;
00290
00291 static const unsigned int FILENUM_LOWER_BOUND;
00292 static const unsigned int FILENUM_UPPER_BOUND;
00293
00294 typedef std::pair<std::string, unsigned int> ratio_name_and_file_index_t;
00295 typedef std::set<ratio_name_and_file_index_t> ratio_name_in_files_t;
00296 ratio_name_in_files_t ratioNamesInFiles_;
00297
00298 typedef std::list<ms_quant_ratio> quant_ratio_list_t;
00299 std::vector<quant_ratio_list_t> fileToQuantRatioList_;
00300
00301 std::vector<msparser_internal::ms_ms2ratiocalculator> ratioCalculators_;
00302
00303 typedef std::map<std::string, std::set<ms_peptide_quant_key> > sequence_to_peptide_quant_key_t;
00304 sequence_to_peptide_quant_key_t sequencePeptideQuantKeys_;
00305 std::map<ms_peptide_quant_key, std::string> peptideQuantKeySequence_;
00306
00307 typedef std::pair<protein_key_t, std::string> protein_ratio_key_t;
00308 typedef std::map<protein_ratio_key_t, ms_peptide_quant_key_vector> user_prot_to_pept_quantkey_override_t;
00309
00310 user_prot_to_pept_quantkey_override_t userExcludedKeys_;
00311
00312 user_prot_to_pept_quantkey_override_t userIncludedKeys_;
00313
00314 void fixRatioSourceRemovalInQM(const std::string &ratioName);
00315 void setRatioContentInQM(const std::string &ratioName, unsigned int fileNum);
00316
00317 bool calculateUnnormalisedPeptideRatio(const ms_peptide_quant_key &key, const std::string &ratioName, int *fileNum, bool *isInfinite, double *value) const;
00318
00319 void setQuantNormalisationOnly(const ms_quant_normalisation *norm);
00320
00321 double calculatePeptideNormalisationBase(const std::string &ratioName) const;
00322 std::map<std::string, double> calculatePeptideNormalisationBases() const;
00323 std::list<ms_peptide_quant_key> selectKeysForNormalisation(const ms_quant_normalisation *norm);
00324 void selectAllKeysForNormalisation(std::map<int, std::pair<int, ms_peptide_quant_key> > &query_keys);
00325 std::vector<double> normalisedComponentIntensities(const std::vector<double> &intensities) const;
00326
00327 bool initialiseReportRatios();
00328
00329 bool initialiseQuantHelper();
00330
00331 void setReportRatioInFileOnly(unsigned int fileNum, const std::string &ratioName, const ms_quant_ratio &ratioDef);
00332 void setReportRatioInFileOnly(unsigned int fileNum, const std::string &ratioName, const ms_quant_ratio &ratioDef, std::string &oldName, std::string &newName);
00333
00334 bool removeReportRatioInFileOnly(unsigned int fileNum, const std::string &ratioName);
00335
00336 std::map<ms_peptide_quant_key, bool>::const_iterator testPeptideQuantKeyQuality(int q, int p, const ms_peptide_quant_key &key);
00337 void initialiseProteinPeptideMapping(const std::string &accession, int dbIdx);
00338
00339 bool savePeptideGroupingToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const matrix_science::ms_protein * protein, int hitId, int memberNumber) const;
00340
00341 bool savePeptideMatchXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & root, const ms_peptide_quant_key & key, long matchid) const;
00342
00343 bool saveEmptyMatrixXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & parent, const std::string matrixName) const;
00344
00345 bool savePeptideRatioToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const ms_peptide_quant_ratio ratio, const ms_protein * protein = NULL) const;
00346
00347 bool saveProteinHitRatiosToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const ms_protein * protein, int q, int p) const;
00348
00350 bool isPeptideRatioUserExcluded(const ms_protein * protein, const std::string & ratioName, const ms_peptide_quant_key & key) const;
00351
00353 bool isPeptideRatioUserIncluded(const ms_protein * protein, const std::string & ratioName, const ms_peptide_quant_key & key) const;
00354
00356 static void saveResfileDetailsToCdb(ms_tinycdb & cdbFile, const ms_mascotresfile & resfile);
00357
00359 static bool readCdbCounterData(ms_tinycdb & cdbFile, unsigned & count);
00360
00361 static bool readUserRatioStream(ms_tinycdb & cdbFile, const unsigned & index, std::string & accession, int & db, std::string & ratio, ms_peptide_quant_key_vector & included, ms_peptide_quant_key_vector & excluded);
00362 };
00364 }
00365
00366 #endif // MS_MS2QUANTITATION_HPP
00367
00368