libpappsomspp
Library for mass spectrometry
Toggle main menu visibility
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
"
31
#include "
pappsomspp/core/utils.h
"
32
#include "
pappsomspp/core/pappsoexception.h
"
33
#include "
pappsomspp/core/exception/exceptionnotrecognized.h
"
34
#include <QJsonObject>
35
#include <QJsonArray>
36
#include <QDir>
37
#include <QCborValue>
38
39
namespace
pappso
40
{
41
namespace
cbor
42
{
43
namespace
psm
44
{
45
46
SageFileReader::SageFileReader
(
pappso::UiMonitorInterface
*p_monitor,
47
pappso::cbor::CborStreamWriter
*p_output,
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"
);
78
mp_cborWriter
->writeArray(
m_targetFastaFile
);
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
}
88
catch
(
pappso::ExceptionNotRecognized
&err)
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
101
SageFileReader::~SageFileReader
()
102
{
103
}
104
105
106
void
107
SageFileReader::readJson
()
108
{
109
QFile mfile(
m_sageJsonFile
.absoluteFilePath());
110
if
(!mfile.open(QFile::ReadOnly))
111
{
112
throw
pappso::ExceptionNotRecognized
(
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
{
131
throw
pappso::ExceptionNotRecognized
(
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());
140
m_mapFilePath2MsRunSp
.insert(
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
158
const
QJsonDocument &
159
SageFileReader::getJsonDocument
()
const
160
{
161
return
m_jsonData
;
162
}
163
164
165
QString
166
SageFileReader::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
pappso::ExceptionNotRecognized
excetion to use when an item type is not recognized
Definition
exceptionnotrecognized.h:42
pappso::PappsoException
Definition
pappsoexception.h:41
pappso::PappsoException::qwhat
virtual const QString & qwhat() const
Definition
pappsoexception.h:66
pappso::UiMonitorInterface
Definition
uimonitorinterface.h:50
pappso::UiMonitorInterface::setStatus
virtual void setStatus(const QString &status)=0
current status of the process
pappso::Utils::getVersion
static QString getVersion()
Definition
utils.cpp:669
pappso::cbor::CborStreamWriter
overrides QCborStreamWriter base class to provide convenient functions
Definition
cborstreamwriter.h:46
pappso::cbor::psm::SageFileReader::SageFileReader
SageFileReader(pappso::UiMonitorInterface *p_monitor, pappso::cbor::CborStreamWriter *p_output, const QFileInfo &sage_json_file)
main function to convert Sage results to CBOR output
Definition
sagefilereader.cpp:46
pappso::cbor::psm::SageFileReader::m_mapFilePath2MsRunSp
std::map< QString, QString > m_mapFilePath2MsRunSp
Definition
sagefilereader.h:77
pappso::cbor::psm::SageFileReader::mp_cborWriter
pappso::cbor::CborStreamWriter * mp_cborWriter
Definition
sagefilereader.h:79
pappso::cbor::psm::SageFileReader::m_targetFastaFile
QStringList m_targetFastaFile
Definition
sagefilereader.h:82
pappso::cbor::psm::SageFileReader::m_generateDecoy
bool m_generateDecoy
Definition
sagefilereader.h:81
pappso::cbor::psm::SageFileReader::readJson
void readJson()
Definition
sagefilereader.cpp:107
pappso::cbor::psm::SageFileReader::m_sageVersion
QString m_sageVersion
Definition
sagefilereader.h:78
pappso::cbor::psm::SageFileReader::m_jsonData
QJsonDocument m_jsonData
Definition
sagefilereader.h:75
pappso::cbor::psm::SageFileReader::m_decoyTag
QString m_decoyTag
Definition
sagefilereader.h:80
pappso::cbor::psm::SageFileReader::getMsRunSpWithFileName
QString getMsRunSpWithFileName(const QString &msrun_filename) const
Definition
sagefilereader.cpp:166
pappso::cbor::psm::SageFileReader::getJsonDocument
const QJsonDocument & getJsonDocument() const
Definition
sagefilereader.cpp:159
pappso::cbor::psm::SageFileReader::~SageFileReader
virtual ~SageFileReader()
Definition
sagefilereader.cpp:101
pappso::cbor::psm::SageFileReader::m_sageJsonFile
const QFileInfo m_sageJsonFile
Definition
sagefilereader.h:74
pappso::cbor::psm::SageReader
Definition
sagereader.h:42
pappso::cbor::psm::SageReader::read
void read()
Definition
sagereader.cpp:68
exceptionnotrecognized.h
pappso::cbor::psm
Definition
cborscanmapbase.h:40
pappso::cbor
Definition
cborstreamreader.cpp:35
pappso
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition
aa.cpp:39
pappsoexception.h
sagefilereader.h
sagereader.h
utils.h
pappsomspp
core
processing
cbor
psm
sage
sagefilereader.cpp
Generated on
for libpappsomspp by
1.17.0