libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
sagefilereader.cpp
Go to the documentation of this file.
1/**
2 * \file input/sage/sagefilereader.cpp
3 * \date 11/10/2024
4 * \author Olivier Langella
5 * \brief read data files from Sage output containin multiple samples
6 */
7
8/*******************************************************************************
9 * Copyright (c) 2024 Olivier Langella
10 *<Olivier.Langella@universite-paris-saclay.fr>.
11 *
12 * This file is part of i2MassChroQ.
13 *
14 * i2MassChroQ is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * i2MassChroQ is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with i2MassChroQ. If not, see <http://www.gnu.org/licenses/>.
26 *
27 ******************************************************************************/
28
29#include "sagefilereader.h"
30#include "sagereader.h"
34#include <QJsonObject>
35#include <QJsonArray>
36#include <QDir>
37#include <QCborValue>
38
39namespace pappso
40{
41namespace cbor
42{
43namespace psm
44{
45
48 const QFileInfo &sage_json_file)
49 : m_sageJsonFile(sage_json_file)
50{
51 qDebug() << m_sageJsonFile.absoluteFilePath() << "'";
52 try
53 {
54
55 mp_cborWriter = p_output;
56
57 mp_cborWriter->startMap();
58 mp_cborWriter->writeInformations(
59 "sage_file_reader", Utils::getVersion(), "psm", "sage reader");
60
61 QDir::setCurrent(sage_json_file.absolutePath());
62 readJson();
63 mp_cborWriter->append("parameter_map");
64 mp_cborWriter->startMap();
65 mp_cborWriter->append("sage");
66 QCborValue::fromJsonValue(m_jsonData.object()).toCbor(*mp_cborWriter);
67 mp_cborWriter->endMap();
68
69 p_monitor->setStatus(
70 QObject::tr("reading Sage json file %1").arg(sage_json_file.absoluteFilePath()));
71
72 // "decoy_tag": "rev_",
73 // "generate_decoys": true,
74 // "target_fasta_files": ["zea_mays.fasta", "contaminant.fasta"],
75 //"decoy_fasta_files": ["rev_zea_mays.fasta", "rev_contaminant.fasta"],
76
77 mp_cborWriter->append("target_fasta_files");
79
80 SageReader sage_reader(p_monitor, mp_cborWriter, *this, sage_json_file.absoluteFilePath());
81 sage_reader.read();
82
83 // mp_cborWriter->append("protein_map");
84 // sage_reader.getPsmProteinMap().
85
86 mp_cborWriter->endMap();
87 }
89 {
90 throw err;
91 }
92 catch(pappso::PappsoException &other_err)
93 {
94 throw pappso::PappsoException(QObject::tr("Error reading Sage JSON file %1:\n%2")
95 .arg(m_sageJsonFile.absoluteFilePath())
96 .arg(other_err.qwhat()));
97 }
98}
99
100
104
105
106void
108{
109 QFile mfile(m_sageJsonFile.absoluteFilePath());
110 if(!mfile.open(QFile::ReadOnly))
111 {
113 QObject::tr("Unable to read Sage JSON file %1").arg(m_sageJsonFile.absoluteFilePath()));
114 }
115 QByteArray iContents = mfile.readAll();
116
117 QJsonParseError parseError;
118 m_jsonData = QJsonDocument::fromJson(iContents, &parseError);
119 if(parseError.error != QJsonParseError::NoError)
120 {
121 throw pappso::ExceptionNotRecognized(QObject::tr("Error reading Sage JSON file %1 at %2:%3")
122 .arg(m_sageJsonFile.absoluteFilePath())
123 .arg(parseError.offset)
124 .arg(parseError.errorString()));
125 }
126
127 QJsonValue mzml_value = m_jsonData.object().value("mzml_paths");
128
129 if(mzml_value.isNull())
130 {
132 QObject::tr("Sage JSON file %1 does not contain mzml_paths")
133 .arg(m_sageJsonFile.absoluteFilePath()));
134 }
135 for(const QJsonValue &value : m_jsonData.object().value("mzml_paths").toArray())
136 {
137 qDebug() << value.toString();
138
139 // MsRunSp msrun_sp = p_project->getMsRunStore().getInstance(value.toString());
141 {QFileInfo(value.toString()).fileName(), QFileInfo(value.toString()).absoluteFilePath()});
142 }
143
144
145 m_sageVersion = m_jsonData.object().value("version").toString();
146
147
148 QJsonObject sage_object = m_jsonData.object();
149
150
151 QJsonObject database = sage_object.value("database").toObject();
152
153 m_decoyTag = database.value("decoy_tag").toString();
154 m_generateDecoy = database.value("generate_decoy").toBool();
155 m_targetFastaFile << database.value("fasta").toString();
156}
157
158const QJsonDocument &
160{
161 return m_jsonData;
162}
163
164
165QString
166SageFileReader::getMsRunSpWithFileName(const QString &msrun_filename) const
167{
168 auto it = m_mapFilePath2MsRunSp.find(msrun_filename);
169 if(it != m_mapFilePath2MsRunSp.end())
170 return it->second;
171
172
173 throw pappso::PappsoException(QObject::tr("msrun filename %1 not found").arg(msrun_filename));
174}
175
176} // namespace psm
177} // namespace cbor
178} // namespace pappso
excetion to use when an item type is not recognized
virtual const QString & qwhat() const
virtual void setStatus(const QString &status)=0
current status of the process
static QString getVersion()
Definition utils.cpp:650
overrides QCborStreamWriter base class to provide convenient functions
SageFileReader(pappso::UiMonitorInterface *p_monitor, pappso::cbor::CborStreamWriter *p_output, const QFileInfo &sage_json_file)
main function to convert Sage results to CBOR output
std::map< QString, QString > m_mapFilePath2MsRunSp
pappso::cbor::CborStreamWriter * mp_cborWriter
QString getMsRunSpWithFileName(const QString &msrun_filename) const
const QJsonDocument & getJsonDocument() const
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39