libpappsomspp
Library for mass spectrometry
peptidemodificatorpipeline.cpp
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Copyright (c) 2016 Olivier Langella <Olivier.Langella@moulon.inra.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  * Contributors:
21  * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
22  *implementation
23  ******************************************************************************/
24 
28 #include "../pappsoexception.h"
29 #include <QStringList>
30 using namespace pappso;
31 
32 
33 // QRegExp PeptideModificatorPipeline::_rx_modmass("[-+]?[0-9]*\\.?[0-9]*");
34 
36 {
37 }
38 
40  const PeptideModificatorPipeline &other)
41 {
42  throw PappsoException(
43  QObject::tr("unable to copy PeptideModificatorPipeline object"));
44  if(other.mp_peptideModificatorTee != nullptr)
45  {
46  // mp_peptideModificatorTee = new
47  // PeptideModificatorTee(other.mp_peptideModificatorTee);
48  }
49 
51  mp_firstModificator = nullptr;
52  for(auto p_mod : other.m_pepModificatorPtrList)
53  {
54  delete(p_mod);
55  }
56 
57 
58  m_sink = other.m_sink;
59 
61 
63 
65 }
66 
68 {
69 
70  for(auto p_mod : m_pepModificatorPtrList)
71  {
72  delete(p_mod);
73  }
74  if(mp_peptideModificatorTee == nullptr)
75  {
77  }
78 }
79 
80 void
82 {
83  if(mp_peptideModificatorTee != nullptr)
84  {
85  throw PappsoException(QObject::tr(
86  "Please use setSink before addLabeledModificationString function"));
87  }
88 
89  m_sink = sink;
90  if(mp_firstModificator != nullptr)
91  {
93  }
94 };
95 
96 void
98 {
99  privAddFixedModificationString(mod_str, true, true, true);
100 }
101 void
103  const QString &mod_str)
104 {
105  privAddFixedModificationString(mod_str, true, false, false);
106 }
107 void
109  const QString &mod_str)
110 {
111  privAddFixedModificationString(mod_str, false, true, false);
112 }
113 
114 void
116  const QString &mod_str, bool Nter, bool Cter, bool else_prot)
117 {
118  //"MOD:00397@C, MOD:00398@R"
119  if(mp_peptideModificatorTee != nullptr)
120  {
121  throw PappsoException(
122  QObject::tr("Unable to add fixed modification string after "
123  "addLabeledModificationString function"));
124  }
125  QStringList mod_list_str =
126  mod_str.simplified().replace(" ", "").split(",", QString::SkipEmptyParts);
127  for(auto i = 0; i < mod_list_str.size(); ++i)
128  {
129  parseFixedModification(mod_list_str[i], Nter, Cter, else_prot);
130  }
131 }
132 
133 
134 void
136  bool Nter,
137  bool Cter,
138  bool else_prot)
139 {
140 
141  QStringList str_split = mod_str.split("@", QString::SkipEmptyParts);
143 
146  mod->setModificationPattern(str_split[1]);
147  mod->setSink(m_sink);
148  mod->setProtNter(Nter);
149  mod->setProtCter(Cter);
150  mod->setProtElse(else_prot);
151 
152  m_pepModificatorPtrList.push_back(mod);
153 
154  if(mp_firstModificator == nullptr)
155  {
156  mp_firstModificator = mod;
157  }
158  else
159  {
161  }
163 }
164 
165 void
167  const QString &mod_str)
168 {
169  privAddPotentialModificationString(mod_str, true, true, true);
170 }
171 // protein Nter modification
172 void
174  const QString &mod_str)
175 {
176  privAddPotentialModificationString(mod_str, true, false, false);
177 }
178 // protein Cter modification
179 void
181  const QString &mod_str)
182 {
183  privAddPotentialModificationString(mod_str, false, true, false);
184 }
185 
186 void
188  const QString &mod_str, bool Nter, bool Cter, bool else_prot)
189 {
190  //"MOD:00397@C, MOD:00398@R"
191  if(mp_peptideModificatorTee != nullptr)
192  {
193  throw PappsoException(
194  QObject::tr("Unable to add potential modification string after "
195  "addLabeledModificationString function"));
196  }
197 
198  QStringList mod_list_str =
199  mod_str.simplified().replace(" ", "").split(",", QString::SkipEmptyParts);
200  for(auto i = 0; i < mod_list_str.size(); ++i)
201  {
202  parsePotentialModification(mod_list_str[i], Nter, Cter, else_prot);
203  }
204 }
205 
206 
207 void
209  bool Nter,
210  bool Cter,
211  bool else_prot)
212 {
213 
214  QStringList str_split = mod_str.split("@", QString::SkipEmptyParts);
215 
216  QString mod_acc_str = str_split[0];
217  QStringList str_acc_split = mod_acc_str.split("(", QString::SkipEmptyParts);
218  pappso::AaModificationP aa_mod =
219  AaModification::getInstance(str_acc_split[0]);
220 
223 
224  // qDebug() << "PeptideModificatorPipeline::parsePotentialModification " << ;
225  if(str_acc_split.length() == 2)
226  {
227  QStringList max_num_str_list =
228  str_acc_split[1].replace(")", "").split("-", QString::SkipEmptyParts);
229  if(max_num_str_list.length() == 1)
230  {
231  mod->setModificationCounter(max_num_str_list[0].toUInt());
232  }
233  else if(max_num_str_list.length() == 2)
234  {
235  mod->setMinNumberMod(max_num_str_list[0].toUInt());
236  mod->setMaxNumberMod(max_num_str_list[1].toUInt());
237  }
238  }
239  mod->setModificationPattern(str_split[1]);
240  mod->setSink(m_sink);
241  mod->setProtNter(Nter);
242  mod->setProtCter(Cter);
243  mod->setProtElse(else_prot);
244 
245  m_pepModificatorPtrList.push_back(mod);
246 
247  if(mp_firstModificator == nullptr)
248  {
249  mp_firstModificator = mod;
250  }
251  else
252  {
254  }
256 }
257 
258 
259 void
261 {
262 
263  if(m_sink == nullptr)
264  {
265  throw PappsoException(QObject::tr(
266  "Please use setSink before addLabeledModificationString function"));
267  }
268  if(mp_peptideModificatorTee == nullptr)
269  {
271  }
272  if(mp_firstModificator == nullptr)
273  {
275  }
276 
277  // backup pointers
278  PeptideModificatorInterface *backup_sink = m_sink;
279 
280  PeptideSpSinkInterface *backup_p_last_peptide_sink_interface =
282 
283  PeptideModificatorInterface *backup_p_first_modificator = mp_firstModificator;
284 
285 
286  QStringList mod_list_str =
287  mod_str.simplified().replace(" ", "").split(",", QString::SkipEmptyParts);
288  for(auto i = 0; i < mod_list_str.size(); ++i)
289  {
290  parseLabeledModification(mod_list_str[i], true, true, true);
291 
292  if(i == 0)
293  {
295  }
296  }
297 
298  m_sink = backup_sink;
299  mp_lastPeptideSinkInterface = backup_p_last_peptide_sink_interface;
300  mp_firstModificator = backup_p_first_modificator;
301 
303 }
304 
305 
306 void
308  bool Nter,
309  bool Cter,
310  bool else_prot)
311 {
312 
313  QStringList str_split = mod_str.split("@", QString::SkipEmptyParts);
315 
318  mod->setModificationPattern(str_split[1]);
319  mod->setSink(m_sink);
320  mod->setProtNter(Nter);
321  mod->setProtCter(Cter);
322  mod->setProtCter(else_prot);
323 
324  m_pepModificatorPtrList.push_back(mod);
325 
328  mp_firstModificator = mod;
329 }
330 
331 
332 void
333 PeptideModificatorPipeline::setPeptideSp(std::int8_t sequence_database_id,
334  const ProteinSp &protein_sp,
335  bool is_decoy,
336  const PeptideSp &peptide_sp_original,
337  unsigned int start,
338  bool is_nter,
339  unsigned int missed_cleavage_number,
340  bool semi_enzyme)
341 {
342  mp_firstModificator->setPeptideSp(sequence_database_id,
343  protein_sp,
344  is_decoy,
345  peptide_sp_original,
346  start,
347  is_nter,
348  missed_cleavage_number,
349  semi_enzyme);
350 }
351 
352 
353 void
354 PeptideModificatorPipeline::setPeptide(std::int8_t sequence_database_id,
355  const ProteinSp &protein_sp,
356  bool is_decoy,
357  const QString &peptide_str,
358  unsigned int start,
359  bool is_nter,
360  unsigned int missed_cleavage_number,
361  bool semi_enzyme)
362 {
363 
364  qDebug() << "PeptideModificatorPipeline::setPeptide begin";
365 
366  Peptide peptide(peptide_str);
367 
368  PeptideSp peptide_sp = peptide.makePeptideSp();
369 
370  qDebug() << "PeptideModificatorPipeline::setPeptide m_sink->setPeptideSp";
371  setPeptideSp(sequence_database_id,
372  protein_sp,
373  is_decoy,
374  peptide_sp,
375  start,
376  is_nter,
377  missed_cleavage_number,
378  semi_enzyme);
379  qDebug() << "PeptideModificatorPipeline::setPeptide end";
380 }
static AaModificationP getInstance(const QString &accession)
void setProtElse(bool arg1)
this modification concerns all peptides between Nter and Cter
void setProtCter(bool arg1)
this modification concerns the Cter peptide
void setSink(PeptideModificatorInterface *sink) override
void setProtNter(bool arg1)
this modification concerns the Nter peptide
virtual void setModificationPattern(QString &pattern) final
set the pattern on which the modification will be applied (usually the list of concerned AA)
virtual void setPeptideSp(std::int8_t sequence_database_id, const ProteinSp &protein_sp, bool is_decoy, const PeptideSp &peptide_sp, unsigned int start, bool is_nter, unsigned int missed_cleavage_number, bool semi_enzyme)=0
function to give the products of modifications for a digested peptide
void addFixedNterModificationString(const QString &mod_str)
void addPotentialCterModificationString(const QString &mod_str)
void parsePotentialModification(const QString &mod_str, bool Nter, bool Cter, bool else_prot)
void addLabeledModificationString(const QString &mod_str)
void setSink(PeptideModificatorInterface *sink) override
void parseLabeledModification(const QString &mod_str, bool Nter, bool Cter, bool else_prot)
void privAddFixedModificationString(const QString &mod_str, bool Nter, bool Cter, bool else_prot)
void privAddPotentialModificationString(const QString &mod_str, bool Nter, bool Cter, bool else_prot)
void setPeptideSp(std::int8_t sequence_database_id, const ProteinSp &protein_sp, bool is_decoy, const PeptideSp &peptide_sp_original, unsigned int start, bool is_nter, unsigned int missed_cleavage_number, bool semi_enzyme) override
function to give the products of modifications for a digested peptide
void addFixedModificationString(const QString &mod_str)
std::vector< PeptideModificatorInterface * > m_pepModificatorPtrList
PeptideModificatorInterface * mp_firstModificator
void setPeptide(std::int8_t sequence_database_id, const ProteinSp &protein_sp, bool is_decoy, const QString &peptide_str, unsigned int start, bool is_nter, unsigned int missed_cleavage_number, bool semi_enzyme) override
function to give the products of a protein digestion by an enzyme
PeptideSpSinkInterface * mp_lastPeptideSinkInterface
void addFixedCterModificationString(const QString &mod_str)
void addPotentialNterModificationString(const QString &mod_str)
void addPotentialModificationString(const QString &mod_str)
void parseFixedModification(const QString &mod_str, bool Nter, bool Cter, bool else_prot)
void addModificator(PeptideModificatorInterface *p_peptide_mod)
virtual void setSink(PeptideModificatorInterface *sink)=0
Modify a peptide shared pointer with a variable modification on one AA.
void setSink(PeptideModificatorInterface *sink) override
void setProtNter(bool arg1)
this modification concerns the Nter peptide
void setProtElse(bool arg1)
this modification concerns all peptides between Nter and Cter
void setProtCter(bool arg1)
this modification concerns the Cter peptide
PeptideSp makePeptideSp() const
Definition: peptide.cpp:109
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
std::shared_ptr< const Peptide > PeptideSp
std::shared_ptr< const Protein > ProteinSp
shared pointer on a Protein object
Definition: protein.h:43