Matrix Science Mascot Parser toolkit
 
Loading...
Searching...
No Matches
ms_ms1quantitation.hpp
1/*
2##############################################################################
3# file: ms_ms1quantitation.hpp
4# 'msparser' toolkit
5# An extracted ion chromatogram
6##############################################################################
7# COPYRIGHT NOTICE
8# Copyright 1998-2014 Matrix Science Limited All Rights Reserved.
9#
10##############################################################################
11 * @(#)$Source: parser/inc/ms_ms1quantitation.hpp $
12 * @(#)$Revision: 89fdd131b46df750b15607fe93a5737171311c08 | MSPARSER_REL_3_0_0-2024-09-24-0-g93ebaeb4f4 $
13 * @(#)$Date: 2024-04-18 14:13:15 +0100 $
14##############################################################################
15 */
16
17#ifndef MS_MS1QUANTITATION_HPP
18#define MS_MS1QUANTITATION_HPP
19
20
21
22
23// Includes from the standard template library
24#include <string>
25#include <vector>
26
27namespace msparser_internal
28{
29 class ms_XMLElement;
30 class ms_XMLHelper;
31}
32
33namespace matrix_science
34{
35 //=========================================================================
41 class ms_msquant1_mod_format;
42 class ms_cache_stream;
43 class ms_progress_info;
44 class ms_mascotresults_params;
45
47
90 class MS_MASCOTRESFILE_API ms_ms1quantitation :
92 {
93 public:
96 MERGE_QUANT_QUERY_NUMBERS_ARE_FROM_MERGED_RESULTS = 0x0001,
97 MERGE_QUANT_MERGE_COMPONENTS_INTO_QUANT_MATCH = 0x0002,
98 MERGE_QUANT_USE_COMPONENT_FILE_INDEX_TO_FIND_XIC = 0x0004,
99 MERGE_QUANT_APPLY_THRESHOLDS_AFTER_MERGE = 0x0008,
100
101 MERGE_QUANT_DEFAULT_PRECURSOR_METHOD = MERGE_QUANT_APPLY_THRESHOLDS_AFTER_MERGE,
102 MERGE_QUANT_DEFAULT_REPLICATE_METHOD = (MERGE_QUANT_QUERY_NUMBERS_ARE_FROM_MERGED_RESULTS | MERGE_QUANT_MERGE_COMPONENTS_INTO_QUANT_MATCH | MERGE_QUANT_USE_COMPONENT_FILE_INDEX_TO_FIND_XIC)
103 };
104
106
116 BUGFIX_12409 = 12409
117 };
118
120 ms_ms1quantitation(const ms_peptidesummary & summary, const ms_quant_method & method);
121
123
125 int getNumPeptideStatuses() const;
127 ms_ms1quant_peptide_status getPeptideStatus(int index) const;
128
130 int getNumHits() const;
132 ms_protein * getHit(int index1) const;
133
135 int getNumProteinFamilies() const;
136
138 int getNumMatches() const;
140 ms_ms1quant_match getMatch(int index) const;
142 ms_ms1quant_match getMatch(const ms_peptide_quant_key & key) const;
143
144 void clearMatches();
145
147 void addMatchStatus(
151
153 void addMatchPeptide(
156 const matrix_science::ms_quant_component & component,
157 const std::string & matchBelongsToComponent,
159
161 matrix_science::ms_ms1quant_match addMatchInferred(
162 const ms_ms1quant_match & siblingMatch,
163 int newCharge);
164
166 void removeMatch(matrix_science::ms_peptide_quant_key matchKey);
167
169 bool findPeptideStatus(int query, int rank, ms_ms1quant_peptide_status * peptideStatus) const;
170
172 bool findMatch(matrix_science::ms_peptide_quant_key matchKey, ms_ms1quant_match * match) const;
173
175 const ms_ms1quant_average_results * getAverageResults() const;
176
178 bool loadXmlFile(const std::string & filename, const std::string & xmlSchemaPath);
179
181 bool saveXmlFile(const std::string & xmlFilename, bool completeReport, bool saveTimeAlignmentData = false);
182
184 bool loadCdbFile(const std::string & cdbFilename, const std::string & cacheFilename, bool revalidateQualityThresholds=true);
185
187 bool saveCdbFile(const std::string & cdbFilename, const std::string & cacheFilename, bool createEmptyMissingComponents = false);
188
190 const ms_peptidesummary & getPeptideSummary() const;
191
193 const ms_peptidesummary & getSummary() const;
194
196 std::string getReadableVarMods(std::string varmods);
197
199 std::string getReadableVarModsConcise(std::string varmods);
200
202 std::string getLabelFree(std::string peptideStr, std::string varMods, std::string summedMods, const matrix_science::ms_quant_component & comp) const;
203
205 int getNumMatchesForHit(int hitId, int memberNumber) const;
207 ms_ms1quant_match getMatchForHit(int index, int hitId, int memberNumber) const;
208
210 int getNumGroups() const;
211
212 int getDatasourceForGroup(int groupIndex1) const;
213
215 int getNumMatchesForGroup(int groupIndex1) const;
216
217 ms_ms1quant_match getMatchForGroup(int matchIndex1, int groupIndex1) const;
218
220 virtual ms_protein_quant_ratio getProteinRatio(const std::string &accession, int dbIdx, const std::string &ratioName) const;
221
223 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;
224
226 std::vector<double> getAllProteinRatios(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
227
229 std::vector<std::vector<bool> > getAllProteinRatioFlags(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
230
232 std::vector<std::vector<double> > getAllProteinRatioValues(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
233
235 std::vector<std::string> getAllProteinRatioPepSeqs(const std::string & accession, const int dbIdx, const std::string & ratioName) const;
236
238 bool isAverageProtocol() const;
240 void setAverageReferenceProtein(const char *accession, int dbIdx, bool isReferenceUserSelected);
242 void setAverageNumPeptides(unsigned int num = 3);
244 void setAverageSelection(const char * value);
245#ifndef SWIG
247 bool getAveragePeptideIntensity(
248 const std::string &accession,
249 int dbIdx,
250 double * averageIntensity, // average of grouped intensities (each peptide ratio group summed and then average of those sums)
251 int * sampleSize, // number of different peptide groups available (after grouping by selection type)
252 ms_peptide_quant_key_vector * includeKeys, // peptide ratios selected (may be greater then sampleSize)
253 ms_peptide_quant_key_vector * excludeKeys // peptide ratios not selected
254 ) const;
255#else // SWIG Multiple return values
256 bool getAveragePeptideIntensity(
257 const std::string & accession,
258 int dbIdx,
259 double * OUTPUT,
260 int * OUTPUT,
261 ms_peptide_quant_key_vector * includeKeys,
262 ms_peptide_quant_key_vector * excludeKeys
263 ) const;
264#endif
266 std::vector<int> getQuantitationDatasources() const;
267
268 int getNumMatchedPeptideStatuses() const;
269
271 void initGroupChargeStates(
272 std::set<int> * calc_chargestates,
273 int iGroup1,
274 int minCharge,
275 int maxCharge);
276
277 void calc_complete();
278
280 bool isDataCached(MS1QUANT_BUGFIX_NUM bugNum) const;
281
283 const matrix_science::ms_ms1quant_time_align & getTimeAlignmentData() const;
284
285#ifndef SWIG
287 matrix_science::ms_ms1quant_time_align & getTimeAlignmentData();
288
289 void setTimeAlignmentData(matrix_science::ms_ms1quant_time_align & alignmentData);
290#endif
291
293 using ms_quantitation::countDistinctPeptides;
294
295#ifndef SWIG
297 virtual int countDistinctPeptides(const std::vector<ms_peptide_quant_key> & activeKeys) const;
298#endif
300 static matrix_science::ms_ms1quantitation * openQuantitationCdbResults(
301 const matrix_science::ms_peptidesummary & summary,
302 const matrix_science::ms_quant_method & method,
303 const std::string & cdbFilename,
304 const std::string & cacheFilename,
305 const matrix_science::ms_quant_method * originalMethod = 0);
306
308 static matrix_science::ms_ms1quantitation * openQuantitationXmlResults(
309 const matrix_science::ms_peptidesummary & summary,
310 const matrix_science::ms_quant_method & method,
311 const std::string & filename,
312 const std::string & xmlSchemaPath="",
313 const matrix_science::ms_quant_method * originalMethod = 0);
314
316 bool mergeQuantitationResults(const std::vector<std::string> & cdbFilenames,
317 const std::vector<std::string> & cacheFilenames,
318 const MERGE_QUANT_RESULTS_FLAGS flags,
319 const matrix_science::ms_quant_method * originalMethod = 0);
320
322 bool mergeQuantitationResults(const std::vector<std::string> & xmlFilenames,
323 const MERGE_QUANT_RESULTS_FLAGS flags,
324 const std::string & xmlSchemaPath="",
325 const matrix_science::ms_quant_method * originalMethod = 0);
326#ifndef SWIG
328 static bool readResultCounters(const std::string & cdbFile,
329 int &numMatches, int &numHits, int &numPepGrp, int &numPeptideComponents);
330#else // SWIG Multiple return values
331 static bool readResultCounters(const std::string & cdbFile,
332 int &OUTPUT, int &OUTPUT, int &OUTPUT, int &OUTPUT);
333#endif
334
335 protected:
336
337 private:
338 //Do not copy this object
340 ms_ms1quantitation& operator=(const ms_ms1quantitation & right);
341
342 void initialiseAfterLoad();
343 // normalisation
344 std::list<ms_ms1quant_match> selectMatchesForNormalisation(const ms_quant_normalisation *norm);
345 double calculatePeptideNormalisationBase(const std::string &ratioName) const;
347 void normalisePeptideRatios();
348 // end normalisation
349
350 bool saveHitToCdb(matrix_science::ms_tinycdb & cdbFile, const matrix_science::ms_protein * protein, int streamNumber) const;
351 bool saveHitToStream(matrix_science::ms_cache_stream & stream, const matrix_science::ms_protein * protein) const;
352 bool saveHitToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const matrix_science::ms_protein * protein, int hitId, int memberNumber);
353
354 void getProteinRatioOverrideKeys(
357 const std::string & ratioName,
358 int hitId,
359 int memberNumber) const;
360
361 ms_protein_quant_ratio getProteinAverageIntensityRatio(
362 const std::string &accession,
363 int dbIdx
364 ) const;
365
366 void rematchInferredMatches(const bool allowMassTimeMatches); // populates inferredMatchSource_
367 void updatePeptideStatus(matrix_science::ms_ms1quant_peptide_status status, const matrix_science::ms_quant_quality * quality);
368 void updateMatches(const matrix_science::ms_quant_method * method); // removes any ms1 quant matches which don't have any valid ms2 peptide matches
369 void updateMatchPeptideEvidence(); // updates the ms2 matches associated (or not associated) with an ms1 quant match
370 bool updateProteinMatches(); // ensures only valid anchor proteins are returned
371
372 // Can the new settings be handled my ms_ms1quantitation, or do additional values need to be calculated by MsQuantLib
373 static bool canHandleSettings(const matrix_science::ms_quant_method * originalMethod, const matrix_science::ms_quant_method * newMethod, matrix_science::ms_ms1quantitation * quantResults);
374
375 std::map<matrix_science::ms_peptide_quant_key, ms_ms1quant_peptide_status_body> getMatchedPeptideStatuses() const;
376
378 std::vector<ms_ms1quant_match> getMatchesForHit(int hitId, int memberNumber) const;
379
381 bool saveGroupToXml(msparser_internal::ms_XMLHelper & helper, msparser_internal::ms_XMLElement & element, const matrix_science::ms_protein * protein, int hitId, int memberNumber) const;
382 void reorderMatchesAfterMerge();
383
385 bool mergeCdbFiles(const std::vector<std::string> & cdbFilenames,
386 const std::vector<std::string> & cacheFilenames,
387 const std::vector<std::string> & resultFilenames,
389 const std::string & cacheDirectory,
390 const MERGE_QUANT_RESULTS_FLAGS flags);
391
393 bool mergeXmlFiles(
394 const std::vector<std::string> & xmlFilenames,
395 const std::vector<std::string> & resultFilenames,
396 const std::string & cacheDirectory,
397 const std::string & xmlSchemaPath,
398 const MERGE_QUANT_RESULTS_FLAGS flags);
399
401 void getKeyStrings(const int dataSourceId, const std::string & peptideStr, const std::string & labelFreeVarMods, const int chargeState,
402 std::string & groupKey, std::string & uniqueKey) const;
403
404 const ms_peptidesummary & peptideSummary_;
405 int nextMatchId_;
406 std::map<ms_peptide_quant_key, ms_ms1quant_match> matches_; // matchId -> match
407 std::map<std::pair<int, int>, ms_ms1quant_peptide_status> peptideStatuses_; // [query, rank] -> status
408 std::map<std::string, ms_peptide_quant_key> matchKeys_; // peptideStr:datasourceId:labelFree:charge -> matchId
409 std::map<std::string, std::set<ms_peptide_quant_key> > matchGroups_; // "datasource:peptideStr:labelFree" -> matchId[]
410 std::vector<std::string> matchGroupNames_; // names in matchGroups in order of addition (to match with processing order in Distiller)
411
412
413 // matchId -> matchId of the 'source/sibling' identified match - always the most intense sibling if there is more than one possibility
414 std::map<ms_peptide_quant_key, ms_peptide_quant_key> inferredMatchSource_;
415
416 typedef std::pair<int, int> Hitkey; // hitId, memberNumber (0 if not a family)
417 std::vector<Hitkey> hitkeys_;
418
419 bool hasAverageResults_;
420 ms_ms1quant_average_results averageResults_;
421
422 matrix_science::ms_cache_file cacheFile_;
423
424 mutable const ms_msquant1_mod_format * modFormat_;
425
426 std::vector<matrix_science::ms_cache_file *> multifileCacheFiles_;
427
428 std::string bugsfixed_;
429
430 ms_ms1quant_time_align timeAlignment_;
431 };
432 // end of quantitation_group
434 //=========================================================================
435
436} // matrix_science namespace
437
438
439#endif // MS_MS1QUANTITATION_HPP
440
441/*------------------------------- End of File -------------------------------*/
Peptide and protein quantitation using custom peptide ratios and protein-peptide mappings.
Definition: ms_customquantitation.hpp:119
Class which provides constructor parameters for either ms_peptidesummary or ms_proteinsummary.
Definition: ms_mascotresults_params.hpp:32
Results specific to an 'average' type quantitation method.
Definition: ms_ms1quant_average_results.hpp:42
A peptide that has been matched, in quantitation, to a protein hit.
Definition: ms_ms1quant_match.hpp:47
An individual peptide's quantitation status.
Definition: ms_ms1quant_peptide_status.hpp:41
peptideStatus
Status codes from fitting peptides.
Definition: ms_ms1quant_peptide_status.hpp:48
Time alignment between multiple runs (raw files) is performed in Mascot Distiller for label free quan...
Definition: ms_ms1quant_time_align.hpp:47
The result of quantitation calculations applied to peptide summary.
Definition: ms_ms1quantitation.hpp:92
MERGE_QUANT_RESULTS_FLAGS
Enum for mergeQuantitationResults()
Definition: ms_ms1quantitation.hpp:95
MS1QUANT_BUGFIX_NUM
bugNum values for isDataCached().
Definition: ms_ms1quantitation.hpp:115
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
This class encapsulates a peptide from the mascot results file.
Definition: ms_peptide.hpp:57
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
An object of this class represent a single component element in quantitation.xml.
Definition: ms_quant_component.hpp:48
static const int file_index_value_not_set
A file_index value is a 1 based number. In cases where file_index values are not used (e....
Definition: ms_quant_file_index.hpp:112
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 quality element in quantitation.xml.
Definition: ms_quant_quality.hpp:40
Wrapper for the public domain tinycdb package http://www.corpit.ru/mjt/tinycdb.html by Michael Tokare...
Definition: ms_tinycdb.hpp:124