libpappsomspp
Library for mass spectrometry
grpmappeptidetosubgroupset.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#include <QDebug>
26#include "grppeptideset.h"
27
28#include "../pappsoexception.h"
29
30
31namespace pappso
32{
34{
35}
36
38{
39}
40
42 const GrpMapPeptideToSubGroupSet &other)
43 : m_mapPeptideToSubGroupSet(other.m_mapPeptideToSubGroupSet)
44{
45}
46unsigned int
47GrpMapPeptideToSubGroupSet::GrpMapPeptideToSubGroupSet::size() const
48{
49 return m_mapPeptideToSubGroupSet.size();
50}
51
52void
54 const GrpPeptideSet &peptide_set_in,
55 GrpSubGroupSet &impacted_subgroup_set) const
56{
57 qDebug() << "GrpMapPeptideToSubGroupSet::getSubGroupSet begin ";
58 auto it_peptide_end = peptide_set_in.m_peptidePtrList.end();
59 std::map<GrpPeptide *, GrpSubGroupSet>::const_iterator it_map_end =
61
62 for(auto it_peptide = peptide_set_in.m_peptidePtrList.begin();
63 it_peptide != it_peptide_end;
64 it_peptide++)
65 {
66 std::map<GrpPeptide *, GrpSubGroupSet>::const_iterator it_map =
67 m_mapPeptideToSubGroupSet.find(*it_peptide);
68 if(it_map != it_map_end)
69 {
70 impacted_subgroup_set.addAll(it_map->second);
71 }
72 }
73 qDebug() << "GrpMapPeptideToSubGroupSet::getSubGroupSet end ";
74}
75void
77 std::list<GrpSubGroupSp> &m_grpSubGroupSpList) const
78{
79 qDebug() << "GrpMapPeptideToSubGroupSet::std begin ";
81 qDebug() << "GrpMapPeptideToSubGroupSet::std before test.size() "
82 << test.size();
83
84 for(auto pair : m_mapPeptideToSubGroupSet)
85 {
86 qDebug() << "GrpMapPeptideToSubGroupSet::std before peptide "
87 << pair.first->getSequence() << " " << pair.first;
88 }
89
90 for(GrpSubGroupSp &sub_group_sp : m_grpSubGroupSpList)
91 {
92 test.remove(sub_group_sp.get());
93 }
94 qDebug() << "GrpMapPeptideToSubGroupSet::std after test.size() "
95 << test.size();
96
97 qDebug() << "GrpMapPeptideToSubGroupSet::std begin ";
98}
99
100void
102{
103 qDebug() << "GrpMapPeptideToSubGroupSet::remove begin "
104 << p_remove_sub_group->getFirstAccession();
105 // std::list<std::pair<GrpPeptide*, GrpSubGroupSet>>
106 // m_mapPeptideToSubGroupSet;
107 const GrpPeptideSet &peptide_set_in = p_remove_sub_group->getPeptideSet();
108
109 auto it_peptide_end = peptide_set_in.m_peptidePtrList.end();
110 std::map<GrpPeptide *, GrpSubGroupSet>::const_iterator it_map_end =
112
113 for(auto it_peptide = peptide_set_in.m_peptidePtrList.begin();
114 it_peptide != it_peptide_end;
115 it_peptide++)
116 {
117 std::map<GrpPeptide *, GrpSubGroupSet>::iterator it_map =
118 m_mapPeptideToSubGroupSet.find(*it_peptide);
119 if(it_map != it_map_end)
120 {
121 it_map->second.remove(p_remove_sub_group);
122 if(it_map->second.size() == 0)
123 {
124 m_mapPeptideToSubGroupSet.erase(it_map);
125 }
126 }
127 else
128 {
129 throw PappsoException(
130 QObject::tr("remove ERROR, peptide %1 from subgroup %2 not "
131 "referenced in GrpMapPeptideToSubGroupSet")
132 .arg((*it_peptide)->getSequence())
133 .arg(p_remove_sub_group->getFirstAccession()));
134 }
135 }
136
137 qDebug() << "GrpMapPeptideToSubGroupSet::remove end "
138 << p_remove_sub_group->getFirstAccession();
139}
140void
142{
143 qDebug()
144 << "GrpMapPeptideToSubGroupSet::add begin m_mapPeptideToSubGroupSet.size()"
146
147
148 const GrpPeptideSet &peptide_set_in = p_add_sub_group->getPeptideSet();
149
150 auto it_peptide_end = peptide_set_in.m_peptidePtrList.end();
151
152 for(auto it_peptide = peptide_set_in.m_peptidePtrList.begin();
153 it_peptide != it_peptide_end;
154 it_peptide++)
155 {
156 std::pair<std::map<GrpPeptide *, GrpSubGroupSet>::iterator, bool> ret =
158 std::pair<GrpPeptide *, GrpSubGroupSet>(*it_peptide,
159 GrpSubGroupSet()));
160 // if (ret.second==false) { => key already exists
161 ret.first->second.add(p_add_sub_group);
162 }
163
164 qDebug() << "GrpMapPeptideToSubGroupSet::add end";
165}
166
167
168bool
170 const GrpSubGroup *p_sub_group) const
171{
172 qDebug() << "GrpMapPeptideToSubGroupSet::hasSpecificPeptide begin";
173
174 const GrpPeptideSet &peptide_set_in = p_sub_group->getPeptideSet();
175
176 auto it_peptide_end = peptide_set_in.m_peptidePtrList.end();
177 std::map<GrpPeptide *, GrpSubGroupSet>::const_iterator it_map_end =
179
180 for(auto it_peptide = peptide_set_in.m_peptidePtrList.begin();
181 it_peptide != it_peptide_end;
182 it_peptide++)
183 {
184 std::map<GrpPeptide *, GrpSubGroupSet>::const_iterator it_map =
185 m_mapPeptideToSubGroupSet.find(*it_peptide);
186 if(it_map != it_map_end)
187 {
188 if(it_map->second.size() == 1)
189 {
190 return true;
191 }
192 }
193 else
194 {
195 throw PappsoException(
196 QObject::tr("hasSpecificPeptide ERROR, peptide %1 from subgroup %2 "
197 "not referenced in GrpMapPeptideToSubGroupSet")
198 .arg((*it_peptide)->getSequence())
199 .arg(p_sub_group->getFirstAccession()));
200 }
201 }
202
203 qDebug() << "GrpMapPeptideToSubGroupSet::hasSpecificPeptide end";
204 return false;
205}
206
207const QString
209{
210 QString infos;
211 auto itMap = m_mapPeptideToSubGroupSet.begin();
212 auto itMapEnd = m_mapPeptideToSubGroupSet.end();
213
214 while(itMap != itMapEnd)
215 {
216 infos.append(
217 itMap->first->getSequence() + " " +
218 QString("0x%1").arg(
219 (quintptr)itMap->first, QT_POINTER_SIZE * 2, 16, QChar('0')) +
220 "\n");
221 itMap++;
222 }
223
224 return infos;
225}
226
227} // namespace pappso
bool hasSpecificPeptide(const GrpSubGroup *get) const
tells if this subgroup contains a specific peptide
void check(std::list< GrpSubGroupSp > &m_grpSubGroupSpList) const
check function only usefull for testing purpose
void getSubGroupSet(const GrpPeptideSet &peptide_set_in, GrpSubGroupSet &impacted_subgroup_set) const
get all subgroups concerned by a list of peptides
void remove(GrpSubGroup *p_remove_sub_group)
removes in the map all references of the group to remove (p_remove_sub_group)
std::map< GrpPeptide *, GrpSubGroupSet > m_mapPeptideToSubGroupSet
void add(GrpSubGroup *p_add_sub_group)
add in the map all peptides of the subgroup to add
std::list< GrpPeptide * > m_peptidePtrList
Definition: grppeptideset.h:41
void addAll(const GrpSubGroupSet &other)
const GrpPeptideSet & getPeptideSet() const
const QString & getFirstAccession() const
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