libpappsomspp
Library for mass spectrometry
msrunretentiontime.h
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Copyright (c) 2019 Olivier Langella <Olivier.Langella@u-psud.fr>.
4  *
5  * This file is part of the PAPPSOms++ library.
6  *
7  * PAPPSOms++ is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * PAPPSOms++ is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
19  *
20  ******************************************************************************/
21 
22 #pragma once
23 
24 #include "../msrunid.h"
25 #include "../msrunreader.h"
26 #include <vector>
27 #include "../../processing/filters/filtermorpho.h"
28 
29 namespace pappso
30 {
31 
32 struct RtPoint
33 {
34  double retentionTime;
35  std::size_t spectrumIndex;
36 };
37 
38 
39 template <class T>
40 struct MsRunRetentionTimeSeamarkPoint
41 {
42  T entityHash;
43  double retentionTime;
44  double intensity;
45 };
46 
47 
48 template <class T>
49 class PMSPP_LIB_DECL MsRunRetentionTime
50 {
51  private:
52  struct PeptideMs2Point
53  {
54  double retentionTime;
55  double precursorIntensity;
56  T entityHash;
57  };
58 
59  enum class ComputeRetentionTimeReference
60  {
61  maximum_intensity,
62  weighted_intensity,
63  last
64  };
65 
66  public:
70 
71  void setMs2MedianFilter(const FilterMorphoMedian &ms2MedianFilter);
72  void setMs2MeanFilter(const FilterMorphoMean &ms2MeanFilter);
73  void setMs1MeanFilter(const FilterMorphoMean &ms1MeanFilter);
74 
75  Trace getCommonDeltaRt(
76  const std::vector<MsRunRetentionTimeSeamarkPoint<T>> &other_seamarks) const;
77 
78  /** @brief collects all peptide evidences of a given MSrun
79  * seamarks has to be converted to peptide retention time using
80  * computePeptideRetentionTimes
81  */
82  void addPeptideAsSeamark(const T &peptide_str,
83  std::size_t ms2_spectrum_index);
84 
85  /** @brief convert Peptide seamarks into PeptideMs2Point
86  * this is required before computing alignment
87  */
88  void computePeptideRetentionTimes();
89 
90  std::size_t getNumberOfCorrectedValues() const;
91 
92  Trace align(const MsRunRetentionTime<T> &msrun_retention_time_reference);
93 
94  const std::vector<MsRunRetentionTimeSeamarkPoint<T>> &getSeamarks() const;
95  const std::vector<double> &getAlignedRetentionTimeVector() const;
96  const std::vector<RtPoint> &getMs1RetentionTimeVector() const;
97 
98  bool isAligned() const;
99 
100  double
101  translateOriginal2AlignedRetentionTime(double original_retention_time) const;
102 
103  protected:
104  double getFrontRetentionTimeReference() const;
105  double getBackRetentionTimeReference() const;
106  const std::vector<MsRunRetentionTimeSeamarkPoint<T>>
107  getSeamarksReferences() const;
108 
109  private:
110  void getCommonDeltaRt(
111  Trace &delta_rt,
112  const std::vector<MsRunRetentionTimeSeamarkPoint<T>> &other_seamarks) const;
113  void correctNewTimeValues(Trace &ms1_aligned_points,
114  double correction_parameter);
115 
116  void linearRegressionMs2toMs1(Trace &ms1_aligned_points,
117  const Trace &common_points);
118 
119  private:
120  FilterMorphoMedian m_ms2MedianFilter;
121  FilterMorphoMean m_ms2MeanFilter;
122  FilterMorphoMean m_ms1MeanFilter;
123  pappso::MsRunReaderSPtr msp_msrunReader;
124  pappso::MsRunIdCstSPtr mcsp_msrunId;
125  std::vector<RtPoint> m_ms1RetentionTimeVector;
126  std::vector<double> m_alignedRetentionTimeVector;
127 
128  std::vector<MsRunRetentionTimeSeamarkPoint<T>> m_seamarks;
129  std::size_t m_valuesCorrected = 0;
130 
131  std::vector<PeptideMs2Point> m_allMs2Points;
132 
133  ComputeRetentionTimeReference m_retentionTimeReferenceMethod =
134  ComputeRetentionTimeReference::maximum_intensity;
135 };
136 
137 } // namespace pappso
pappso::MsRunRetentionTimeSeamarkPoint::retentionTime
double retentionTime
Definition: msrunretentiontime.h:61
pappso::FilterMorphoMedian
median filter apply median of y values inside the window
Definition: filtermorpho.h:195
pappso::MsRunRetentionTimeSeamarkPoint::intensity
double intensity
Definition: msrunretentiontime.h:62
pappso::MsRunRetentionTimeSeamarkPoint::entityHash
T entityHash
Definition: msrunretentiontime.h:60
PMSPP_LIB_DECL
#define PMSPP_LIB_DECL
Definition: exportinmportconfig.h:14
pappso::RtPoint::spectrumIndex
std::size_t spectrumIndex
Definition: msrunretentiontime.h:71
pappso
Definition: aa.cpp:38
pappso::MsRunReaderSPtr
std::shared_ptr< MsRunReader > MsRunReaderSPtr
Definition: msrunreader.h:172
pappso::MsRunIdCstSPtr
std::shared_ptr< const MsRunId > MsRunIdCstSPtr
Definition: msrunid.h:65
pappso::MsRunRetentionTimeSeamarkPoint
Definition: msrunretentiontime.h:58
pappso::Trace
A simple container of DataPoint instances.
Definition: trace.h:126
pappso::QualifiedMassSpectrumParameter::last
@ last
pappso::MsRunRetentionTime
Definition: msrunretentiontime.h:67
pappso::FilterMorphoMean
mean filter apply mean of y values inside the window : this results in a kind of smoothing
Definition: filtermorpho.h:214
pappso::RtPoint::retentionTime
double retentionTime
Definition: msrunretentiontime.h:70
pappso::MsRunRetentionTime::ComputeRetentionTimeReference
ComputeRetentionTimeReference
Definition: msrunretentiontime.h:77