libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
grpexperiment.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 "grpexperiment.h"
26#include "grpprotein.h"
27#include "grppeptide.h"
28
29#include "grpgroup.h"
30#include "grpsubgroup.h"
32
33#include <QObject>
34
35using namespace pappso;
36
41
45void
50
51void
53{
54 GrpPeptideSet peptide_set(sp_protein.get());
55 m_grpPostGroupingProteinListRemoval.addAll(peptide_set);
56}
57
58
59void
61{
62 GrpPeptideSet peptide_set(sp_protein.get());
63 m_grpPreGroupingProteinListRemoval.addAll(peptide_set);
64}
65
66std::vector<GrpGroupSpConst>
68{
69 std::vector<GrpGroupSpConst> grp_list;
70 for(GrpGroupSp group : m_grpGroupSpList)
71 {
72 grp_list.push_back(group);
73 }
74 return grp_list;
75}
76
78GrpExperiment::getGrpProteinSp(const QString &accession, const QString &description)
79{
80 GrpProtein grpProtein(accession, description);
81 auto insertedPair = m_mapProteins.insert(
82 std::pair<QString, GrpProteinSp>(accession, std::make_shared<GrpProtein>(grpProtein)));
83 if(insertedPair.second)
84 {
85 m_grpProteinList.push_back(insertedPair.first->second);
86 m_remainingGrpProteinList.push_back(insertedPair.first->second.get());
87 }
88 return (insertedPair.first->second);
89}
90
93 const QString &sequence,
94 pappso_double mass)
95{
96 proteinSp.get()->countPlus();
97 GrpPeptideSp sp_grppeptide = std::make_shared<GrpPeptide>(GrpPeptide(sequence, mass));
98
99 auto insertedPair =
100 m_mapPeptides.insert(std::pair<QString, std::map<unsigned long, GrpPeptideSp>>(
101 sp_grppeptide.get()->m_sequence, std::map<unsigned long, GrpPeptideSp>()));
102 auto secondInsertedPair = insertedPair.first->second.insert(
103 std::pair<unsigned long, GrpPeptideSp>((unsigned long)(mass * 100), sp_grppeptide));
104 if(secondInsertedPair.second)
105 {
106 m_grpPeptideList.push_back(secondInsertedPair.first->second);
107 }
108 proteinSp.get()->push_back(secondInsertedPair.first->second.get());
109 return (secondInsertedPair.first->second);
110}
111
112void
114{
115 qDebug() << "GrpExperiment::startGrouping begin";
116 if(mp_monitor != nullptr)
117 mp_monitor->startGrouping(m_remainingGrpProteinList.size(), m_grpPeptideList.size());
118 m_isGroupingStarted = true;
119 m_mapPeptides.clear();
120 m_mapProteins.clear();
121 qDebug() << "GrpExperiment::startGrouping sort protein list "
122 "m_remainingGrpProteinList.size() "
124 // m_remainingGrpProteinList.sort();
125 // m_remainingGrpProteinList.unique();
126
128 {
129 // TODO clean protein list to remove contaminant peptides before grouping
130 }
131
132
133 GrpMapPeptideToGroup grp_map_peptide_to_group;
134 qDebug() << "GrpExperiment::startGrouping grouping begin";
135 for(auto p_grpProtein : m_remainingGrpProteinList)
136 {
137 p_grpProtein->strip();
138 if(p_grpProtein->m_count == 0)
139 {
140 // no peptides : do not group this protein
141 }
142 else
143 {
144 GrpSubGroupSp grpSubGroupSp = GrpSubGroup(p_grpProtein).makeGrpSubGroupSp();
145
146 if(mp_monitor != nullptr)
147 mp_monitor->groupingProtein();
148 this->addSubGroupSp(grp_map_peptide_to_group, grpSubGroupSp);
149 }
150 }
151 grp_map_peptide_to_group.clear(m_grpGroupSpList);
152 qDebug() << "GrpExperiment::startGrouping grouping end";
153
154 qDebug() << "GrpExperiment::startGrouping grouping m_grpGroupSpList.size() "
155 << m_grpGroupSpList.size();
156
158 {
160 }
161
162 // post grouping protein group removal
163 // remove any group containing contaminants
164 m_grpGroupSpList.remove_if([this](GrpGroupSp &groupSp) {
165 return (groupSp.get()->containsAny(this->m_grpPostGroupingProteinListRemoval));
166 });
167
168
169 numbering();
170 if(mp_monitor != nullptr)
171 mp_monitor->stopGrouping();
172 // GrpGroup(this, *m_remainingGrpProteinList.begin());
173 qDebug() << "GrpExperiment::startGrouping end";
174}
175
176
178{
179 ContainsAny(const GrpPeptideSet &peptide_set) : _peptide_set(peptide_set)
180 {
181 }
182
183 typedef bool result_type;
184
185 bool
186 operator()(const GrpGroupSp &testGroupSp)
187 {
188 return testGroupSp.get()->containsAny(_peptide_set);
189 }
190
192};
193
194
195void
197 GrpSubGroupSp &grpSubGroupSp) const
198{
199 qDebug() << "GrpExperiment::addSubGroupSp begin " << grpSubGroupSp.get()->getFirstAccession();
200
201 std::list<GrpGroupSp> new_group_list;
202 grp_map_peptide_to_group.getGroupList(grpSubGroupSp.get()->getPeptideSet(), new_group_list);
203
204 if(new_group_list.size() == 0)
205 {
206 qDebug() << "GrpExperiment::addSubGroupSp create a new group";
207 // create a new group
208 GrpGroupSp sp_group = GrpGroup(grpSubGroupSp).makeGrpGroupSp();
209 // m_grpGroupSpList.push_back(sp_group);
210
211 grp_map_peptide_to_group.set(grpSubGroupSp.get()->getPeptideSet(), sp_group);
212 }
213 else
214 {
215 qDebug() << "GrpExperiment::addSubGroupSp fusion groupList.size() " << new_group_list.size();
216 // fusion group and add the subgroup
217 auto itGroup = new_group_list.begin();
218 GrpGroupSp p_keepGroup = *itGroup;
219 qDebug() << "GrpExperiment::addSubGroupSp "
220 "p_keepGroup->addSubGroupSp(grpSubGroupSp) "
221 << p_keepGroup.get();
222 p_keepGroup->addSubGroupSp(grpSubGroupSp);
223 grp_map_peptide_to_group.set(grpSubGroupSp.get()->getPeptideSet(), p_keepGroup);
224
225 itGroup++;
226 while(itGroup != new_group_list.end())
227 {
228 qDebug() << "GrpExperiment::addSubGroupSp p_keepGroup->addGroup(*itGroup) "
229 << itGroup->get();
230 p_keepGroup->addGroup(itGroup->get());
231 grp_map_peptide_to_group.set((*itGroup)->getGrpPeptideSet(), p_keepGroup);
232
233 // m_grpGroupSpList.remove_if([itGroup](GrpGroupSp & groupSp) {
234 // return (itGroup->get() == groupSp.get()) ;
235 //});
236 itGroup++;
237 }
238 }
239
240 qDebug() << "GrpExperiment::addSubGroupSp end";
241}
242
243void
245{
246 qDebug() << "GrpExperiment::numbering begin";
247 if(mp_monitor != nullptr)
248 mp_monitor->startNumberingAllGroups(m_grpGroupSpList.size());
249 for(auto &&group_sp : m_grpGroupSpList)
250 {
251 group_sp.get()->numbering();
252 }
253 m_grpGroupSpList.sort(
254 [](GrpGroupSp &first, GrpGroupSp &second) { return ((*first.get()) < (*second.get())); });
255 unsigned int i = 1;
256 for(auto &&group_sp : m_grpGroupSpList)
257 {
258 group_sp.get()->setGroupNumber(i);
259 i++;
260 }
261
262 qDebug() << "GrpExperiment::numbering end";
263}
264
265std::vector<GrpProteinSpConst>
267{
268 std::vector<GrpProteinSpConst> grouped_protein_list;
270 {
271 throw PappsoException(QObject::tr("unable to get grouped protein list before grouping"));
272 }
273 for(auto &&protein_sp : m_grpProteinList)
274 {
275 if(protein_sp.get()->getGroupNumber() > 0)
276 {
277 grouped_protein_list.push_back(protein_sp);
278 }
279 }
280 return grouped_protein_list;
281}
282
283void
285{
286 qDebug() << "GrpExperiment::removeNonInformativeSubGroups begin";
287 if(mp_monitor != nullptr)
288 mp_monitor->startRemovingNonInformativeSubGroupsInAllGroups(m_grpGroupSpList.size());
289
290 std::list<GrpGroupSp> old_grp_group_sp_list(m_grpGroupSpList);
291 m_grpGroupSpList.clear();
292 auto it_group = old_grp_group_sp_list.begin();
293 while(it_group != old_grp_group_sp_list.end())
294 {
295 if(mp_monitor != nullptr)
296 mp_monitor->removingNonInformativeSubGroupsInGroup();
297 if(it_group->get()->removeNonInformativeSubGroups())
298 {
299 // need to regroup it
300 GrpGroupSp old_group_sp = *it_group;
301 GrpMapPeptideToGroup grp_map_peptide_to_group;
302
303 std::list<GrpSubGroupSp> dispatch_sub_group_set = old_group_sp.get()->getSubGroupSpList();
304 for(GrpSubGroupSp &grp_subgroup : dispatch_sub_group_set)
305 {
306 addSubGroupSp(grp_map_peptide_to_group, grp_subgroup);
307 }
308 grp_map_peptide_to_group.clear(m_grpGroupSpList);
309 }
310 else
311 {
312 qDebug() << "GrpExperiment::removeNonInformativeSubGroups no "
313 "removeNonInformativeSubGroups";
314 m_grpGroupSpList.push_back(*it_group);
315 }
316 it_group++;
317 }
318 if(mp_monitor != nullptr)
319 mp_monitor->stopRemovingNonInformativeSubGroupsInAllGroups(m_grpGroupSpList.size());
320
321 qDebug() << "GrpExperiment::removeNonInformativeSubGroups end";
322}
void addSubGroupSp(GrpMapPeptideToGroup &grp_map_peptide_to_group, GrpSubGroupSp &grpSubGroupSp) const
std::list< GrpGroupSp > m_grpGroupSpList
GrpPeptideSp & setGrpPeptide(const GrpProteinSp &proteinSp, const QString &sequence, pappso_double mass)
GrpGroupingMonitorInterface * mp_monitor
GrpProteinSp & getGrpProteinSp(const QString &acc, const QString &description)
void addPostGroupingGrpProteinSpRemoval(GrpProteinSp sp_protein)
protein to remove with its entire group after grouping is completed typically : to use with protein c...
std::list< GrpPeptideSp > m_grpPeptideList
std::vector< GrpGroupSpConst > getGrpGroupSpList() const
void setRemoveNonInformativeSubgroups(bool ok)
GrpPeptideSet m_grpPreGroupingProteinListRemoval
GrpExperiment(GrpGroupingMonitorInterface *p_monitor)
void addPreGroupingGrpProteinSpRemoval(GrpProteinSp sp_protein)
protein peptides to remove before grouping typically : remove protein contaminants in special metapro...
std::map< QString, std::map< unsigned long, GrpPeptideSp > > m_mapPeptides
std::list< GrpProteinSp > m_grpProteinList
GrpPeptideSet m_grpPostGroupingProteinListRemoval
std::list< GrpProtein * > m_remainingGrpProteinList
std::vector< GrpProteinSpConst > getGrpProteinSpList() const
std::map< QString, GrpProteinSp > m_mapProteins
GrpGroupSp makeGrpGroupSp()
Definition grpgroup.cpp:97
bool containsAny(const GrpPeptideSet &peptideSet) const
Definition grpgroup.cpp:103
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
void clear(std::list< GrpGroupSp > &grp_group_list)
void getGroupList(const GrpPeptideSet &peptide_set_in, std::list< GrpGroupSp > &impacted_group_list) const
get all groups concerned by a list of peptides
void set(const GrpPeptideSet &peptide_set_in, GrpGroupSp grp_group)
set peptide keys pointing on the group
const QString m_sequence
Definition grppeptide.h:50
void push_back(GrpPeptide *p_grpPeptide)
const GrpPeptideSet & getPeptideSet() const
const QString & getFirstAccession() const
GrpSubGroupSp makeGrpSubGroupSp()
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39
std::shared_ptr< GrpProtein > GrpProteinSp
Definition grpprotein.h:37
std::shared_ptr< GrpSubGroup > GrpSubGroupSp
Definition grpsubgroup.h:39
std::shared_ptr< GrpPeptide > GrpPeptideSp
Definition grppeptide.h:40
double pappso_double
A type definition for doubles.
Definition types.h:60
std::shared_ptr< GrpGroup > GrpGroupSp
Definition grpgroup.h:39
bool operator()(const GrpGroupSp &testGroupSp)
GrpPeptideSet _peptide_set
ContainsAny(const GrpPeptideSet &peptide_set)