libpappsomspp
Library for mass spectrometry
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
74 : mp_mod(mod)
75{
76}
77
79{
80}
81
82void
84{
85
86 m_aaModificationList.append(aa);
87
88 m_pattern.setPattern(QString("[%1]").arg(m_aaModificationList));
89}
90
91void
93 std::int8_t sequence_database_id,
94 const ProteinSp &protein_sp,
95 bool is_decoy,
96 const PeptideSp &peptide_sp_original,
97 unsigned int start,
98 bool is_nter,
99 unsigned int missed_cleavage_number,
100 bool semi_enzyme)
101{
102 // QString s = "Banana";
103 // s.replace(QRegExp("a[mn]"), "ox");
104
105
106 bool modify_this_peptide = true;
108 {
109 modify_this_peptide = false;
110 if((m_isProtNterMod) && (is_nter))
111 {
112 // this an Nter peptide
113 modify_this_peptide = true;
114 }
115 else if((m_isProtCterMod) &&
116 (protein_sp.get()->size() ==
117 (start + peptide_sp_original.get()->size())))
118 {
119 // this is a Cter peptide
120 modify_this_peptide = true;
121 }
122 else if(m_isProtElseMod)
123 {
124 modify_this_peptide = true;
125 }
126 }
127
128 if(modify_this_peptide)
129 {
130
131 std::vector<unsigned int> position_list;
133 position_list, peptide_sp_original.get(), mp_mod, m_modificationCount);
134
135
136 // std::vector< unsigned int > position_list =
137 // peptide_sp_original.get()->getAaPositionList(m_aaModificationList);
138 // std::string s = "12345";
139 // no AA modification :
140 if(m_minNumberMod == 0)
141 {
142 m_sink->setPeptideSp(sequence_database_id,
143 protein_sp,
144 is_decoy,
145 peptide_sp_original,
146 start,
147 is_nter,
148 missed_cleavage_number,
149 semi_enzyme);
150 }
151
152 unsigned int nb_pos = position_list.size();
153 if(nb_pos > 0)
154 {
155 // loop to find 1 to n-1 AA modification combinations
156 unsigned int comb_size = 1;
157 while((comb_size < nb_pos) && (comb_size <= m_maxNumberMod))
158 {
159 do
160 {
161 // std::cout << std::string(being,begin + comb_size) <<
162 // std::endl;
163 Peptide new_peptide(*(peptide_sp_original.get()));
164 for(unsigned int i = 0; i < comb_size; i++)
165 {
166 new_peptide.addAaModification(mp_mod, position_list[i]);
167 }
168 PeptideSp new_peptide_sp = new_peptide.makePeptideSp();
169 m_sink->setPeptideSp(sequence_database_id,
170 protein_sp,
171 is_decoy,
172 new_peptide_sp,
173 start,
174 is_nter,
175 missed_cleavage_number,
176 semi_enzyme);
177 }
178 while(next_combination(position_list.begin(),
179 position_list.begin() + comb_size,
180 position_list.end()));
181 comb_size++;
182 }
183
184 if(nb_pos <= m_maxNumberMod)
185 {
186 // the last combination : all aa are modified :
187 Peptide new_peptide(*(peptide_sp_original.get()));
188 for(unsigned int i = 0; i < nb_pos; i++)
189 {
190 new_peptide.addAaModification(mp_mod, position_list[i]);
191 }
192 PeptideSp new_peptide_sp = new_peptide.makePeptideSp();
193 m_sink->setPeptideSp(sequence_database_id,
194 protein_sp,
195 is_decoy,
196 new_peptide_sp,
197 start,
198 is_nter,
199 missed_cleavage_number,
200 semi_enzyme);
201 }
202 }
203 }
204 else
205 {
206 // no modification
207 m_sink->setPeptideSp(sequence_database_id,
208 protein_sp,
209 is_decoy,
210 peptide_sp_original,
211 start,
212 is_nter,
213 missed_cleavage_number,
214 semi_enzyme);
215 }
216}
217
218} // namespace pappso
virtual void getModificationPositionList(std::vector< unsigned int > &position_list, const QString &peptide_str) final
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 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:125
void addAaModification(AaModificationP aaModification, unsigned int position)
adds a modification to amino acid sequence
Definition: peptide.cpp:187
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:47