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