libpappsomspp
Library for mass spectrometry
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"
31
32
36
40
41std::pair<std::map<QString, pappso::cbor::psm::PsmProtein>::iterator, bool>
43{
44 return m_proteinMap.insert(
45 std::pair<QString, PsmProtein>(psm_protein.protein_sp.get()->getAccession(), psm_protein));
46}
47
48void
50{
51 // writer.append("protein_map");
52 writer.startMap(m_proteinMap.size()); // protein map
53 for(auto &protein_pair : m_proteinMap)
54 {
55 writer.append(protein_pair.first);
56
57 qDebug() << protein_pair.first;
58 writer.startMap(); // protein
59 writer.append("description");
60 writer.append(protein_pair.second.protein_sp.get()->getDescription());
61 writer.append("sequence");
62 writer.append(protein_pair.second.protein_sp.get()->getSequence());
63 writer.append("target");
64 writer.append(protein_pair.second.isTarget);
65 writer.append("contaminant");
66 writer.append(protein_pair.second.isContaminant);
67
68 if(!protein_pair.second.cborEval.isEmpty())
69 {
70 writer.append("eval");
71 writer.writeCborMap(protein_pair.second.cborEval);
72 }
73 writer.endMap(); // protein
74 }
75
76 writer.endMap(); // protein map
77}
78
79void
81{
82 PsmProtein psm_protein;
83 reader.enterContainer();
84 while(!reader.lastError() && reader.hasNext())
85 {
86 bool is_ok;
87
88 QString accession;
89 is_ok = reader.decodeString(accession);
90 qDebug() << accession;
91 if(is_ok)
92 {
93 reader.enterContainer();
94 pappso::Protein protein;
95 protein.setAccession(accession);
96 psm_protein.protein_sp = std::make_shared<pappso::Protein>(protein);
97 psm_protein.isContaminant = false;
98 psm_protein.isTarget = true;
99 auto it = m_proteinMap.insert(std::pair<QString, PsmProtein>(accession, psm_protein));
100
101 QString tag;
102 while(!reader.lastError() && reader.hasNext())
103 {
104 is_ok = reader.decodeString(tag);
105 qDebug() << tag;
106 if(is_ok)
107 {
108 if(tag == "description")
109 {
110 QString description;
111 is_ok = reader.decodeString(description);
112 qDebug() << description;
113 it.first->second.protein_sp.get()->setDescription(description);
114 }
115 else if(tag == "sequence")
116 {
117 QString sequence;
118 reader.decodeString(sequence);
119 it.first->second.protein_sp.get()->setSequence(sequence);
120 }
121 else if(tag == "target")
122 {
123 it.first->second.isTarget = reader.toBool();
124 reader.next();
125 }
126 else if(tag == "contaminant")
127 {
128 it.first->second.isContaminant = reader.toBool();
129 reader.next();
130 }
131 else if(tag == "eval")
132 {
133 reader.readCborMap(it.first->second.cborEval);
134 }
135 }
136 }
137 reader.leaveContainer();
138 }
139 else
140 {
141 // no accession
142 }
143 // reader.next();
144 // }
145 }
146 reader.leaveContainer();
147}
148
149std::size_t
151{
152 return m_proteinMap.size();
153}
154
157{
158 auto it = m_proteinMap.find(accession);
159
160 if(it == m_proteinMap.end())
161 {
162 throw pappso::ExceptionNotFound(QObject::tr("%1 accession not found").arg(accession));
163 }
164 return it->second;
165}
virtual void setAccession(const QString &accession)
Definition protein.cpp:132
bool readCborMap(QCborMap &cbor_map)
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...
void writeCborMap(const QCborMap &cbor_map)
std::map< QString, PsmProtein > m_proteinMap
const pappso::cbor::psm::PsmProtein & getByAccession(const QString &accession) const
std::pair< std::map< QString, pappso::cbor::psm::PsmProtein >::iterator, bool > insert(const PsmProtein &psm_protein)
void readMap(CborStreamReader &reader)
void writeMap(CborStreamWriter &writer) const
std::shared_ptr< Protein > protein_sp