libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
Loading...
Searching...
No Matches
psmproteinmap.cpp
Go to the documentation of this file.
1
/**
2
* \file pappsomspp/processing/cbor/psm/psmproteinmap.cpp
3
* \date 05/07/2025
4
* \author Olivier Langella
5
* \brief PAPPSO CBOR protein map
6
*/
7
8
/*******************************************************************************
9
* Copyright (c) 2025 Olivier Langella <Olivier.Langella@universite-paris-saclay.fr>.
10
*
11
* This file is part of PAPPSOms-tools.
12
*
13
* PAPPSOms-tools is free software: you can redistribute it and/or modify
14
* it under the terms of the GNU General Public License as published by
15
* the Free Software Foundation, either version 3 of the License, or
16
* (at your option) any later version.
17
*
18
* PAPPSOms-tools is distributed in the hope that it will be useful,
19
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21
* GNU General Public License for more details.
22
*
23
* You should have received a copy of the GNU General Public License
24
* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>.
25
*
26
******************************************************************************/
27
28
#include <QObject>
29
#include "
psmproteinmap.h
"
30
#include "
pappsomspp/core/exception/exceptionnotfound.h
"
31
32
33
pappso::cbor::psm::PsmProteinMap::PsmProteinMap
()
34
{
35
}
36
37
pappso::cbor::psm::PsmProteinMap::~PsmProteinMap
()
38
{
39
}
40
41
42
std::map<QString, pappso::cbor::psm::PsmProtein> &
43
pappso::cbor::psm::PsmProteinMap::getProteinMap
()
44
{
45
return
m_proteinMap
;
46
}
47
48
49
std::pair<std::map<QString, pappso::cbor::psm::PsmProtein>::iterator,
bool
>
50
pappso::cbor::psm::PsmProteinMap::insert
(
const
pappso::cbor::psm::PsmProtein
&psm_protein)
51
{
52
return
m_proteinMap
.insert(
53
std::pair<QString, PsmProtein>(psm_protein.
protein_sp
.get()->getAccession(), psm_protein));
54
}
55
56
void
57
pappso::cbor::psm::PsmProteinMap::writeMap
(
pappso::cbor::CborStreamWriter
&writer)
const
58
{
59
// writer.append("protein_map");
60
writer.startMap(
m_proteinMap
.size());
// protein map
61
for
(
auto
&protein_pair :
m_proteinMap
)
62
{
63
writer.append(protein_pair.first);
64
65
qDebug() << protein_pair.first;
66
writer.startMap();
// protein
67
writer.append(
"description"
);
68
writer.append(protein_pair.second.protein_sp.get()->getDescription());
69
writer.append(
"sequence"
);
70
writer.append(protein_pair.second.protein_sp.get()->getSequence());
71
writer.append(
"target"
);
72
writer.append(protein_pair.second.isTarget);
73
writer.append(
"contaminant"
);
74
writer.append(protein_pair.second.isContaminant);
75
76
if
(!protein_pair.second.cborEval.isEmpty())
77
{
78
writer.append(
"eval"
);
79
writer.
writeCborMap
(protein_pair.second.cborEval);
80
}
81
writer.endMap();
// protein
82
}
83
84
writer.endMap();
// protein map
85
}
86
87
void
88
pappso::cbor::psm::PsmProteinMap::readMap
(
pappso::cbor::CborStreamReader
&reader)
89
{
90
PsmProtein
psm_protein;
91
reader.enterContainer();
92
while
(!reader.lastError() && reader.hasNext())
93
{
94
bool
is_ok;
95
96
QString accession;
97
is_ok = reader.
decodeString
(accession);
98
qDebug() << accession;
99
if
(is_ok)
100
{
101
reader.enterContainer();
102
pappso::Protein
protein;
103
protein.
setAccession
(accession);
104
psm_protein.
protein_sp
= std::make_shared<pappso::Protein>(protein);
105
psm_protein.
isContaminant
=
false
;
106
psm_protein.
isTarget
=
true
;
107
auto
it =
m_proteinMap
.insert(std::pair<QString, PsmProtein>(accession, psm_protein));
108
109
QString tag;
110
while
(!reader.lastError() && reader.hasNext())
111
{
112
is_ok = reader.
decodeString
(tag);
113
qDebug() << tag;
114
if
(is_ok)
115
{
116
if
(tag ==
"description"
)
117
{
118
QString description;
119
is_ok = reader.
decodeString
(description);
120
qDebug() << description;
121
it.first->second.protein_sp.get()->setDescription(description);
122
}
123
else
if
(tag ==
"sequence"
)
124
{
125
QString sequence;
126
reader.
decodeString
(sequence);
127
it.first->second.protein_sp.get()->setSequence(sequence);
128
}
129
else
if
(tag ==
"target"
)
130
{
131
it.first->second.isTarget = reader.toBool();
132
reader.next();
133
}
134
else
if
(tag ==
"contaminant"
)
135
{
136
it.first->second.isContaminant = reader.toBool();
137
reader.next();
138
}
139
else
if
(tag ==
"eval"
)
140
{
141
reader.
readCborMap
(it.first->second.cborEval);
142
}
143
}
144
}
145
reader.leaveContainer();
146
}
147
else
148
{
149
// no accession
150
}
151
// reader.next();
152
// }
153
}
154
reader.leaveContainer();
155
}
156
157
std::size_t
158
pappso::cbor::psm::PsmProteinMap::size
()
const
159
{
160
return
m_proteinMap
.size();
161
}
162
163
const
pappso::cbor::psm::PsmProtein
&
164
pappso::cbor::psm::PsmProteinMap::getByAccession
(
const
QString &accession)
const
165
{
166
auto
it =
m_proteinMap
.find(accession);
167
168
if
(it ==
m_proteinMap
.end())
169
{
170
throw
pappso::ExceptionNotFound
(QObject::tr(
"%1 accession not found"
).arg(accession));
171
}
172
return
it->second;
173
}
174
175
void
176
pappso::cbor::psm::PsmProteinMap::merge
(
const
PsmProteinMap
&other_protein_map)
177
{
178
for
(
auto
&it_prot : other_protein_map.
m_proteinMap
)
179
{
180
m_proteinMap
.insert(std::pair<QString, PsmProtein>(it_prot.first, it_prot.second));
181
}
182
}
183
184
void
185
pappso::cbor::psm::PsmProteinMap::reduce
(
const
QStringList &accession_list)
186
{
187
std::map<QString, PsmProtein> new_protein_map;
188
189
for
(
const
QString &accession : accession_list)
190
{
191
new_protein_map.insert(std::pair<QString, PsmProtein>(accession,
getByAccession
(accession)));
192
}
193
m_proteinMap
= new_protein_map;
194
}
pappso::ExceptionNotFound
Definition
exceptionnotfound.h:32
pappso::Protein
Definition
protein.h:50
pappso::Protein::setAccession
virtual void setAccession(const QString &accession)
Definition
protein.cpp:132
pappso::cbor::CborStreamReader
simple override of the raw QCborStreamReader This adds convenient functions to put CBOR data into C++...
Definition
cborstreamreader.h:47
pappso::cbor::CborStreamReader::readCborMap
bool readCborMap(QCborMap &cbor_map)
transfer the entire current CBOR map to a QCborMap object
Definition
cborstreamreader.cpp:232
pappso::cbor::CborStreamReader::decodeString
bool decodeString(QString &the_str)
decode the current cbor value as a string the point to the next value the current value is decoded as...
Definition
cborstreamreader.cpp:48
pappso::cbor::CborStreamWriter
overrides QCborStreamWriter base class to provide convenient functions
Definition
cborstreamwriter.h:46
pappso::cbor::CborStreamWriter::writeCborMap
void writeCborMap(const QCborMap &cbor_map)
Definition
cborstreamwriter.cpp:179
pappso::cbor::psm::PsmProteinMap::~PsmProteinMap
virtual ~PsmProteinMap()
Definition
psmproteinmap.cpp:37
pappso::cbor::psm::PsmProteinMap::reduce
void reduce(const QStringList &accession_list)
reduce to protein accessions listed in input
Definition
psmproteinmap.cpp:185
pappso::cbor::psm::PsmProteinMap::size
std::size_t size() const
get protein map size
Definition
psmproteinmap.cpp:158
pappso::cbor::psm::PsmProteinMap::merge
void merge(const PsmProteinMap &other_protein_map)
merge with other protein map
Definition
psmproteinmap.cpp:176
pappso::cbor::psm::PsmProteinMap::m_proteinMap
std::map< QString, PsmProtein > m_proteinMap
Definition
psmproteinmap.h:111
pappso::cbor::psm::PsmProteinMap::getByAccession
const pappso::cbor::psm::PsmProtein & getByAccession(const QString &accession) const
retrieve a PsmProtein with its accession
Definition
psmproteinmap.cpp:164
pappso::cbor::psm::PsmProteinMap::getProteinMap
std::map< QString, PsmProtein > & getProteinMap()
Definition
psmproteinmap.cpp:43
pappso::cbor::psm::PsmProteinMap::insert
std::pair< std::map< QString, PsmProtein >::iterator, bool > insert(const PsmProtein &psm_protein)
standard map insert of a PsmProtein (accession is the key)
Definition
psmproteinmap.cpp:50
pappso::cbor::psm::PsmProteinMap::readMap
void readMap(CborStreamReader &reader)
reads the protein map from a cbor input stream
Definition
psmproteinmap.cpp:88
pappso::cbor::psm::PsmProteinMap::PsmProteinMap
PsmProteinMap()
Definition
psmproteinmap.cpp:33
pappso::cbor::psm::PsmProteinMap::writeMap
void writeMap(CborStreamWriter &writer) const
writes the protein map in a cbor output stream this output a CborMap structure directly in the output...
Definition
psmproteinmap.cpp:57
exceptionnotfound.h
psmproteinmap.h
pappso::cbor::psm::PsmProtein
Definition
psmproteinmap.h:46
pappso::cbor::psm::PsmProtein::isTarget
bool isTarget
Definition
psmproteinmap.h:48
pappso::cbor::psm::PsmProtein::isContaminant
bool isContaminant
Definition
psmproteinmap.h:49
pappso::cbor::psm::PsmProtein::protein_sp
std::shared_ptr< Protein > protein_sp
Definition
psmproteinmap.h:47
pappsomspp
core
processing
cbor
psm
psmproteinmap.cpp
Generated on
for libpappsomspp by
1.17.0