Commit a373f979 authored by Langella Olivier's avatar Langella Olivier
Browse files

convenient functions to get a spectrum index even if we have only a scan number

parent b9155c9e
...@@ -674,3 +674,47 @@ MsRun::getQualifiedMassSpectrumBySpectrumIndex(std::size_t spectrum_index, ...@@ -674,3 +674,47 @@ MsRun::getQualifiedMassSpectrumBySpectrumIndex(std::size_t spectrum_index,
<< " index=" << spectrum_index; << " index=" << spectrum_index;
return msrun_reader_sp.get()->qualifiedMassSpectrum(spectrum_index, data); return msrun_reader_sp.get()->qualifiedMassSpectrum(spectrum_index, data);
} }
std::size_t
MsRun::scanNumber2SpectrumIndex(std::size_t scan_number)
{
qDebug() << "scan=" << scan_number;
if(getMzFormat() == pappso::MzFormat::MGF)
{
scan_number = scan_number - 1;
qDebug() << "MGF format";
}
pappso::MsRunReaderSPtr msrun_reader_sp = getMsRunReaderSPtr();
if(msrun_reader_sp == nullptr)
{
msrun_reader_sp = findMsRunFile();
if(msrun_reader_sp == nullptr)
{
throw pappso::ExceptionNotFound(
QObject::tr("mz data \"%1\" file not found").arg(getFileName()));
}
}
qDebug();
msrun_reader_sp = getMsRunReaderSPtr();
if(msrun_reader_sp == nullptr)
{
throw pappso::ExceptionNotFound(
QObject::tr("mz data \"%1\" file not found").arg(getFileName()));
}
if(msrun_reader_sp.get()->hasScanNumbers())
{
qDebug() << "HAS SCAN NUMBERS";
return msrun_reader_sp.get()->scanNumber2SpectrumIndex(scan_number);
}
else
{
throw pappso::ExceptionNotFound(
QObject::tr("mz data \"%1\" file does not contain scan numbers")
.arg(getFileName()));
}
}
...@@ -144,6 +144,14 @@ class MsRun : public pappso::MsRunId ...@@ -144,6 +144,14 @@ class MsRun : public pappso::MsRunId
pappso::QualifiedMassSpectrum pappso::QualifiedMassSpectrum
getQualifiedMassSpectrumByScanNumber(std::size_t scan_number, bool data); getQualifiedMassSpectrumByScanNumber(std::size_t scan_number, bool data);
/** @brief finds the spectrum index corresponding to a scan number
*
* @param scan_number the scan number to convert
* @return spectrum index or an exception
*/
std::size_t scanNumber2SpectrumIndex(std::size_t scan_number);
private: private:
void buildMsRunReaderSp(); void buildMsRunReaderSp();
......
...@@ -446,11 +446,33 @@ PeptideEvidence::getSpectrumIndex() const ...@@ -446,11 +446,33 @@ PeptideEvidence::getSpectrumIndex() const
} }
throw pappso::ExceptionNotFound( throw pappso::ExceptionNotFound(
QObject::tr( QObject::tr(
"this peptide evidence has no spectrum index, only a scan number : ") "this peptide evidence has no spectrum index, only a scan number : %1")
.arg(m_scan_number)); .arg(m_scan_number));
} }
std::size_t
PeptideEvidence::getSpectrumIndexByScanNumber() const
{
if(m_isSpectrumIndex)
{
return m_scan_number;
}
else
{
if(_msrunid_sp != nullptr)
{
return _msrunid_sp->scanNumber2SpectrumIndex(m_scan_number);
}
else
{
throw pappso::PappsoException(
QObject::tr("_msrunid_sp == nullptr"));
}
}
}
QString QString
PeptideEvidence::getHtmlSequence() const PeptideEvidence::getHtmlSequence() const
{ {
......
...@@ -200,6 +200,16 @@ class PeptideEvidence ...@@ -200,6 +200,16 @@ class PeptideEvidence
* @return spectrum index or not found exception * @return spectrum index or not found exception
*/ */
std::size_t getSpectrumIndex() const; std::size_t getSpectrumIndex() const;
/** @brief get the spectrum index from the scan number
*
* finds a spectrum index using a scan number if necessary
*
* @return spectrum_index or not found exception
*
*/
std::size_t getSpectrumIndexByScanNumber() const;
/** @brief get HTML sequence of the peptide /** @brief get HTML sequence of the peptide
......
...@@ -636,7 +636,7 @@ XicBox::setIsotopeMassList( ...@@ -636,7 +636,7 @@ XicBox::setIsotopeMassList(
->getMsRunReaderSPtr() ->getMsRunReaderSPtr()
.get() .get()
->newXicCoordSPtrFromSpectrumIndex( ->newXicCoordSPtrFromSpectrumIndex(
_p_peptide_evidence->getSpectrumIndex(), _p_peptide_evidence->getSpectrumIndexByScanNumber(),
_p_xic_window->getXicExtractPrecision()); _p_xic_window->getXicExtractPrecision());
std::vector<pappso::XicCoordSPtr> mass_list; std::vector<pappso::XicCoordSPtr> mass_list;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment