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
 

Private Member Functions

void readTsvFile ()
 
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
 

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:96
const SageFileReader & m_sageFileReader
Definition sagereader.h:94
pappso::UiMonitorInterface * mp_monitor
Definition sagereader.h:95

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

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

300{
301 QString path;
302 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
303 QJsonValue database = sage_object.value("database");
304 if(database.isUndefined())
305 {
306 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
307 }
308 path = database.toObject().value("decoy_tag").toString();
309 if(path.isEmpty())
310 {
311 throw pappso::ExceptionNotFound(QObject::tr("decoy_tag value is empty"));
312 }
313 return path;
314}

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

196{
197 QString path;
198 QJsonObject sage_object = json_doc.object();
199 QJsonValue database = sage_object.value("database");
200 if(database.isUndefined())
201 {
202 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
203 }
204 path = database.toObject().value("fasta").toString();
205 if(path.isEmpty())
206 {
207 throw pappso::ExceptionNotFound(QObject::tr("fasta value is empty"));
208 }
209 return path;
210}

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.

◆ getSageFileReader()

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

Definition at line 317 of file sagereader.cpp.

318{
319 return m_sageFileReader;
320}

References m_sageFileReader.

◆ getStaticModificationList()

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

Definition at line 214 of file sagereader.cpp.

215{
216 std::vector<SageReader::SageModification> list;
217 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
218 QJsonValue database = sage_object.value("database");
219 if(database.isUndefined())
220 {
221 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
222 }
223
224 QJsonValue static_mods = database.toObject().value("static_mods");
225 if(static_mods.isUndefined())
226 {
227 throw pappso::ExceptionNotFound(QObject::tr("static_mods not found in Sage json document"));
228 }
229 for(QString residue_str : static_mods.toObject().keys())
230 {
231 SageModification modif;
232 modif.residue = residue_str.at(0);
234 (Enums::AminoAcidChar)modif.residue.toLatin1(),
235 static_mods.toObject().value(residue_str).toDouble());
236 modif.strModification =
237 QString::number(static_mods.toObject().value(residue_str).toDouble(), 'f', 6);
238 if(modif.strModification.isEmpty())
239 {
240 throw pappso::PappsoException(QObject::tr(" modif.strModification is empty"));
241 }
242 if(modif.modification->getMass() < 0)
243 {
244 modif.strModification = QString("[%1]").arg(modif.strModification);
245 }
246 else
247 {
248 modif.strModification = QString("[+%1]").arg(modif.strModification);
249 }
250 list.push_back(modif);
251 }
252 return list;
253}
static AaModificationP guessAaModificationPbyMonoisotopicMassDelta(Enums::AminoAcidChar aa, pappso_double mass)
Definition utils.cpp:631

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

168{
169 QString path;
170 QJsonObject sage_object = json_doc.object();
171 QJsonValue output_path = sage_object.value("output_paths");
172 if(output_path.isUndefined())
173 {
174 throw pappso::ExceptionNotFound(QObject::tr("output_paths not found in Sage json document"));
175 }
176
177 if(!output_path.isArray())
178 {
179 throw pappso::ExceptionNotFound(QObject::tr("output_paths is not an array"));
180 }
181 for(auto element : output_path.toArray())
182 {
183 if(element.isString())
184 {
185 if(element.toString().endsWith(".tsv"))
186 {
187 path = element.toString();
188 }
189 }
190 }
191 return path;
192}

Referenced by readTsvFile().

◆ getVariableModificationList()

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

Definition at line 256 of file sagereader.cpp.

257{
258 std::vector<SageReader::SageModification> list;
259 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
260 QJsonValue database = sage_object.value("database");
261 if(database.isUndefined())
262 {
263 throw pappso::ExceptionNotFound(QObject::tr("database not found in Sage json document"));
264 }
265
266 QJsonValue var_mods = database.toObject().value("variable_mods");
267 if(var_mods.isUndefined())
268 {
269 throw pappso::ExceptionNotFound(QObject::tr("static_mods not found in Sage json document"));
270 }
271 for(QString residue_str : var_mods.toObject().keys())
272 {
273 SageModification modif;
274 modif.residue = residue_str.at(0);
275 for(QJsonValue one_mass : var_mods.toObject().value(residue_str).toArray())
276 {
278 (Enums::AminoAcidChar)modif.residue.toLatin1(), one_mass.toDouble());
279 modif.strModification = QString::number(one_mass.toDouble(), 'f', 6);
280 if(modif.strModification.isEmpty())
281 {
282 throw pappso::PappsoException(QObject::tr(" modif.strModification is empty"));
283 }
284 if(modif.modification->getMass() < 0)
285 {
286 modif.strModification = QString("[%1]").arg(modif.strModification);
287 }
288 else
289 {
290 modif.strModification = QString("[+%1]").arg(modif.strModification);
291 }
292 list.push_back(modif);
293 }
294 }
295 return list;
296}

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

References getFastaFilePath(), getTsvFilePath(), m_psmProteinMap, m_sageFileReader, mp_cborWriter, mp_monitor, and pappso::FastaReader::parse().

Referenced by read().

Member Data Documentation

◆ m_jsonAbsoluteFilePath

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

Definition at line 98 of file sagereader.h.

Referenced by SageReader(), and getmJsonAbsoluteFilePath().

◆ m_psmProteinMap

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

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

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

◆ mp_monitor

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

Definition at line 95 of file sagereader.h.

Referenced by SageReader(), and readTsvFile().


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