Skip to content
Snippets Groups Projects
Commit 7ea294d8 authored by Langella Olivier's avatar Langella Olivier
Browse files

xic extractor is now embedded in msrun

parent 59cc11bc
No related branches found
No related tags found
No related merge requests found
...@@ -7,26 +7,27 @@ ...@@ -7,26 +7,27 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2017 Olivier Langella <Olivier.Langella@u-psud.fr>. * Copyright (c) 2017 Olivier Langella <Olivier.Langella@u-psud.fr>.
* *
* This file is part of XTPcpp. * This file is part of XTPcpp.
* *
* XTPcpp is free software: you can redistribute it and/or modify * XTPcpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* XTPcpp is distributed in the hope that it will be useful, * XTPcpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with XTPcpp. If not, see <http://www.gnu.org/licenses/>. * along with XTPcpp. If not, see <http://www.gnu.org/licenses/>.
* *
* Contributors: * Contributors:
* Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and implementation * Olivier Langella <Olivier.Langella@u-psud.fr> - initial API and
******************************************************************************/ *implementation
******************************************************************************/
#include "msrun.h" #include "msrun.h"
...@@ -36,92 +37,147 @@ ...@@ -36,92 +37,147 @@
#include <QDir> #include <QDir>
#include <pappsomspp/msrun/msrunreaderfactory.h> #include <pappsomspp/msrun/msrunreaderfactory.h>
#include <pappsomspp/exception/exceptionnotfound.h> #include <pappsomspp/exception/exceptionnotfound.h>
#include <pappsomspp/xicextractor/msrunxicextractorfactory.h>
MsRun::MsRun(const QString & location):pappso::MsRunId(location) { MsRun::MsRun(const QString &location) : pappso::MsRunId(location)
QFileInfo fileinfo(location); {
QFileInfo fileinfo(location);
} }
MsRun::MsRun(const MsRun& other):pappso::MsRunId(other) { MsRun::MsRun(const MsRun &other) : pappso::MsRunId(other)
_param_stats = other._param_stats; {
_param_stats = other._param_stats;
} }
MsRun::~MsRun() { MsRun::~MsRun()
{
} }
pappso::MsRunReaderSp & MsRun::getMsRunReaderSp() { pappso::MsRunReaderSp &
return _msrun_reader_sp; MsRun::getMsRunReaderSp()
{
return _msrun_reader_sp;
} }
void MsRun::setMsRunStatistics(MsRunStatistics param, const QVariant& value) { void
_param_stats.insert(std::pair<MsRunStatistics, QVariant>(param, value)); MsRun::setMsRunStatistics(MsRunStatistics param, const QVariant &value)
{
_param_stats.insert(std::pair<MsRunStatistics, QVariant>(param, value));
} }
const std::map<MsRunStatistics, QVariant> & MsRun::getMsRunStatisticsMap() const { const std::map<MsRunStatistics, QVariant> &
return _param_stats; MsRun::getMsRunStatisticsMap() const
{
return _param_stats;
} }
const QVariant MsRun::getMsRunStatistics(MsRunStatistics param) const { const QVariant
try { MsRun::getMsRunStatistics(MsRunStatistics param) const
return _param_stats.at(param); {
try
{
return _param_stats.at(param);
} }
catch (std::out_of_range) { catch(std::out_of_range)
return QVariant(); {
return QVariant();
} }
} }
bool MsRun::findMsRunFile() { bool
MsRun::findMsRunFile()
{
QFileInfo file(this->getFilename()); QFileInfo file(this->getFilename());
bool file_ok = false; bool file_ok = false;
if (file.exists()) { if(file.exists())
file_ok = true; {
file_ok = true;
} }
QString basename = file.baseName(); QString basename = file.baseName();
QString onlyfilename = file.fileName(); QString onlyfilename = file.fileName();
QSettings settings; QSettings settings;
QString path = settings.value("path/mzdatadir", "").toString(); QString path = settings.value("path/mzdatadir", "").toString();
QDir dir_search(path); QDir dir_search(path);
QFileInfoList files = dir_search.entryInfoList(); QFileInfoList files = dir_search.entryInfoList();
foreach (QFileInfo file, files) { foreach(QFileInfo file, files)
if (file.isDir()) { {
qDebug() << "DIR: " << file.fileName(); if(file.isDir())
} else { {
qDebug() << "FILE: " << file.fileName(); qDebug() << "DIR: " << file.fileName();
if (onlyfilename == file.fileName()) { }
this->setFilename(file.absoluteFilePath()); else
file_ok = true; {
qDebug() << "FILE: " << file.fileName();
if(onlyfilename == file.fileName())
{
this->setFilename(file.absoluteFilePath());
file_ok = true;
} }
if (file.fileName().contains(onlyfilename)) { if(file.fileName().contains(onlyfilename))
this->setFilename(file.absoluteFilePath()); {
file_ok = true; this->setFilename(file.absoluteFilePath());
file_ok = true;
} }
} }
} }
if (file_ok) { if(file_ok)
if (_msrun_reader_sp == nullptr) { {
_msrun_reader_sp = pappso::MsRunReaderFactory::getInstance().buildPwizMsRunReaderSp(*this); if(_msrun_reader_sp == nullptr)
{
_msrun_reader_sp =
pappso::MsRunReaderFactory::getInstance().buildPwizMsRunReaderSp(
*this);
} }
} }
return file_ok; return file_ok;
} }
void MsRun::checkMsRunStatistics() { void
QVariant msrun_var = getMsRunStatistics(MsRunStatistics::total_spectra); MsRun::checkMsRunStatistics()
if (msrun_var.isNull()) { {
try { QVariant msrun_var = getMsRunStatistics(MsRunStatistics::total_spectra);
pappso::MsRunSimpleStatistics stats; if(msrun_var.isNull())
_msrun_reader_sp.get()->readSpectrumCollection(stats); {
try
setMsRunStatistics(MsRunStatistics::total_spectra, (unsigned int) stats.getTotalCount()); {
setMsRunStatistics(MsRunStatistics::total_spectra_ms1, (unsigned int) stats.getMsLevelCount(1)); pappso::MsRunSimpleStatistics stats;
setMsRunStatistics(MsRunStatistics::total_spectra_ms2, (unsigned int) stats.getMsLevelCount(2)); _msrun_reader_sp.get()->readSpectrumCollection(stats);
setMsRunStatistics(MsRunStatistics::total_spectra_ms3, (unsigned int) stats.getMsLevelCount(3));
setMsRunStatistics(MsRunStatistics::total_spectra,
(unsigned int)stats.getTotalCount());
setMsRunStatistics(MsRunStatistics::total_spectra_ms1,
(unsigned int)stats.getMsLevelCount(1));
setMsRunStatistics(MsRunStatistics::total_spectra_ms2,
(unsigned int)stats.getMsLevelCount(2));
setMsRunStatistics(MsRunStatistics::total_spectra_ms3,
(unsigned int)stats.getMsLevelCount(3));
} }
catch (pappso::ExceptionNotFound& error) { catch(pappso::ExceptionNotFound &error)
//no file found, no statistics {
// no file found, no statistics
} }
} }
} }
pappso::MsRunXicExtractorSp
MsRun::getMsRunXicExtractorSp()
{
if(_xic_extractor_sp != nullptr)
{
return _xic_extractor_sp;
}
if(this->findMsRunFile())
{
pappso::MsRunXicExtractorFactory::getInstance().setTmpDir("/tmp");
//_xic_extractor_sp = pappso::MsRunXicExtractorFactory::getInstance()
// .buildMsRunXicExtractorDiskBufferSp(*this);
_xic_extractor_sp = pappso::MsRunXicExtractorFactory::getInstance()
.buildMsRunXicExtractorPwizSp(*this);
}
return _xic_extractor_sp;
}
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include <QVariant> #include <QVariant>
#include <pappsomspp/msrun/msrunid.h> #include <pappsomspp/msrun/msrunid.h>
#include <pappsomspp/msrun/msrunreader.h> #include <pappsomspp/msrun/msrunreader.h>
#include <pappsomspp/xicextractor/msrunxicextractor.h>
#include "../utils/types.h" #include "../utils/types.h"
class MsRun; class MsRun;
...@@ -69,11 +70,16 @@ public: ...@@ -69,11 +70,16 @@ public:
pappso::MsRunReaderSp & getMsRunReaderSp(); pappso::MsRunReaderSp & getMsRunReaderSp();
void checkMsRunStatistics(); void checkMsRunStatistics();
pappso::MsRunXicExtractorSp getMsRunXicExtractorSp();
private : private :
std::map<MsRunStatistics, QVariant> _param_stats; std::map<MsRunStatistics, QVariant> _param_stats;
pappso::MsRunReaderSp _msrun_reader_sp; pappso::MsRunReaderSp _msrun_reader_sp;
pappso::MsRunXicExtractorSp _xic_extractor_sp;
}; };
#endif // MSRUN_H #endif // MSRUN_H
...@@ -5,92 +5,101 @@ ...@@ -5,92 +5,101 @@
* \brief XIC worker * \brief XIC worker
*/ */
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>. * Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>.
* *
* This file is part of XTPcpp. * This file is part of XTPcpp.
* *
* XTPcpp is free software: you can redistribute it and/or modify * XTPcpp is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or * the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version. * (at your option) any later version.
* *
* XTPcpp is distributed in the hope that it will be useful, * XTPcpp is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with XTPcpp. If not, see <http://www.gnu.org/licenses/>. * along with XTPcpp. If not, see <http://www.gnu.org/licenses/>.
* *
* Contributors: * Contributors:
* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation * Olivier Langella <olivier.langella@u-psud.fr> - initial API and
******************************************************************************/ *implementation
******************************************************************************/
#include <tuple> #include <tuple>
#include "xicworkerthread.h" #include "xicworkerthread.h"
#include <pappsomspp/peptide/peptidenaturalisotopelist.h> #include <pappsomspp/peptide/peptidenaturalisotopelist.h>
#include <pappsomspp/pappsoexception.h> #include <pappsomspp/pappsoexception.h>
#include <pappsomspp/xicextractor/msrunxicextractorfactory.h>
#include <pappsomspp/exception/exceptionnotfound.h> #include <pappsomspp/exception/exceptionnotfound.h>
#include <QDebug> #include <QDebug>
void XicWorkerThread::doXicLoad(MsRunSp p_msrun, std::vector<pappso::mz> mz_list, pappso::PrecisionP precision, pappso::XicExtractMethod method) { void
XicWorkerThread::doXicLoad(MsRunSp p_msrun, std::vector<pappso::mz> mz_list,
pappso::PrecisionP precision,
pappso::XicExtractMethod method)
{
try { try
std::vector<pappso::MassRange> mass_list; {
for (pappso::mz mass:mz_list) { std::vector<pappso::MassRange> mass_list;
mass_list.push_back(pappso::MassRange(mass, precision)); for(pappso::mz mass : mz_list)
{
mass_list.push_back(pappso::MassRange(mass, precision));
} }
//std::vector<pappso::XicSp> xic_sp_list = SpectrumStore::getXicSpFromMsRunSp(p_msrun.get(), mass_list, method); // std::vector<pappso::XicSp> xic_sp_list =
// SpectrumStore::getXicSpFromMsRunSp(p_msrun.get(), mass_list, method);
if (p_msrun.get()->findMsRunFile()) { pappso::MsRunXicExtractorSp extractor =
pappso::MsRunId msrun_id = * (p_msrun.get()); p_msrun.get()->getMsRunXicExtractorSp();
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " " << msrun_id.getFilename(); if(extractor != nullptr)
auto it = std::find_if(_extractor_list.begin(), _extractor_list.end(), [msrun_id](const pappso::MsRunXicExtractorSp & extractor_sp) { {
return extractor_sp.get()->getMsRunId().getXmlId() == msrun_id.getXmlId(); qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
}); extractor.get()->setXicExtractMethod(method);
pappso::MsRunXicExtractorSp extractor;
if (it == _extractor_list.end()) {
pappso::MsRunXicExtractorFactory::getInstance().setTmpDir("/tmp"); qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
extractor = pappso::MsRunXicExtractorFactory::getInstance().buildMsRunXicExtractorDiskBufferSp(msrun_id); std::vector<pappso::XicSp> xic_sp_list =
_extractor_list.push_back(extractor); extractor.get()->getXicSpList(mass_list);
}
else {
extractor = *it;
}
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ;
extractor.get()->setXicExtractMethod(method);
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__;
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ; emit xicLoaded(xic_sp_list);
std::vector<pappso::XicSp> xic_sp_list = extractor.get()->getXicSpList(mass_list);
qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ;
emit xicLoaded(xic_sp_list);
} }
} }
catch (pappso::PappsoException & error) { catch(pappso::PappsoException &error)
emit operationFailed(tr("Error extracting XIC for MSrun %1:\n%2").arg(p_msrun->getFilename()).arg(error.qwhat())); {
emit operationFailed(tr("Error extracting XIC for MSrun %1:\n%2")
.arg(p_msrun->getFilename())
.arg(error.qwhat()));
} }
} }
void XicWorkerThread::doComputeIsotopeMassList(pappso::PeptideSp peptide_sp, unsigned int charge, pappso::PrecisionP precision, double minimum_isotope_pattern_ratio) { void
qDebug() << "XicWorkerThread::doComputeIsotopeMassList " << precision->toString(); XicWorkerThread::doComputeIsotopeMassList(pappso::PeptideSp peptide_sp,
std::vector<pappso::PeptideNaturalIsotopeAverageSp> isotope_mass_list; unsigned int charge,
//compute isotope masses : pappso::PrecisionP precision,
if (peptide_sp != nullptr) { double minimum_isotope_pattern_ratio)
pappso::PeptideNaturalIsotopeList isotope_list(peptide_sp); {
isotope_mass_list = isotope_list.getByIntensityRatio(charge, precision, minimum_isotope_pattern_ratio); qDebug() << "XicWorkerThread::doComputeIsotopeMassList "
<< precision->toString();
std::vector<pappso::PeptideNaturalIsotopeAverageSp> isotope_mass_list;
// compute isotope masses :
if(peptide_sp != nullptr)
{
pappso::PeptideNaturalIsotopeList isotope_list(peptide_sp);
isotope_mass_list = isotope_list.getByIntensityRatio(
charge, precision, minimum_isotope_pattern_ratio);
std::sort (isotope_mass_list.begin(), isotope_mass_list.end(), [](const pappso::PeptideNaturalIsotopeAverageSp & m,const pappso::PeptideNaturalIsotopeAverageSp & n)-> bool { std::sort(isotope_mass_list.begin(), isotope_mass_list.end(),
unsigned int mn(m.get()->getIsotopeNumber()), nn(n.get()->getIsotopeNumber()); [](const pappso::PeptideNaturalIsotopeAverageSp &m,
unsigned int mr(m.get()->getIsotopeRank()), nr(n.get()->getIsotopeRank()); const pappso::PeptideNaturalIsotopeAverageSp &n) -> bool {
return (std::tie(mn, mr) < std::tie(nn, nr)); unsigned int mn(m.get()->getIsotopeNumber()),
}); nn(n.get()->getIsotopeNumber());
emit isotopeMassListComputed(isotope_mass_list); unsigned int mr(m.get()->getIsotopeRank()),
nr(n.get()->getIsotopeRank());
return (std::tie(mn, mr) < std::tie(nn, nr));
});
emit isotopeMassListComputed(isotope_mass_list);
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment