libpappsomspp
Library for mass spectrometry
filtercomplementionenhancer.cpp
Go to the documentation of this file.
1 /**
2  * \file pappsomspp/processing/filters/filtercomplementionenhancer.cpp
3  * \date 21/08/2020
4  * \author Olivier Langella
5  * \brief enhance ion intensity of ion fragment complement
6  */
7 
8 /*******************************************************************************
9  * Copyright (c) 2020 Olivier Langella <Olivier.Langella@u-psud.fr>.
10  *
11  * This file is part of the PAPPSOms++ library.
12  *
13  * PAPPSOms++ is free software: you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation, either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * PAPPSOms++ is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
25  *
26  ******************************************************************************/
27 
29 #include "../../exception/exceptionnotrecognized.h"
30 
31 using namespace pappso;
32 
34  double target_mz, PrecisionPtr precision_ptr)
35  : m_targetMzSum(target_mz), m_precisionPtr(precision_ptr)
36 {
37 }
38 
40  const FilterComplementIonEnhancer &other)
41  : m_targetMzSum(other.m_targetMzSum), m_precisionPtr(other.m_precisionPtr)
42 {
43 }
44 
46  const pappso::QualifiedMassSpectrum &qmass_spectrum,
47  pappso::PrecisionPtr precision_ptr)
48  : m_targetMzSum(((qmass_spectrum.getPrecursorMz() -
49  (qmass_spectrum.getPrecursorCharge() * MHPLUS /
50  qmass_spectrum.getPrecursorCharge())) *
51  qmass_spectrum.getPrecursorCharge() +
52  (MHPLUS + MHPLUS))),
53  m_precisionPtr(precision_ptr)
54 {
55 }
56 
58  const QString &strBuildParams)
59 {
60  buildFilterFromString(strBuildParams);
61 }
62 
63 void
65  const QString &strBuildParams)
66 {
67  //"complementIonEnhancer|456.567;0.02dalton"
68  if(strBuildParams.startsWith("complementIonEnhancer|"))
69  {
70  QStringList params = strBuildParams.split("|").back().split(";");
71 
72  m_targetMzSum = params.at(0).toDouble();
73  QString precision = params.at(1);
74  m_precisionPtr =
75  PrecisionFactory::fromString(precision.replace("dalton", " dalton")
76  .replace("ppm", " ppm")
77  .replace("res", " res"));
78  }
79  else
80  {
82  QString(
83  "building FilterComplementIonEnhancer from string %1 is not possible")
84  .arg(strBuildParams));
85  }
86 }
87 
88 
89 QString
91 {
92  return "complementIonEnhancer";
93 }
94 
95 
96 QString
98 {
99  QString strCode = QString("%1|%2;%3")
100  .arg(name())
101  .arg(QString::number(m_targetMzSum, 'g', 15))
102  .arg(m_precisionPtr->toString());
103  strCode.replace(" ", "");
104 
105  return strCode;
106 }
107 
109 {
110 }
111 
114 {
115 
116  auto it_end = data_points.end();
117  std::sort(data_points.begin(),
118  it_end,
119  [](const DataPoint &a, const DataPoint &b) { return (a.y > b.y); });
120 
121  for(auto it = data_points.begin(); it != it_end; it++)
122  {
123  double mz_complement = m_targetMzSum - it->x;
124  if(mz_complement > 0)
125  {
126  MzRange mz_range(mz_complement, m_precisionPtr);
127  enhanceComplementMassInRange(
128  it->y, mz_range.lower(), mz_range.upper(), it, it_end);
129  }
130  }
131 
132  data_points.sortX();
133  return data_points;
134 }
135 
136 
137 void
139  double new_intensity,
140  double mz_lower_bound,
141  double mz_upper_bound,
142  std::vector<DataPoint>::iterator it_begin,
143  std::vector<DataPoint>::iterator it_end) const
144 {
145  for(std::vector<DataPoint>::iterator it = it_begin; it != it_end; it++)
146  {
147  if((it->x >= mz_lower_bound) && (it->x <= mz_upper_bound))
148  {
149  if(it->y < new_intensity)
150  {
151  it->y = new_intensity;
152  }
153  }
154  }
155 }
excetion to use when an item type is not recognized
try to detect complementary ions and assign maximum intensity of both elements
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string
Trace & filter(Trace &data_points) const override
FilterComplementIonEnhancer(double target_mz, PrecisionPtr precision_ptr)
void enhanceComplementMassInRange(double new_intensity, double mz_lower_bound, double mz_upper_bound, std::vector< DataPoint >::iterator it_begin, std::vector< DataPoint >::iterator it_end) const
pappso_double lower() const
Definition: mzrange.h:71
pappso_double upper() const
Definition: mzrange.h:77
static PrecisionPtr fromString(const QString &str)
get a precision pointer from a string
Definition: precision.cpp:72
Class representing a fully specified mass spectrum.
A simple container of DataPoint instances.
Definition: trace.h:148
void sortX()
Definition: trace.cpp:956
enhance ion intensity of ion fragment complement
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
const pappso_double MHPLUS(1.007276466879)