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"
35#include <QJsonObject>
36#include <QJsonArray>
37#include <QDir>
38#include <QCborValue>
39
40namespace pappso
41{
42namespace cbor
43{
44namespace psm
45{
46
49 const QFileInfo &sage_json_file)
50 : m_sageJsonFile(sage_json_file)
51{
52 qDebug() << m_sageJsonFile.absoluteFilePath() << "'";
53 try
54 {
55
56 mp_cborWriter = p_output;
57
58 mp_cborWriter->startMap();
59 mp_cborWriter->writeInformations(
60 "sage_file_reader", Utils::getVersion(), "psm", "sage reader");
61
62 QDir::setCurrent(sage_json_file.absolutePath());
63 readJson();
64 mp_cborWriter->append("parameter_map");
65 mp_cborWriter->startMap();
66 mp_cborWriter->append("sage");
67 QCborValue::fromJsonValue(m_jsonData.object()).toCbor(*mp_cborWriter);
68 mp_cborWriter->endMap();
69
70 p_monitor->setStatus(
71 QObject::tr("reading Sage json file %1").arg(sage_json_file.absoluteFilePath()));
72
73 // "decoy_tag": "rev_",
74 // "generate_decoys": true,
75 // "target_fasta_files": ["zea_mays.fasta", "contaminant.fasta"],
76 //"decoy_fasta_files": ["rev_zea_mays.fasta", "rev_contaminant.fasta"],
77
78 mp_cborWriter->append("target_fasta_files");
80
81 SageReader sage_reader(p_monitor, mp_cborWriter, *this, sage_json_file.absoluteFilePath());
82 sage_reader.read();
83
84 // mp_cborWriter->append("protein_map");
85 // sage_reader.getPsmProteinMap().
86
87 mp_cborWriter->endMap();
88 }
90 {
91 throw err;
92 }
93 catch(pappso::PappsoException &other_err)
94 {
95 throw pappso::PappsoException(QObject::tr("Error reading Sage JSON file %1:\n%2")
96 .arg(m_sageJsonFile.absoluteFilePath())
97 .arg(other_err.qwhat()));
98 }
99}
100
101
105
106
107void
109{
110 QFile mfile(m_sageJsonFile.absoluteFilePath());
111 if(!mfile.open(QFile::ReadOnly))
112 {
114 QObject::tr("Unable to read Sage JSON file %1").arg(m_sageJsonFile.absoluteFilePath()));
115 }
116 QByteArray iContents = mfile.readAll();
117
118 QJsonParseError parseError;
119 m_jsonData = QJsonDocument::fromJson(iContents, &parseError);
120 if(parseError.error != QJsonParseError::NoError)
121 {
122 throw pappso::ExceptionNotRecognized(QObject::tr("Error reading Sage JSON file %1 at %2:%3")
123 .arg(m_sageJsonFile.absoluteFilePath())
124 .arg(parseError.offset)
125 .arg(parseError.errorString()));
126 }
127
128 QJsonValue mzml_value = m_jsonData.object().value("mzml_paths");
129
130 if(mzml_value.isNull())
131 {
133 QObject::tr("Sage JSON file %1 does not contain mzml_paths")
134 .arg(m_sageJsonFile.absoluteFilePath()));
135 }
136 for(const QJsonValue &value : m_jsonData.object().value("mzml_paths").toArray())
137 {
138 qDebug() << value.toString();
139
140 // MsRunSp msrun_sp = p_project->getMsRunStore().getInstance(value.toString());
142 {QFileInfo(value.toString()).fileName(), QFileInfo(value.toString()).absoluteFilePath()});
143 }
144
145
146 m_sageVersion = m_jsonData.object().value("version").toString();
147
148
149 QJsonObject sage_object = m_jsonData.object();
150
151
152 QJsonObject database = sage_object.value("database").toObject();
153
154 m_decoyTag = database.value("decoy_tag").toString();
155 m_generateDecoy = database.value("generate_decoy").toBool();
156 m_targetFastaFile << database.value("fasta").toString();
157}
158
159const QJsonDocument &
161{
162 return m_jsonData;
163}
164
165
166QString
167SageFileReader::getMsRunSpWithFileName(const QString &msrun_filename) const
168{
169 auto it = m_mapFilePath2MsRunSp.find(msrun_filename);
170 if(it != m_mapFilePath2MsRunSp.end())
171 return it->second;
172
173
174 throw pappso::PappsoException(QObject::tr("msrun filename %1 not found").arg(msrun_filename));
175}
176
177} // namespace psm
178} // namespace cbor
179} // namespace pappso
180
181
182
183
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:623
SageFileReader(pappso::UiMonitorInterface *p_monitor, pappso::cbor::CborStreamWriter *p_output, const QFileInfo &sage_json_file)
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