Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_ms2quantitation.hpp
1/*
2##############################################################################
3# file: ms_ms2quantitation.hpp #
4# 'msparser' toolkit #
5# Quantitation for Reporter and Multiplex protocols #
6##############################################################################
7# COPYRIGHT NOTICE #
8# Copyright 1998-2013 Matrix Science Limited All Rights Reserved. #
9# #
10##############################################################################
11# $Author: patricke@matrixscience.com $ #
12# $Date: 2024-04-18 14:13:15 +0100 $ #
13# $Revision: 89fdd131b46df750b15607fe93a5737171311c08 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $ #
14# $NoKeywords:: $ #
15##############################################################################
16*/
17
18#ifndef MS_MS2QUANTITATION_HPP
19#define MS_MS2QUANTITATION_HPP
20
21
22// Includes from the standard template library
23#include <string>
24#include <vector>
25#include <list>
26#include <utility>
27
28namespace msparser_internal {
29 class ms_ms2ratiocalculator;
30 class ms_XMLElement;
31 class ms_XMLHelper;
32}
33
34namespace matrix_science {
35 class ms_quant_ratio;
36 class ms_quantitation;
37 class ms_peptidesummary;
38 class ms_peptide_quant_key;
39 class ms_peptide_quant_key_vector;
40 class ms_quant_helper;
41 class ms_protein;
42 class ms_mascotresfilebase;
43
50
126 class MS_MASCOTRESFILE_API ms_ms2quantitation: public ms_quantitation
127 {
128 friend class ms_customquantitation;
129 public:
131 explicit ms_ms2quantitation(const ms_peptidesummary& pepsum);
132
134 ms_ms2quantitation(const ms_peptidesummary& pepsum, const ms_quant_method &qm);
135
137 virtual ~ms_ms2quantitation();
138
139 virtual bool hasPeptideRatio(const ms_peptide_quant_key &key, const std::string &ratioName) const;
140 virtual ms_peptide_quant_ratio getPeptideRatio(const ms_peptide_quant_key &key, const std::string &ratioName) const;
141
142 virtual void setPeptideRatioIncluded(const ms_peptide_quant_key &key, const std::string &ratioName);
143 virtual void setPeptideRatioExcluded(const ms_peptide_quant_key &key, const std::string &ratioName);
144 virtual bool isPeptideRatioExcluded(const ms_peptide_quant_key &key, const std::string &ratioName) const;
145
146 virtual void setProteinRatioType(const char *value);
147
148 virtual void setQuantOutliers(const ms_quant_outliers *);
149
150 virtual ms_protein_quant_ratio getProteinRatio(const std::string &accession, int dbIdx, const std::string &ratioName) const;
151
152 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;
153
155 const ms_peptidesummary & getPeptideSummary() const;
156
158 bool getAllProteinRatios(const std::string & accession, const int dbIdx,
159 const std::string & ratioName,
160 std::vector<double> & ratios,
161 std::vector<std::vector<bool> > & flags,
162 ms_peptide_quant_key_vector & keys) const;
163
165 std::vector<double> getAllProteinRatios(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
166
168 std::vector<std::vector<bool> > getAllProteinRatioFlags(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
169
171 void setQuantNormalisation(const ms_quant_normalisation *norm);
172
174 bool hasPeptideRatioNormalisation() const;
175
177 void normalisePeptideRatios();
178
180 std::vector<double> getComponentIntensities(const ms_peptide_quant_key &key, bool raw = false) const;
181
183 void includeProteinPeptideRatioKeys(const std::string &accession, int dbIdx, const std::string &ratioName, const ms_peptide_quant_key_vector &includeKeys);
184
186 void excludeProteinPeptideRatioKeys(const std::string &accession, int dbIdx, const std::string &ratioName, const ms_peptide_quant_key_vector &excludeKeys);
187
189 std::vector<std::string> getReportRatioNamesInFile(unsigned int fileNum) const;
190
192 const ms_quant_ratio* getReportRatioFromFile(unsigned int fileNum, const std::string &ratioName) const;
193
195 void setReportRatioInFile(unsigned int fileNum, const std::string &ratioName, const ms_quant_ratio &ratioDef);
196
198 void removeReportRatioInFile(unsigned int fileNum, const std::string &ratioName);
199
200
202 std::vector<std::string> getCombinedReportRatioNames() const;
203
205 const ms_quant_ratio* getCombinedReportRatio(const std::string &ratioName) const;
206
208 void removeCombinedReportRatio(const std::string &ratioName);
209
211 void setCombinedReportRatio(const std::string &ratioName, const ms_quant_ratio &ratioDef);
212
214 double getIntensityNormalisationBase(const std::string &componentName) const;
215
217 void setIntensityNormalisationBase(const std::string &componentName, double b);
218
220 void removeIntensityNormalisationBase(const std::string &componentName);
221
223 void removeIntensityNormalisationBases();
224
226 bool hasIntensityNormalisation() const;
227
229 void normaliseIntensities();
230
232 bool loadCdbFile(const char* path);
233
235 bool loadCdbFiles(const std::vector<std::string> & cdbFiles);
236
238 bool saveXmlFile(const std::string & xmlFilename, bool completeReport);
239
241 bool saveCdbFile(const std::string & cdbFilename);
242
244 using ms_quantitation::countDistinctPeptides;
245
246#ifndef SWIG
248 virtual int countDistinctPeptides(const std::vector<ms_peptide_quant_key> & activeKeys) const;
249#endif
250 protected:
251 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;
252
253
254 private:
255 // No copying.
256 ms_ms2quantitation(const ms_ms2quantitation &copyFrom);
257 ms_ms2quantitation& operator=(const ms_ms2quantitation &right);
258
259 enum SUPPORTED_PROTEIN_RATIO_TYPE {
260 PROTEIN_RATIO_TYPE_MEDIAN = 0,
261 PROTEIN_RATIO_TYPE_AVERAGE,
262 PROTEIN_RATIO_TYPE_WEIGHTED
263 };
264
265 int proteinRatioType_;
266
267 const ms_peptidesummary &pepsum_;
268 const unsigned int numResfiles_;
269
270 std::vector<std::string> componentNames_;
271 std::vector<double>::size_type numComponents_;
272
273 std::vector<double> componentIntensityNormalisationBase_;
274 bool normaliseComponentIntensities_;
275
276 bool renormaliseOnDemand_;
277
278 std::map<ms_peptide_quant_key, bool> peptideQuantKeyQualityTest_;
279 bool testPeptideQuantKeyUniqueness_;
280 bool testedAllKeysForNormalisation_;
281 ms_quant_helper *quantHelper_;
282
283 typedef std::map< std::string, std::set<ms_peptide_quant_key> > ratio_name_to_peptide_quant_key_exclusion_t;
284 std::vector< ratio_name_to_peptide_quant_key_exclusion_t > isPeptideQuantKeyExcluded_;
285
286 bool useCanonicalQPvalues_;
287
288 typedef std::pair<int, int> qp_t;
289 qp_t keyToCanonicalQP(const ms_peptide_quant_key &key) const;
290 int rankToCanonicalRank(int p) const;
291
292 std::vector<double> loadIntensities(const ms_peptide_quant_key &key) const;
293 std::vector<double> loadIntensities(int q, int p) const;
294
295 static const unsigned int FILENUM_LOWER_BOUND;
296 static const unsigned int FILENUM_UPPER_BOUND;
297
298 typedef std::pair<std::string, unsigned int> ratio_name_and_file_index_t;
299 typedef std::set<ratio_name_and_file_index_t> ratio_name_in_files_t;
300 ratio_name_in_files_t ratioNamesInFiles_;
301
302 typedef std::list<ms_quant_ratio> quant_ratio_list_t;
303 std::vector<quant_ratio_list_t> fileToQuantRatioList_;
304
305 std::vector<msparser_internal::ms_ms2ratiocalculator> ratioCalculators_;
306
307 typedef std::map<std::string, std::set<ms_peptide_quant_key> > sequence_to_peptide_quant_key_t;
308 sequence_to_peptide_quant_key_t sequencePeptideQuantKeys_;
309 std::map<ms_peptide_quant_key, std::string> peptideQuantKeySequence_;
310
311 typedef std::pair<protein_key_t, std::string> protein_ratio_key_t;
312 typedef std::map<protein_ratio_key_t, ms_peptide_quant_key_vector> user_prot_to_pept_quantkey_override_t;
313 // used to record protein match-peptide keys which have been user excluded
314 user_prot_to_pept_quantkey_override_t userExcludedKeys_;
315 // used to record protein match-peptide keys which have been user included
316 user_prot_to_pept_quantkey_override_t userIncludedKeys_;
317
318 void fixRatioSourceRemovalInQM(const std::string &ratioName);
319 void setRatioContentInQM(const std::string &ratioName, unsigned int fileNum);
320
321 bool calculateUnnormalisedPeptideRatio(const ms_peptide_quant_key &key, const std::string &ratioName, int *fileNum, bool *isInfinite, double *value) const;
322
323 void setQuantNormalisationOnly(const ms_quant_normalisation *norm);
324
325 double calculatePeptideNormalisationBase(const std::string &ratioName) const;
326 std::map<std::string, double> calculatePeptideNormalisationBases() const;
327 std::list<ms_peptide_quant_key> selectKeysForNormalisation(const ms_quant_normalisation *norm);
328 void selectAllKeysForNormalisation(std::map<int, std::pair<int, ms_peptide_quant_key> > &query_keys);
329 std::vector<double> normalisedComponentIntensities(const std::vector<double> &intensities) const;
330
331 bool initialiseReportRatios();
332
333 bool initialiseQuantHelper();
334
335 void setReportRatioInFileOnly(unsigned int fileNum, const std::string &ratioName, const ms_quant_ratio &ratioDef);
336 void setReportRatioInFileOnly(unsigned int fileNum, const std::string &ratioName, const ms_quant_ratio &ratioDef, std::string &oldName, std::string &newName);
337
338 bool removeReportRatioInFileOnly(unsigned int fileNum, const std::string &ratioName);
339
340 std::map<ms_peptide_quant_key, bool>::const_iterator testPeptideQuantKeyQuality(int q, int p, const ms_peptide_quant_key &key);
341 void initialiseProteinPeptideMapping(const std::string &accession, int dbIdx);
342
343 bool savePeptideGroupingToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const matrix_science::ms_protein * protein, int hitId, int memberNumber) const;
344
345 bool savePeptideMatchXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & root, const ms_peptide_quant_key & key, long matchid) const;
346
347 bool saveEmptyMatrixXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & parent, const std::string matrixName) const;
348
349 bool savePeptideRatioToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const ms_peptide_quant_ratio ratio, const ms_protein * protein = NULL) const;
350
351 bool saveProteinHitRatiosToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const ms_protein * protein, int q, int p) const;
352
354 bool isPeptideRatioUserExcluded(const ms_protein * protein, const std::string & ratioName, const ms_peptide_quant_key & key) const;
355
357 bool isPeptideRatioUserIncluded(const ms_protein * protein, const std::string & ratioName, const ms_peptide_quant_key & key) const;
358
360 static void saveResfileDetailsToCdb(ms_tinycdb & cdbFile, const ms_mascotresfilebase& resfile);
361
363 static bool readCdbCounterData(ms_tinycdb & cdbFile, unsigned & count);
364
365 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);
366 }; // end of quantitation_group
368} // matrix_science namespace
369
370#endif // MS_MS2QUANTITATION_HPP
371
372/*------------------------------- End of File -------------------------------*/
Peptide and protein quantitation using custom peptide ratios and protein-peptide mappings.
Definition: ms_customquantitation.hpp:119
Abstract base class of ms_mascotresfile_dat and ms_mascotresfile_msr.
Definition: ms_mascotresfilebase.hpp:72
Peptide and protein quantitation in a Reporter or Multiplex Mascot results file.
Definition: ms_ms2quantitation.hpp:127
A vector of peptide quant keys.
Definition: ms_peptide_quant_key_vector.hpp:47
Feature key identifying a peptide ratio.
Definition: ms_peptide_quant_key.hpp:69
Peptide abundance in one component relative to another in a quantitation experiment.
Definition: ms_peptide_quant_ratio.hpp:61
Use this class to get peptide summary results.
Definition: ms_peptidesummary.hpp:51
Protein abundance in one component relative to another in a quantitation experiment,...
Definition: ms_protein_quant_ratio.hpp:72
This class encapsulates a protein in the mascot results file.
Definition: ms_protein.hpp:57
Helper routines for peptide quantitation.
Definition: ms_quant_helper.hpp:50
An object of this class represent a single quantitation method from quantitation.xml.
Definition: ms_quant_method.hpp:51
An object of this class represent a single normalisation element in quantitation.xml.
Definition: ms_quant_normalisation.hpp:42
An object of this class represent a single OUTLIERS element in quantitation.xml.
Definition: ms_quant_outliers.hpp:44
Represents the ratioType type for the report_ratio element in quantitation.xml.
Definition: ms_quant_ratio.hpp:41
Base class for peptide and protein quantitation.
Definition: ms_quantitation.hpp:138
Wrapper for the public domain tinycdb package http://www.corpit.ru/mjt/tinycdb.html by Michael Tokare...
Definition: ms_tinycdb.hpp:124