libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
"
32
#include "
pappsomspp/core/pappsoexception.h
"
33
#include "
pappsomspp/core/utils.h
"
34
35
using namespace
pappso
;
36
37
GrpGroup::GrpGroup
(
GrpSubGroupSp
&grpSubGroupSp)
38
{
39
m_peptideSet
.addAll(grpSubGroupSp.get()->
getPeptideSet
());
40
m_subGroupList
.push_back(grpSubGroupSp);
41
m_mapPeptideToSubGroupSet
.add(grpSubGroupSp.get());
42
}
43
GrpGroup::GrpGroup
(
const
GrpGroup
&other)
44
:
m_subGroupList
(other.
m_subGroupList
),
45
m_peptideSet
(other.
m_peptideSet
),
46
m_mapPeptideToSubGroupSet
(other.
m_mapPeptideToSubGroupSet
)
47
{
48
}
49
50
GrpGroup::~GrpGroup
()
51
{
52
}
53
54
std::vector<GrpSubGroupSpConst>
55
GrpGroup::getGrpSubGroupSpList
()
const
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
65
const
std::list<GrpSubGroupSp> &
66
GrpGroup::getSubGroupSpList
()
const
67
{
68
return
m_subGroupList
;
69
}
70
71
const
GrpPeptideSet
&
72
GrpGroup::getGrpPeptideSet
()
const
73
{
74
return
m_peptideSet
;
75
}
76
unsigned
int
77
GrpGroup::getGroupNumber
()
const
78
{
79
return
m_groupNumber
;
80
}
81
const
QString
82
GrpGroup::getGroupingId
()
const
83
{
84
if
(
m_groupNumber
== 0)
85
{
86
return
""
;
87
}
88
return
QString(
"%1"
).arg(
Utils::getLexicalOrderedString
(
m_groupNumber
));
89
}
90
bool
91
GrpGroup::operator<
(
const
GrpGroup
&other)
const
92
{
93
return
((*(
m_subGroupList
.begin()->get())) < (*(other.
m_subGroupList
.begin()->get())));
94
}
95
96
GrpGroupSp
97
GrpGroup::makeGrpGroupSp
()
98
{
99
return
std::make_shared<GrpGroup>(*
this
);
100
}
101
102
bool
103
GrpGroup::containsAny
(
const
GrpPeptideSet
&peptideSet)
const
104
{
105
106
return
m_peptideSet
.containsAny(peptideSet);
107
}
108
109
void
110
GrpGroup::addGroup
(
GrpGroup
*p_group_to_add)
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
123
void
124
GrpGroup::check
()
const
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
146
void
147
GrpGroup::addSubGroupSp
(
const
GrpSubGroupSp
&grpSubGroupSp)
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
233
void
234
GrpGroup::setGroupNumber
(
unsigned
int
i)
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
247
void
248
GrpGroup::numbering
()
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
270
bool
271
GrpGroup::removeFirstNonInformativeSubGroup
()
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
318
bool
319
GrpGroup::removeNonInformativeSubGroups
()
320
{
321
qDebug() <<
"GrpGroup::removeNonInformativeSubGroups begin"
;
322
if
(
removeFirstNonInformativeSubGroup
())
323
{
324
while
(
removeFirstNonInformativeSubGroup
())
325
{
326
qDebug() <<
"GrpGroup::removeNonInformativeSubGroups while"
;
327
}
328
}
329
else
330
{
331
return
false
;
332
}
333
return
true
;
334
}
pappso::GrpGroup::makeGrpGroupSp
GrpGroupSp makeGrpGroupSp()
Definition
grpgroup.cpp:97
pappso::GrpGroup::check
void check() const
Definition
grpgroup.cpp:124
pappso::GrpGroup::removeNonInformativeSubGroups
bool removeNonInformativeSubGroups()
Definition
grpgroup.cpp:319
pappso::GrpGroup::setGroupNumber
void setGroupNumber(unsigned int i)
Definition
grpgroup.cpp:234
pappso::GrpGroup::getGroupNumber
unsigned int getGroupNumber() const
Definition
grpgroup.cpp:77
pappso::GrpGroup::containsAny
bool containsAny(const GrpPeptideSet &peptideSet) const
Definition
grpgroup.cpp:103
pappso::GrpGroup::removeFirstNonInformativeSubGroup
bool removeFirstNonInformativeSubGroup()
Definition
grpgroup.cpp:271
pappso::GrpGroup::m_subGroupList
std::list< GrpSubGroupSp > m_subGroupList
Definition
grpgroup.h:48
pappso::GrpGroup::GrpGroup
GrpGroup(GrpSubGroupSp &grpSubGroupSp)
Definition
grpgroup.cpp:37
pappso::GrpGroup::m_groupNumber
unsigned int m_groupNumber
Definition
grpgroup.h:49
pappso::GrpGroup::m_mapPeptideToSubGroupSet
GrpMapPeptideToSubGroupSet m_mapPeptideToSubGroupSet
Definition
grpgroup.h:52
pappso::GrpGroup::getGrpPeptideSet
const GrpPeptideSet & getGrpPeptideSet() const
Definition
grpgroup.cpp:72
pappso::GrpGroup::numbering
void numbering()
Definition
grpgroup.cpp:248
pappso::GrpGroup::getSubGroupSpList
const std::list< GrpSubGroupSp > & getSubGroupSpList() const
Definition
grpgroup.cpp:66
pappso::GrpGroup::addSubGroupSp
void addSubGroupSp(const GrpSubGroupSp &grpSubGroupSp)
Definition
grpgroup.cpp:147
pappso::GrpGroup::addGroup
void addGroup(GrpGroup *p_group_to_add)
Definition
grpgroup.cpp:110
pappso::GrpGroup::operator<
bool operator<(const GrpGroup &other) const
Definition
grpgroup.cpp:91
pappso::GrpGroup::m_peptideSet
GrpPeptideSet m_peptideSet
Definition
grpgroup.h:50
pappso::GrpGroup::~GrpGroup
~GrpGroup()
Definition
grpgroup.cpp:50
pappso::GrpGroup::getGroupingId
const QString getGroupingId() const
Definition
grpgroup.cpp:82
pappso::GrpGroup::getGrpSubGroupSpList
std::vector< GrpSubGroupSpConst > getGrpSubGroupSpList() const
Definition
grpgroup.cpp:55
pappso::GrpPeptideSet
Definition
grppeptideset.h:36
pappso::GrpSubGroupSet
Definition
grpsubgroupset.h:34
pappso::GrpSubGroupSet::contains
bool contains(GrpSubGroup *get) const
Definition
grpsubgroupset.cpp:87
pappso::GrpSubGroupSet::erase
std::list< GrpSubGroup * >::iterator erase(std::list< GrpSubGroup * >::iterator it)
Definition
grpsubgroupset.h:53
pappso::GrpSubGroupSet::printInfos
const QString printInfos() const
Definition
grpsubgroupset.cpp:136
pappso::GrpSubGroupSet::m_grpSubGroupPtrList
std::list< GrpSubGroup * > m_grpSubGroupPtrList
Definition
grpsubgroupset.h:38
pappso::GrpSubGroup
Definition
grpsubgroup.h:43
pappso::GrpSubGroup::getPeptideSet
const GrpPeptideSet & getPeptideSet() const
Definition
grpsubgroup.cpp:132
pappso::GrpSubGroup::includes
bool includes(const GrpSubGroup *p_subgroup) const
Definition
grpsubgroup.cpp:163
pappso::GrpSubGroup::getFirstAccession
const QString & getFirstAccession() const
Definition
grpsubgroup.cpp:223
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::Utils::getLexicalOrderedString
static const QString getLexicalOrderedString(unsigned int num)
Definition
utils.cpp:72
grpexperiment.h
grpgroup.h
grppeptide.h
grppeptideset.h
grpsubgroup.h
grpsubgroupset.h
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappso::GrpSubGroupSp
std::shared_ptr< GrpSubGroup > GrpSubGroupSp
Definition
grpsubgroup.h:39
pappso::GrpGroupSp
std::shared_ptr< GrpGroup > GrpGroupSp
Definition
grpgroup.h:39
pappsoexception.h
utils.h
pappsomspp
core
grouping
grpgroup.cpp
Generated on
for libpappsomspp by
1.17.0