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