libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
peptidevariablemodificationbuilder.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
26
27namespace pappso
28{
29bool
31 const std::vector<unsigned int>::iterator first,
32 std::vector<unsigned int>::iterator k,
33 const std::vector<unsigned int>::iterator last)
34{
35 /* Credits: Mark Nelson http://marknelson.us */
36 if((first == last) || (first == k) || (last == k))
37 return false;
38 std::vector<unsigned int>::iterator i1 = first;
39 std::vector<unsigned int>::iterator i2 = last;
40 ++i1;
41 if(last == i1)
42 return false;
43 i1 = last;
44 --i1;
45 i1 = k;
46 --i2;
47 while(first != i1)
48 {
49 if(*--i1 < *i2)
50 {
51 std::vector<unsigned int>::iterator j = k;
52 while(!(*i1 < *j))
53 ++j;
54 std::iter_swap(i1, j);
55 ++i1;
56 ++j;
57 i2 = k;
58 std::rotate(i1, j, last);
59 while(last != j)
60 {
61 ++j;
62 ++i2;
63 }
64 std::rotate(k, i2, last);
65 return true;
66 }
67 }
68 std::rotate(first, k, last);
69 return false;
70}
71
76
80
81void
83{
84
85 m_aaModificationList.append(aa);
86
87 m_pattern.setPattern(QString("[%1]").arg(m_aaModificationList));
88}
89
90void
91PeptideVariableModificationBuilder::setPeptideSp(std::int8_t sequence_database_id,
92 const ProteinSp &protein_sp,
93 bool is_decoy,
94 const PeptideSp &peptide_sp_original,
95 unsigned int start,
96 bool is_nter,
97 unsigned int missed_cleavage_number,
98 bool semi_enzyme)
99{
100 // QString s = "Banana";
101 // s.replace(QRegExp("a[mn]"), "ox");
102
103
104 bool modify_this_peptide = true;
106 {
107 modify_this_peptide = false;
108 if((m_isProtNterMod) && (is_nter))
109 {
110 // this an Nter peptide
111 modify_this_peptide = true;
112 }
113 else if((m_isProtCterMod) &&
114 (protein_sp.get()->size() == (start + peptide_sp_original.get()->size())))
115 {
116 // this is a Cter peptide
117 modify_this_peptide = true;
118 }
119 else if(m_isProtElseMod)
120 {
121 modify_this_peptide = true;
122 }
123 }
124
125 if(modify_this_peptide)
126 {
127
128 std::vector<unsigned int> position_list;
130 position_list, peptide_sp_original.get(), mp_mod, m_modificationCount);
131
132
133 // std::vector< unsigned int > position_list =
134 // peptide_sp_original.get()->getAaPositionList(m_aaModificationList);
135 // std::string s = "12345";
136 // no AA modification :
137 if(m_minNumberMod == 0)
138 {
139 m_sink->setPeptideSp(sequence_database_id,
140 protein_sp,
141 is_decoy,
142 peptide_sp_original,
143 start,
144 is_nter,
145 missed_cleavage_number,
146 semi_enzyme);
147 }
148
149 unsigned int nb_pos = position_list.size();
150 if(nb_pos > 0)
151 {
152 // loop to find 1 to n-1 AA modification combinations
153 unsigned int comb_size = 1;
154 while((comb_size < nb_pos) && (comb_size <= m_maxNumberMod))
155 {
156 do
157 {
158 // std::cout << std::string(being,begin + comb_size) <<
159 // std::endl;
160 Peptide new_peptide(*(peptide_sp_original.get()));
161 for(unsigned int i = 0; i < comb_size; i++)
162 {
163 new_peptide.addAaModification(mp_mod, position_list[i]);
164 }
165 PeptideSp new_peptide_sp = new_peptide.makePeptideSp();
166 m_sink->setPeptideSp(sequence_database_id,
167 protein_sp,
168 is_decoy,
169 new_peptide_sp,
170 start,
171 is_nter,
172 missed_cleavage_number,
173 semi_enzyme);
174 }
175 while(next_combination(
176 position_list.begin(), position_list.begin() + comb_size, position_list.end()));
177 comb_size++;
178 }
179
180 if(nb_pos <= m_maxNumberMod)
181 {
182 // the last combination : all aa are modified :
183 Peptide new_peptide(*(peptide_sp_original.get()));
184 for(unsigned int i = 0; i < nb_pos; i++)
185 {
186 new_peptide.addAaModification(mp_mod, position_list[i]);
187 }
188 PeptideSp new_peptide_sp = new_peptide.makePeptideSp();
189 m_sink->setPeptideSp(sequence_database_id,
190 protein_sp,
191 is_decoy,
192 new_peptide_sp,
193 start,
194 is_nter,
195 missed_cleavage_number,
196 semi_enzyme);
197 }
198 }
199 }
200 else
201 {
202 // no modification
203 m_sink->setPeptideSp(sequence_database_id,
204 protein_sp,
205 is_decoy,
206 peptide_sp_original,
207 start,
208 is_nter,
209 missed_cleavage_number,
210 semi_enzyme);
211 }
212}
213
214} // namespace pappso
virtual void getModificationPositionList(std::vector< unsigned int > &position_list, const QString &peptide_str) final
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
static bool next_combination(const std::vector< unsigned int >::iterator first, std::vector< unsigned int >::iterator k, const std::vector< unsigned int >::iterator last)
PeptideSp makePeptideSp() const
Definition peptide.cpp:160
void addAaModification(AaModificationP aaModification, unsigned int position)
adds a modification to amino acid sequence
Definition peptide.cpp:222
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
const AaModification * AaModificationP
std::shared_ptr< const Protein > ProteinSp
shared pointer on a Protein object
Definition protein.h:47