libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
psmfileappend.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/processing/cbor/psm/psmfileappend.cpp
3 * \date 10/07/2025
4 * \author Olivier Langella
5 * \brief append many PSM cbor file into a single one
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 "psmfileappend.h"
30
32{
33 mp_output = p_output;
34
35 mp_output->startMap();
36
37 mpa_temporaryDirectory = new QTemporaryDir();
38 mpa_temporaryDirectory->setAutoRemove(false);
39}
40
45
46void
48 [[maybe_unused]])
49{
51 {
52 mp_output->append("informations");
53 mp_output->writeCborMap(m_cborInformations);
54 m_isInformations = true;
55 }
56}
57
58void
64
65
66void
68{
69
70
71 qDebug();
72 mp_output->append("parameter_map");
73 mp_output->writeCborMap(m_outputParameterMap);
74
75
76 if(!m_outputTargetFastaFiles.isEmpty())
77 {
78 mp_output->append("target_fasta_files");
80 }
81 if(!m_outputDecoyFastaFiles.isEmpty())
82 {
83 mp_output->append("decoy_fasta_files");
85 }
86
87 mp_output->append("protein_map");
88 m_proteinMap.writeMap(*mp_output);
89
90 qDebug();
91 mp_output->append("sample_list");
92 mp_output->startArray();
93 for(auto &tmp_sample : m_sampleStorageList)
94 {
95 QFile store_sample_file(tmp_sample.temporaryFile);
96 store_sample_file.open(QIODevice::ReadOnly);
97 CborStreamReader tmp_reader(&store_sample_file);
98 if(tmp_reader.isTag() && tmp_reader.toTag() == QCborKnownTags::Signature)
99 tmp_reader.next();
100 QCborMap cbor_sample;
101 if(!tmp_reader.readCborMap(cbor_sample))
102 {
104 QObject::tr("ERROR writing sample %1").arg(tmp_sample.fileId));
105 }
106 mp_output->writeCborMap(cbor_sample);
107 store_sample_file.close();
108 }
109 mp_output->endArray();
110
111
112 qDebug();
113 mp_output->endMap();
114}
115
116void
118{
119 for(auto cbor_key : m_cborParameterMap.keys())
120 {
121 if(!m_outputParameterMap.contains(cbor_key))
122 {
123 m_outputParameterMap.insert(cbor_key, m_cborParameterMap.value(cbor_key));
124 }
125 }
126}
127
128void
135
136void
138{
139 QCborMap cbor_current_sample;
140
141 mpa_cborReader->readCborMap(cbor_current_sample);
142
143 SampleStorage sample_file;
144 sample_file.fileId = cbor_current_sample.value("name").toString();
145 QString sample_name = sample_file.fileId;
146 auto it = std::find_if(m_sampleStorageList.begin(),
148 [sample_name](const SampleStorage &sample) {
149 if(sample.fileId == sample_name)
150 return true;
151 return false;
152 });
153 if(it != m_sampleStorageList.end())
154 {
156 QObject::tr("adding the same sample twice is forbidden %1").arg(sample_name));
157 }
158 sample_file.temporaryFile =
159 mpa_temporaryDirectory->filePath(QString("file_%1").arg(m_sampleStorageList.size()));
160 m_sampleStorageList.push_back(sample_file);
161
162 QFile store_sample_file(sample_file.temporaryFile);
163 store_sample_file.open(QIODevice::WriteOnly);
164 CborStreamWriter tmp_writer(&store_sample_file);
165 tmp_writer.writeCborMap(cbor_current_sample);
166 store_sample_file.close();
167}
bool readCborMap(QCborMap &cbor_map)
void writeCborMap(const QCborMap &cbor_map)
void informationsReady(pappso::UiMonitorInterface &monitor) override
void readSample(pappso::UiMonitorInterface &monitor) override
pappso::cbor::CborStreamWriter * mp_output
std::vector< SampleStorage > m_sampleStorageList
PsmFileAppend(pappso::cbor::CborStreamWriter *p_output)
void fastaFilesReady(pappso::UiMonitorInterface &monitor) override
void parameterMapReady(pappso::UiMonitorInterface &monitor) override