libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
filterchargedeconvolution.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/filters/filtertdfcorrectpeak.cpp
3 * \date 30/09/2020
4 * \author Thomas Renne
5 * \brief Sum peaks and transform mz to fit charge = 1
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 ******************************************************************************/
28#include <QDebug>
30
31using namespace pappso;
32
34 const QString &strBuildParams)
35{
36 buildFilterFromString(strBuildParams);
37 // qInfo() << "ChargeDeconvolution created";
38}
39
40
42 : m_precisionPtrZ1(precision_ptr)
43{
46 m_precisionPtrZ1 = precision_ptr;
48 m_precisionPtrZ1, 0.5);
49
50 // pappso::PrecisionFactory::getPrecisionDividedBy(m_precisionPtrZ1, 2):
51
52 // qInfo() << m_precisionPtrZ2->getNominal();
53}
54
56 const FilterChargeDeconvolution &other)
57 : m_precisionPtrZ1(other.m_precisionPtrZ1),
58 m_precisionPtrZ2(other.m_precisionPtrZ2)
59{
62}
63
65{
66 qDebug() << "ChargeDeconvolution destroyed";
67}
68
69
70void
72 const QString &strBuildParams)
73{
74 //"chargeDeconvolution|0.02dalton"
75 qDebug();
76 if(strBuildParams.startsWith("chargeDeconvolution|"))
77 {
78 QStringList params =
79 strBuildParams.split("|").back().split(";", Qt::SkipEmptyParts);
80
81 QString precision = params.at(0);
82 m_precisionPtrZ1 =
83 PrecisionFactory::fromString(precision.replace("dalton", " dalton")
84 .replace("ppm", " ppm")
85 .replace("res", " res"));
86 qDebug();
87 m_precisionPtrZ2 =
89 m_precisionPtrZ1, 0.5);
90
91
92 m_diffC12C13_z1 = DIFFC12C13;
93 m_diffC12C13_z2 = DIFFC12C13 / 2;
94 }
95 else
96 {
98 QString("building chargeDeconvolution from string %1 is not possible")
99 .arg(strBuildParams));
100 }
101 qDebug();
102}
103
104
105QString
107{
108 return "chargeDeconvolution";
109}
110
111
112QString
114{
115 QString strCode =
116 QString("%1|%2").arg(name()).arg(m_precisionPtrZ1->toString());
117
118 strCode.replace(" ", "");
119
120 return strCode;
121}
122
123Trace &
125{
126 qDebug();
127 std::vector<FilterChargeDeconvolution::DataPointInfoSp> data_points_info;
128 data_points.sortY(SortOrder::descending);
129 qDebug() << data_points.size();
130 Trace new_trace;
131
132 for(auto &data_point : data_points)
133 {
134 addDataPointToList(data_points_info, data_point);
135 }
136 computeBestChargeOfDataPoint(data_points_info);
137
138 // qDebug() << data_points_info.size();
139 computeIsotopeDeconvolution(data_points_info);
140 // qDebug() << data_points_info.size();
142 for(DataPointInfoSp &dpi : data_points_info)
143 {
144 // qDebug() << dpi->new_mono_charge_data_point.x << dpi->z_charge;
145 new_trace.push_back(dpi->new_mono_charge_data_point);
146 }
147
148 new_trace.sortX();
149 data_points = std::move(new_trace);
150 qDebug() << data_points.size();
151 qDebug();
152 return data_points;
153}
154
155void
157 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &points,
158 pappso::DataPoint &data_point) const
159{
160 DataPointInfoSp new_dpi(std::make_shared<DataPointInfo>());
161
162 new_dpi->data_point = data_point;
163 MzRange range1(data_point.x + m_diffC12C13_z1, m_precisionPtrZ1);
164 new_dpi->z1_range = std::pair<double, double>(range1.lower(), range1.upper());
165 MzRange range2(data_point.x + m_diffC12C13_z2, m_precisionPtrZ2);
166 new_dpi->z2_range = std::pair<double, double>(range2.lower(), range2.upper());
167 addDataPointRefByExclusion(points, new_dpi);
168 points.push_back(new_dpi);
169}
170
171void
173 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &points,
175{
176 // add datapoint which match the mz_range = 1 to z1_list
177 auto i_z1 = points.begin(), end = points.end();
178 while(i_z1 != end)
179 {
180 // get the datapoint which match the range
181 i_z1 = std::find_if(i_z1, end, [&new_dpi](DataPointInfoSp dpi) {
182 return (new_dpi->data_point.x >= dpi->z1_range.first &&
183 new_dpi->data_point.x <= dpi->z1_range.second);
184 });
185 if(i_z1 != end)
186 {
187 // add the datapoint to the list and add the parent pointer
188 i_z1->get()->z1_vect.push_back(new_dpi);
189 new_dpi->parent = *i_z1;
190 DataPointInfoSp parent_z1 = i_z1->get()->parent.lock();
191 while(parent_z1 != nullptr)
192 {
193 parent_z1.get()->z1_vect.push_back(new_dpi);
194 parent_z1 = parent_z1->parent.lock();
195 }
196 i_z1++;
197 }
198 }
199
200 // add datapoint which match the mz_range = 2 to z2_list
201 auto i_z2 = points.begin();
202 while(i_z2 != end)
203 {
204 // get the datapoint which match the range
205 i_z2 = std::find_if(i_z2, end, [&new_dpi](DataPointInfoSp dpi) {
206 return (new_dpi->data_point.x >= dpi->z2_range.first &&
207 new_dpi->data_point.x <= dpi->z2_range.second);
208 });
209 if(i_z2 != end)
210 {
211 // add the datapoint to the list and add the parent pointer
212 i_z2->get()->z2_vect.push_back(new_dpi);
213 new_dpi->parent = *i_z2;
214 DataPointInfoSp parent_z2 = i_z2->get()->parent.lock();
215 while(parent_z2 != nullptr)
216 {
217 parent_z2.get()->z2_vect.push_back(new_dpi);
218 parent_z2 = parent_z2->parent.lock();
219 }
220 i_z2++;
221 }
222 }
223}
224
225void
227 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &data_points_info)
228 const
229{
230 for(DataPointInfoSp &data_point_info : data_points_info)
231 {
232 if(data_point_info.get()->z1_vect.size() >= 1 &&
233 data_point_info.get()->z2_vect.size() == 0)
234 {
235 for(std::weak_ptr<DataPointInfo> other :
236 data_point_info.get()->z1_vect)
237 {
238 other.lock()->z_charge = 1;
239 }
240 data_point_info.get()->z_charge = 1;
241 }
242 else if(data_point_info.get()->z1_vect.size() == 0 &&
243 data_point_info.get()->z2_vect.size() >= 1)
244 {
245 for(std::weak_ptr<DataPointInfo> other :
246 data_point_info.get()->z2_vect)
247 {
248 other.lock()->z_charge = 2;
249 }
250 data_point_info.get()->z_charge = 2;
251 }
252 else if(data_point_info.get()->z1_vect.size() >= 1 &&
253 data_point_info.get()->z2_vect.size() >= 1)
254 {
255 for(std::weak_ptr<DataPointInfo> other :
256 data_point_info.get()->z2_vect)
257 {
258 other.lock()->z_charge = 2;
259 }
260 data_point_info.get()->z_charge = 2;
261 }
262 else
263 {
264 if(data_point_info.get()->z_charge == -1)
265 {
266 data_point_info.get()->z_charge = 0;
267 }
268 }
269 }
270}
271
272void
274 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &data_points_info)
275 const
276{
277 std::vector<FilterChargeDeconvolution::DataPointInfoSp>
278 deconvoluted_points_info;
279
280 for(DataPointInfoSp &data_point_info : data_points_info)
281 {
282 if(data_point_info->parent.lock() == nullptr)
283 {
284 DataPointInfoSp deconvoluted_point(std::make_shared<DataPointInfo>());
285
286 deconvoluted_point->z_charge = data_point_info->z_charge;
287 deconvoluted_point->new_mono_charge_data_point =
288 data_point_info->data_point;
289
290 if(data_point_info->z_charge == 1)
291 {
292
293 for(std::weak_ptr<DataPointInfo> data : data_point_info->z1_vect)
294 {
295 deconvoluted_point->new_mono_charge_data_point.y +=
296 data.lock()->data_point.y;
297 }
298 }
299 else if(data_point_info->z_charge == 2)
300 {
301 for(std::weak_ptr<DataPointInfo> data : data_point_info->z2_vect)
302 {
303 deconvoluted_point->new_mono_charge_data_point.y +=
304 data.lock()->data_point.y;
305 }
306 }
307 else // if z.charge == 0
308 {
309 deconvoluted_point->new_mono_charge_data_point =
310 data_point_info->data_point;
311 }
312 deconvoluted_points_info.push_back(deconvoluted_point);
313 }
314 }
315 data_points_info = deconvoluted_points_info;
316}
317
318void
320 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &data_points_info)
321 const
322{
323 for(DataPointInfoSp &dpi : data_points_info)
324 {
325 if(dpi->z_charge == 2)
326 {
327 dpi->new_mono_charge_data_point.x +=
328 dpi->new_mono_charge_data_point.x - MHPLUS;
329 }
330 }
331}
excetion to use when an item type is not recognized
void addDataPointRefByExclusion(std::vector< FilterChargeDeconvolution::DataPointInfoSp > &points, FilterChargeDeconvolution::DataPointInfoSp &new_dpi) const
For each datapointInfo add the datapoint to the lists by their exclusion range.
void buildFilterFromString(const QString &strBuildParams) override
build this filter using a string
virtual QString name() const override
std::shared_ptr< DataPointInfo > DataPointInfoSp
void computeBestChargeOfDataPoint(std::vector< FilterChargeDeconvolution::DataPointInfoSp > &data_points_info) const
Compare both list (z1 and z2) and add the right level of charge.
FilterChargeDeconvolution(PrecisionPtr precision_ptr)
void transformToMonoChargedForAllDataPoint(std::vector< FilterChargeDeconvolution::DataPointInfoSp > &data_points_info) const
For eache datapointInfo with a charge = 2 transform the peak to a charge = 1 by multiplying the mz by...
void addDataPointToList(std::vector< FilterChargeDeconvolution::DataPointInfoSp > &points, DataPoint &data_point) const
Add each datapoint to a vector of structure describe above.
Trace & filter(Trace &data_points) const override
get all the datapoints and remove different isotope and add their intensity and change to charge = 1 ...
void computeIsotopeDeconvolution(std::vector< FilterChargeDeconvolution::DataPointInfoSp > &data_points_info) const
For eache datapointInfo whith no parent copy info in new vector with the intensity of the monoistipic...
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
static PrecisionPtr getPrecisionPtrFractionInstance(PrecisionPtr origin, double fraction)
get the fraction of an existing precision pointer
A simple container of DataPoint instances.
Definition trace.h:148
void sortX(SortOrder sort_order=SortOrder::ascending)
Definition trace.cpp:1086
void sortY(SortOrder sort_order=SortOrder::ascending)
Definition trace.cpp:1100
excetion to use when an item type is not recognized (file format, object type...)
Sum peaks and transform mz to fit charge = 1.
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)
const pappso_double DIFFC12C13(1.0033548378)
pappso_double x
Definition datapoint.h:23