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