libpappsomspp
Library for mass spectrometry
peptidestrparser.cpp
Go to the documentation of this file.
1 
2 /*******************************************************************************
3  * Copyright (c) 2015 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 
25 #include <QStringList>
26 #include "peptidestrparser.h"
27 #include "../obo/filterobopsimodtermlabel.h"
28 #include "../obo/filterobopsimodsink.h"
29 
30 namespace pappso
31 {
32 
33 
34 QRegExp PeptideStrParser::_mod_parser("\\([^)]*\\)");
35 QRegExp PeptideStrParser::_rx_psimod("MOD:[0-9]+");
36 QRegExp PeptideStrParser::_rx_modmass("[-+]?[0-9]*\\.?[0-9]*");
37 
38 void
39 PeptideStrParser::parseStringToPeptide(const QString &pepstr, Peptide &peptide)
40 {
41  // Peptide
42  // peptide2("C(MOD:00397+MOD:01160)C(MOD:00397)AADDKEAC(MOD:00397)FAVEGPK");
43  // CCAADDKEACFAVEGPK
44  QRegExp mod_parser(_mod_parser);
45  QRegExp rx_psimod(_rx_psimod);
46  QRegExp rx_modmass(_rx_modmass);
47  /*
48  <psimod position="1" accession="MOD:00397"/>
49  <psimod position="2" accession="MOD:00397"/>
50  <psimod position="10" accession="MOD:00397"/>
51  <psimod position="1" accession="MOD:01160"/>
52  */
53  int pos = 0;
54  int matched_length_cumul = 0;
55  while((pos = mod_parser.indexIn(pepstr, pos)) != -1)
56  {
57  QStringList mod_list = pepstr.mid(pos + 1, mod_parser.matchedLength() - 2)
58  .split(QRegExp("[+,\\,]"));
59  for(QString &mod : mod_list)
60  {
61  qDebug() << "PeptideStrParser::parseString mod " << mod;
62  if(rx_psimod.exactMatch(mod))
63  {
64  qDebug() << "PeptideStrParser::parseString pos-1 "
65  << (pos - 1 - matched_length_cumul);
67  pos - 1 - matched_length_cumul);
68  }
69  else if(mod.startsWith("internal:Nter_"))
70  {
73  }
74  else if(mod.startsWith("internal:Cter_"))
75  {
78  }
79  else if(rx_modmass.exactMatch(mod))
80  {
81  // number
82  if(!mod.contains("."))
83  {
84  // integer
85  mod = "MOD:0000" + mod;
86  while(mod.size() > 9)
87  {
88  mod = mod.replace(4, 1, "");
89  }
91  pos - 1 - matched_length_cumul);
92  }
93  else
94  {
95  peptide.addAaModification(
97  pos - 1 - matched_length_cumul);
98  }
99  }
100  else
101  {
102  FilterOboPsiModSink term_list;
103  FilterOboPsiModTermLabel filter_label(term_list, mod);
104 
105  OboPsiMod psimod(filter_label);
106 
107  peptide.addAaModification(
109  pos - 1 - matched_length_cumul);
110  }
111  }
112  matched_length_cumul += mod_parser.matchedLength();
113  pos += mod_parser.matchedLength();
114  }
115 }
116 
117 PeptideSp
118 PeptideStrParser::parseString(const QString &pepstr)
119 {
120 
121  // QMutexLocker locker(&_mutex);
122  Peptide peptide(QString(pepstr).replace(_mod_parser, ""));
124 
125  return (peptide.makePeptideSp());
126 }
127 
130 {
131 
132  // QMutexLocker locker(&_mutex);
133  Peptide peptide(QString(pepstr).replace(_mod_parser, ""));
135 
136  return (peptide.makeNoConstPeptideSp());
137 }
138 } // namespace pappso
static AaModificationP getInstance(const QString &accession)
static AaModificationP getInstanceCustomizedMod(pappso_double modificationMass)
const OboPsiModTerm & getFirst()
static NoConstPeptideSp parseNoConstString(const QString &pepstr)
static PeptideSp parseString(const QString &pepstr)
static void parseStringToPeptide(const QString &pepstr, Peptide &peptide)
PeptideSp makePeptideSp() const
Definition: peptide.cpp:109
NoConstPeptideSp makeNoConstPeptideSp() const
Definition: peptide.cpp:115
void setInternalCterModification(AaModificationP mod)
Definition: peptide.cpp:454
void setInternalNterModification(AaModificationP mod)
Definition: peptide.cpp:431
void addAaModification(AaModificationP aaModification, unsigned int position)
adds a modification to amino acid sequence
Definition: peptide.cpp:121
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< Peptide > NoConstPeptideSp
Definition: peptide.h:90