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< SageModification > getStaticModificationList () const
std::vector< SageModification > getVariableModificationList () const
QString getDecoyTag () const
const SageFileReader & getSageFileReader () const
pappso::cbor::CborStreamWriter & getCborStreamWriter () 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 SageFileReader & m_sageFileReader
pappso::UiMonitorInterface * mp_monitor
pappso::cbor::CborStreamWriter * mp_cborWriter
PsmProteinMap m_psmProteinMap
QString m_jsonAbsoluteFilePath
QStringList m_mzmlPathList

Detailed Description

Todo
write docs

Definition at line 42 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 47 of file sagereader.cpp.

51 : m_sageFileReader(sage_file_reader)
52{
53 mp_monitor = p_monitor;
54 mp_cborWriter = p_output;
55 m_jsonAbsoluteFilePath = sage_json_file;
56}
pappso::cbor::CborStreamWriter * mp_cborWriter
Definition sagereader.h:116
const SageFileReader & m_sageFileReader
Definition sagereader.h:114
pappso::UiMonitorInterface * mp_monitor
Definition sagereader.h:115

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 58 of file sagereader.cpp.

59{
60}

Member Function Documentation

◆ convertToLocalFileOrDie()

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

Definition at line 254 of file sagereader.cpp.

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

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

◆ extractMzmlPathList()

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

Definition at line 174 of file sagereader.cpp.

175{
176
177 QJsonObject sage_object = json_doc.object();
178 QJsonValue json_mzml_path_list = sage_object.value("mzml_paths");
179 if(json_mzml_path_list.isUndefined())
180 {
181 throw pappso::ExceptionNotFound(QObject::tr("mzml_paths not found in Sage json document"));
182 }
183 m_mzmlPathList.clear();
184
185 for(auto path_mzml : json_mzml_path_list.toArray())
186 {
187 m_mzmlPathList << convertToLocalFileOrDie(path_mzml.toString());
188 }
189}
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 115 of file sagereader.cpp.

116{
117 return *mp_cborWriter;
118}

References mp_cborWriter.

◆ getDecoyTag()

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

Definition at line 406 of file sagereader.cpp.

407{
408 QString path;
409 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
410 QJsonValue database = sage_object.value("database");
411 if(database.isUndefined())
412 {
413 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
414 }
415 path = database.toObject().value("decoy_tag").toString();
416 if(path.isEmpty())
417 {
418 throw pappso::ExceptionNotFound(QObject::tr("decoy_tag value is empty"));
419 }
420 return path;
421}

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 234 of file sagereader.cpp.

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

References convertToLocalFileOrDie().

Referenced by readTsvFile().

◆ getmJsonAbsoluteFilePath()

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

Definition at line 63 of file sagereader.cpp.

64{
66}

References m_jsonAbsoluteFilePath.

◆ getMzmlPath()

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

Definition at line 192 of file sagereader.cpp.

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

References m_mzmlPathList.

◆ getSageFileReader()

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

Definition at line 424 of file sagereader.cpp.

425{
426 return m_sageFileReader;
427}

References m_sageFileReader.

◆ getStaticModificationList()

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

Definition at line 281 of file sagereader.cpp.

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

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 205 of file sagereader.cpp.

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

References convertToLocalFileOrDie().

Referenced by readTsvFile().

◆ getVariableModificationList()

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

Definition at line 322 of file sagereader.cpp.

323{
324 std::vector<SageReader::SageModification> list;
325 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
326 QJsonValue database = sage_object.value("database");
327 if(database.isUndefined())
328 {
329 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
330 }
331
332 QJsonValue var_mods = database.toObject().value("variable_mods");
333 if(var_mods.isUndefined())
334 {
335 throw pappso::ExceptionNotFound(QObject::tr("variable_mods not found in Sage json document"));
336 }
337 for(QString residue_str : var_mods.toObject().keys())
338 {
339 qDebug() << residue_str;
340 SageModification modif;
341 modif.residue = (Enums::AminoAcidChar)residue_str.at(0).toLatin1();
342 if(!Utils::isAminoAcidChar(modif.residue))
343 {
344 qDebug() << "not amino acid";
345 QChar pos = residue_str.at(0).toLatin1();
346 qDebug() << residue_str << "not amino acid " << pos;
347 if(pos == '^')
348 {
349 modif.position = pos;
350 modif.residue = (Enums::AminoAcidChar)residue_str.at(1).toLatin1();
351 qDebug() << (char)modif.residue;
352 if(!Utils::isAminoAcidChar(modif.residue))
353 {
354 throw pappso::PappsoException(QObject::tr("unable to parse %1").arg(residue_str));
355 }
356 }
357 else if((pos == '[') || (pos == ']'))
358 {
359 modif.position = pos;
360 // modif.residue = (Enums::AminoAcidChar)residue_str.at(1).toLatin1();
361 // qDebug() << (char)modif.residue;
362 }
363 else
364 {
365 throw pappso::PappsoException(QObject::tr("unable to parse %1").arg(residue_str));
366 }
367 qDebug() << (char)modif.residue;
368
369 qDebug() << (char)modif.residue;
370 }
371
372 // Enums::AminoAcidChar aa = (Enums::AminoAcidChar)modif.residue.toLatin1();
373 qDebug() << residue_str << " " << (char)modif.residue;
374 for(QJsonValue one_mass : var_mods.toObject().value(residue_str).toArray())
375 {
377 modif.residue, one_mass.toDouble(), modif.position);
378 qDebug() << modif.modification->getAccession();
379 modif.strModification = QString::number(one_mass.toDouble(), 'f', 6);
380 if(modif.strModification.isEmpty())
381 {
382 throw pappso::PappsoException(QObject::tr(" modif.strModification is empty"));
383 }
384 if(modif.modification->getMass() < 0)
385 {
386 modif.strModification = QString("[%1]").arg(modif.strModification);
387 }
388 else
389 {
390 modif.strModification = QString("[+%1]").arg(modif.strModification);
391 }
392
393 qDebug() << modif.strModification;
394 list.push_back(modif);
395 qDebug() << modif.strModification;
396 }
397 qDebug() << list.size();
398 }
399
400 qDebug() << list.size();
401
402 return list;
403}
static bool isAminoAcidChar(Enums::AminoAcidChar x)
Definition utils.cpp:822

References pappso::AaModification::getAccession(), pappso::AaModification::getMass(), pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta(), pappso::Utils::isAminoAcidChar(), m_sageFileReader, pappso::cbor::psm::SageReader::SageModification::modification, pappso::cbor::psm::SageReader::SageModification::position, 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 70 of file sagereader.cpp.

References readTsvFile().

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

◆ readTsvFile()

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

Definition at line 122 of file sagereader.cpp.

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

Referenced by SageReader(), and getmJsonAbsoluteFilePath().

◆ m_mzmlPathList

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

Definition at line 119 of file sagereader.h.

Referenced by extractMzmlPathList(), and getMzmlPath().

◆ m_psmProteinMap

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

Definition at line 117 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 116 of file sagereader.h.

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

◆ mp_monitor

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

Definition at line 115 of file sagereader.h.

Referenced by SageReader(), and readTsvFile().


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