libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
peptidestrparser.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 * Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>.
3 *
4 * This file is part of the PAPPSOms++ library.
5 *
6 * PAPPSOms++ is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * PAPPSOms++ is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
18 *
19 * Contributors:
20 * Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and
21 *implementation
22 ******************************************************************************/
23
24#include <QStringList>
25#include "peptidestrparser.h"
28
29namespace pappso
30{
31
32
33QRegularExpression PeptideStrParser::_mod_parser("\\([^)]*\\)");
34QRegularExpression PeptideStrParser::_rx_psimod("MOD:[0-9]+");
35QRegularExpression PeptideStrParser::_rx_modmass("[-+]?[0-9]+\\.?[0-9]*");
36
37void
38PeptideStrParser::parseStringToPeptide(const QString &pepstr, Peptide &peptide)
39{
40 // Peptide
41 // peptide2("C(MOD:00397+MOD:01160)C(MOD:00397)AADDKEAC(MOD:00397)FAVEGPK");
42 // CCAADDKEACFAVEGPK
43 /*
44 <psimod position="1" accession="MOD:00397"/>
45 <psimod position="2" accession="MOD:00397"/>
46 <psimod position="10" accession="MOD:00397"/>
47 <psimod position="1" accession="MOD:01160"/>
48 */
49 int matched_length_cumul = 0;
50 int pos = 0;
51
52 QRegularExpressionMatch match_mod = _mod_parser.match(pepstr, pos);
53
54 while(match_mod.hasMatch())
55 {
56 pos = match_mod.capturedStart(0);
57 QString captured = match_mod.captured(0);
58 qDebug() << " captured=" << captured << " pos=" << pos
59 << " match_mod.lastCapturedIndex()="
60 << match_mod.lastCapturedIndex();
61 QStringList mod_list = captured.mid(1, captured.size() - 2)
62 .split(QRegularExpression("[+,\\,]"));
63 for(QString &mod : mod_list)
64 {
65 qDebug() << "PeptideStrParser::parseString mod " << mod;
66 QRegularExpressionMatch match_psimod = _rx_psimod.match(mod);
67 if(match_psimod.hasMatch())
68 {
69 qDebug() << "PeptideStrParser::parseString pos-1 "
70 << (pos - 1 - matched_length_cumul);
72 pos - 1 - matched_length_cumul);
73 }
74 else if(mod.startsWith("internal:Nter_"))
75 {
78 }
79 else if(mod.startsWith("internal:Cter_"))
80 {
83 }
84 else if(mod.startsWith("C13N15:"))
85 {
86 qDebug() << "PeptideStrParser::parseString pos-1 "
87 << (pos - 1 - matched_length_cumul);
89 pos - 1 - matched_length_cumul);
90 }
91 else
92 {
93 qDebug() << "mod=" << mod;
94 QRegularExpressionMatch match_modmass = _rx_modmass.match(mod);
95 if(match_modmass.hasMatch())
96 {
97 // number
98 qDebug() << "number mod=" << mod
99 << " cap=" << match_modmass.captured(0);
100 if(!mod.contains("."))
101 {
102 // integer
103 qDebug() << "integer mod=" << mod;
104 mod = "MOD:0000" + mod;
105 while(mod.size() > 9)
106 {
107 mod = mod.replace(4, 1, "");
108 }
109 peptide.addAaModification(
111 pos - 1 - matched_length_cumul);
112 }
113 else
114 {
115 qDebug() << "double mod=" << mod;
116 peptide.addAaModification(
118 mod.toDouble()),
119 pos - 1 - matched_length_cumul);
120 }
121 }
122 else
123 {
124 qDebug() << "not a number mod=" << mod;
125 FilterOboPsiModSink term_list;
126 FilterOboPsiModTermLabel filter_label(term_list, mod);
127
128 OboPsiMod psimod(filter_label);
129
130 peptide.addAaModification(
132 pos - 1 - matched_length_cumul);
133 }
134 }
135 }
136 qDebug();
137 matched_length_cumul += captured.size();
138 match_mod = _mod_parser.match(pepstr, pos + 1);
139 qDebug();
140 }
141}
142
144PeptideStrParser::parseString(const QString &pepstr)
145{
146
147 qDebug();
148 // QMutexLocker locker(&_mutex);
149 Peptide peptide(QString(pepstr).replace(_mod_parser, ""));
151
152 return (peptide.makePeptideSp());
153}
154
157{
158
159 qDebug() << pepstr;
160 QString new_pep = QString(pepstr).replace(_mod_parser, "");
161 qDebug() << new_pep;
162 // QMutexLocker locker(&_mutex);
163 Peptide peptide(new_pep);
164 qDebug();
166
167 return (peptide.makeNoConstPeptideSp());
168}
169} // namespace pappso
static AaModificationP getInstance(const QString &accession)
static AaModificationP getInstanceCustomizedMod(pappso_double modificationMass)
const OboPsiModTerm & getFirst()
static NoConstPeptideSp parseNoConstString(const QString &pepstr)
static QRegularExpression _rx_psimod
static PeptideSp parseString(const QString &pepstr)
static void parseStringToPeptide(const QString &pepstr, Peptide &peptide)
static QRegularExpression _rx_modmass
static QRegularExpression _mod_parser
PeptideSp makePeptideSp() const
Definition peptide.cpp:126
NoConstPeptideSp makeNoConstPeptideSp() const
Definition peptide.cpp:132
void setInternalCterModification(AaModificationP mod)
Definition peptide.cpp:538
void setInternalNterModification(AaModificationP mod)
Definition peptide.cpp:515
void addAaModification(AaModificationP aaModification, unsigned int position)
adds a modification to amino acid sequence
Definition peptide.cpp:188
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:97