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{
35 buildFilterFromString(strBuildParams);
36 // qInfo() << "ChargeDeconvolution created";
37}
38
39
41 : m_precisionPtrZ1(precision_ptr)
42{
45 m_precisionPtrZ1 = precision_ptr;
48
49 // pappso::PrecisionFactory::getPrecisionDividedBy(m_precisionPtrZ1, 2):
50
51 // qInfo() << m_precisionPtrZ2->getNominal();
52}
53
60
62{
63 qDebug() << "ChargeDeconvolution destroyed";
64}
65
66
67void
69{
70 //"chargeDeconvolution|0.02dalton"
71 qDebug();
72 if(strBuildParams.startsWith("chargeDeconvolution|"))
73 {
74 QStringList params = strBuildParams.split("|").back().split(";", Qt::SkipEmptyParts);
75
76 QString precision = params.at(0);
78 precision.replace("dalton", " dalton").replace("ppm", " ppm").replace("res", " res"));
79 qDebug();
82
83
86 }
87 else
88 {
90 QString("building chargeDeconvolution from string %1 is not possible").arg(strBuildParams));
91 }
92 qDebug();
93}
94
95
96QString
98{
99 return "chargeDeconvolution";
100}
101
102
103QString
105{
106 QString strCode = QString("%1|%2").arg(name()).arg(m_precisionPtrZ1->toString());
107
108 strCode.replace(" ", "");
109
110 return strCode;
111}
112
113Trace &
115{
116 qDebug();
117 std::vector<FilterChargeDeconvolution::DataPointInfoSp> data_points_info;
119 qDebug() << data_points.size();
120 Trace new_trace;
121
122 for(auto &data_point : data_points)
123 {
124 addDataPointToList(data_points_info, data_point);
125 }
126 computeBestChargeOfDataPoint(data_points_info);
127
128 // qDebug() << data_points_info.size();
129 computeIsotopeDeconvolution(data_points_info);
130 // qDebug() << data_points_info.size();
132 for(DataPointInfoSp &dpi : data_points_info)
133 {
134 // qDebug() << dpi->new_mono_charge_data_point.x << dpi->z_charge;
135 new_trace.push_back(dpi->new_mono_charge_data_point);
136 }
137
138 new_trace.sortX();
139 data_points = std::move(new_trace);
140 qDebug() << data_points.size();
141 qDebug();
142 return data_points;
143}
144
145void
147 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &points,
148 pappso::DataPoint &data_point) const
149{
150 DataPointInfoSp new_dpi(std::make_shared<DataPointInfo>());
151
152 new_dpi->data_point = data_point;
153 MzRange range1(data_point.x + m_diffC12C13_z1, m_precisionPtrZ1);
154 new_dpi->z1_range = std::pair<double, double>(range1.lower(), range1.upper());
155 MzRange range2(data_point.x + m_diffC12C13_z2, m_precisionPtrZ2);
156 new_dpi->z2_range = std::pair<double, double>(range2.lower(), range2.upper());
157 addDataPointRefByExclusion(points, new_dpi);
158 points.push_back(new_dpi);
159}
160
161void
163 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &points,
165{
166 // add datapoint which match the mz_range = 1 to z1_list
167 auto i_z1 = points.begin(), end = points.end();
168 while(i_z1 != end)
169 {
170 // get the datapoint which match the range
171 i_z1 = std::find_if(i_z1, end, [&new_dpi](DataPointInfoSp dpi) {
172 return (new_dpi->data_point.x >= dpi->z1_range.first &&
173 new_dpi->data_point.x <= dpi->z1_range.second);
174 });
175 if(i_z1 != end)
176 {
177 // add the datapoint to the list and add the parent pointer
178 i_z1->get()->z1_vect.push_back(new_dpi);
179 new_dpi->parent = *i_z1;
180 DataPointInfoSp parent_z1 = i_z1->get()->parent.lock();
181 while(parent_z1 != nullptr)
182 {
183 parent_z1.get()->z1_vect.push_back(new_dpi);
184 parent_z1 = parent_z1->parent.lock();
185 }
186 i_z1++;
187 }
188 }
189
190 // add datapoint which match the mz_range = 2 to z2_list
191 auto i_z2 = points.begin();
192 while(i_z2 != end)
193 {
194 // get the datapoint which match the range
195 i_z2 = std::find_if(i_z2, end, [&new_dpi](DataPointInfoSp dpi) {
196 return (new_dpi->data_point.x >= dpi->z2_range.first &&
197 new_dpi->data_point.x <= dpi->z2_range.second);
198 });
199 if(i_z2 != end)
200 {
201 // add the datapoint to the list and add the parent pointer
202 i_z2->get()->z2_vect.push_back(new_dpi);
203 new_dpi->parent = *i_z2;
204 DataPointInfoSp parent_z2 = i_z2->get()->parent.lock();
205 while(parent_z2 != nullptr)
206 {
207 parent_z2.get()->z2_vect.push_back(new_dpi);
208 parent_z2 = parent_z2->parent.lock();
209 }
210 i_z2++;
211 }
212 }
213}
214
215void
217 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &data_points_info) const
218{
219 for(DataPointInfoSp &data_point_info : data_points_info)
220 {
221 if(data_point_info.get()->z1_vect.size() >= 1 && data_point_info.get()->z2_vect.size() == 0)
222 {
223 for(std::weak_ptr<DataPointInfo> other : data_point_info.get()->z1_vect)
224 {
225 other.lock()->z_charge = 1;
226 }
227 data_point_info.get()->z_charge = 1;
228 }
229 else if(data_point_info.get()->z1_vect.size() == 0 &&
230 data_point_info.get()->z2_vect.size() >= 1)
231 {
232 for(std::weak_ptr<DataPointInfo> other : data_point_info.get()->z2_vect)
233 {
234 other.lock()->z_charge = 2;
235 }
236 data_point_info.get()->z_charge = 2;
237 }
238 else if(data_point_info.get()->z1_vect.size() >= 1 &&
239 data_point_info.get()->z2_vect.size() >= 1)
240 {
241 for(std::weak_ptr<DataPointInfo> other : data_point_info.get()->z2_vect)
242 {
243 other.lock()->z_charge = 2;
244 }
245 data_point_info.get()->z_charge = 2;
246 }
247 else
248 {
249 if(data_point_info.get()->z_charge == -1)
250 {
251 data_point_info.get()->z_charge = 0;
252 }
253 }
254 }
255}
256
257void
259 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &data_points_info) const
260{
261 std::vector<FilterChargeDeconvolution::DataPointInfoSp> deconvoluted_points_info;
262
263 for(DataPointInfoSp &data_point_info : data_points_info)
264 {
265 if(data_point_info->parent.lock() == nullptr)
266 {
267 DataPointInfoSp deconvoluted_point(std::make_shared<DataPointInfo>());
268
269 deconvoluted_point->z_charge = data_point_info->z_charge;
270 deconvoluted_point->new_mono_charge_data_point = data_point_info->data_point;
271
272 if(data_point_info->z_charge == 1)
273 {
274
275 for(std::weak_ptr<DataPointInfo> data : data_point_info->z1_vect)
276 {
277 deconvoluted_point->new_mono_charge_data_point.y += data.lock()->data_point.y;
278 }
279 }
280 else if(data_point_info->z_charge == 2)
281 {
282 for(std::weak_ptr<DataPointInfo> data : data_point_info->z2_vect)
283 {
284 deconvoluted_point->new_mono_charge_data_point.y += data.lock()->data_point.y;
285 }
286 }
287 else // if z.charge == 0
288 {
289 deconvoluted_point->new_mono_charge_data_point = data_point_info->data_point;
290 }
291 deconvoluted_points_info.push_back(deconvoluted_point);
292 }
293 }
294 data_points_info = deconvoluted_points_info;
295}
296
297void
299 std::vector<FilterChargeDeconvolution::DataPointInfoSp> &data_points_info) const
300{
301 for(DataPointInfoSp &dpi : data_points_info)
302 {
303 if(dpi->z_charge == 2)
304 {
305 dpi->new_mono_charge_data_point.x += dpi->new_mono_charge_data_point.x - MHPLUS;
306 }
307 }
308}
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:80
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 sortY(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1049
void sortX(Enums::SortOrder sort_order=Enums::SortOrder::ascending)
Definition trace.cpp:1039
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 PrecisionBase * PrecisionPtr
Definition precision.h:122
const pappso_double DIFFC12C13(1.0033548378)
pappso_double x
Definition datapoint.h:24