libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
grpgroup.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 <QDebug>
26#include "grppeptideset.h"
27#include "grpsubgroup.h"
28#include "grppeptide.h"
29#include "grpsubgroupset.h"
30#include "grpgroup.h"
31#include "grpexperiment.h"
34
35using namespace pappso;
36
38{
39 m_peptideSet.addAll(grpSubGroupSp.get()->getPeptideSet());
40 m_subGroupList.push_back(grpSubGroupSp);
41 m_mapPeptideToSubGroupSet.add(grpSubGroupSp.get());
42}
49
53
54std::vector<GrpSubGroupSpConst>
56{
57 std::vector<GrpSubGroupSpConst> subgroup_list;
58 for(GrpSubGroupSp subgroup : m_subGroupList)
59 {
60 subgroup_list.push_back(subgroup);
61 }
62 return subgroup_list;
63};
64
65const std::list<GrpSubGroupSp> &
70
71const GrpPeptideSet &
73{
74 return m_peptideSet;
75}
76unsigned int
78{
79 return m_groupNumber;
80}
81const QString
83{
84 if(m_groupNumber == 0)
85 {
86 return "";
87 }
88 return QString("%1").arg(Utils::getLexicalOrderedString(m_groupNumber));
89}
90bool
91GrpGroup::operator<(const GrpGroup &other) const
92{
93 return ((*(m_subGroupList.begin()->get())) < (*(other.m_subGroupList.begin()->get())));
94}
95
98{
99 return std::make_shared<GrpGroup>(*this);
100}
101
102bool
103GrpGroup::containsAny(const GrpPeptideSet &peptideSet) const
104{
105
106 return m_peptideSet.containsAny(peptideSet);
107}
108
109void
111{
112 if(this == p_group_to_add)
113 {
114 throw PappsoException(QObject::tr("addGroup ERROR, this == p_group_to_add"));
115 }
116
117 for(GrpSubGroupSp &sgToAdd : p_group_to_add->m_subGroupList)
118 {
119 addSubGroupSp(sgToAdd);
120 }
121}
122
123void
125{
126 qDebug() << "GrpGroup::check begin ";
127 GrpSubGroupSet impacted_subgroup_list;
128 m_mapPeptideToSubGroupSet.getSubGroupSet(this->m_peptideSet, impacted_subgroup_list);
129
130 // if (impacted_subgroup_list.size() != this->m_subGroupList.size()) {
131 qDebug() << "GrpGroup::check impacted_subgroup_list.size() != "
132 "this->m_subGroupList.size()";
133 qDebug() << impacted_subgroup_list.printInfos();
134
135 for(auto sg : m_subGroupList)
136 {
137 qDebug() << sg->getFirstAccession() << " " << sg.get();
138 }
139 //}
140 qDebug() << m_mapPeptideToSubGroupSet.printInfos();
141 qDebug() << m_peptideSet.printInfos();
142 qDebug() << "GrpGroup::check end ";
143}
144
145
146void
148{
149
150 qDebug() << "GrpGroup::addSubGroupSp begin " << grpSubGroupSp.get()->getFirstAccession();
151
152
153 // look for impacted subgroups (containing peptides alsoe present in incoming
154 // subgroup
155 GrpSubGroupSet impacted_subgroup_list;
156 m_mapPeptideToSubGroupSet.getSubGroupSet(grpSubGroupSp.get()->getPeptideSet(),
157 impacted_subgroup_list);
158 if(impacted_subgroup_list.contains(grpSubGroupSp.get()))
159 {
160 throw PappsoException(QObject::tr("addSubGroupSp ERROR, subgroup %1 is already in group")
161 .arg(grpSubGroupSp.get()->getFirstAccession()));
162 }
163
164 // look for impacted subgroup equal to incoming subgroup and merge it and exit
165 qDebug() << "GrpGroup::addSubGroupSp look for impacted subgroup equal to "
166 "incoming subgroup and merge it and exit";
167 auto it_impacted_sg = impacted_subgroup_list.m_grpSubGroupPtrList.begin();
168 auto it_impacted_sg_end = impacted_subgroup_list.m_grpSubGroupPtrList.end();
169 while(it_impacted_sg != it_impacted_sg_end)
170 {
171
172 if((*it_impacted_sg)->merge(grpSubGroupSp.get()))
173 {
174 qDebug() << "GrpGroup::addSubGroupSp merge";
175 return;
176 }
177 it_impacted_sg++;
178 }
179
180 // look for impacted subgroup including totally the incoming subgroup and exit
181 qDebug() << "GrpGroup::addSubGroupSp look for impacted subgroup including "
182 "totally the incoming subgroup and exit";
183 it_impacted_sg = impacted_subgroup_list.m_grpSubGroupPtrList.begin();
184 while(it_impacted_sg != it_impacted_sg_end)
185 {
186 if((*it_impacted_sg)->includes(grpSubGroupSp.get()))
187 {
188 qDebug() << "GrpGroup::addSubGroupSp includes";
189 return;
190 }
191 it_impacted_sg++;
192 }
193
194 // look for impacted subgroup totally included in incoming subgroup and remove
195 // it
196 qDebug() << "GrpGroup::addSubGroupSp look for impacted subgroup totally "
197 "included in incoming subgroup and remove it";
198 it_impacted_sg = impacted_subgroup_list.m_grpSubGroupPtrList.begin();
199 while(it_impacted_sg != it_impacted_sg_end)
200 {
201 if(grpSubGroupSp.get()->includes((*it_impacted_sg)))
202 {
203 // this->removeSubGroup(*it_impacted_sg);
204 // it_impacted_sg = impacted_subgroup_list.erase(it_impacted_sg);
205 GrpSubGroup *sg_to_remove = *it_impacted_sg;
206 it_impacted_sg = impacted_subgroup_list.erase(it_impacted_sg);
207 m_mapPeptideToSubGroupSet.remove(sg_to_remove);
208 m_subGroupList.remove_if([sg_to_remove](GrpSubGroupSp &sub_groupSp) {
209 return (sg_to_remove == sub_groupSp.get());
210 });
211 // m_mapPeptideToSubGroupSet.check(m_subGroupList);
212 }
213 else
214 {
215 it_impacted_sg++;
216 }
217 }
218 qDebug() << "GrpGroup::addSubGroupSp finally add the new subgroup to current group";
219
220 // finally add the new subgroup to current group
221 m_subGroupList.push_back(grpSubGroupSp);
222 m_mapPeptideToSubGroupSet.add(grpSubGroupSp.get());
223 m_peptideSet.addAll(grpSubGroupSp.get()->getPeptideSet());
224
225
226 // check();
227 // m_mapPeptideToSubGroupSet.check(m_subGroupList);
228
229 qDebug() << "GrpGroup::addSubGroupSp end";
230}
231
232
233void
235{
236 qDebug() << "GrpGroup::setGroupNumber begin";
237 m_groupNumber = i;
238 for(auto &&sub_group_sp : m_subGroupList)
239 {
240 sub_group_sp->setGroupNumber(i);
241 }
242 m_peptideSet.setGroupNumber(i);
243 qDebug() << "GrpGroup::setGroupNumber end";
244}
245
246
247void
249{
250 qDebug() << "GrpGroup::numbering begin";
251
252 for(auto &&sub_group_sp : m_subGroupList)
253 {
254 sub_group_sp.get()->numbering();
255 }
256 m_subGroupList.sort(
257 [](GrpSubGroupSp &first, GrpSubGroupSp &second) { return ((*first.get()) < (*second.get())); });
258 unsigned int i = 1;
259 for(auto &&sub_group_sp : m_subGroupList)
260 {
261 sub_group_sp.get()->setSubGroupNumber(i);
262 i++;
263 }
264
265 m_peptideSet.numbering();
266 qDebug() << "GrpGroup::numbering end";
267}
268
269
270bool
272{
273 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup begin";
274 std::list<GrpSubGroup *> subgroup_list_to_remove;
275
276 for(auto &&sub_group_sp : m_subGroupList)
277 {
278 if(m_mapPeptideToSubGroupSet.hasSpecificPeptide(sub_group_sp.get()))
279 {
280 }
281 else
282 {
283 subgroup_list_to_remove.push_back(sub_group_sp.get());
284 }
285 }
286 if(subgroup_list_to_remove.size() == 0)
287 {
288 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup end false";
289 return false;
290 }
291
292 // sort subgroup to remove
293 subgroup_list_to_remove.sort(
294 [](GrpSubGroup *first, GrpSubGroup *second) { return ((*first) < (*second)); });
295
296 // remove the last one
297 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup "
298 "subgroup_list_to_remove.front()->peptideListSize() "
299 << subgroup_list_to_remove.front()->peptideListSize();
300 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup "
301 "subgroup_list_to_remove.back()->peptideListSize() "
302 << subgroup_list_to_remove.back()->peptideListSize();
303
304 // the first subgroup is weaker (less peptides or less protein than others)
305 GrpSubGroup *sg_to_remove = subgroup_list_to_remove.front();
306 m_mapPeptideToSubGroupSet.remove(sg_to_remove);
307 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup m_subGroupList.size() "
308 << m_subGroupList.size();
309 m_subGroupList.remove_if(
310 [sg_to_remove](GrpSubGroupSp &sub_groupSp) { return (sg_to_remove == sub_groupSp.get()); });
311 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup after remove if "
312 "m_subGroupList.size() "
313 << m_subGroupList.size();
314 qDebug() << "GrpGroup::removeFirstNonInformativeSubGroup end true";
315 return true;
316}
317
318bool
320{
321 qDebug() << "GrpGroup::removeNonInformativeSubGroups begin";
323 {
325 {
326 qDebug() << "GrpGroup::removeNonInformativeSubGroups while";
327 }
328 }
329 else
330 {
331 return false;
332 }
333 return true;
334}
GrpGroupSp makeGrpGroupSp()
Definition grpgroup.cpp:97
void check() const
Definition grpgroup.cpp:124
bool removeNonInformativeSubGroups()
Definition grpgroup.cpp:319
void setGroupNumber(unsigned int i)
Definition grpgroup.cpp:234
unsigned int getGroupNumber() const
Definition grpgroup.cpp:77
bool containsAny(const GrpPeptideSet &peptideSet) const
Definition grpgroup.cpp:103
bool removeFirstNonInformativeSubGroup()
Definition grpgroup.cpp:271
std::list< GrpSubGroupSp > m_subGroupList
Definition grpgroup.h:48
GrpGroup(GrpSubGroupSp &grpSubGroupSp)
Definition grpgroup.cpp:37
unsigned int m_groupNumber
Definition grpgroup.h:49
GrpMapPeptideToSubGroupSet m_mapPeptideToSubGroupSet
Definition grpgroup.h:52
const GrpPeptideSet & getGrpPeptideSet() const
Definition grpgroup.cpp:72
const std::list< GrpSubGroupSp > & getSubGroupSpList() const
Definition grpgroup.cpp:66
void addSubGroupSp(const GrpSubGroupSp &grpSubGroupSp)
Definition grpgroup.cpp:147
void addGroup(GrpGroup *p_group_to_add)
Definition grpgroup.cpp:110
bool operator<(const GrpGroup &other) const
Definition grpgroup.cpp:91
GrpPeptideSet m_peptideSet
Definition grpgroup.h:50
const QString getGroupingId() const
Definition grpgroup.cpp:82
std::vector< GrpSubGroupSpConst > getGrpSubGroupSpList() const
Definition grpgroup.cpp:55
bool contains(GrpSubGroup *get) const
std::list< GrpSubGroup * >::iterator erase(std::list< GrpSubGroup * >::iterator it)
const QString printInfos() const
std::list< GrpSubGroup * > m_grpSubGroupPtrList
const GrpPeptideSet & getPeptideSet() const
bool includes(const GrpSubGroup *p_subgroup) const
const QString & getFirstAccession() const
static const QString getLexicalOrderedString(unsigned int num)
Definition utils.cpp:72
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< GrpSubGroup > GrpSubGroupSp
Definition grpsubgroup.h:39
std::shared_ptr< GrpGroup > GrpGroupSp
Definition grpgroup.h:39