libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
pappso::cbor::psm::SageReader Class Reference

#include <sagereader.h>

Classes

struct  SageModification
class  FastaSeq

Public Member Functions

 SageReader (pappso::UiMonitorInterface *p_monitor, pappso::cbor::CborStreamWriter *p_output, const SageFileReader &sage_file_reader, const QString &sage_json_file)
void read ()
virtual ~SageReader ()
std::vector< SageModificationgetStaticModificationList () const
std::vector< SageModificationgetVariableModificationList () const
QString getDecoyTag () const
const SageFileReadergetSageFileReader () const
pappso::cbor::CborStreamWritergetCborStreamWriter () const
const QString & getmJsonAbsoluteFilePath () const
const QString & getMzmlPath (const QString &file_msrun) const

Private Member Functions

void readTsvFile ()
void extractMzmlPathList (const QJsonDocument &json_doc)
QString getTsvFilePath (const QJsonDocument &json_doc)
QString getFastaFilePath (const QJsonDocument &json_doc)
QString convertToLocalFileOrDie (const QString &file_str) const

Private Attributes

const SageFileReaderm_sageFileReader
pappso::UiMonitorInterfacemp_monitor
pappso::cbor::CborStreamWritermp_cborWriter
PsmProteinMap m_psmProteinMap
QString m_jsonAbsoluteFilePath
QStringList m_mzmlPathList

Detailed Description

Todo
write docs

Definition at line 41 of file sagereader.h.

Constructor & Destructor Documentation

◆ SageReader()

pappso::cbor::psm::SageReader::SageReader ( pappso::UiMonitorInterface * p_monitor,
pappso::cbor::CborStreamWriter * p_output,
const SageFileReader & sage_file_reader,
const QString & sage_json_file )

Default constructor

Definition at line 45 of file sagereader.cpp.

49 : m_sageFileReader(sage_file_reader)
50{
51 mp_monitor = p_monitor;
52 mp_cborWriter = p_output;
53 m_jsonAbsoluteFilePath = sage_json_file;
54}
pappso::cbor::CborStreamWriter * mp_cborWriter
Definition sagereader.h:100
const SageFileReader & m_sageFileReader
Definition sagereader.h:98
pappso::UiMonitorInterface * mp_monitor
Definition sagereader.h:99

References m_jsonAbsoluteFilePath, m_sageFileReader, mp_cborWriter, and mp_monitor.

Referenced by pappso::cbor::psm::SageReader::FastaSeq::FastaSeq().

◆ ~SageReader()

pappso::cbor::psm::SageReader::~SageReader ( )
virtual

Destructor

Definition at line 56 of file sagereader.cpp.

57{
58}

Member Function Documentation

◆ convertToLocalFileOrDie()

QString pappso::cbor::psm::SageReader::convertToLocalFileOrDie ( const QString & file_str) const
private

Definition at line 250 of file sagereader.cpp.

251{
252
253 // if we have an URL : convert it to local file
254 qDebug() << path;
255 if(path.startsWith("file:") || path.startsWith("http:") || path.startsWith("https:"))
256 {
257 QUrl tsv_url(path);
258 if(tsv_url.isValid())
259 {
260 qDebug() << "tsv_url.isValid()";
261 if(tsv_url.isLocalFile())
262 {
263 qDebug() << "tsv_url.isLocalFile()";
264 return tsv_url.toLocalFile();
265 }
266 else
267 {
268 throw pappso::PappsoException(
269 QObject::tr("Unable to load data from remote URL %1").arg(tsv_url.toString()));
270 }
271 }
272 }
273 return path;
274}

Referenced by extractMzmlPathList(), getFastaFilePath(), and getTsvFilePath().

◆ extractMzmlPathList()

void pappso::cbor::psm::SageReader::extractMzmlPathList ( const QJsonDocument & json_doc)
private

Definition at line 170 of file sagereader.cpp.

171{
172
173 QJsonObject sage_object = json_doc.object();
174 QJsonValue json_mzml_path_list = sage_object.value("mzml_paths");
175 if(json_mzml_path_list.isUndefined())
176 {
177 throw pappso::ExceptionNotFound(QObject::tr("mzml_paths not found in Sage json document"));
178 }
179 m_mzmlPathList.clear();
180
181 for(auto path_mzml : json_mzml_path_list.toArray())
182 {
183 m_mzmlPathList << convertToLocalFileOrDie(path_mzml.toString());
184 }
185}
QString convertToLocalFileOrDie(const QString &file_str) const

References convertToLocalFileOrDie(), and m_mzmlPathList.

Referenced by readTsvFile().

◆ getCborStreamWriter()

pappso::cbor::CborStreamWriter & pappso::cbor::psm::SageReader::getCborStreamWriter ( ) const

Definition at line 111 of file sagereader.cpp.

112{
113 return *mp_cborWriter;
114}

References mp_cborWriter.

◆ getDecoyTag()

QString pappso::cbor::psm::SageReader::getDecoyTag ( ) const

Definition at line 362 of file sagereader.cpp.

363{
364 QString path;
365 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
366 QJsonValue database = sage_object.value("database");
367 if(database.isUndefined())
368 {
369 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
370 }
371 path = database.toObject().value("decoy_tag").toString();
372 if(path.isEmpty())
373 {
374 throw pappso::ExceptionNotFound(QObject::tr("decoy_tag value is empty"));
375 }
376 return path;
377}

References m_sageFileReader.

Referenced by pappso::cbor::psm::SageTsvHandler::SageTsvHandler().

◆ getFastaFilePath()

QString pappso::cbor::psm::SageReader::getFastaFilePath ( const QJsonDocument & json_doc)
private

Definition at line 230 of file sagereader.cpp.

231{
232 QString path;
233 QJsonObject sage_object = json_doc.object();
234 QJsonValue database = sage_object.value("database");
235 if(database.isUndefined())
236 {
237 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
238 }
239 path = database.toObject().value("fasta").toString();
240 if(path.isEmpty())
241 {
242 throw pappso::ExceptionNotFound(QObject::tr("fasta value is empty"));
243 }
244
245
246 return convertToLocalFileOrDie(path);
247}

References convertToLocalFileOrDie().

Referenced by readTsvFile().

◆ getmJsonAbsoluteFilePath()

const QString & pappso::cbor::psm::SageReader::getmJsonAbsoluteFilePath ( ) const

Definition at line 61 of file sagereader.cpp.

62{
64}

References m_jsonAbsoluteFilePath.

◆ getMzmlPath()

const QString & pappso::cbor::psm::SageReader::getMzmlPath ( const QString & file_msrun) const

Definition at line 188 of file sagereader.cpp.

189{
190 for(auto &file_path : m_mzmlPathList)
191 {
192 if(file_path.endsWith(file_msrun))
193 return file_path;
194 }
195 throw pappso::ExceptionNotFound(
196 QObject::tr("MS run %1 not found in Sage json document").append(file_msrun));
197}

References m_mzmlPathList.

◆ getSageFileReader()

const pappso::cbor::psm::SageFileReader & pappso::cbor::psm::SageReader::getSageFileReader ( ) const

Definition at line 380 of file sagereader.cpp.

381{
382 return m_sageFileReader;
383}

References m_sageFileReader.

◆ getStaticModificationList()

std::vector< pappso::cbor::psm::SageReader::SageModification > pappso::cbor::psm::SageReader::getStaticModificationList ( ) const

Definition at line 277 of file sagereader.cpp.

278{
279 std::vector<SageReader::SageModification> list;
280 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
281 QJsonValue database = sage_object.value("database");
282 if(database.isUndefined())
283 {
284 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
285 }
286
287 QJsonValue static_mods = database.toObject().value("static_mods");
288 if(static_mods.isUndefined())
289 {
290 throw pappso::ExceptionNotFound(QObject::tr("static_mods not found in Sage json document"));
291 }
292 for(QString residue_str : static_mods.toObject().keys())
293 {
294 SageModification modif;
295 modif.residue = residue_str.at(0);
297 (Enums::AminoAcidChar)modif.residue.toLatin1(),
298 static_mods.toObject().value(residue_str).toDouble());
299 modif.strModification =
300 QString::number(static_mods.toObject().value(residue_str).toDouble(), 'f', 6);
301 if(modif.strModification.isEmpty())
302 {
303 throw pappso::PappsoException(QObject::tr(" modif.strModification is empty"));
304 }
305 if(modif.modification->getMass() < 0)
306 {
307 modif.strModification = QString("[%1]").arg(modif.strModification);
308 }
309 else
310 {
311 modif.strModification = QString("[+%1]").arg(modif.strModification);
312 }
313 list.push_back(modif);
314 }
315 return list;
316}
static AaModificationP guessAaModificationPbyMonoisotopicMassDelta(Enums::AminoAcidChar aa, pappso_double mass)
Definition utils.cpp:677

References pappso::AaModification::getMass(), pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta(), m_sageFileReader, pappso::cbor::psm::SageReader::SageModification::modification, pappso::cbor::psm::SageReader::SageModification::residue, and pappso::cbor::psm::SageReader::SageModification::strModification.

Referenced by pappso::cbor::psm::SageTsvHandler::SageTsvHandler().

◆ getTsvFilePath()

QString pappso::cbor::psm::SageReader::getTsvFilePath ( const QJsonDocument & json_doc)
private

Definition at line 201 of file sagereader.cpp.

202{
203 QString path;
204 QJsonObject sage_object = json_doc.object();
205 QJsonValue output_path = sage_object.value("output_paths");
206 if(output_path.isUndefined())
207 {
208 throw pappso::ExceptionNotFound(QObject::tr("output_paths not found in Sage json document"));
209 }
210
211 if(!output_path.isArray())
212 {
213 throw pappso::ExceptionNotFound(QObject::tr("output_paths is not an array"));
214 }
215 for(auto element : output_path.toArray())
216 {
217 if(element.isString())
218 {
219 if(element.toString().endsWith(".tsv"))
220 {
221 path = element.toString();
222 }
223 }
224 }
225
226 return convertToLocalFileOrDie(path);
227}

References convertToLocalFileOrDie().

Referenced by readTsvFile().

◆ getVariableModificationList()

std::vector< pappso::cbor::psm::SageReader::SageModification > pappso::cbor::psm::SageReader::getVariableModificationList ( ) const

Definition at line 319 of file sagereader.cpp.

320{
321 std::vector<SageReader::SageModification> list;
322 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
323 QJsonValue database = sage_object.value("database");
324 if(database.isUndefined())
325 {
326 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
327 }
328
329 QJsonValue var_mods = database.toObject().value("variable_mods");
330 if(var_mods.isUndefined())
331 {
332 throw pappso::ExceptionNotFound(QObject::tr("static_mods not found in Sage json document"));
333 }
334 for(QString residue_str : var_mods.toObject().keys())
335 {
336 SageModification modif;
337 modif.residue = residue_str.at(0);
338 for(QJsonValue one_mass : var_mods.toObject().value(residue_str).toArray())
339 {
341 (Enums::AminoAcidChar)modif.residue.toLatin1(), one_mass.toDouble());
342 modif.strModification = QString::number(one_mass.toDouble(), 'f', 6);
343 if(modif.strModification.isEmpty())
344 {
345 throw pappso::PappsoException(QObject::tr(" modif.strModification is empty"));
346 }
347 if(modif.modification->getMass() < 0)
348 {
349 modif.strModification = QString("[%1]").arg(modif.strModification);
350 }
351 else
352 {
353 modif.strModification = QString("[+%1]").arg(modif.strModification);
354 }
355 list.push_back(modif);
356 }
357 }
358 return list;
359}

References pappso::AaModification::getMass(), pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta(), m_sageFileReader, pappso::cbor::psm::SageReader::SageModification::modification, pappso::cbor::psm::SageReader::SageModification::residue, and pappso::cbor::psm::SageReader::SageModification::strModification.

Referenced by pappso::cbor::psm::SageTsvHandler::SageTsvHandler().

◆ read()

void pappso::cbor::psm::SageReader::read ( )

Definition at line 68 of file sagereader.cpp.

References readTsvFile().

Referenced by pappso::cbor::psm::SageFileReader::SageFileReader().

◆ readTsvFile()

void pappso::cbor::psm::SageReader::readTsvFile ( )
private

Definition at line 118 of file sagereader.cpp.

119{
120
121 extractMzmlPathList(m_sageFileReader.getJsonDocument());
122 // getTsvFilePath(mp_identificationDataSource->getJsonDocument().object());
123 QString file_str = getTsvFilePath(m_sageFileReader.getJsonDocument());
124 QFileInfo tsv_file_info(file_str);
125 SageTsvHandler handler(mp_monitor, *this, m_psmProteinMap);
126 try
127 {
128 TsvReader tsv_reader(handler);
129
130 QFile tsv_file(tsv_file_info.absoluteFilePath());
131 tsv_reader.parse(tsv_file);
132 tsv_file.close();
133 }
134 catch(OdsException &error_ods)
135 {
136 throw pappso::PappsoException(QObject::tr("Error reading %1 file:\n %2")
137 .arg(tsv_file_info.absoluteFilePath())
138 .arg(error_ods.qwhat()));
139 }
140
141
142 // collect protein sequences
143 QFile fastaFile(getFastaFilePath(m_sageFileReader.getJsonDocument()));
144 SageReader::FastaSeq seq(this);
145 pappso::FastaReader reader(seq);
146 reader.parse(fastaFile);
147
148 qDebug();
149 mp_cborWriter->append("protein_map");
151
152
153 mp_cborWriter->append("sample_list");
154 mp_cborWriter->startArray();
155 try
156 {
157 handler.writeSampleList();
158 }
159 catch(OdsException &error_ods)
160 {
161 throw pappso::PappsoException(QObject::tr("Error reading %1 file:\n %2")
162 .arg(tsv_file_info.absoluteFilePath())
163 .arg(error_ods.qwhat()));
164 }
165
166 mp_cborWriter->endArray();
167}
void extractMzmlPathList(const QJsonDocument &json_doc)
QString getFastaFilePath(const QJsonDocument &json_doc)
QString getTsvFilePath(const QJsonDocument &json_doc)

References extractMzmlPathList(), getFastaFilePath(), getTsvFilePath(), m_psmProteinMap, m_sageFileReader, mp_cborWriter, mp_monitor, pappso::FastaReader::parse(), and pappso::cbor::psm::SageTsvHandler::writeSampleList().

Referenced by read().

Member Data Documentation

◆ m_jsonAbsoluteFilePath

QString pappso::cbor::psm::SageReader::m_jsonAbsoluteFilePath
private

Definition at line 102 of file sagereader.h.

Referenced by SageReader(), and getmJsonAbsoluteFilePath().

◆ m_mzmlPathList

QStringList pappso::cbor::psm::SageReader::m_mzmlPathList
private

Definition at line 103 of file sagereader.h.

Referenced by extractMzmlPathList(), and getMzmlPath().

◆ m_psmProteinMap

PsmProteinMap pappso::cbor::psm::SageReader::m_psmProteinMap
private

Definition at line 101 of file sagereader.h.

Referenced by readTsvFile().

◆ m_sageFileReader

const SageFileReader& pappso::cbor::psm::SageReader::m_sageFileReader
private

◆ mp_cborWriter

pappso::cbor::CborStreamWriter* pappso::cbor::psm::SageReader::mp_cborWriter
private

Definition at line 100 of file sagereader.h.

Referenced by SageReader(), getCborStreamWriter(), and readTsvFile().

◆ mp_monitor

pappso::UiMonitorInterface* pappso::cbor::psm::SageReader::mp_monitor
private

Definition at line 99 of file sagereader.h.

Referenced by SageReader(), and readTsvFile().


The documentation for this class was generated from the following files: