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
104
105 bool modify_this_peptide = true;
107 {
108 modify_this_peptide = false;
109 if((m_isProtNterMod) && (is_nter))
110 {
111 // this an Nter peptide
112 modify_this_peptide = true;
113 }
114 else if((m_isProtCterMod) &&
115 (protein_sp.get()->size() ==
116 (start + peptide_sp_original.get()->size())))
117 {
118 // this is a Cter peptide
119 modify_this_peptide = true;
120 }
121 else if(m_isProtElseMod)
122 {
123 modify_this_peptide = true;
124 }
125 }
126
127 if(modify_this_peptide)
128 {
129
130 std::vector<unsigned int> position_list;
132 position_list, peptide_sp_original.get(), mp_mod, m_modificationCount);
133
134
135 // std::vector< unsigned int > position_list =
136 // peptide_sp_original.get()->getAaPositionList(m_aaModificationList);
137 // std::string s = "12345";
138 // no AA modification :
139 if(m_minNumberMod == 0)
140 {
141 m_sink->setPeptideSp(sequence_database_id,
142 protein_sp,
143 is_decoy,
144 peptide_sp_original,
145 start,
146 is_nter,
147 missed_cleavage_number,
148 semi_enzyme);
149 }
150
151 unsigned int nb_pos = position_list.size();
152 if(nb_pos > 0)
153 {
154 // loop to find 1 to n-1 AA modification combinations
155 unsigned int comb_size = 1;
156 while((comb_size < nb_pos) && (comb_size <= m_maxNumberMod))
157 {
158 do
159 {
160 // std::cout << std::string(being,begin + comb_size) <<
161 // std::endl;
162 Peptide new_peptide(*(peptide_sp_original.get()));
163 for(unsigned int i = 0; i < comb_size; i++)
164 {
165 new_peptide.addAaModification(mp_mod, position_list[i]);
166 }
167 PeptideSp new_peptide_sp = new_peptide.makePeptideSp();
168 m_sink->setPeptideSp(sequence_database_id,
169 protein_sp,
170 is_decoy,
171 new_peptide_sp,
172 start,
173 is_nter,
174 missed_cleavage_number,
175 semi_enzyme);
176 }
177 while(next_combination(position_list.begin(),
178 position_list.begin() + comb_size,
179 position_list.end()));
180 comb_size++;
181 }
182
183 if(nb_pos <= m_maxNumberMod)
184 {
185 // the last combination : all aa are modified :
186 Peptide new_peptide(*(peptide_sp_original.get()));
187 for(unsigned int i = 0; i < nb_pos; i++)
188 {
189 new_peptide.addAaModification(mp_mod, position_list[i]);
190 }
191 PeptideSp new_peptide_sp = new_peptide.makePeptideSp();
192 m_sink->setPeptideSp(sequence_database_id,
193 protein_sp,
194 is_decoy,
195 new_peptide_sp,
196 start,
197 is_nter,
198 missed_cleavage_number,
199 semi_enzyme);
200 }
201 }
202 }
203 else
204 {
205 // no modification
206 m_sink->setPeptideSp(sequence_database_id,
207 protein_sp,
208 is_decoy,
209 peptide_sp_original,
210 start,
211 is_nter,
212 missed_cleavage_number,
213 semi_enzyme);
214 }
215}
216
217} // 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:137
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