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