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

#include <sagereader.h>

Classes

class  FastaSeq
 
struct  SageModification
 

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, mp_cborWriter, and mp_monitor.

◆ ~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 252 of file sagereader.cpp.

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

◆ extractMzmlPathList()

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

Definition at line 172 of file sagereader.cpp.

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

◆ getCborStreamWriter()

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

◆ getDecoyTag()

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

Definition at line 364 of file sagereader.cpp.

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

Referenced by pappso::cbor::psm::SageReader::FastaSeq::FastaSeq(), and pappso::cbor::psm::SageTsvHandler::SageTsvHandler().

◆ getFastaFilePath()

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

Definition at line 232 of file sagereader.cpp.

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

◆ getmJsonAbsoluteFilePath()

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

Definition at line 61 of file sagereader.cpp.

62{
64}

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

◆ getMzmlPath()

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

Definition at line 190 of file sagereader.cpp.

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

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

◆ getSageFileReader()

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

Definition at line 382 of file sagereader.cpp.

383{
384 return m_sageFileReader;
385}

◆ getStaticModificationList()

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

Definition at line 279 of file sagereader.cpp.

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

References pappso::AaModification::getMass(), pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta(), 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 203 of file sagereader.cpp.

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

◆ getVariableModificationList()

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

Definition at line 321 of file sagereader.cpp.

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

References pappso::AaModification::getMass(), pappso::Utils::guessAaModificationPbyMonoisotopicMassDelta(), 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.

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

◆ readTsvFile()

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

Definition at line 120 of file sagereader.cpp.

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

References pappso::FastaReader::parse(), and pappso::cbor::psm::SageTsvHandler::writeSampleList().

Member Data Documentation

◆ m_jsonAbsoluteFilePath

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

Definition at line 102 of file sagereader.h.

Referenced by SageReader().

◆ m_mzmlPathList

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

Definition at line 103 of file sagereader.h.

◆ m_psmProteinMap

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

Definition at line 101 of file sagereader.h.

◆ m_sageFileReader

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

Definition at line 98 of file sagereader.h.

◆ mp_cborWriter

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

Definition at line 100 of file sagereader.h.

Referenced by SageReader().

◆ mp_monitor

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

Definition at line 99 of file sagereader.h.

Referenced by SageReader().


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