diff --git a/debian/control.cmake b/debian/control.cmake index e54f68d519c1202e6ebd34a11f1d3d2056b8d431..d3f83a02400edae8c4a08565f20a6b5409f36b88 100644 --- a/debian/control.cmake +++ b/debian/control.cmake @@ -7,6 +7,7 @@ Build-Depends: debhelper (>= 9), cmake (>= 2.6), qtbase5-dev, libpappsomspp-widget-qt5-dev (= @LIBPAPPSOMSPP_VERSION@), + libpwiz-dev, libodsstream-qt5-dev, libboost1.62-dev, libqt5svg5-dev, @@ -20,6 +21,7 @@ Multi-Arch: no Depends: ${shlibs:Depends}, ${misc:Depends}, libpappsomspp-widget-qt5-0 (= @LIBPAPPSOMSPP_VERSION@), + libpwiz3, libodsstream-qt5-0, libqt5gui5, libqt5core5a, diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 76b83adf50be9ec63c244513e6eda552724d2113..a11e04512986f4189066da1ae8e0a6f1c851ef83 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -154,7 +154,6 @@ SET(CPP_FILES utils/peptideevidencestore.cpp utils/peptidestore.cpp utils/proteinstore.cpp - utils/readspectrum.cpp utils/utils.cpp ) diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp index dfdfe885dc665934bcdac0242d76ec0033d35857..0f21750d3a4793713edd73a124d765b42693dfe5 100644 --- a/src/core/identification_sources/identificationdatasource.cpp +++ b/src/core/identification_sources/identificationdatasource.cpp @@ -24,8 +24,8 @@ #include "identificationdatasource.h" #include "identificationxtandemfile.h" #include <pappsomspp/pappsoexception.h> +#include <pappsomspp/exception/exceptionnotfound.h> #include <QFileInfo> -#include "../../utils/readspectrum.h" #include "../peptideevidence.h" IdentificationDataSource::IdentificationDataSource(const QString resource_name) @@ -142,10 +142,17 @@ const QVariant IdentificationDataSource::getIdentificationEngineStatistics(Ident } pappso::SpectrumSp IdentificationDataSource::getSpectrumSp(unsigned int scan_number) const { + qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ; if (_ms_run_sp.get()->getMzFormat() == pappso::MzFormat::MGF) { scan_number = scan_number-1; } - pappso::SpectrumSp spectrum_sp = SpectrumStore::getSpectrumSpFromMsRunSp(_ms_run_sp.get(), scan_number); + if (_ms_run_sp.get()->findMsRunFile() == false) { + throw pappso::ExceptionNotFound(QObject::tr("mz data \"%1\" file not found").arg(_ms_run_sp.get()->getFilename())); + } + + //qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << _ms_run_sp.get()->getMsRunReaderSp().get()->getSpectrumListSize(); + pappso::SpectrumSp spectrum_sp = _ms_run_sp.get()->getMsRunReaderSp().get()->getSpectrumSp(scan_number); + qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ; return spectrum_sp; } diff --git a/src/core/msrun.cpp b/src/core/msrun.cpp index 6ff532309cf476e7599a6860e381b6fb031ad092..d1a0ad8ce93b49f2b35b0d73eeca3cb76d51218e 100644 --- a/src/core/msrun.cpp +++ b/src/core/msrun.cpp @@ -31,6 +31,11 @@ #include "msrun.h" #include <QFileInfo> +#include <QSettings> +#include <QDebug> +#include <QDir> +#include <pappsomspp/msrun/msrunreaderfactory.h> +#include <pappsomspp/exception/exceptionnotfound.h> MsRun::MsRun(const QString & location):pappso::MsRunId(location) { QFileInfo fileinfo(location); @@ -42,6 +47,9 @@ MsRun::MsRun(const MsRun& other):pappso::MsRunId(other) { MsRun::~MsRun() { } +pappso::MsRunReaderSp & MsRun::getMsRunReaderSp() { + return _msrun_reader_sp; +} void MsRun::setMsRunStatistics(MsRunStatistics param, const QVariant& value) { _param_stats.insert(std::pair<MsRunStatistics, QVariant>(param, value)); @@ -59,3 +67,61 @@ const QVariant MsRun::getMsRunStatistics(MsRunStatistics param) const { return QVariant(); } } + +bool MsRun::findMsRunFile() { + + QFileInfo file(this->getFilename()); + bool file_ok = false; + + if (file.exists()) { + file_ok = true; + } + + QString basename = file.baseName(); + QString onlyfilename = file.fileName(); + QSettings settings; + QString path = settings.value("path/mzdatadir", "").toString(); + + QDir dir_search(path); + + QFileInfoList files = dir_search.entryInfoList(); + foreach (QFileInfo file, files) { + if (file.isDir()) { + qDebug() << "DIR: " << file.fileName(); + } else { + qDebug() << "FILE: " << file.fileName(); + if (onlyfilename == file.fileName()) { + this->setFilename(file.absoluteFilePath()); + file_ok = true; + } + if (file.fileName().contains(onlyfilename)) { + this->setFilename(file.absoluteFilePath()); + file_ok = true; + } + } + } + if (file_ok) { + if (_msrun_reader_sp == nullptr) { + _msrun_reader_sp = pappso::MsRunReaderFactory::getInstance().buildPwizMsRunReaderSp(*this); + } + } + return file_ok; +} + +void MsRun::checkMsRunStatistics() { + QVariant msrun_var = getMsRunStatistics(MsRunStatistics::total_spectra); + if (msrun_var.isNull()) { + try { + pappso::MsRunSimpleStatistics stats; + _msrun_reader_sp.get()->readSpectrumCollection(stats); + + 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) { + //no file found, no statistics + } + } +} diff --git a/src/core/msrun.h b/src/core/msrun.h index f6429edb0d873bf3ac99551d5bbeb4b4661a17b3..fd711b1e0ca90df8b6b43348c3a65755c36483e2 100644 --- a/src/core/msrun.h +++ b/src/core/msrun.h @@ -36,6 +36,7 @@ #include <QString> #include <QVariant> #include <pappsomspp/msrun/msrunid.h> +#include <pappsomspp/msrun/msrunreader.h> #include "../utils/types.h" class MsRun; @@ -62,9 +63,17 @@ public: /** \brief get MS run statistics map */ virtual const std::map<MsRunStatistics, QVariant> & getMsRunStatisticsMap() const; + + bool findMsRunFile(); + + pappso::MsRunReaderSp & getMsRunReaderSp(); + + void checkMsRunStatistics(); private : std::map<MsRunStatistics, QVariant> _param_stats; + + pappso::MsRunReaderSp _msrun_reader_sp; }; #endif // MSRUN_H diff --git a/src/gui/mainwindow.h b/src/gui/mainwindow.h index dd71b7fb1a1605e35721dc1c6671712c1418f2a8..3aed2e9b0eefc7f8c6f3eb8f23467cbafca51314 100644 --- a/src/gui/mainwindow.h +++ b/src/gui/mainwindow.h @@ -31,8 +31,6 @@ #include <pappsomspp/types.h> #include <pappsomspp/peptide/peptide.h> #include <pappsomspp/spectrum/spectrum.h> -#include <pwiz/data/msdata/MSDataFile.hpp> -#include "../utils/readspectrum.h" #include "core/project.h" #include "project_view/projectwindow.h" #include "load_results_dialog/loadresultsdialog.h" diff --git a/src/gui/peptide_detail_view/peptidewindow.cpp b/src/gui/peptide_detail_view/peptidewindow.cpp index cfda3d450d2438589fcca0694a35e25d5fa580e3..9e8591291ce5fdc56aa8add50c3e7bb9a4556d6e 100644 --- a/src/gui/peptide_detail_view/peptidewindow.cpp +++ b/src/gui/peptide_detail_view/peptidewindow.cpp @@ -23,7 +23,6 @@ #include "peptidewindow.h" #include "../project_view/projectwindow.h" -#include "../../utils/readspectrum.h" #include "../../config.h" #include "ui_peptide_detail_view.h" #include <pappsomspp/exception/exceptionnotfound.h> diff --git a/src/gui/xic_view/xicworkerthread.cpp b/src/gui/xic_view/xicworkerthread.cpp index 63858aa38b3456f41ef1cdc660ca6b17ac2f2658..3f83a25d6076e3af508b0fcf3f5a85fe73958fa5 100644 --- a/src/gui/xic_view/xicworkerthread.cpp +++ b/src/gui/xic_view/xicworkerthread.cpp @@ -28,9 +28,11 @@ #include <tuple> #include "xicworkerthread.h" -#include "../../utils/readspectrum.h" #include <pappsomspp/peptide/peptidenaturalisotopelist.h> #include <pappsomspp/pappsoexception.h> +#include <pappsomspp/xicextractor/msrunxicextractorfactory.h> +#include <pappsomspp/exception/exceptionnotfound.h> +#include <QDebug> void XicWorkerThread::doXicLoad(MsRunSp p_msrun, std::vector<pappso::mz> mz_list, pappso::PrecisionP precision, pappso::XicExtractMethod method) { @@ -39,9 +41,35 @@ void XicWorkerThread::doXicLoad(MsRunSp p_msrun, std::vector<pappso::mz> mz_list 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); - emit xicLoaded(xic_sp_list); + if (p_msrun.get()->findMsRunFile()) { + pappso::MsRunId msrun_id = * (p_msrun.get()); + qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ << " " << msrun_id.getFilename(); + 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(); + }); + + pappso::MsRunXicExtractorSp extractor; + if (it == _extractor_list.end()) { + + pappso::MsRunXicExtractorFactory::getInstance().setTmpDir("/tmp"); + extractor = pappso::MsRunXicExtractorFactory::getInstance().buildMsRunXicExtractorPwizSp(msrun_id); + _extractor_list.push_back(extractor); + } + else { + extractor = *it; + } + qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ; + extractor.get()->setXicExtractMethod(method); + + + qDebug() << __FILE__ << " " << __FUNCTION__ << " " << __LINE__ ; + 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) { diff --git a/src/gui/xic_view/xicworkerthread.h b/src/gui/xic_view/xicworkerthread.h index a59b86c58d45fd84a7e7af4ea136f1ea7dc61db1..36f4cce343057365ba16b01e7425fe9d8b9b07f6 100644 --- a/src/gui/xic_view/xicworkerthread.h +++ b/src/gui/xic_view/xicworkerthread.h @@ -33,6 +33,7 @@ #include<QObject> #include "../../core/msrun.h" #include <pappsomspp/xic/xic.h> +#include <pappsomspp/xicextractor/msrunxicextractor.h> class XicWorkerThread : public QObject { @@ -47,6 +48,9 @@ signals: void xicLoaded(std::vector<pappso::XicSp> xic_sp_list); void isotopeMassListComputed(std::vector<pappso::PeptideNaturalIsotopeAverageSp> isotope_mass_list); void operationFailed(QString error); + +private: + std::vector<pappso::MsRunXicExtractorSp> _extractor_list; }; #endif // XICWORKERTHREAD_H diff --git a/src/output/ods/samplesheet.cpp b/src/output/ods/samplesheet.cpp index bd14cf75a786c54ffbfa0d660800af7b9e8d455c..a9f2665a6e2e92641758dcd2c484fc5bb4635ed4 100644 --- a/src/output/ods/samplesheet.cpp +++ b/src/output/ods/samplesheet.cpp @@ -28,7 +28,6 @@ ******************************************************************************/ #include "samplesheet.h" -#include "../../utils/readspectrum.h" SampleSheet::SampleSheet (OdsExport * p_ods_export, CalcWriterInterface * p_writer, const Project * p_project): _p_project(p_project) { _p_writer = p_writer; @@ -109,7 +108,7 @@ void SampleSheet::writeIdentificationDataSource(IdentificationDataSource * p_ide _p_writer->writeLine(); MsRunSp msrun_sp = p_ident_data_source->getMsRunSp(); if (_msrun_statistics) { - SpectrumStore::checkMsRunStatistics(msrun_sp.get()); + if (msrun_sp->findMsRunFile()) msrun_sp->checkMsRunStatistics(); } _p_writer->writeCell(msrun_sp.get()->getXmlId()); diff --git a/src/utils/readspectrum.cpp b/src/utils/readspectrum.cpp deleted file mode 100644 index 935d916003701d595b20cbfe3272dc02def1f01b..0000000000000000000000000000000000000000 --- a/src/utils/readspectrum.cpp +++ /dev/null @@ -1,359 +0,0 @@ - -/******************************************************************************* -* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. -* -* This file is part of PAPPSOms-tools. -* -* PAPPSOms-tools is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* PAPPSOms-tools is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. -* -* Contributors: -* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation -******************************************************************************/ - -#include "readspectrum.h" - -#include <QDebug> -#include <QSettings> -#include <QFileInfo> -#include <QDir> -#include <QString> -#include <pappsomspp/spectrum/spectrum.h> -#include <pappsomspp/exception/exceptionnotfound.h> -#include <pappsomspp/xicextractor/msrunxicextractorfactory.h> - -#include <pwiz/data/common/cv.hpp> -#include <pwiz_tools/common/FullReaderList.hpp> -//#include <pwiz/utility/misc/Std.hpp> -#include <pwiz/data/msdata/SpectrumInfo.hpp> -#include <pwiz/data/msdata/MSData.hpp> -#include <locale> - -#include <pwiz/data/msdata/MSDataFile.hpp> -//http://sourceforge.net/p/proteowizard/mailman/message/28245157/ - -using namespace pappso; - -pwiz::msdata::MSDataFile * getPwizMSDataFile(const QString & filename); - -pappso::QualifiedSpectrum getQualifiedSpectrumFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, unsigned int scan_num); - - -pwiz::msdata::MSDataFile * getPwizMSDataFile(const QString & filename) { - qDebug() << "getPwizMSDataFile opening file " << filename ; - std::string env; - env=setlocale(LC_ALL,""); - struct lconv * lc = localeconv (); - qDebug() << " env=" << env.c_str() << " lc->decimal_point " << lc->decimal_point; - setlocale(LC_ALL,"C"); - //lc = localeconv (); - //qDebug() << " env=" << localeconv () << " lc->decimal_point " << lc->decimal_point; - pwiz::msdata::MSDataFile * dataFile; - try { - QByteArray byte_array = filename.toUtf8(); - std::string res = ""; - for (char c : byte_array) { - res += c; - } - dataFile = new pwiz::msdata::MSDataFile(res); - } - catch (std::exception& error) - { - qDebug() << "getPwizMSDataFile std error "; - throw pappso::PappsoException(QObject::tr("Error reading file (%1) using proteowizard library : %2").arg(filename).arg(error.what())); - } - setlocale(LC_ALL,env.c_str()); - - return dataFile; -} - -pappso::QualifiedSpectrum getQualifiedSpectrumFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, unsigned int scan_num) { - unsigned int precursor_charge_state=0; - - pappso::QualifiedSpectrum qspectrum; - - vector< pwiz::msdata::SourceFilePtr >::iterator source_file_it = p_ms_data_file->fileDescription.sourceFilePtrs.begin(); - if (source_file_it != p_ms_data_file->fileDescription.sourceFilePtrs.end()) { - qspectrum.setSpectrumId(SpectrumId(MsRunId((*source_file_it)->name.c_str()), scan_num)); - } - else { - qspectrum.setSpectrumId(SpectrumId(MsRunId("no msrun id"), scan_num)); - } - if (p_ms_data_file == nullptr) { - return (qspectrum); - } - std::string env; - env=setlocale(LC_ALL,""); - setlocale(LC_ALL,"C"); - const bool getBinaryData = true; - pwiz::msdata::SpectrumListPtr spectrum_list_ptr = p_ms_data_file->run.spectrumListPtr; - pwiz::msdata::CVID native_id_format; - unsigned int spectrum_index = 0; - if (spectrum_list_ptr.get()->size() == 1) { - spectrum_index = 0; - } - else { - // turn our scan numbers into navtieId strings for pwiz - native_id_format = pwiz::msdata::id::getDefaultNativeIDFormat(*p_ms_data_file); - string nativeScanId = pwiz::msdata::id::translateScanNumberToNativeID(native_id_format, QString("%1").arg(scan_num).toStdString()); - spectrum_index = spectrum_list_ptr.get()->find(nativeScanId); - } - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile spectrum_index " << spectrum_index; - if (spectrum_index == spectrum_list_ptr.get()->size()) { - //pwiz::msdata::SpectrumPtr simple_spectrum_pwiz = spectrum_list_ptr.get()->spectrum(10, getBinaryData); - //qDebug() << "spectrum id 10 " << simple_spectrum_pwiz.get()->get; - throw ExceptionNotFound(QObject::tr("scan number %1 not found in MS file").arg(scan_num)); - } - pwiz::msdata::SpectrumPtr simple_spectrum_pwiz; - try { - simple_spectrum_pwiz = spectrum_list_ptr.get()->spectrum(spectrum_index, getBinaryData); - } catch (std::runtime_error & error) { - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile error " << error.what() << " " << typeid(error).name(); - throw ExceptionNotFound(QObject::tr("scan number %1 not found in MS file std::runtime_error :\n%2").arg(scan_num).arg(error.what())); - } - catch (std::exception & error) { - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile error " << error.what() << " " << typeid(error).name(); - throw ExceptionNotFound(QObject::tr("scan number %1 not found in MS file :\n%2").arg(scan_num).arg(error.what())); - } - if (simple_spectrum_pwiz.get() == nullptr) { - throw ExceptionNotFound(QObject::tr("scan number %1 not found in MS file : null pointer").arg(scan_num)); - } - - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile precursors.size() " << simple_spectrum_pwiz.get()->precursors.size(); - if (simple_spectrum_pwiz.get()->precursors.size() > 0) { - pwiz::msdata::Precursor & precursor = *(simple_spectrum_pwiz.get()->precursors.begin()); - if (precursor.selectedIons.size() > 0) { - pwiz::msdata::SelectedIon & ion = *(precursor.selectedIons.begin()); - - //selected ion m/z - mz selected_ion_mz = QString(ion.cvParam(pwiz::cv::MS_selected_ion_m_z).value.c_str()).toDouble(); - //peak intensity - pappso_double peak_intensity = QString(ion.cvParam(pwiz::cv::MS_peak_intensity).value.c_str()).toDouble(); - - // unsigned int test = QString(ion.cvParam(pwiz::cv::MS_1200_series_LC_MSD_SL).value.c_str()).toUInt(); - // qDebug() << " tes "<< test; - //charge state - unsigned int charge_state = QString(ion.cvParam(pwiz::cv::MS_charge_state).value.c_str()).toUInt(); - - - qspectrum.setPrecursorMz(selected_ion_mz); - qDebug() << " selected_ion_mz "<< selected_ion_mz ; - qDebug() << " peak_intensity "<< peak_intensity; - qDebug() << " charge_state "<< charge_state; - if (charge_state > 0) { - precursor_charge_state = charge_state; - qspectrum.setPrecursorCharge(charge_state); - - } - } - } - - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile msLevel" ; - unsigned int msLevel(QString(simple_spectrum_pwiz->cvParam(pwiz::msdata::MS_ms_level).value.c_str()).toUInt()); - - pappso_double retentionTime = QString(simple_spectrum_pwiz->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time).value.c_str()).toDouble(); - qspectrum.setRtInSeconds(retentionTime); - qspectrum.setMsLevel(msLevel); - - /* for (pwiz::data::CVParam cv_param :ion.cvParams) { - pwiz::msdata::CVID param_id = cv_param.cvid; - qDebug() << param_id ; - //qDebug() << cv_param.cvid.c_str(); - qDebug() << cv_param.name().c_str(); - qDebug() << cv_param.value.c_str(); - }*/ - // fill in MZIntensityPair vector for convenient access to binary data - vector<pwiz::msdata::MZIntensityPair> pairs; - simple_spectrum_pwiz->getMZIntensityPairs(pairs); - // cout << "spectrum_simple size:" << pairs.size() << endl; - setlocale(LC_ALL,env.c_str()); - - Spectrum spectrum; - - // iterate through the m/z-intensity pairs - for (vector<pwiz::msdata::MZIntensityPair>::const_iterator it=pairs.begin(), end=pairs.end(); it!=end; ++it) - { - //qDebug() << "it->mz " << it->mz << " it->intensity" << it->intensity; - spectrum.push_back(Peak(it->mz, it->intensity)); - } - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile spectrum size " << spectrum.size(); - if (native_id_format == pwiz::cv::CVID::MS_Mascot_MGF_format) { - //sort peaks by mz - spectrum = spectrum.takeNmostIntense(1000); - //spectrum.sortMz(); - } - //cout << "spectrum_simple size " << spectrum_simple.getSpectrumSize()<< endl; - - // lc = localeconv (); - //qDebug() << " env=" << localeconv () << " lc->decimal_point " << lc->decimal_point; - SpectrumSp spectrum_sp = spectrum.makeSpectrumSp(); - qspectrum.setOriginalSpectrumSp(spectrum_sp); - qDebug() << "getQualifiedSpectrumFromPwizMSDataFile end "; - return qspectrum; -} - -std::map<const MsRun *, pwiz::msdata::MSDataFile *> create_map() -{ - std::map<const MsRun *, pwiz::msdata::MSDataFile *> m; - return m; -} - -std::map<const MsRun *, pwiz::msdata::MSDataFile *> SpectrumStore::_map_msrun_msdatafile = create_map(); - -std::map<const MsRun *, pappso::MsRunXicExtractorSp> create_xicmap() -{ - std::map<const MsRun *, pappso::MsRunXicExtractorSp> m; - return m; -} - -std::map<const MsRun *, pappso::MsRunXicExtractorSp> SpectrumStore::_map_msrun_msrunxicextractor = create_xicmap(); - - -const QString SpectrumStore::findMzFile(const QString &filename) { - - QFileInfo file(filename); - - if (file.exists()) { - return file.absoluteFilePath(); - } - - QString basename = file.baseName(); - QString onlyfilename = file.fileName(); - QSettings settings; - QString path = settings.value("path/mzdatadir", "").toString(); - - QDir dir_search(path); - - QFileInfoList files = dir_search.entryInfoList(); - foreach (QFileInfo file, files) { - if (file.isDir()) { - qDebug() << "DIR: " << file.fileName(); - } else { - qDebug() << "FILE: " << file.fileName(); - if (onlyfilename == file.fileName()) { - return file.absoluteFilePath(); - } - if (file.fileName().contains(onlyfilename)) { - return file.absoluteFilePath(); - } - } - } - return QString(); -} - -void SpectrumStore::checkMsRunStatistics(MsRun * msrun) { - QVariant msrun_var = msrun->getMsRunStatistics(MsRunStatistics::total_spectra); - if (msrun_var.isNull()) { - try { - pwiz::msdata::MSDataFile * p_msdatafile = findPwizMSDataFile(msrun); - const pwiz::msdata::SpectrumList * p_spectrum_list = p_msdatafile->run.spectrumListPtr.get(); - std::size_t spectrum_list_size = p_spectrum_list->size(); - msrun->setMsRunStatistics(MsRunStatistics::total_spectra, (unsigned int) spectrum_list_size); - - unsigned int count_mslevel[50] = {0}; - for (std::size_t i=0; i < spectrum_list_size; i++) { - pwiz::msdata::SpectrumPtr spectrum = p_spectrum_list->spectrum(i, false); - unsigned int msLevel(QString(spectrum->cvParam(pwiz::msdata::MS_ms_level).value.c_str()).toUInt()); - count_mslevel[msLevel]++; - } - - msrun->setMsRunStatistics(MsRunStatistics::total_spectra, (unsigned int) spectrum_list_size); - msrun->setMsRunStatistics(MsRunStatistics::total_spectra_ms1, (unsigned int) count_mslevel[1]); - msrun->setMsRunStatistics(MsRunStatistics::total_spectra_ms2, (unsigned int) count_mslevel[2]); - msrun->setMsRunStatistics(MsRunStatistics::total_spectra_ms3, (unsigned int) count_mslevel[3]); - } - catch (pappso::ExceptionNotFound& error) { - //no file found, no statistics - } - } -} - -pwiz::msdata::MSDataFile * SpectrumStore::findPwizMSDataFile(const MsRun * p_msrun) { - pwiz::msdata::MSDataFile * p_msdatafile = nullptr; - std::map<const MsRun *, pwiz::msdata::MSDataFile *>::iterator it_msdata = _map_msrun_msdatafile.find(p_msrun); - if (it_msdata == _map_msrun_msdatafile.end()) { - //not found - throw pappso::ExceptionNotFound(QObject::tr("mz data \"%1\" file not found").arg(p_msrun->getFilename())); - } - else { - p_msdatafile =it_msdata->second; - } - return p_msdatafile; -} - -pwiz::msdata::MSDataFile * SpectrumStore::findPwizMSDataFile(MsRun * p_msrun) { - pwiz::msdata::MSDataFile * p_msdatafile = nullptr; - std::map<const MsRun *, pwiz::msdata::MSDataFile *>::iterator it_msdata = _map_msrun_msdatafile.find(p_msrun); - if (it_msdata == _map_msrun_msdatafile.end()) { - //not found - - QString mz_file = findMzFile(p_msrun->getFilename()); - if (mz_file.isEmpty()) { - qDebug() << "SpectrumStore::getSpectrumSpFromMsRunIdSp ERROR file not found " << p_msrun->getFilename(); - throw pappso::ExceptionNotFound(QObject::tr("mz data \"%1\" file not found").arg(p_msrun->getFilename())); - //return spectrum; - } - p_msrun->setFilename(mz_file); - p_msdatafile = getPwizMSDataFile(mz_file); - //msrun.get()->setMzFormat(getPwizMSDataFileFormat(p_msdatafile)); - _map_msrun_msdatafile.insert(std::pair<const MsRun *, pwiz::msdata::MSDataFile *>(p_msrun, p_msdatafile)); - } - else { - p_msdatafile =it_msdata->second; - } - return p_msdatafile; -} - -pappso::SpectrumSp SpectrumStore::getSpectrumSpFromMsRunSp(MsRun * msrun, unsigned int scan_num) { - pappso::QualifiedSpectrum spectrum; - pwiz::msdata::MSDataFile * p_msdatafile = findPwizMSDataFile(msrun); - - if (p_msdatafile == nullptr) { - return spectrum.getOriginalSpectrumSp(); - } - spectrum = getQualifiedSpectrumFromPwizMSDataFile(p_msdatafile, scan_num); - if (msrun->getMzFormat() == pappso::MzFormat::MGF) { - if (spectrum.getRtInSeconds() == 0) { - spectrum = getQualifiedSpectrumFromPwizMSDataFile(p_msdatafile, scan_num-1); - } - } - return spectrum.getOriginalSpectrumSp(); - -} - -std::vector<pappso::XicSp> SpectrumStore::getXicSpFromMsRunSp(MsRun * p_msrun, const std::vector<pappso::MassRange> & mass_range_list, pappso::XicExtractMethod method) { - qDebug() << "SpectrumStore::getXicSpFromMsRunSp begin" ; - pappso::MsRunXicExtractorFactory::getInstance().setTmpDir("/tmp"); - std::vector<pappso::XicSp> xic_sp_list; - if (p_msrun == nullptr) { - qDebug() << "SpectrumStore::getXicSpFromMsRunSp ERROR p_msrun == nullptr " ; - throw pappso::ExceptionNotFound(QObject::tr("SpectrumStore::getXicSpFromMsRunSp ERROR p_msrun == nullptr")); - //return spectrum; - } - - pwiz::msdata::MSDataFile * p_msdatafile = findPwizMSDataFile(p_msrun); - - if (p_msdatafile != nullptr) { - auto it = _map_msrun_msrunxicextractor.find(p_msrun); - if (it == _map_msrun_msrunxicextractor.end()) { - pappso::MsRunXicExtractorSp extractor = pappso::MsRunXicExtractorFactory::getInstance().buildMsRunXicExtractorPwizSp(*p_msrun); - - _map_msrun_msrunxicextractor.insert(std::pair<MsRun *, pappso::MsRunXicExtractorSp>(p_msrun, extractor)); - extractor->setXicExtractMethod(method); - return extractor.get()->getXicSpList(mass_range_list); - } - it->second.get()->setXicExtractMethod(method); - return it->second.get()->getXicSpList(mass_range_list); - } - return (xic_sp_list); -} diff --git a/src/utils/readspectrum.h b/src/utils/readspectrum.h deleted file mode 100644 index 1f5c916eae2c7aac971ea6b21656ac01d2a11369..0000000000000000000000000000000000000000 --- a/src/utils/readspectrum.h +++ /dev/null @@ -1,58 +0,0 @@ - -/******************************************************************************* -* Copyright (c) 2015 Olivier Langella <Olivier.Langella@moulon.inra.fr>. -* -* This file is part of PAPPSOms-tools. -* -* PAPPSOms-tools is free software: you can redistribute it and/or modify -* it under the terms of the GNU General Public License as published by -* the Free Software Foundation, either version 3 of the License, or -* (at your option) any later version. -* -* PAPPSOms-tools is distributed in the hope that it will be useful, -* but WITHOUT ANY WARRANTY; without even the implied warranty of -* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -* GNU General Public License for more details. -* -* You should have received a copy of the GNU General Public License -* along with PAPPSOms-tools. If not, see <http://www.gnu.org/licenses/>. -* -* Contributors: -* Olivier Langella <Olivier.Langella@moulon.inra.fr> - initial API and implementation -******************************************************************************/ - -#ifndef READSPECTRUM_H -#define READSPECTRUM_H - -#include <QString> -#include <pappsomspp/spectrum/qualifiedspectrum.h> -#include <pappsomspp/xicextractor/msrunxicextractor.h> -#include <map> -#include "../core/msrun.h" - -pappso::Spectrum readSpectrum(const QString & filename, unsigned int scan_num,unsigned int & precursor_charge_state); - - -namespace pwiz { -namespace msdata { -class MSDataFile; -} -} -//MzFormat getPwizMSDataFileFormat(pwiz::msdata::MSDataFile * p_ms_data_file); - -class SpectrumStore { -public: - static pappso::SpectrumSp getSpectrumSpFromMsRunSp(MsRun * p_msrun, unsigned int scan_num); - static std::vector<pappso::XicSp> getXicSpFromMsRunSp(MsRun * p_msrun, const std::vector<pappso::MassRange> & mass_range_list, pappso::XicExtractMethod method); - /** @brief try to find MS run statistics - */ - static void checkMsRunStatistics(MsRun *); -private: - static const QString findMzFile(const QString &filename); - static pwiz::msdata::MSDataFile * findPwizMSDataFile(MsRun * p_msrun) ; - static pwiz::msdata::MSDataFile * findPwizMSDataFile(const MsRun * p_msrun) ; -private: - static std::map<const MsRun *, pwiz::msdata::MSDataFile *> _map_msrun_msdatafile; - static std::map<const MsRun *, pappso::MsRunXicExtractorSp> _map_msrun_msrunxicextractor; -}; -#endif // READSPECTRUM_H