libpappsomspp
Library for mass spectrometry
grpsubgroup.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 "grpsubgroup.h"
27#include "grppeptideset.h"
28#include "../pappsoexception.h"
29#include "../utils.h"
30
31
32namespace pappso
33{
34
35
36GrpSubGroup::GrpSubGroup(GrpProtein *p_protein) : m_peptidePtrList(p_protein)
37{
38 m_grpProteinPtrList.push_back(p_protein);
39}
40
42 : m_grpProteinPtrList(other.m_grpProteinPtrList),
43 m_peptidePtrList(other.m_peptidePtrList)
44{
45}
46
47unsigned int
49{
50 return m_groupNumber;
51}
52unsigned int
54{
55 return m_subGroupNumber;
56}
57const std::vector<GrpProtein *> &
59{
61}
62const QString
64{
65 if(m_groupNumber == 0)
66 {
67 return "";
68 }
69 return QString("%1.%2")
72}
73unsigned int
75{
76 unsigned int max = 0;
77 for(GrpProtein *p_protein : m_grpProteinPtrList)
78 {
79 if(max < p_protein->getCount())
80 {
81 max = p_protein->getCount();
82 }
83 }
84 return max;
85}
86bool
87GrpSubGroup::operator<(const GrpSubGroup &other) const
88{
90 {
91 if(maxCount() == other.maxCount())
92 {
93 if(m_grpProteinPtrList.size() == other.m_grpProteinPtrList.size())
94 {
95 // compare peptide set surface ?
96 // alphabetic order taken into account
97 return ((*(m_grpProteinPtrList.begin()))->getAccession() <
98 (*(other.m_grpProteinPtrList.begin()))->getAccession());
99 }
100 else
101 {
102 // if there is same peptide size evidence, then perhaps it's
103 // better to consider that
104 // the best group is the one that include more proteins
105 return (m_grpProteinPtrList.size() >
106 other.m_grpProteinPtrList.size());
107 }
108 }
109 else
110 {
111 // counts are evidences of the presence of a subgroup
112 // the fewer is the count, the weaker is the subgroup
113 return (maxCount() > other.maxCount());
114 }
115 }
116 else
117 {
118 // peptides are evidences of the presence of a subgroup
119 // the fewer is the peptide list, the weaker is the subgroup
120 return (m_peptidePtrList.size() > other.m_peptidePtrList.size());
121 }
122}
123
125{
126}
129{
130 return std::make_shared<GrpSubGroup>(*this);
131}
132
133const GrpPeptideSet &
135{
136 return m_peptidePtrList;
137}
138
139bool
141{
142 qDebug() << "GrpSubGroup::merge begin " << m_grpProteinPtrList.size() << " "
143 << this->getFirstAccession() << " "
144 << p_subgroup->getFirstAccession();
145 // if (this == p_subgroup) {
146 // return true;
147 //}
148 if(p_subgroup->m_peptidePtrList == m_peptidePtrList)
149 {
150 // m_grpProteinPtrList.splice (m_grpProteinPtrList.end(),
151 // p_subgroup->m_grpProteinPtrList);
153 p_subgroup->m_grpProteinPtrList.begin(),
154 p_subgroup->m_grpProteinPtrList.end());
155 // m_grpProteinPtrList.insert (m_grpProteinPtrList.end(),
156 // p_subgroup->m_grpProteinPtrList.begin(),p_subgroup->m_grpProteinPtrList.end());
157 return true;
158 }
159 else
160 {
161 return false;
162 }
163}
164
165bool
166GrpSubGroup::includes(const GrpSubGroup *p_subgroup) const
167{
169 {
170 return true;
171 }
172 else
173 {
174 return false;
175 }
176}
177
178void
180{
181 m_groupNumber = i;
182 for(auto &&p_protein : m_grpProteinPtrList)
183 {
184 p_protein->setGroupNumber(i);
185 }
186}
187
188void
190{
192 for(auto &&p_protein : m_grpProteinPtrList)
193 {
194 p_protein->setSubGroupNumber(i);
195 }
196}
197
198void
200{
201 qDebug() << "GrpSubGroup::numbering begin";
202
203 // sort proteins by accession numbers :
204 // m_grpProteinPtrList.sort([](GrpProtein * first, GrpProtein * second) {
205 // return (first->getAccession() < second->getAccession()) ;
206 //});
207 std::sort(m_grpProteinPtrList.begin(),
209 [](GrpProtein *first, GrpProtein *second) {
210 return (first->getAccession() < second->getAccession());
211 });
212 // list unique removes all but the first element from every consecutive group
213 // of equal elements in the container
214 // m_grpProteinPtrList.unique();
215
216
217 unsigned int i = 1;
218 for(auto &&p_protein : m_grpProteinPtrList)
219 {
220 p_protein->setRank(i);
221 i++;
222 }
223 qDebug() << "GrpSubGroup::numbering end";
224}
225const QString &
227{
228 auto it = m_grpProteinPtrList.begin();
229 if(it == m_grpProteinPtrList.end())
230 {
231 throw PappsoException(QObject::tr("m_grpProteinPtrList is empty"));
232 }
233 else
234 {
235 return (*it)->getAccession();
236 }
237}
238
239std::size_t
241{
242 return m_peptidePtrList.size();
243}
244
245} // namespace pappso
unsigned int size() const
Definition: grppeptideset.h:54
bool biggerAndContainsAll(const GrpPeptideSet &peptideSet) const
bool operator<(const GrpSubGroup &other) const
sort subgroups between each other a subgroup containing less peptides is weaker (less) than the other
Definition: grpsubgroup.cpp:87
std::vector< GrpProtein * > m_grpProteinPtrList
Definition: grpsubgroup.h:45
unsigned int getSubGroupNumber() const
Definition: grpsubgroup.cpp:53
unsigned int getGroupNumber() const
Definition: grpsubgroup.cpp:48
void setSubGroupNumber(unsigned int i)
const GrpPeptideSet & getPeptideSet() const
GrpSubGroup(GrpProtein *p_protein)
Definition: grpsubgroup.cpp:36
const QString getGroupingId() const
Definition: grpsubgroup.cpp:63
void setGroupNumber(unsigned int i)
bool includes(const GrpSubGroup *p_subgroup) const
std::size_t peptideListSize() const
unsigned int maxCount() const
Definition: grpsubgroup.cpp:74
unsigned int m_groupNumber
Definition: grpsubgroup.h:48
const QString & getFirstAccession() const
bool merge(GrpSubGroup *p_subgroup)
unsigned int m_subGroupNumber
Definition: grpsubgroup.h:47
const std::vector< GrpProtein * > & getGrpProteinList() const
Definition: grpsubgroup.cpp:58
GrpPeptideSet m_peptidePtrList
Definition: grpsubgroup.h:46
GrpSubGroupSp makeGrpSubGroupSp()
static const QString getLexicalOrderedString(unsigned int num)
Definition: utils.cpp:52
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
@ max
maximum of intensities