32#include <odsdochandlerinterface.h>
33#include <odsstream/tsvreader.h>
34#include <odsstream/odsexception.h>
36#include <qcontainerfwd.h>
45#include "../../../../fasta/fastareader.h"
50 const QString &sage_json_file)
51 : m_sageFileReader(sage_file_reader)
65 return m_jsonAbsoluteFilePath;
83 const QString &sequence_in)
86 QStringList description_split = description_in.split(
" ", Qt::SkipEmptyParts);
87 QString accession = description_split.at(0);
88 if(description_split.length() > 0)
89 description_split.remove(0);
92 const PsmProtein &psm_protein = mp_self->m_psmProteinMap.getByAccession(accession);
93 psm_protein.
protein_sp.get()->setSequence(sequence_in);
94 psm_protein.
protein_sp.get()->setDescription(description_split.join(
" "));
101 QString rev_accession = accession.prepend(m_decoyTag);
102 const PsmProtein &psm_protein = mp_self->m_psmProteinMap.getByAccession(rev_accession);
103 psm_protein.
protein_sp.get()->setSequence(sequence_in);
106 psm_protein.
protein_sp.get()->setDescription(description_split.join(
" "));
117 return *mp_cborWriter;
125 extractMzmlPathList(m_sageFileReader.getJsonDocument());
127 QString file_str = getTsvFilePath(m_sageFileReader.getJsonDocument());
128 QFileInfo tsv_file_info(file_str);
132 TsvReader tsv_reader(handler);
134 QFile tsv_file(tsv_file_info.absoluteFilePath());
135 tsv_reader.parse(tsv_file);
138 catch(OdsException &error_ods)
141 .arg(tsv_file_info.absoluteFilePath())
142 .arg(error_ods.qwhat()));
147 QFile fastaFile(getFastaFilePath(m_sageFileReader.getJsonDocument()));
150 reader.
parse(fastaFile);
153 mp_cborWriter->append(
"protein_map");
154 m_psmProteinMap.writeMap(*mp_cborWriter);
157 mp_cborWriter->append(
"sample_list");
158 mp_cborWriter->startArray();
163 catch(OdsException &error_ods)
166 .arg(tsv_file_info.absoluteFilePath())
167 .arg(error_ods.qwhat()));
170 mp_cborWriter->endArray();
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())
183 m_mzmlPathList.clear();
185 for(
auto path_mzml : json_mzml_path_list.toArray())
187 m_mzmlPathList << convertToLocalFileOrDie(path_mzml.toString());
194 for(
auto &file_path : m_mzmlPathList)
196 if(file_path.endsWith(file_msrun))
200 QObject::tr(
"MS run %1 not found in Sage json document").append(file_msrun));
208 QJsonObject sage_object = json_doc.object();
209 QJsonValue output_path = sage_object.value(
"output_paths");
210 if(output_path.isUndefined())
215 if(!output_path.isArray())
219 for(
auto element : output_path.toArray())
221 if(element.isString())
223 if(element.toString().endsWith(
".tsv"))
225 path = element.toString();
230 return convertToLocalFileOrDie(path);
237 QJsonObject sage_object = json_doc.object();
238 QJsonValue database = sage_object.value(
"database");
239 if(database.isUndefined())
243 path = database.toObject().value(
"fasta").toString();
250 return convertToLocalFileOrDie(path);
259 if(path.startsWith(
"file:") || path.startsWith(
"http:") || path.startsWith(
"https:"))
262 if(tsv_url.isValid())
264 qDebug() <<
"tsv_url.isValid()";
265 if(tsv_url.isLocalFile())
267 qDebug() <<
"tsv_url.isLocalFile()";
268 return tsv_url.toLocalFile();
273 QObject::tr(
"Unable to load data from remote URL %1").arg(tsv_url.toString()));
280std::vector<pappso::cbor::psm::SageReader::SageModification>
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())
291 QJsonValue static_mods = database.toObject().value(
"static_mods");
292 if(static_mods.isUndefined())
296 for(QString residue_str : static_mods.toObject().keys())
301 modif.
residue, static_mods.toObject().value(residue_str).toDouble());
303 QString::number(static_mods.toObject().value(residue_str).toDouble(),
'f', 6);
316 list.push_back(modif);
321std::vector<pappso::cbor::psm::SageReader::SageModification>
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())
332 QJsonValue var_mods = database.toObject().value(
"variable_mods");
333 if(var_mods.isUndefined())
337 for(QString residue_str : var_mods.toObject().keys())
339 qDebug() << residue_str;
344 qDebug() <<
"not amino acid";
345 QChar pos = residue_str.at(0).toLatin1();
346 qDebug() << residue_str <<
"not amino acid " << pos;
351 qDebug() << (char)modif.
residue;
357 else if((pos ==
'[') || (pos ==
']'))
367 qDebug() << (char)modif.
residue;
369 qDebug() << (char)modif.
residue;
373 qDebug() << residue_str <<
" " << (char)modif.
residue;
374 for(QJsonValue one_mass : var_mods.toObject().value(residue_str).toArray())
394 list.push_back(modif);
397 qDebug() << list.size();
400 qDebug() << list.size();
409 QJsonObject sage_object = m_sageFileReader.getJsonDocument().object();
410 QJsonValue database = sage_object.value(
"database");
411 if(database.isUndefined())
415 path = database.toObject().value(
"decoy_tag").toString();
426 return m_sageFileReader;
const QString & getAccession() const
pappso_double getMass() const
void parse(QFile &fastaFile)
static bool isAminoAcidChar(Enums::AminoAcidChar x)
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
overrides QCborStreamWriter base class to provide convenient functions
void setSequence(const QString &description_in, const QString &sequence_in) override
FastaSeq(SageReader *self)
const QString & getMzmlPath(const QString &file_msrun) const
SageReader(pappso::UiMonitorInterface *p_monitor, pappso::cbor::CborStreamWriter *p_output, const SageFileReader &sage_file_reader, const QString &sage_json_file)
std::vector< SageModification > getStaticModificationList() const
pappso::cbor::CborStreamWriter * mp_cborWriter
const QString & getmJsonAbsoluteFilePath() const
void extractMzmlPathList(const QJsonDocument &json_doc)
pappso::cbor::CborStreamWriter & getCborStreamWriter() const
QString m_jsonAbsoluteFilePath
std::vector< SageModification > getVariableModificationList() const
QString getFastaFilePath(const QJsonDocument &json_doc)
QString getDecoyTag() const
const SageFileReader & getSageFileReader() const
QString getTsvFilePath(const QJsonDocument &json_doc)
pappso::UiMonitorInterface * mp_monitor
QString convertToLocalFileOrDie(const QString &file_str) const
std::shared_ptr< Protein > protein_sp
pappso::AaModificationP modification
Enums::AminoAcidChar residue