From d4397f216a5e58f17d3977b472b0af28e79d203b Mon Sep 17 00:00:00 2001 From: Olivier Langella <olivier.langella@u-psud.fr> Date: Thu, 11 Jan 2018 23:06:04 +0100 Subject: [PATCH] new window to display XIC --- src/CMakeLists.txt | 13 ++-- .../identificationdatasource.cpp | 2 +- .../peptide_detail_view.ui | 51 ++++++++++--- src/gui/peptide_detail_view/peptidewindow.cpp | 22 +++++- src/gui/peptide_detail_view/peptidewindow.h | 1 + src/gui/project_view/projectwindow.cpp | 10 +++ src/gui/project_view/projectwindow.h | 3 + src/gui/xic_view/xic_window.ui | 37 ++++++++++ src/gui/xic_view/xicwindow.cpp | 60 ++++++++++++++++ src/gui/xic_view/xicwindow.h | 69 ++++++++++++++++++ src/output/ods/samplesheet.cpp | 2 +- src/utils/readspectrum.cpp | 71 +++++++++++-------- src/utils/readspectrum.h | 11 +-- 13 files changed, 301 insertions(+), 51 deletions(-) create mode 100644 src/gui/xic_view/xic_window.ui create mode 100644 src/gui/xic_view/xicwindow.cpp create mode 100644 src/gui/xic_view/xicwindow.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2548c7a41..eab1a55a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,12 +27,12 @@ SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${Qt5Xml_EXECUTABLE_COMPILE_FLAGS} ${Qt5 #sudo apt-get install libpappsomspp-dev -FIND_PACKAGE( Pappsomspp REQUIRED ) -# SET (PAPPSOMSPP_DIR "/home/olivier/eclipse/git/pappsomspp") +#FIND_PACKAGE( Pappsomspp REQUIRED ) + SET (PAPPSOMSPP_DIR "/home/olivier/eclipse/git/pappsomspp") # SET (PAPPSOMSPP_DIR "/home/langella/developpement/git/pappsomspp") -# SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src") -# SET (PAPPSOMSPP_QT5_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt5.so") -# SET (PAPPSOMSPP_WIDGET_QT5_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/pappsomspp/widget/libpappsomspp-widget-qt5.so") + SET (PAPPSOMSPP_INCLUDE_DIR "${PAPPSOMSPP_DIR}/src") + SET (PAPPSOMSPP_QT5_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt5.so") + SET (PAPPSOMSPP_WIDGET_QT5_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/pappsomspp/widget/libpappsomspp-widget-qt5.so") # SET (PAPPSOMSPP_QT4_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt4.so") IF (PAPPSOMSPP_QT5_FOUND) ELSE (PAPPSOMSPP_QT5_FOUND) @@ -158,6 +158,7 @@ SET(XTPCPP_SRCS ./gui/ptm_peptide_list_view/ptmsequencedelegate.cpp ./gui/tandem_run_dialog/tandemrundialog.cpp ./gui/waiting_message_dialog/waitingmessagedialog.cpp + ./gui/xic_view/xicwindow.cpp ./gui/workerthread.cpp ./utils/workmonitor.cpp ) @@ -182,6 +183,7 @@ SET (GUI_UIS ./gui/ptm_peptide_list_view/ptm_peptide_list_view.ui ./gui/tandem_run_dialog/tandem_run_dialog.ui ./gui/waiting_message_dialog/waiting_message_dialog.ui + ./gui/xic_view/xic_window.ui ) SET(XTPCPP_MOC_HDRS @@ -213,6 +215,7 @@ SET(XTPCPP_MOC_HDRS ./gui/ptm_peptide_list_view/ptmsequencedelegate.h ./gui/tandem_run_dialog/tandemrundialog.h ./gui/waiting_message_dialog/waitingmessagedialog.h + ./gui/xic_view/xicwindow.h ./gui/workerthread.h ./utils/workmonitor.h ) diff --git a/src/core/identification_sources/identificationdatasource.cpp b/src/core/identification_sources/identificationdatasource.cpp index 0cf8bcc2c..d368fd091 100644 --- a/src/core/identification_sources/identificationdatasource.cpp +++ b/src/core/identification_sources/identificationdatasource.cpp @@ -144,7 +144,7 @@ pappso::SpectrumSp IdentificationDataSource::getSpectrumSp(unsigned int scan_num if (_ms_run_sp.get()->getMzFormat() == MzFormat::MGF) { scan_number = scan_number-1; } - pappso::SpectrumSp spectrum_sp = SpectrumStore::getSpectrumSpFromMsRunSp(_ms_run_sp, scan_number); + pappso::SpectrumSp spectrum_sp = SpectrumStore::getSpectrumSpFromMsRunSp(_ms_run_sp.get(), scan_number); return spectrum_sp; } diff --git a/src/gui/peptide_detail_view/peptide_detail_view.ui b/src/gui/peptide_detail_view/peptide_detail_view.ui index dfa3b2df1..73c43a1b9 100644 --- a/src/gui/peptide_detail_view/peptide_detail_view.ui +++ b/src/gui/peptide_detail_view/peptide_detail_view.ui @@ -7,7 +7,7 @@ <x>0</x> <y>0</y> <width>826</width> - <height>430</height> + <height>443</height> </rect> </property> <property name="windowTitle"> @@ -114,11 +114,25 @@ </layout> </item> <item> - <widget class="QPushButton" name="pushButton"> - <property name="text"> - <string>Open in peptide viewer</string> - </property> - </widget> + <layout class="QVBoxLayout" name="verticalLayout_3"> + <item> + <widget class="QPushButton" name="pushButton"> + <property name="text"> + <string>Open in peptide viewer</string> + </property> + </widget> + </item> + <item> + <widget class="QPushButton" name="xic_button"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>XIC</string> + </property> + </widget> + </item> + </layout> </item> </layout> </item> @@ -397,8 +411,8 @@ <slot>chooseDefaultMzDataDir()</slot> <hints> <hint type="sourcelabel"> - <x>373</x> - <y>117</y> + <x>462</x> + <y>145</y> </hint> <hint type="destinationlabel"> <x>977</x> @@ -413,8 +427,8 @@ <slot>doMsmsPrecisionChanged(pappso::PrecisionP)</slot> <hints> <hint type="sourcelabel"> - <x>373</x> - <y>117</y> + <x>801</x> + <y>346</y> </hint> <hint type="destinationlabel"> <x>977</x> @@ -422,11 +436,28 @@ </hint> </hints> </connection> + <connection> + <sender>xic_button</sender> + <signal>clicked()</signal> + <receiver>PeptideDetailView</receiver> + <slot>openInXicViewer()</slot> + <hints> + <hint type="sourcelabel"> + <x>685</x> + <y>86</y> + </hint> + <hint type="destinationlabel"> + <x>924</x> + <y>119</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>chooseDefaultMzDataDir()</slot> <slot>openInPeptideViewer()</slot> <slot>doSaveSvg()</slot> <slot>doMsmsPrecisionChanged(pappso::PrecisionP)</slot> + <slot>openInXicViewer()</slot> </slots> </ui> diff --git a/src/gui/peptide_detail_view/peptidewindow.cpp b/src/gui/peptide_detail_view/peptidewindow.cpp index 07b41feee..01bd32985 100644 --- a/src/gui/peptide_detail_view/peptidewindow.cpp +++ b/src/gui/peptide_detail_view/peptidewindow.cpp @@ -23,6 +23,7 @@ #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> @@ -77,7 +78,7 @@ PeptideWindow::PeptideWindow(ProjectWindow *parent): QSettings settings; QString precision_str = settings.value("peptideview/precision", "0.2 dalton").toString(); - + _p_precision = pappso::Precision::fromString(precision_str); ui->file_not_found->setVisible(false); @@ -199,6 +200,7 @@ void PeptideWindow::chooseDefaultMzDataDir() { qDebug() << "PeptideWindow::chooseDefaultMzDataDir begin"; ui->file_not_found->setVisible(false); + ui->xic_button->setEnabled(true); ui->spectrum_widget->setVisible(true); emit loadSpectrumSp(_p_peptide_evidence); ui->statusbar->showMessage(tr("loading spectrum")); @@ -216,12 +218,18 @@ void PeptideWindow::openInPeptideViewer() { myProcess->start(program, arguments); } + +void PeptideWindow::openInXicViewer() { + _p_project_window->openInXicViewer(_p_peptide_evidence); +} + void PeptideWindow::doSpectrumSpReady(pappso::SpectrumSp spectrum_sp, QString error, QString fatal_error) { qDebug() << "PeptideWindow::doSpectrumSpReady begin error=" << error << " fatal_error=" << fatal_error; if ((error.isEmpty()) && (fatal_error.isEmpty())) { ui->statusbar->showMessage(tr("")); ui->file_not_found->setVisible(false); ui->spectrum_widget->setVisible(true); + ui->xic_button->setEnabled(true); ui->spectrum_widget->setMsLevel(2); ui->spectrum_widget->setSpectrumSp(spectrum_sp); @@ -230,6 +238,17 @@ void PeptideWindow::doSpectrumSpReady(pappso::SpectrumSp spectrum_sp, QString er qDebug() << "PeptideWindow::doSpectrumSpReady rescale"; ui->spectrum_widget->rescale(); _spectrum_is_ready = true; + + + try { + pappso::MassRange mass_range(_p_peptide_evidence->getPeptideXtpSp().get()->getMz(_p_peptide_evidence->getCharge()), pappso::Precision::getPpmInstance(10)); + + pappso::XicSp xic_sp = SpectrumStore::getXicSpFromMsRunSp(_p_peptide_evidence->getMsRunP(), mass_range, XixExtactMethod::max); + } + catch (pappso::PappsoException & error) { + QMessageBox::warning(this, + tr("Error trying to save spectrum to SVG file :"), error.qwhat()); + } } if (!error.isEmpty()) { //not found @@ -242,6 +261,7 @@ void PeptideWindow::doSpectrumSpReady(pappso::SpectrumSp spectrum_sp, QString er ui->file_not_found->setVisible(true); ui->spectrum_widget->setVisible(false); + ui->xic_button->setEnabled(false); _spectrum_is_ready = false; } if (!fatal_error.isEmpty()) { diff --git a/src/gui/peptide_detail_view/peptidewindow.h b/src/gui/peptide_detail_view/peptidewindow.h index 6c1709138..c165f1649 100644 --- a/src/gui/peptide_detail_view/peptidewindow.h +++ b/src/gui/peptide_detail_view/peptidewindow.h @@ -83,6 +83,7 @@ protected slots: void doSaveSvg(); void chooseDefaultMzDataDir(); void openInPeptideViewer(); + void openInXicViewer(); protected : void updateDisplay(); diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp index 5a9189483..134f16d82 100644 --- a/src/gui/project_view/projectwindow.cpp +++ b/src/gui/project_view/projectwindow.cpp @@ -762,3 +762,13 @@ void ProjectWindow::doAcceptedLabelingMethod() { } + +void ProjectWindow::openInXicViewer(const PeptideEvidence * p_peptide_evidence) { + qDebug() << "ProjectWindow::openInXicViewer begin"; + if (_p_xic_window == nullptr) { + _p_xic_window = new XicWindow(this); + } + + _p_xic_window->show(); + qDebug() << "ProjectWindow::openInXicViewer end"; +} diff --git a/src/gui/project_view/projectwindow.h b/src/gui/project_view/projectwindow.h index 727708b8b..a9439ef4f 100644 --- a/src/gui/project_view/projectwindow.h +++ b/src/gui/project_view/projectwindow.h @@ -37,6 +37,7 @@ #include "../peptide_detail_view/peptidewindow.h" #include "gui/project_view/automatic_filter_widget/automaticfilterwidget.h" #include "../waiting_message_dialog/waitingmessagedialog.h" +#include "../xic_view/xicwindow.h" #include <qcustomplot.h> class MainWindow; @@ -58,6 +59,7 @@ public: void setProjectSp(ProjectSp project_sp); void editModifications(); void editLabelingMethods(); + void openInXicViewer(const PeptideEvidence * p_peptide_evidence); ~ProjectWindow(); public slots: @@ -127,6 +129,7 @@ private: EditModifications * _p_edit_modifications = nullptr; EditLabelMethods * _p_edit_label_methods = nullptr; + XicWindow * _p_xic_window = nullptr; ProjectSp _project_sp; diff --git a/src/gui/xic_view/xic_window.ui b/src/gui/xic_view/xic_window.ui new file mode 100644 index 000000000..fa9b6cb85 --- /dev/null +++ b/src/gui/xic_view/xic_window.ui @@ -0,0 +1,37 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>XicWindow</class> + <widget class="QMainWindow" name="XicWindow"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>600</height> + </rect> + </property> + <property name="windowTitle"> + <string>XIC viewer</string> + </property> + <widget class="QWidget" name="centralwidget"> + <layout class="QVBoxLayout" name="verticalLayout_2"> + <item> + <layout class="QVBoxLayout" name="xic_vertical_layout"/> + </item> + </layout> + </widget> + <widget class="QMenuBar" name="menubar"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>800</width> + <height>25</height> + </rect> + </property> + </widget> + <widget class="QStatusBar" name="statusbar"/> + </widget> + <resources/> + <connections/> +</ui> diff --git a/src/gui/xic_view/xicwindow.cpp b/src/gui/xic_view/xicwindow.cpp new file mode 100644 index 000000000..4c5f13f2e --- /dev/null +++ b/src/gui/xic_view/xicwindow.cpp @@ -0,0 +1,60 @@ +/** + * \file src/gui/xic_view/xicwindow.cpp + * \date 11/1/2018 + * \author Olivier Langella + * \brief XIC window + */ + +/******************************************************************************* +* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>. +* +* This file is part of XTPcpp. +* +* XTPcpp 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. +* +* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation +******************************************************************************/ + +#include "xicwindow.h" +#include "ui_xic_window.h" +#include "../project_view/projectwindow.h" + + +XicWindow::XicWindow(ProjectWindow *parent): + QMainWindow(parent), + ui(new Ui::XicWindow) +{ + _project_window = parent; + + ui->setupUi(this); + XicWorkerThread * p_worker = new XicWorkerThread(); + p_worker->moveToThread(&_xic_thread); + _xic_thread.start(); + + +#if QT_VERSION >= 0x050000 + // Qt5 code + +#else +// Qt4 code +#endif + + +} + +XicWindow::~XicWindow() +{ + qDebug() << "XicWindow::~XicWindow"; +} diff --git a/src/gui/xic_view/xicwindow.h b/src/gui/xic_view/xicwindow.h new file mode 100644 index 000000000..6cfe806be --- /dev/null +++ b/src/gui/xic_view/xicwindow.h @@ -0,0 +1,69 @@ +/** + * \file src/gui/xic_view/xicwindow.h + * \date 11/1/2018 + * \author Olivier Langella + * \brief XIC window + */ +/******************************************************************************* +* Copyright (c) 2018 Olivier Langella <olivier.langella@u-psud.fr>. +* +* This file is part of XTPcpp. +* +* XTPcpp 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. +* +* XTPcpp 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 XTPcpp. If not, see <http://www.gnu.org/licenses/>. +* +* Contributors: +* Olivier Langella <olivier.langella@u-psud.fr> - initial API and implementation +******************************************************************************/ + +#ifndef XICWINDOW_H +#define XICWINDOW_H + +#include <QThread> +#include <QMainWindow> + +class ProjectWindow; + + +class XicWorkerThread : public QObject +{ + Q_OBJECT +public: + + +protected: + + void closeEvent(QCloseEvent *event); + +}; + + +namespace Ui { +class XicWindow; +} + +class XicWindow: public QMainWindow { + Q_OBJECT + +public: + + explicit XicWindow(ProjectWindow * parent = 0); + ~XicWindow(); + + +private: + ProjectWindow * _project_window; + QThread _xic_thread; + Ui::XicWindow *ui; +}; +#endif // XICWINDOW_H diff --git a/src/output/ods/samplesheet.cpp b/src/output/ods/samplesheet.cpp index a435cd359..e7b647de2 100644 --- a/src/output/ods/samplesheet.cpp +++ b/src/output/ods/samplesheet.cpp @@ -105,7 +105,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); + SpectrumStore::checkMsRunStatistics(msrun_sp.get()); } _p_writer->writeCell(msrun_sp.get()->getXmlId()); diff --git a/src/utils/readspectrum.cpp b/src/utils/readspectrum.cpp index d889642a1..bb9d4082f 100644 --- a/src/utils/readspectrum.cpp +++ b/src/utils/readspectrum.cpp @@ -90,9 +90,9 @@ void getXicFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, pappso: const pwiz::msdata::SpectrumList * p_spectrum_list = p_ms_data_file->run.spectrumListPtr.get(); std::size_t spectrum_list_size = p_spectrum_list->size(); pwiz::msdata::SpectrumPtr spectrum; - + XicElement peak; - + for (std::size_t i=0; i < spectrum_list_size; i++) { spectrum = p_spectrum_list->spectrum(i, false); unsigned int ms_level(QString(spectrum->cvParam(pwiz::msdata::MS_ms_level).value.c_str()).toUInt()); @@ -101,7 +101,7 @@ void getXicFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, pappso: spectrum = p_spectrum_list->spectrum(i, true); peak.rt = QString(spectrum->scanList.scans[0].cvParam(pwiz::msdata::MS_scan_start_time).value.c_str()).toDouble(); peak.intensity = 0; - + vector<pwiz::msdata::MZIntensityPair> pairs; spectrum->getMZIntensityPairs(pairs); @@ -109,7 +109,7 @@ void getXicFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, pappso: 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; - if (mass_range.contains(it->mz)){ + if (mass_range.contains(it->mz)) { if (method == XixExtactMethod::max) { if (peak.intensity < it->intensity) { peak.intensity = it->intensity; @@ -120,7 +120,7 @@ void getXicFromPwizMSDataFile(pwiz::msdata::MSDataFile * p_ms_data_file, pappso: } } } - + p_xic->push_back(peak); } @@ -259,13 +259,13 @@ pappso::QualifiedSpectrum getQualifiedSpectrumFromPwizMSDataFile(pwiz::msdata::M return qspectrum; } -std::map<MsRunSp, pwiz::msdata::MSDataFile *> create_map() +std::map<const MsRun *, pwiz::msdata::MSDataFile *> create_map() { - std::map<MsRunSp, pwiz::msdata::MSDataFile *> m; + std::map<const MsRun *, pwiz::msdata::MSDataFile *> m; return m; } -std::map<MsRunSp, pwiz::msdata::MSDataFile *> SpectrumStore::_map_msrun_msdatafile = create_map(); +std::map<const MsRun *, pwiz::msdata::MSDataFile *> SpectrumStore::_map_msrun_msdatafile = create_map(); const QString SpectrumStore::findMzFile(const QString &filename) { @@ -300,14 +300,14 @@ const QString SpectrumStore::findMzFile(const QString &filename) { return QString(); } -void SpectrumStore::checkMsRunStatistics(MsRunSp msrun) { - QVariant msrun_var = msrun.get()->getMsRunStatistics(MsRunStatistics::total_spectra); +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.get()->setMsRunStatistics(MsRunStatistics::total_spectra, (unsigned int) 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++) { @@ -316,10 +316,10 @@ void SpectrumStore::checkMsRunStatistics(MsRunSp msrun) { count_mslevel[msLevel]++; } - msrun.get()->setMsRunStatistics(MsRunStatistics::total_spectra, (unsigned int) spectrum_list_size); - msrun.get()->setMsRunStatistics(MsRunStatistics::total_spectra_ms1, (unsigned int) count_mslevel[1]); - msrun.get()->setMsRunStatistics(MsRunStatistics::total_spectra_ms2, (unsigned int) count_mslevel[2]); - msrun.get()->setMsRunStatistics(MsRunStatistics::total_spectra_ms3, (unsigned int) count_mslevel[3]); + 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 @@ -327,22 +327,35 @@ void SpectrumStore::checkMsRunStatistics(MsRunSp msrun) { } } -pwiz::msdata::MSDataFile * SpectrumStore::findPwizMSDataFile(MsRunSp msrun) { +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<MsRunSp, pwiz::msdata::MSDataFile *>::iterator it_msdata = _map_msrun_msdatafile.find(msrun); + 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(msrun.get()->getFilename()); + QString mz_file = findMzFile(p_msrun->getFilename()); if (mz_file.isEmpty()) { - qDebug() << "SpectrumStore::getSpectrumSpFromMsRunIdSp ERROR file not found " << msrun.get()->getFilename(); - throw pappso::ExceptionNotFound(QObject::tr("mz data \"%1\" file not found").arg(msrun.get()->getFilename())); + 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; } - msrun.get()->setFilename(mz_file); + p_msrun->setFilename(mz_file); p_msdatafile = getPwizMSDataFile(mz_file); //msrun.get()->setMzFormat(getPwizMSDataFileFormat(p_msdatafile)); - _map_msrun_msdatafile.insert(std::pair<MsRunSp, pwiz::msdata::MSDataFile *>(msrun, p_msdatafile)); + _map_msrun_msdatafile.insert(std::pair<const MsRun *, pwiz::msdata::MSDataFile *>(p_msrun, p_msdatafile)); } else { p_msdatafile =it_msdata->second; @@ -350,7 +363,7 @@ pwiz::msdata::MSDataFile * SpectrumStore::findPwizMSDataFile(MsRunSp msrun) { return p_msdatafile; } -pappso::SpectrumSp SpectrumStore::getSpectrumSpFromMsRunSp(MsRunSp msrun, unsigned int scan_num) { +pappso::SpectrumSp SpectrumStore::getSpectrumSpFromMsRunSp(MsRun * msrun, unsigned int scan_num) { pappso::QualifiedSpectrum spectrum; pwiz::msdata::MSDataFile * p_msdatafile = findPwizMSDataFile(msrun); @@ -358,7 +371,7 @@ pappso::SpectrumSp SpectrumStore::getSpectrumSpFromMsRunSp(MsRunSp msrun, unsign return spectrum.getOriginalSpectrumSp(); } spectrum = getQualifiedSpectrumFromPwizMSDataFile(p_msdatafile, scan_num); - if (msrun.get()->getMzFormat() == MzFormat::MGF) { + if (msrun->getMzFormat() == MzFormat::MGF) { if (spectrum.getRtInSeconds() == 0) { spectrum = getQualifiedSpectrumFromPwizMSDataFile(p_msdatafile, scan_num-1); } @@ -367,14 +380,16 @@ pappso::SpectrumSp SpectrumStore::getSpectrumSpFromMsRunSp(MsRunSp msrun, unsign } -pappso::XicSp SpectrumStore::getXicSpFromMsRunSp(MsRunSp msrun, const pappso::MassRange & mass_range, XixExtactMethod method) { - pwiz::msdata::MSDataFile * p_msdatafile = findPwizMSDataFile(msrun); +pappso::XicSp SpectrumStore::getXicSpFromMsRunSp(const MsRun * p_msrun, const pappso::MassRange & mass_range, XixExtactMethod method) { + qDebug() << "SpectrumStore::getXicSpFromMsRunSp begin" ; + pwiz::msdata::MSDataFile * p_msdatafile = findPwizMSDataFile(p_msrun); XicSp xic_sp; - if (p_msdatafile == nullptr) { - Xix xic; + if (p_msdatafile != nullptr) { + Xic xic; getXicFromPwizMSDataFile(p_msdatafile, &xic, mass_range, method); xic_sp = xic.makeXicSp(); + qDebug() << "SpectrumStore::getXicSpFromMsRunSp end" << xic_sp.get()->size(); } return (xic_sp); } diff --git a/src/utils/readspectrum.h b/src/utils/readspectrum.h index 507bb2fd5..c8eef8cc1 100644 --- a/src/utils/readspectrum.h +++ b/src/utils/readspectrum.h @@ -42,15 +42,16 @@ class MSDataFile; class SpectrumStore { public: - static pappso::SpectrumSp getSpectrumSpFromMsRunSp(MsRunSp msrun, unsigned int scan_num); - static pappso::XicSp getXicSpFromMsRunSp(MsRunSp msrun, const pappso::MassRange & mass_range, XixExtactMethod method); + static pappso::SpectrumSp getSpectrumSpFromMsRunSp(MsRun * p_msrun, unsigned int scan_num); + static pappso::XicSp getXicSpFromMsRunSp(const MsRun * p_msrun, const pappso::MassRange & mass_range, XixExtactMethod method); /** @brief try to find MS run statistics */ - static void checkMsRunStatistics(MsRunSp msrun); + static void checkMsRunStatistics(MsRun *); private: static const QString findMzFile(const QString &filename); - static pwiz::msdata::MSDataFile * findPwizMSDataFile(MsRunSp msrun) ; + static pwiz::msdata::MSDataFile * findPwizMSDataFile(MsRun * p_msrun) ; + static pwiz::msdata::MSDataFile * findPwizMSDataFile(const MsRun * p_msrun) ; private: - static std::map<MsRunSp, pwiz::msdata::MSDataFile *> _map_msrun_msdatafile; + static std::map<const MsRun *, pwiz::msdata::MSDataFile *> _map_msrun_msdatafile; }; #endif // READSPECTRUM_H -- GitLab