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