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);
66  peptide.addAaModification(AaModification::getInstance(mod),
67  pos - 1 - matched_length_cumul);
68  }
69  else if(mod.startsWith("internal:Nter_"))
70  {
71  peptide.setInternalNterModification(
73  }
74  else if(mod.startsWith("internal:Cter_"))
75  {
76  peptide.setInternalCterModification(
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  }
90  peptide.addAaModification(AaModification::getInstance(mod),
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 
129 PeptideStrParser::parseNoConstString(const QString &pepstr)
130 {
131 
132  // QMutexLocker locker(&_mutex);
133  Peptide peptide(QString(pepstr).replace(_mod_parser, ""));
135 
136  return (peptide.makeNoConstPeptideSp());
137 }
138 } // namespace pappso
peptidestrparser.h
pappso::PeptideStrParser::parseNoConstString
static NoConstPeptideSp parseNoConstString(const QString &pepstr)
Definition: peptidestrparser.cpp:150
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition: aa.cpp:39
pappso::FilterOboPsiModSink
Definition: filterobopsimodsink.h:57
pappso::OboPsiMod
Definition: obopsimod.h:92
pappso::PeptideStrParser::_rx_modmass
static QRegExp _rx_modmass
Definition: peptidestrparser.h:85
pappso::PeptideStrParser::parseString
static PeptideSp parseString(const QString &pepstr)
Definition: peptidestrparser.cpp:139
pappso::AaModification::getInstance
static AaModificationP getInstance(const QString &accession)
Definition: aamodification.cpp:388
pappso::PeptideStrParser::_rx_psimod
static QRegExp _rx_psimod
Definition: peptidestrparser.h:84
pappso::AaModification::getInstanceCustomizedMod
static AaModificationP getInstanceCustomizedMod(pappso_double modificationMass)
Definition: aamodification.cpp:368
pappso::PeptideStrParser::_mod_parser
static QRegExp _mod_parser
Definition: peptidestrparser.h:83
pappso::PeptideStrParser::parseStringToPeptide
static void parseStringToPeptide(const QString &pepstr, Peptide &peptide)
Definition: peptidestrparser.cpp:60
pappso::PeptideSp
std::shared_ptr< const Peptide > PeptideSp
Definition: aamodification.h:68
pappso::FilterOboPsiModSink::getFirst
const OboPsiModTerm & getFirst()
Definition: filterobopsimodsink.cpp:90
pappso::FilterOboPsiModTermLabel
Definition: filterobopsimodtermlabel.h:54
pappso::NoConstPeptideSp
std::shared_ptr< Peptide > NoConstPeptideSp
Definition: peptide.h:111