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)

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

44 : m_sageFileReader(sage_file_reader)
45{
46 mp_monitor = p_monitor;
47 mp_cborWriter = p_output;
48 m_jsonAbsoluteFilePath = sage_json_file;
49}
pappso::cbor::CborStreamWriter * mp_cborWriter
Definition sagereader.h:99
const SageFileReader & m_sageFileReader
Definition sagereader.h:97
pappso::UiMonitorInterface * mp_monitor
Definition sagereader.h:98

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

52{
53}

Member Function Documentation

◆ extractMzmlPathList()

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

Definition at line 160 of file sagereader.cpp.

161{
162
163 QJsonObject sage_object = json_doc.object();
164 QJsonValue json_mzml_path_list = sage_object.value("mzml_paths");
165 if(json_mzml_path_list.isUndefined())
166 {
167 throw pappso::ExceptionNotFound(QObject::tr("mzml_paths not found in Sage json document"));
168 }
169 m_mzmlPathList.clear();
170
171 for(auto path_mzml : json_mzml_path_list.toArray())
172 {
173 m_mzmlPathList << path_mzml.toString();
174 }
175}

References m_mzmlPathList.

Referenced by readTsvFile().

◆ getCborStreamWriter()

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

Definition at line 102 of file sagereader.cpp.

103{
104 return *mp_cborWriter;
105}

References mp_cborWriter.

◆ getDecoyTag()

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

Definition at line 323 of file sagereader.cpp.

324{
325 QString path;
326 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
327 QJsonValue database = sage_object.value("database");
328 if(database.isUndefined())
329 {
330 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
331 }
332 path = database.toObject().value("decoy_tag").toString();
333 if(path.isEmpty())
334 {
335 throw pappso::ExceptionNotFound(QObject::tr("decoy_tag value is empty"));
336 }
337 return path;
338}

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

220{
221 QString path;
222 QJsonObject sage_object = json_doc.object();
223 QJsonValue database = sage_object.value("database");
224 if(database.isUndefined())
225 {
226 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
227 }
228 path = database.toObject().value("fasta").toString();
229 if(path.isEmpty())
230 {
231 throw pappso::ExceptionNotFound(QObject::tr("fasta value is empty"));
232 }
233 return path;
234}

Referenced by readTsvFile().

◆ getmJsonAbsoluteFilePath()

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

Definition at line 56 of file sagereader.cpp.

57{
59}

References m_jsonAbsoluteFilePath.

◆ getMzmlPath()

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

Definition at line 178 of file sagereader.cpp.

179{
180 for(auto &file_path : m_mzmlPathList)
181 {
182 if(file_path.endsWith(file_msrun))
183 return file_path;
184 }
185 throw pappso::ExceptionNotFound(
186 QObject::tr("MS run %1 not found in Sage json document").append(file_msrun));
187}

References m_mzmlPathList.

◆ getSageFileReader()

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

Definition at line 341 of file sagereader.cpp.

342{
343 return m_sageFileReader;
344}

References m_sageFileReader.

◆ getStaticModificationList()

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

Definition at line 238 of file sagereader.cpp.

239{
240 std::vector<SageReader::SageModification> list;
241 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
242 QJsonValue database = sage_object.value("database");
243 if(database.isUndefined())
244 {
245 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
246 }
247
248 QJsonValue static_mods = database.toObject().value("static_mods");
249 if(static_mods.isUndefined())
250 {
251 throw pappso::ExceptionNotFound(QObject::tr("static_mods not found in Sage json document"));
252 }
253 for(QString residue_str : static_mods.toObject().keys())
254 {
255 SageModification modif;
256 modif.residue = residue_str.at(0);
258 (Enums::AminoAcidChar)modif.residue.toLatin1(),
259 static_mods.toObject().value(residue_str).toDouble());
260 modif.strModification =
261 QString::number(static_mods.toObject().value(residue_str).toDouble(), 'f', 6);
262 if(modif.strModification.isEmpty())
263 {
264 throw pappso::PappsoException(QObject::tr(" modif.strModification is empty"));
265 }
266 if(modif.modification->getMass() < 0)
267 {
268 modif.strModification = QString("[%1]").arg(modif.strModification);
269 }
270 else
271 {
272 modif.strModification = QString("[+%1]").arg(modif.strModification);
273 }
274 list.push_back(modif);
275 }
276 return list;
277}
static AaModificationP guessAaModificationPbyMonoisotopicMassDelta(Enums::AminoAcidChar aa, pappso_double mass)
Definition utils.cpp:658

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

192{
193 QString path;
194 QJsonObject sage_object = json_doc.object();
195 QJsonValue output_path = sage_object.value("output_paths");
196 if(output_path.isUndefined())
197 {
198 throw pappso::ExceptionNotFound(QObject::tr("output_paths not found in Sage json document"));
199 }
200
201 if(!output_path.isArray())
202 {
203 throw pappso::ExceptionNotFound(QObject::tr("output_paths is not an array"));
204 }
205 for(auto element : output_path.toArray())
206 {
207 if(element.isString())
208 {
209 if(element.toString().endsWith(".tsv"))
210 {
211 path = element.toString();
212 }
213 }
214 }
215 return path;
216}

Referenced by readTsvFile().

◆ getVariableModificationList()

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

Definition at line 280 of file sagereader.cpp.

281{
282 std::vector<SageReader::SageModification> list;
283 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
284 QJsonValue database = sage_object.value("database");
285 if(database.isUndefined())
286 {
287 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
288 }
289
290 QJsonValue var_mods = database.toObject().value("variable_mods");
291 if(var_mods.isUndefined())
292 {
293 throw pappso::ExceptionNotFound(QObject::tr("static_mods not found in Sage json document"));
294 }
295 for(QString residue_str : var_mods.toObject().keys())
296 {
297 SageModification modif;
298 modif.residue = residue_str.at(0);
299 for(QJsonValue one_mass : var_mods.toObject().value(residue_str).toArray())
300 {
302 (Enums::AminoAcidChar)modif.residue.toLatin1(), one_mass.toDouble());
303 modif.strModification = QString::number(one_mass.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 }
319 return list;
320}

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

References readTsvFile().

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

◆ readTsvFile()

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

Definition at line 109 of file sagereader.cpp.

110{
111
112 extractMzmlPathList(m_sageFileReader.getJsonDocument());
113 // getTsvFilePath(mp_identificationDataSource->getJsonDocument().object());
114 QFileInfo tsv_file_info(getTsvFilePath(m_sageFileReader.getJsonDocument()));
115 SageTsvHandler handler(mp_monitor, *this, m_psmProteinMap);
116 try
117 {
118 TsvReader tsv_reader(handler);
119
120 QFile tsv_file(tsv_file_info.absoluteFilePath());
121 tsv_reader.parse(tsv_file);
122 tsv_file.close();
123 }
124 catch(OdsException &error_ods)
125 {
126 throw pappso::PappsoException(QObject::tr("Error reading %1 file:\n %2")
127 .arg(tsv_file_info.absoluteFilePath())
128 .arg(error_ods.qwhat()));
129 }
130
131
132 // collect protein sequences
133 QFile fastaFile(getFastaFilePath(m_sageFileReader.getJsonDocument()));
134 SageReader::FastaSeq seq(this);
135 pappso::FastaReader reader(seq);
136 reader.parse(fastaFile);
137
138 qDebug();
139 mp_cborWriter->append("protein_map");
141
142
143 mp_cborWriter->append("sample_list");
144 mp_cborWriter->startArray();
145 try
146 {
147 handler.writeSampleList();
148 }
149 catch(OdsException &error_ods)
150 {
151 throw pappso::PappsoException(QObject::tr("Error reading %1 file:\n %2")
152 .arg(tsv_file_info.absoluteFilePath())
153 .arg(error_ods.qwhat()));
154 }
155
156 mp_cborWriter->endArray();
157}
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 101 of file sagereader.h.

Referenced by SageReader(), and getmJsonAbsoluteFilePath().

◆ m_mzmlPathList

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

Definition at line 102 of file sagereader.h.

Referenced by extractMzmlPathList(), and getMzmlPath().

◆ m_psmProteinMap

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

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

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

◆ mp_monitor

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

Definition at line 98 of file sagereader.h.

Referenced by SageReader(), and readTsvFile().


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