diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 78e9cbc056f6f1ccb5180f19930730847cfffd4a..0e6e3ffb594abeff4f574f776eb73d39334845a0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -32,7 +32,19 @@ FIND_PACKAGE( Pappsomspp REQUIRED ) # 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_QT4_LIBRARY "${PAPPSOMSPP_DIR}/cbuild/src/libpappsomspp-qt4.so") +IF (PAPPSOMSPP_QT5_FOUND) +ELSE (PAPPSOMSPP_QT5_FOUND) + MESSAGE("PAPPSOms++ library not found") + MESSAGE("did you apt-get install libpappsomspp-dev ?") +ENDIF (PAPPSOMSPP_QT5_FOUND) + +IF (PAPPSOMSPP_WIDGET_QT5_FOUND) +ELSE (PAPPSOMSPP_WIDGET_QT5_FOUND) + MESSAGE("PAPPSOms++ widget library not found") + MESSAGE("did you apt-get install libpappsomspp-widget-dev ?") +ENDIF (PAPPSOMSPP_WIDGET_QT5_FOUND) set(CMAKE_MODULE_PATH ${CMAKE_SOURCE_DIR}/cmake_modules) @@ -80,7 +92,6 @@ SET(CPP_FILES grouping/ptm/ptmislandgroup.cpp grouping/ptm/ptmislandsubgroup.cpp grouping/ptm/ptmsamplescan.cpp - gui/peptide_detail_view/spectrum_widget/spectrumpainter.cpp input/condorqxmlsaxhandler.cpp input/identificationpwizreader.cpp input/xpipsaxhandler.cpp @@ -128,8 +139,6 @@ SET(XTPCPP_SRCS ./gui/load_results_dialog/loadresultsdialog.cpp ./gui/mainwindow.cpp ./gui/peptide_detail_view/peptidewindow.cpp - ./gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp - ./gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp ./gui/peptide_list_view/peptidelistwindow.cpp ./gui/peptide_list_view/peptidetablemodel.cpp ./gui/peptide_list_view/peptidetableproxymodel.cpp @@ -185,8 +194,6 @@ SET(XTPCPP_MOC_HDRS ./gui/load_results_dialog/loadresultsdialog.h ./gui/mainwindow.h ./gui/peptide_detail_view/peptidewindow.h - ./gui/peptide_detail_view/spectrum_widget/overlaywidget.h - ./gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h ./gui/peptide_list_view/peptidelistwindow.h ./gui/peptide_list_view/peptidetablemodel.h ./gui/peptide_list_view/peptidetableproxymodel.h @@ -223,8 +230,7 @@ MESSAGE("XTPCPP_SRCS: ${XTPCPP_SRCS}") ADD_EXECUTABLE(xtpcpp main.cpp ${CPP_FILES} ${XTPCPP_SRCS} ${GUI_UI_HDRS} ${XTPCPP_MOC_SRCS} ${xtpcpp_RCC_SRCS}) target_include_directories (xtpcpp PUBLIC ${Pwiz_INCLUDE_DIR} ${PAPPSOMSPP_INCLUDE_DIR} ${ODSSTREAM_INCLUDE_DIR} -${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} -${CMAKE_CURRENT_BINARY_DIR}/gui/peptide_detail_view/spectrum_widget ${CMAKE_CURRENT_SOURCE_DIR}/gui/peptide_detail_view/spectrum_widget) +${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_BINARY_DIR} ) target_compile_definitions(xtpcpp PUBLIC ${QT_DEFINITIONS}) SET_TARGET_PROPERTIES(xtpcpp @@ -233,7 +239,7 @@ target_compile_definitions(xtpcpp PUBLIC ${QT_DEFINITIONS}) #COMPILE_DEFINITIONS "${QT_DEFINITIONS}" #INCLUDE_DIRECTORIES "${QT_INCLUDE_DIR} ${QT_QTCORE_INCLUDE_DIR}" ) -TARGET_LINK_LIBRARIES(xtpcpp ${PAPPSOMSPP_QT5_LIBRARY} ${Pwiz_LIBRARY} ${ODSSTREAM_QT5_LIBRARY} ${QCustomPlot_LIBRARIES} +TARGET_LINK_LIBRARIES(xtpcpp ${PAPPSOMSPP_QT5_LIBRARY} ${PAPPSOMSPP_WIDGET_QT5_LIBRARY} ${Pwiz_LIBRARY} ${ODSSTREAM_QT5_LIBRARY} ${QCustomPlot_LIBRARIES} Qt5::Gui Qt5::Xml Qt5::Svg Qt5::PrintSupport) INSTALL(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xtpcpp DESTINATION bin) diff --git a/src/gui/edit_modifications/editmodifications.cpp b/src/gui/edit_modifications/editmodifications.cpp index 5eb3e1ace3ce454d9d1c202aaa89ea51c8f85a89..ad688acd01474b94077f8d34873e214d62518b46 100644 --- a/src/gui/edit_modifications/editmodifications.cpp +++ b/src/gui/edit_modifications/editmodifications.cpp @@ -102,7 +102,7 @@ void EditModifications::ItemClicked (QModelIndex index ) qDebug() << "EditModifications::ItemClicked data=" << index.data().toString(); qDebug() << "EditModifications::ItemClicked acc=" << _p_modification_str_li->data(index,Qt::UserRole).toString(); qDebug() << "EditModifications::ItemClicked str=" << _p_modification_str_li->data(index,Qt::DisplayRole).toString(); - pappso::AaModificationP modification = AaModification::getInstance(index.data(Qt::UserRole).toString()); + pappso::AaModificationP modification = pappso::AaModification::getInstance(index.data(Qt::UserRole).toString()); setSelectedModification(modification); setReplaceModification(nullptr); } diff --git a/src/gui/peptide_detail_view/peptide_detail_view.ui b/src/gui/peptide_detail_view/peptide_detail_view.ui index 14e90e9e76b4d5f46a2d7b58af6243f83c52dd49..d0fd5c0816d0feabbd3d74eedb6f0471b57499aa 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>404</height> + <height>430</height> </rect> </property> <property name="windowTitle"> @@ -127,31 +127,31 @@ <item> <layout class="QVBoxLayout" name="verticalLayout_9"> <item> - <widget class="QWidget" name="file_not_found"> - <layout class="QFormLayout" name="file_not_found_layout"> - <item row="0" column="0"> - <widget class="QLabel" name="mz_data_dir_label"> - <property name="text"> - <string>TextLabel</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QPushButton" name="select_dir"> - <property name="text"> - <string>set mz data directory</string> - </property> - </widget> - </item> - </layout> - </widget> + <widget class="QWidget" name="file_not_found" native="true"> + <layout class="QFormLayout" name="file_not_found_layout"> + <item row="0" column="0"> + <widget class="QLabel" name="mz_data_dir_label"> + <property name="text"> + <string>TextLabel</string> + </property> + </widget> + </item> + <item row="0" column="1"> + <widget class="QPushButton" name="select_dir"> + <property name="text"> + <string>set mz data directory</string> + </property> + </widget> + </item> + </layout> + </widget> </item> <item> <layout class="QHBoxLayout" name="horizontalLayout_2"> <item> <layout class="QHBoxLayout" name="horizontalLayout_4"> <item> - <widget class="QSpectrumWidget" name="spectrumWidget" native="true"> + <widget class="pappso::SpectrumWidget" name="spectrum_widget" native="true"> <property name="sizePolicy"> <sizepolicy hsizetype="Expanding" vsizetype="Expanding"> <horstretch>0</horstretch> @@ -340,7 +340,7 @@ <x>0</x> <y>0</y> <width>826</width> - <height>23</height> + <height>25</height> </rect> </property> </widget> @@ -348,29 +348,14 @@ </widget> <customwidgets> <customwidget> - <class>QSpectrumWidget</class> + <class>pappso::SpectrumWidget</class> <extends>QWidget</extends> - <header>qspectrumwidget.h</header> + <header>pappsomspp/widget/spectrumwidget/spectrumwidget.h</header> + <container>1</container> </customwidget> </customwidgets> <resources/> <connections> - <connection> - <sender>select_dir</sender> - <signal>clicked()</signal> - <receiver>PeptideDetailView</receiver> - <slot>chooseDefaultMzDataDir()</slot> - <hints> - <hint type="sourcelabel"> - <x>371</x> - <y>101</y> - </hint> - <hint type="destinationlabel"> - <x>838</x> - <y>384</y> - </hint> - </hints> - </connection> <connection> <sender>pushButton</sender> <signal>clicked()</signal> @@ -394,8 +379,8 @@ <slot>doMsmsPrecisionValueChanged(double)</slot> <hints> <hint type="sourcelabel"> - <x>804</x> - <y>325</y> + <x>801</x> + <y>346</y> </hint> <hint type="destinationlabel"> <x>870</x> @@ -426,8 +411,8 @@ <slot>doSaveSvg()</slot> <hints> <hint type="sourcelabel"> - <x>729</x> - <y>348</y> + <x>813</x> + <y>392</y> </hint> <hint type="destinationlabel"> <x>866</x> @@ -435,6 +420,22 @@ </hint> </hints> </connection> + <connection> + <sender>select_dir</sender> + <signal>clicked()</signal> + <receiver>PeptideDetailView</receiver> + <slot>chooseDefaultMzDataDir()</slot> + <hints> + <hint type="sourcelabel"> + <x>373</x> + <y>117</y> + </hint> + <hint type="destinationlabel"> + <x>977</x> + <y>204</y> + </hint> + </hints> + </connection> </connections> <slots> <slot>chooseDefaultMzDataDir()</slot> diff --git a/src/gui/peptide_detail_view/peptidewindow.cpp b/src/gui/peptide_detail_view/peptidewindow.cpp index c500a83d4706236df20c3f567def50c03ce26cb2..415e08c83ad70ab20ebe6fc4736a14fbe923ecd7 100644 --- a/src/gui/peptide_detail_view/peptidewindow.cpp +++ b/src/gui/peptide_detail_view/peptidewindow.cpp @@ -45,17 +45,17 @@ void SpectrumSpLoaderThread::doLoadSpectrumSp (PeptideEvidence * p_peptide_evide } catch (pappso::ExceptionNotFound & error) { - qDebug() << "SpectrumSpLoaderThread::doLoadSpectrumSp error " << error.qwhat(); + qDebug() << "SpectrumSpLoaderThread::doLoadSpectrumSp error " << error.qwhat(); emit spectrumSpReady(spectrum, error.qwhat(), QString("")); } - + catch (pappso::PappsoException & error) { qDebug() << "SpectrumSpLoaderThread::doLoadSpectrumSp error " << error.qwhat(); emit spectrumSpReady(spectrum, QString(""), error.qwhat()); } - + catch (std::exception & error) { - qDebug() << "SpectrumSpLoaderThread::doLoadSpectrumSp error " << error.what(); + qDebug() << "SpectrumSpLoaderThread::doLoadSpectrumSp error " << error.what(); emit spectrumSpReady(spectrum, QString(""), QString(error.what())); } qDebug() << "SpectrumSpLoaderThread::doLoadSpectrumSp end"; @@ -68,8 +68,6 @@ PeptideWindow::PeptideWindow(ProjectWindow *parent): qDebug() << "PeptideWindow::PeptideWindow begin"; _p_project_window = parent; ui->setupUi(this); - - _p_spectrum_overlay = new LoadingOverlay(ui->spectrumWidget); /* */ SpectrumSpLoaderThread * worker = new SpectrumSpLoaderThread; @@ -85,13 +83,16 @@ PeptideWindow::PeptideWindow(ProjectWindow *parent): ui->precision_spinbox->setValue(precision); if (unit == "dalton") { - _p_precision = Precision::getDaltonInstance(precision); + _p_precision = pappso::Precision::getDaltonInstance(precision); } else { - _p_precision = Precision::getPpmInstance(precision); + _p_precision = pappso::Precision::getPpmInstance(precision); } ui->file_not_found->setVisible(false); + + //ui->spectrum_widget->setIonList(); + qRegisterMetaType<pappso::SpectrumSp>("pappso::SpectrumSp"); #if QT_VERSION >= 0x050000 // Qt5 code @@ -99,7 +100,7 @@ PeptideWindow::PeptideWindow(ProjectWindow *parent): connect (this, &PeptideWindow::loadSpectrumSp, worker,&SpectrumSpLoaderThread::doLoadSpectrumSp); connect (worker, &SpectrumSpLoaderThread::spectrumSpReady, this,&PeptideWindow::doSpectrumSpReady); - connect (_p_spectrum_overlay,&LoadingOverlay::mzChanged, this, &PeptideWindow::setMz); + connect (ui->spectrum_widget,&pappso::SpectrumWidget::mzChanged, this, &PeptideWindow::setMz); #else // Qt4 code connect (_p_project_window, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), this,SLOT(doIdentificationGroupGrouped(IdentificationGroup *))); @@ -115,7 +116,6 @@ PeptideWindow::PeptideWindow(ProjectWindow *parent): PeptideWindow::~PeptideWindow() { - delete _p_spectrum_overlay; delete ui; } @@ -144,8 +144,6 @@ void PeptideWindow::updateDisplay() { ui->mz_label->setText(QString::number(_p_peptide_evidence->getPeptideXtpSp().get()->getMz(_p_peptide_evidence->getCharge()), 'f', 4)); ui->expmz_label->setText(QString::number(_p_peptide_evidence->getExperimentalMz(), 'f', 4)); ui->delta_label->setText(QString::number(_p_peptide_evidence->getDeltaMass(), 'g', 4)); - - } catch (pappso::PappsoException exception_pappso) { QMessageBox::warning(this, @@ -176,9 +174,8 @@ void PeptideWindow::chooseDefaultMzDataDir() { qDebug() << "PeptideWindow::chooseDefaultMzDataDir begin"; - _p_spectrum_overlay->displayLoadingMessage(); ui->file_not_found->setVisible(false); - ui->spectrumWidget->setVisible(true); + ui->spectrum_widget->setVisible(true); emit loadSpectrumSp(_p_peptide_evidence); ui->statusbar->showMessage(tr("loading spectrum")); @@ -195,18 +192,16 @@ void PeptideWindow::openInPeptideViewer() { myProcess->start(program, arguments); } -void PeptideWindow::doSpectrumSpReady(SpectrumSp spectrum_sp, QString error, QString fatal_error) { +void PeptideWindow::doSpectrumSpReady(pappso::SpectrumSp spectrum_sp, QString error, QString fatal_error) { qDebug() << "PeptideWindow::doSpectrumSpReady begin error=" << error << " fatal_error=" << fatal_error; - _p_spectrum_overlay->hideLoadingMessage(); if ((error.isEmpty()) && (fatal_error.isEmpty())) { ui->statusbar->showMessage(tr("")); - pappso::QualifiedSpectrum spectrum_copy; - spectrum_copy.setPrecursorCharge(_p_peptide_evidence->getCharge()); - spectrum_copy.setOriginalSpectrumSp(spectrum_sp); - - ui->spectrumWidget->setQualifiedSpectrum(spectrum_copy); + ui->spectrum_widget->setMsLevel(2); + ui->spectrum_widget->setSpectrumSp(spectrum_sp); ui->file_not_found->setVisible(false); - ui->spectrumWidget->setVisible(true); + ui->spectrum_widget->setVisible(true); + + ui->spectrum_widget->plot(); _spectrum_is_ready = true; } if (!error.isEmpty()) { @@ -219,14 +214,14 @@ void PeptideWindow::doSpectrumSpReady(SpectrumSp spectrum_sp, QString error, QSt ui->mz_data_dir_label->setText(path); ui->file_not_found->setVisible(true); - ui->spectrumWidget->setVisible(false); + ui->spectrum_widget->setVisible(false); _spectrum_is_ready = false; } if (!fatal_error.isEmpty()) { //fatal_error QMessageBox::warning(this, - tr("Oops! an error occurred in XTPCPP. Dont Panic :"), fatal_error); + tr("Oops! an error occurred in XTPCPP. Dont Panic :"), fatal_error); ui->statusbar->showMessage(tr("ERROR reading spectrum")); QSettings settings; QString path = settings.value("path/mzdatadir", "").toString(); @@ -234,7 +229,7 @@ void PeptideWindow::doSpectrumSpReady(SpectrumSp spectrum_sp, QString error, QSt ui->mz_data_dir_label->setText(path); ui->file_not_found->setVisible(true); - ui->spectrumWidget->setVisible(false); + ui->spectrum_widget->setVisible(false); _spectrum_is_ready = false; } qDebug() << "PeptideWindow::doSpectrumSpReady end"; @@ -242,24 +237,26 @@ void PeptideWindow::doSpectrumSpReady(SpectrumSp spectrum_sp, QString error, QSt } void PeptideWindow::setPeptideEvidence(PeptideEvidence * p_peptide_evidence) { - qDebug() << "PeptideWindow::setPeptideMatch begin"; + qDebug() << "PeptideWindow::setPeptideEvidence begin"; _p_peptide_evidence = p_peptide_evidence; _spectrum_is_ready = false; - qDebug() << "PeptideWindow::setPeptideMatch emit loadSpectrumSp(_p_peptide_match)"; + qDebug() << "PeptideWindow::setPeptideEvidence emit loadSpectrumSp(_p_peptide_match)"; emit loadSpectrumSp(_p_peptide_evidence); - _p_spectrum_overlay->displayLoadingMessage(); ui->file_not_found->setVisible(false); - ui->spectrumWidget->setVisible(true); + ui->spectrum_widget->setVisible(true); ui->statusbar->showMessage(tr("loading spectrum")); pappso::PeptideSp peptide = _p_peptide_evidence->getPeptideXtpSp(); - ui->spectrumWidget->setPrecision(_p_precision); - ui->spectrumWidget->setPeptideSp(peptide); + ui->spectrum_widget->setMs2Precision(_p_precision); + ui->spectrum_widget->setPeptideCharge(_p_peptide_evidence->getCharge()); + ui->spectrum_widget->setMaximumIsotopeLevel(3); + ui->spectrum_widget->setPeptideSp(peptide); + ui->spectrum_widget->plot(); updateDisplay(); - qDebug() << "PeptideWindow::setPeptideMatch end"; + qDebug() << "PeptideWindow::setPeptideEvidence end"; } void PeptideWindow::doMsmsPrecisionUnitChanged(QString unit) { @@ -270,11 +267,12 @@ void PeptideWindow::doMsmsPrecisionUnitChanged(QString unit) { if (unit == "dalton") { - _p_precision = Precision::getDaltonInstance(precision); + _p_precision = pappso::Precision::getDaltonInstance(precision); } else { - _p_precision = Precision::getPpmInstance(precision); + _p_precision = pappso::Precision::getPpmInstance(precision); } - ui->spectrumWidget->setPrecision(_p_precision); + ui->spectrum_widget->setMs2Precision(_p_precision); + ui->spectrum_widget->plot(); settings.setValue("peptideview/precision_unit", unit); @@ -289,11 +287,12 @@ void PeptideWindow::doMsmsPrecisionValueChanged(double precision_value) { if (unit == "dalton") { - _p_precision = Precision::getDaltonInstance(precision); + _p_precision = pappso::Precision::getDaltonInstance(precision); } else { - _p_precision = Precision::getPpmInstance(precision); + _p_precision = pappso::Precision::getPpmInstance(precision); } - ui->spectrumWidget->setPrecision(_p_precision); + ui->spectrum_widget->setMs2Precision(_p_precision); + ui->spectrum_widget->plot(); settings.setValue("peptideview/precision_value", precision); } @@ -329,11 +328,8 @@ void PeptideWindow::doSaveSvg() { generator.setViewBox(QRect(0, 0, 1200, 500)); generator.setTitle(tr("%1 SVG spectrum generator").arg(SOFTWARE_NAME)); generator.setDescription(tr("This is an annotated SVG spectrum")); - QPainter painter; - painter.begin(&generator); - ui->spectrumWidget->paint(painter); - painter.end(); + ui->spectrum_widget->toQPaintDevice(&generator); //emit operateXpipFile(filename); } catch (pappso::PappsoException & error) { diff --git a/src/gui/peptide_detail_view/peptidewindow.h b/src/gui/peptide_detail_view/peptidewindow.h index 419cd3b39d2b220b4e806846f3eb71c7ba2a2dc3..5a9f88b2a95b3db904373384a44745c14aff8e44 100644 --- a/src/gui/peptide_detail_view/peptidewindow.h +++ b/src/gui/peptide_detail_view/peptidewindow.h @@ -30,7 +30,6 @@ #include <pappsomspp/spectrum/spectrum.h> #include "../../core/peptidematch.h" #include "../../core/identificationgroup.h" -#include "spectrum_widget/overlaywidget.h" class ProjectWindow; @@ -93,7 +92,6 @@ private: PeptideEvidence * _p_peptide_evidence = nullptr; pappso::PrecisionP _p_precision; - LoadingOverlay * _p_spectrum_overlay; bool _spectrum_is_ready=false; }; diff --git a/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp b/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp deleted file mode 100644 index 2ee85c70a5258fb28542300fe1b551465d8efd7b..0000000000000000000000000000000000000000 --- a/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.cpp +++ /dev/null @@ -1,148 +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 "overlaywidget.h" -#include <QDebug> - - - -void LoadingOverlay::paintLoadingMessage(QPainter &painter) { - - if (_is_loading) { - //p.fillRect(rect(), QColor(100, 100, 100, 128)); - painter.setPen(QColor(200, 200, 255, 255)); - painter.setFont(QFont("arial,helvetica", 48)); - painter.drawText(rect(), "Loading...", Qt::AlignHCenter | Qt::AlignVCenter); - } -} -void LoadingOverlay::displayLoadingMessage() { - _is_loading= true; -} -void LoadingOverlay::hideLoadingMessage() { - _is_loading= false; -} -void LoadingOverlay::paintEvent(QPaintEvent *) { - QPainter painter; - - painter.begin(this); - painter.setRenderHint(QPainter::Antialiasing); - qDebug() << "LoadingOverlay::paintEvent _is_loading="<< _is_loading; - if (_is_loading) { - paintLoadingMessage(painter); - } - else { - paintUserSelectedZone(painter); - } - painter.end(); -} -void LoadingOverlay::mousePressEvent(QMouseEvent * event) { - - qDebug() << " LoadingOverlay::mousePressEvent"; - - _pressed = true; - _first_point.first = event->x(); - _first_point.second = event->y(); - _current_mouse_mz = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(event->x()); - - _second_point.first = 0; - emit mzChanged(_current_mouse_mz); - update(); -} - - -void LoadingOverlay::mouseReleaseEvent(QMouseEvent * event) { - - qDebug() << " LoadingOverlay::mouseReleaseEvent"; - _pressed = false; - // _press_mz = _spectrum_painter.getMzFromLocalPosX(event->x()); - //_second_point.first = event->x(); - //_second_point.second = event->y(); - if (_second_point.first > 0) { - mz min = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(_first_point.first); - mz max = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(_second_point.first); - if (max < min) { - swap(min,max); - } - pappso_double max_intensity = _p_spectrum_widget->getSpectrumPainter().getIntensityFromLocalPosY(_second_point.second); - _p_spectrum_widget->getSpectrumPainter().setMinMz(min); - _p_spectrum_widget->getSpectrumPainter().setMaxMz(max); - _p_spectrum_widget->getSpectrumPainter().setMaxIntensity(max_intensity); - } - else { - _p_spectrum_widget->getSpectrumPainter().setMaxMz(0); - } - _second_point.first = 0; - update(); - -} -void LoadingOverlay::mouseMoveEvent(QMouseEvent * event) { - qDebug() << "LoadingOverlay::mouseMoveEvent" << event->x(); - mz new_mz = _p_spectrum_widget->getSpectrumPainter().getMzFromLocalPosX(event->x()); - - if (_pressed) { - int min = _p_spectrum_widget->getSpectrumPainter().getMarginLeft(); - _second_point.first = event->x(); - if (_second_point.first < min) { - _second_point.first = min; - } - int max = this->size().width(); - if (_second_point.first > max) { - _second_point.first = max; - } - _second_point.second = event->y(); - - if (_second_point.second < 0) { - _second_point.second = 0; - } - - max = _p_spectrum_widget->getSpectrumPainter().getLocalPosYFromIntensity(0); - if (_second_point.second > max) { - _second_point.second = max; - } - - _first_point.second = _p_spectrum_widget->getSpectrumPainter().getLocalPosYFromIntensity(0); - } - // if (_current_mouse_mz != new_mz) { - _current_mouse_mz = new_mz; - qDebug() << "LoadingOverlay::mouseMoveEvent emit mzChanged(_current_mouse_mz)" ; - emit mzChanged(_current_mouse_mz); - - // if (_press_mz > 0) { - update(); - - // } - // } -} - - -void LoadingOverlay::paintUserSelectedZone(QPainter & painter) { - if (_second_point.first > 0) { - painter.setPen(QColor("red")); - QRect rect(_first_point.first, _first_point.second, _second_point.first-_first_point.first, _second_point.second-_first_point.second); - painter.drawRect(rect); - - // show the classname of the widget - QBrush translucentBrush(QColor(255,246,240, 100)); - painter.fillRect(rect, translucentBrush); - } - -} diff --git a/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.h b/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.h deleted file mode 100644 index 0b264f154f57b26a41cea8286f0acce7207b6611..0000000000000000000000000000000000000000 --- a/src/gui/peptide_detail_view/spectrum_widget/overlaywidget.h +++ /dev/null @@ -1,103 +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 OVERLAYWIDGET_H -#define OVERLAYWIDGET_H -#include <QApplication> -#include <QMainWindow> -#include <QResizeEvent> -#include <QPainter> - -#include "qspectrumwidget.h" - -class OverlayWidget : public QWidget -{ -public: - explicit OverlayWidget(QWidget * parent = 0) : QWidget(parent) { - if (parent) { - parent->installEventFilter(this); - raise(); - } - } -protected: - //! Catches resize and child events from the parent widget - bool eventFilter(QObject * obj, QEvent * ev) { - if (obj == parent()) { - if (ev->type() == QEvent::Resize) { - QResizeEvent * rev = static_cast<QResizeEvent*>(ev); - resize(rev->size()); - } - else if (ev->type() == QEvent::ChildAdded) { - raise(); - } - } - return QWidget::eventFilter(obj, ev); - } - //! Tracks parent widget changes - bool event(QEvent* ev) { - if (ev->type() == QEvent::ParentAboutToChange) { - if (parent()) parent()->removeEventFilter(this); - } - else if (ev->type() == QEvent::ParentChange) { - if (parent()) { - parent()->installEventFilter(this); - raise(); - } - } - return QWidget::event(ev); - } -}; - -class LoadingOverlay : public OverlayWidget -{ - Q_OBJECT -public: - LoadingOverlay(QSpectrumWidget * parent) : OverlayWidget(parent) { - // setAttribute(Qt::WA_TranslucentBackground); - _p_spectrum_widget =parent; - setMouseTracking(true); - } - void displayLoadingMessage(); - void hideLoadingMessage(); -protected: - void paintEvent(QPaintEvent *) override; - void mouseReleaseEvent(QMouseEvent * event) override; - void mousePressEvent(QMouseEvent * event) override; - void mouseMoveEvent(QMouseEvent * event) override; -signals: - void mzChanged(double mz); -private : - void paintLoadingMessage(QPainter & painter); - void paintUserSelectedZone(QPainter & painter); -private: - bool _pressed = false; - QSpectrumWidget * _p_spectrum_widget; - mz _current_mouse_mz; - bool _is_loading=false; - - std::pair<int, int> _first_point; - std::pair<int, int> _second_point; - -}; - -#endif // OVERLAYWIDGET_H diff --git a/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp b/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp deleted file mode 100644 index 0d3eec46937f70fe91c973ac6e90817f785167bf..0000000000000000000000000000000000000000 --- a/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.cpp +++ /dev/null @@ -1,103 +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 "qspectrumwidget.h" -#include <QStyleOption> -#include <pappsomspp/peptide/peptidefragmentionlistbase.h> -#include <pappsomspp/peptide/peptidestrparser.h> - - -QSpectrumWidget::QSpectrumWidget(QWidget *parent) - : QWidget(parent) -{ - qDebug() << "QSpectrumWidget::QSpectrumWidget begin"; - //_ion_list = PeptideFragmentIonListBase::getCIDionList(); - - //_peptide_sp = PeptideStrParser::parseString("AIADGSLLDLLR"); - - //_spectrum_sp = readSpectrum("../../pappsomspp/test/data/peaklist_15046.mgf", 0, _zmax).makeSpectrumSp(); - - unsigned int zmax=3; - - _spectrum_painter.setPeptideSp(Peptide("A").makePeptideSp()); - // _spectrum_painter.setSpectrumSp(Spectrum().makeSpectrumSp()); - - _spectrum_painter.setParentIonCharge(zmax); - _spectrum_painter.setIonList(PeptideFragmentIonListBase::getCIDionList()); - //_spectrum_painter.setPrecision(_p_precision); - - - setMouseTracking(true); - - //SvgSpectrum svgspectrum(_peptide_sp, _spectrum_sp, _zmax, _precision, _ion_list); - - _spectrum_painter.setMarginLeft(60); - _spectrum_painter.setMarginTop(15); - _spectrum_painter.setMarginBottom(20); - _spectrum_painter.setFontPointSize(10); - - qDebug() << "QSpectrumWidget::QSpectrumWidget end"; - -} -QSpectrumWidget::~QSpectrumWidget() -{ - -} - -void QSpectrumWidget::setPrecision(pappso::PrecisionP p_precision) { - qDebug() << "QSpectrumWidget::setPrecision"; - _spectrum_painter.setPrecision(p_precision); - update(); -} - -void QSpectrumWidget::setPeptideSp(pappso::PeptideSp & peptide_sp) { - _spectrum_painter.setPeptideSp(peptide_sp); - update(); -} -void QSpectrumWidget::setQualifiedSpectrum(pappso::QualifiedSpectrum spectrum) { - - _spectrum_painter.setQualifiedSpectrum(spectrum); - update(); - -} - -void QSpectrumWidget::paintEvent(QPaintEvent * /* event */) -{ - QPainter painter; - painter.begin(this); - painter.setRenderHint(QPainter::Antialiasing); - paint(painter); - painter.end(); -} - -void QSpectrumWidget::paint(QPainter &painter) -{ - //painter.drawLine(QLine(0, 35, 200, 35)); - _spectrum_painter.paint(painter, this->size().width(), this->size().height()); -} - -void QSpectrumWidget::setIsotopeMassList(std::vector<pappso::PeptideNaturalIsotopeAverageSp> & isotopeMassList) { - _spectrum_painter.setIsotopeMassList(isotopeMassList); - update(); -} - diff --git a/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h b/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h deleted file mode 100644 index 9134426643aa7264082007ddfdcdaabd50134fcf..0000000000000000000000000000000000000000 --- a/src/gui/peptide_detail_view/spectrum_widget/qspectrumwidget.h +++ /dev/null @@ -1,69 +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 QSPECTRUMWIDGET_H -#define QSPECTRUMWIDGET_H - -#include <QWidget> -#include <QPainter> -#include <QMouseEvent> -#include <pappsomspp/spectrum/qualifiedspectrum.h> -#include <pappsomspp/peptide/peptide.h> -#include <pappsomspp/peptide/peptidefragmention.h> -#include "spectrumpainter.h" - -using namespace pappso; - -class QSpectrumWidget: public QWidget -{ - Q_OBJECT -public: - QSpectrumWidget(QWidget *parent = 0); - ~QSpectrumWidget(); - - void paint(QPainter &painter); - - pappso_double getCanvasWidth() const {return _spectrum_painter.getCanvasWidth();}; - void setPeptideSp(pappso::PeptideSp & peptide_sp); - void setPrecision(pappso::PrecisionP p_precision); - void setIsotopeMassList(std::vector<pappso::PeptideNaturalIsotopeAverageSp> & isotopeMassList); - - SpectrumPainter & getSpectrumPainter() {return _spectrum_painter;}; - - -public slots: - void setQualifiedSpectrum(pappso::QualifiedSpectrum spectrum); - - // void setColor(const QColor &color); - // void setShape(Shape shape); -signals: - void mzChanged(double mz); - -protected: - void paintEvent(QPaintEvent *event) override; - -private : - SpectrumPainter _spectrum_painter; -}; - -#endif // QSPECTRUMWIDGET_H diff --git a/src/gui/peptide_detail_view/spectrum_widget/spectrumpainter.cpp b/src/gui/peptide_detail_view/spectrum_widget/spectrumpainter.cpp deleted file mode 100644 index c06787724cf6e37224926b4218cb03b752e3988c..0000000000000000000000000000000000000000 --- a/src/gui/peptide_detail_view/spectrum_widget/spectrumpainter.cpp +++ /dev/null @@ -1,471 +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 "spectrumpainter.h" - -#include <QDebug> -#include <cmath> - -SpectrumPainter::SpectrumPainter() -{ - _p_precision = pappso::Precision::getDaltonInstance(0.5); -} - -SpectrumPainter::~SpectrumPainter() -{ - //delete _p_precision; -} -void SpectrumPainter::setFontPointSize(int point_size) { - _font_point_size = point_size; -} - -void SpectrumPainter::setMarginLeft(pappso_double margin) { - _margin_left = margin; -} -void SpectrumPainter::setMarginTop(pappso_double margin) { - _margin_top = margin; -} -void SpectrumPainter::setMarginBottom(pappso_double margin) { - _margin_bottom = margin; -} - -void SpectrumPainter::setQualifiedSpectrum(pappso::QualifiedSpectrum & spectrum) { - _ms_level = spectrum.getMsLevel(); - setSpectrumSp(spectrum.getOriginalSpectrumSp()); - setParentIonCharge(spectrum.getPrecursorCharge()); -} - -void SpectrumPainter::setPeptideSp(const pappso::PeptideSp & peptide_sp) { - _peptide_sp = peptide_sp; - _is_isotope = false; - _peptide_fragment_ion_isotope_list.clear(); - - PeptideFragmentIonListBase peptide_ion_list(peptide_sp, _ion_list); - - _peptide_fragment_ion_list.clear(); - _peptide_fragment_ion_charge_list.clear(); - - for (auto ion_type: _ion_list) { - auto ion_list = peptide_ion_list.getPeptideFragmentIonSp(ion_type); - - for (unsigned int charge=1; charge <= _parent_ion_charge; charge++) { - for (auto && ion : ion_list) { - _peptide_fragment_ion_list.push_back(ion); - _peptide_fragment_ion_charge_list.push_back(charge); - } - } - } -} - -void SpectrumPainter::setIsotopeMassList(std::vector<pappso::PeptideNaturalIsotopeAverageSp> & isotopeMassList) { - // list of isotope to display on MS level 1 spectrum - _isotope_mass_list = isotopeMassList; -} - -void SpectrumPainter::setPeptideFragmentIonList(const std::vector<PeptideFragmentIonSp> & peptide_fragment_ion_list, const std::vector<unsigned int> & peptide_fragment_ion_charge_list) { - _peptide_fragment_ion_list = peptide_fragment_ion_list; - _peptide_fragment_ion_charge_list = peptide_fragment_ion_charge_list; - _is_isotope = false; -} - -void SpectrumPainter::setPeptideFragmentIonIsotopeList(const std::vector<PeptideNaturalIsotopeAverageSp> & peptide_fragment_ion_isotope_list, const std::vector<PeptideFragmentIonSp> & peptide_fragment_ion_list) { - _peptide_fragment_ion_list = peptide_fragment_ion_list; - _peptide_fragment_ion_isotope_list = _peptide_fragment_ion_isotope_list; - _is_isotope = true; -} - -void SpectrumPainter::setSpectrumSp(const pappso::SpectrumSp & spectrum_sp) { - _spectrum_sp = spectrum_sp; - _max_mz = 0; -} -void SpectrumPainter::setParentIonCharge(unsigned int parent_ion_charge) { - _parent_ion_charge = parent_ion_charge; -} -void SpectrumPainter::setIonList(const list< PeptideIon > & ion_list) { - _ion_list = ion_list; -} -void SpectrumPainter::setPrecision(PrecisionP precision) { - qDebug() << "SpectrumPainter::setPrecision begin " << precision->toString(); - _p_precision =precision; - //_precision._precision = precision._precision; -} - - -int SpectrumPainter::getLocalPosYFromIntensity(pappso_double intensity) const { - return getY(intensity); -} - -pappso_double SpectrumPainter::getIntensityFromLocalPosY(pappso_double y) const { - return ((_spectrum_height-(y-_margin_top))/_spectrum_height)*_max_int; - //(((_spectrum_height-y)-_margin_top)/_spectrum_height)*_max_int; -} - -mz SpectrumPainter::getMzFromLocalPosX(pappso_double x) const { - mz mz = (x - _margin_left - _padding); - mz = (mz / _spectrum_width) * (_max_mz - _min_mz); - mz = mz + _min_mz; - qDebug() << " pos.x=" << x << " mz=" << mz; - if (mz < _min_mz) return 0; - if (mz > _max_mz) return 0; - return mz; -} - - - -pappso_double SpectrumPainter::getX(pappso_double x) const { - - return ((_spectrum_width / (_max_mz - _min_mz)) * (x - _min_mz)) + _margin_left + _padding; -} - - - -pappso_double SpectrumPainter::getY(pappso_double x) const { - - return ((_max_int - x) * ( _spectrum_height/_max_int)) + _margin_top; -} - -bool SpectrumPainter::peakInPsm(pappso::PeptideSpectrumMatch* p_psm, pappso::PeptideIsotopeSpectrumMatch* p_psm_isotope, mz mz) { - if (_is_isotope) { - for (auto it = p_psm_isotope->begin() ; it != p_psm_isotope->end(); it++) { - if (it->getPeak().mz == mz) { - return true; - } - } - } - else { - for (auto it = p_psm->begin() ; it != p_psm->end(); it++) { - if (it->getPeak().mz == mz) { - return true; - } - } - } - return false; -} - -void SpectrumPainter::convertPsmToSpectrum(Spectrum * spectrum_text_draw, pappso::PeptideSpectrumMatch* p_psm, pappso::PeptideIsotopeSpectrumMatch* p_psm_isotope) { - if (_is_isotope) { - for (auto it = p_psm_isotope->begin() ; it != p_psm_isotope->end(); it++) { - spectrum_text_draw->push_back(it->getPeak()); - } - } - else { - for (auto it = p_psm->begin() ; it != p_psm->end(); it++) { - spectrum_text_draw->push_back(it->getPeak()); - } - } -} - - -//http://stackoverflow.com/questions/24831484/how-to-align-qpainter-drawtext-around-a-point-not-a-rectangle -void drawText(QPainter & painter, qreal x, qreal y, Qt::Alignment flags, - const QString & text, QRectF * boundingRect = 0) -{ - const qreal size = 32767.0; - QPointF corner(x, y - size); - if (flags & Qt::AlignHCenter) corner.rx() -= size/2.0; - else if (flags & Qt::AlignRight) corner.rx() -= size; - if (flags & Qt::AlignVCenter) corner.ry() += size/2.0; - else if (flags & Qt::AlignTop) corner.ry() += size; - else flags |= Qt::AlignBottom; - QRectF rect(corner, QSizeF(size, size)); - painter.drawText(rect, flags, text, boundingRect); -} - -void drawText(QPainter & painter, const QPointF & point, Qt::Alignment flags, - const QString & text, QRectF * boundingRect = 0) -{ - drawText(painter, point.x(), point.y(), flags, text, boundingRect); -} - -bool spectrumContainsMz(const Spectrum & spectrum, const Peak & peak) { - std::vector<Peak>::const_iterator it_peak; - for (it_peak = spectrum.begin() ; it_peak != spectrum.end(); it_peak++) { - if (peak.mz== it_peak->mz) return true; - } - return false; -} - -int NumDigits(int n) { - int digits = 0; - if (n <= 0) { - n = -n; - ++digits; - } - while (n) { - n /= 10; - ++digits; - } - return digits; -} - - - -void SpectrumPainter::paint(QPainter & painter, pappso_double width, pappso_double height) { - qDebug() << "SpectrumPainter::paint begin"; - //if (_peptide_sp.get() == nullptr) return; - //painter.drawLine(QLine(0, 35, 2000, 35)); - _canvas_height = height; - _spectrum_height = height - _margin_bottom - _margin_top; - _canvas_width = width; - _spectrum_width = width - _margin_left - (_padding*2); - - QFont font = painter.font() ; - - /* twice the size than the current font size */ - font.setPointSize(_font_point_size); - - /* set the modified font to the painter */ - painter.setFont(font); - - if (_spectrum_sp.get() != nullptr) { - const Spectrum & spectrum_int_draw = *_spectrum_sp.get(); - if (_max_mz == 0) { - _min_mz = _spectrum_sp.get()->begin()->mz ; - _max_mz = (--_spectrum_sp.get()->end())->mz ; - _max_int = _spectrum_sp.get()->getMaxIntensity().intensity; - } - if (_max_int < 0) { - _max_int = _spectrum_sp.get()->getMaxIntensity().intensity; - } - PeptideSpectrumMatch * p_psm = nullptr; - PeptideIsotopeSpectrumMatch * p_psm_isotope = nullptr; - if (_is_isotope) { - p_psm_isotope = new PeptideIsotopeSpectrumMatch(spectrum_int_draw, _peptide_fragment_ion_isotope_list, _peptide_fragment_ion_list, _p_precision); - } - else { - p_psm = new PeptideSpectrumMatch(spectrum_int_draw,_peptide_fragment_ion_list, _peptide_fragment_ion_charge_list, _p_precision); - } - - //Spectrum spectrum_for_hyperscore = spectrumSp.get()->applyCutOff(150).takeNmostIntense(100).applyDynamicRange(100); - - //XtandemHyperscore hyperscore_withxtspectrum(spectrum_for_hyperscore, peptideSp,zmax, precision, ion_list,true); - //Spectrum spectrum_remains = _spectrum_sp.get()->minus(psm); - pappso_double stroke_width = 0.8; - - //painter.translate(-_min_mz,0); - //painter.scale(0.1,0.5); - painter.setPen(Qt::black); - //painter.setClipRect(QRect(0, 0, _max_mz, _spectrum_height)); - //painter.fillRect(QRect(0, 0, _max_mz, _spectrum_height), Qt::white); - //painter.drawRect(QRect(getX(_min_mz)-_padding, 0,getX(_max_mz)-_padding, _spectrum_height)); - painter.setPen(QPen(Qt::black, 1, Qt::SolidLine) ); - painter.drawLine(QLine(_margin_left, getY(0), _margin_left, getY(_max_int))); - painter.drawLine(QLine(_margin_left-2, getY(_max_int), _margin_left+2, getY(_max_int))); - drawText(painter, QPointF(_margin_left, getY(0)), Qt::AlignVCenter | Qt::AlignRight, "0 "); - drawText(painter, QPointF(_margin_left, getY(_max_int)), Qt::AlignBottom | Qt::AlignHCenter, QString::number(_max_int, 'g', 2)); - - - unsigned long big_tic_int = pow10(NumDigits(_max_int)); - - unsigned long delta = _max_int - 0; - while (big_tic_int > 10) { - if ((delta / big_tic_int) > 1) { - break; - } - big_tic_int = big_tic_int / 10; - } - unsigned long small_tic_int = (unsigned long) floor(big_tic_int / 10); - - pappso_double begin_tic = (unsigned long) ((floor(0 / big_tic_int) + 1) * big_tic_int); - - painter.setPen(QPen(Qt::black, 3, Qt::SolidLine) ); - for (pappso_double ipos = begin_tic; ipos < _max_int; ipos += big_tic_int) { - painter.drawLine(QLine(_margin_left-3, getY(ipos), _margin_left+3, getY(ipos))); - drawText(painter, QPointF(_margin_left-3, getY(ipos)), Qt::AlignVCenter | Qt::AlignRight, QString::number(ipos, 'g', 2)); - //qDebug() << " ipos=" << ipos ; - } - - //small tic - painter.setPen(QPen(Qt::black, 1, Qt::SolidLine) ); - for (pappso_double ipos = 0; ipos < _max_int; ipos += small_tic_int) { - painter.drawLine(QLine(_margin_left-1, getY(ipos), _margin_left+1, getY(ipos))); - //qDebug() << " ipos=" << ipos ; - } - - qDebug() << " NumDigits(_max_int)=" << NumDigits(_max_int) << " big_tic_int=" << big_tic_int << "_min_mz=" << _min_mz << " _max_mz=" << _max_mz ; - if (_ms_level ==1) { - std::vector<Peak>::const_iterator it_peak; - PeptideNaturalIsotopeAverageSp precursor_peptide; - MassRange * p_precursor_mass = nullptr; - pappso_double monoisotope_intensity = 0; - if (_isotope_mass_list.size() > 0) { - precursor_peptide = _isotope_mass_list.at(0); - p_precursor_mass = new MassRange(precursor_peptide.get()->getMz(), _p_precision); - } - for (it_peak = spectrum_int_draw.begin() ; it_peak != spectrum_int_draw.end(); it_peak++) { - //draw all peaks in black - painter.setPen(QPen(Qt::black, stroke_width, Qt::SolidLine) ); - pappso_double x = it_peak->mz; - - if (p_precursor_mass->contains(x)) { - if (it_peak->intensity > monoisotope_intensity) { - monoisotope_intensity = it_peak->intensity; - } - } - - if ((x > _min_mz) && ( x < _max_mz)) { - //pappso_double y = _spectrum_height - it_peak->intensity; - painter.drawLine(QLine(getX(x), getY(it_peak->intensity), getX(x),getY(0))); - } - - // painter.setPen(Qt::black); - - } - if (monoisotope_intensity > 0) { - //draw isotope cluster - std::vector<Peak> cluster; - Peak peak; - peak.mz = precursor_peptide.get()->getMz(); - peak.intensity = monoisotope_intensity; - cluster.push_back(peak); - pappso_double total_intensity = ((pappso_double)1.0 / precursor_peptide.get()->getIntensityRatio())*monoisotope_intensity; - for (int j=1 ; j < _isotope_mass_list.size(); j++) { - peak.mz = _isotope_mass_list.at(j).get()->getMz(); - peak.intensity = _isotope_mass_list.at(j).get()->getIntensityRatio() * total_intensity; - cluster.push_back(peak); - } - for (it_peak = cluster.begin() ; it_peak != cluster.end(); it_peak++) { - //draw all peaks in black - painter.setPen(QPen(Qt::red, stroke_width, Qt::SolidLine) ); - pappso_double x = it_peak->mz; - - if (p_precursor_mass->contains(x)) { - monoisotope_intensity = it_peak->intensity; - } - - if ((x > _min_mz) && ( x < _max_mz)) { - //pappso_double y = _spectrum_height - it_peak->intensity; - //painter.drawLine(QLine(getX(x), getY(it_peak->intensity), getX(x),getY(0))); - painter.drawRect(getX(x)-stroke_width,getY(0),3*stroke_width,getY(it_peak->intensity)-getY(0)); - } - - // painter.setPen(Qt::black); - - } - } - if (p_precursor_mass != nullptr) { - delete p_precursor_mass; - } - } - else { - - std::vector<Peak>::const_iterator it_peak; - for (it_peak = spectrum_int_draw.begin() ; it_peak != spectrum_int_draw.end(); it_peak++) { - if (peakInPsm(p_psm,p_psm_isotope, it_peak->mz)) { - } - else { - //draw only non assigned peaks - painter.setPen(QPen(Qt::black, stroke_width, Qt::SolidLine) ); - pappso_double x = it_peak->mz; - - if ((x > _min_mz) && ( x < _max_mz)) { - //pappso_double y = _spectrum_height - it_peak->intensity; - painter.drawLine(QLine(getX(x), getY(it_peak->intensity), getX(x),getY(0))); - } - } - // painter.setPen(Qt::black); - - } -//painter.rotate(45); - if (_is_isotope) { - p_psm_isotope = new PeptideIsotopeSpectrumMatch(spectrum_int_draw, _peptide_fragment_ion_isotope_list, _peptide_fragment_ion_list, _p_precision); - } - else { - - unsigned int draw_fragment_index = _peptide_fragment_ion_list.size(); - unsigned int write_ion_name = 10; - Spectrum spectrum_text_draw;// = _spectrum_sp.get()->takeNmostIntense(write_ion_name); - convertPsmToSpectrum(&spectrum_text_draw,p_psm,p_psm_isotope); - spectrum_text_draw = spectrum_text_draw.takeNmostIntense(write_ion_name); - - qDebug() << "spectrum_text_draw.size()=" << spectrum_text_draw.size(); - for (int draw_fragment_index = (_peptide_fragment_ion_list.size()-1); draw_fragment_index>=0; draw_fragment_index--) { - for (auto it_psm = p_psm->begin() ; it_psm != p_psm->end(); it_psm++) { - if ((_peptide_fragment_ion_list[draw_fragment_index].get() == it_psm->getPeptideFragmentIonSp().get()) && ( - _peptide_fragment_ion_charge_list[draw_fragment_index] == it_psm->getCharge() - )) { - painter.setPen(QPen(PeptideFragmentIon::getPeptideIonColor(it_psm->getPeptideIonType()), stroke_width, Qt::SolidLine) ); - pappso_double x = it_psm->getPeak().mz; - if ((x > _min_mz) && ( x < _max_mz)) { - //pappso_double y = _spectrum_height - it->getPeak().intensity; - painter.drawLine(QLine(getX(x), getY(it_psm->getPeak().intensity), getX(x), getY(0))); - - if (spectrumContainsMz(spectrum_text_draw, it_psm->getPeak())) { - qDebug() << "ion_name=" << it_psm->getPeptideFragmentIonSp().get()->getPeptideIonName() << " it_psm->getPeak().mz=" << QString::number(it_psm->getPeak().mz, 'g', 8) << " it_psm->getPeak().intensity=" << it_psm->getPeak().intensity; - QString plusstr = "+"; - plusstr = plusstr.repeated(it_psm->getCharge()); - drawText(painter, QPointF(getX(x), getY(it_psm->getPeak().intensity)), Qt::AlignBottom | Qt::AlignHCenter, QString("%1%2%3").arg(it_psm->getPeptideFragmentIonSp().get()->getPeptideIonName()).arg(it_psm->getPeptideFragmentIonSp().get()->size()).arg(plusstr)); - } - } - //painter.setPen(Qt::black); - } - - } - } - } - } - - painter.setPen(QPen(Qt::black, stroke_width, Qt::SolidLine) ); - painter.drawLine(QLine(getX(_min_mz),getY(0), getX(_max_mz), getY(0))); - - - big_tic_int = pow10(NumDigits(_max_mz)); - - delta = _max_mz - _min_mz; - while (big_tic_int > 10) { - if ((delta / big_tic_int) > 2) { - break; - } - big_tic_int = big_tic_int / 10; - } - small_tic_int = (unsigned long) floor(big_tic_int / 10); - - begin_tic = (unsigned long) ((floor(_min_mz / big_tic_int) + 1) * big_tic_int); - - painter.setPen(QPen(Qt::black, 2, Qt::SolidLine) ); - for (pappso_double ipos = begin_tic; ipos < _max_mz; ipos += big_tic_int) { - painter.drawLine(QLine(getX(ipos), getY(0)+1, getX(ipos), getY(0)+3)); - drawText(painter, QPointF(getX(ipos), getY(0)+3), Qt::AlignTop | Qt::AlignHCenter, QString::number(ipos, 'f', 0)); - //qDebug() << " ipos=" << ipos ; - } - - //small tic - begin_tic = (unsigned long) ((floor(_min_mz / small_tic_int) + 1) * small_tic_int); - painter.setPen(QPen(Qt::black, 1, Qt::SolidLine) ); - for (pappso_double ipos = begin_tic; ipos < _max_mz; ipos += small_tic_int) { - painter.drawLine(QLine(getX(ipos), getY(0)+1, getX(ipos), getY(0)+1)); - //qDebug() << " ipos=" << ipos ; - } - - - //painter.scale(0.5,0.5); - if (_is_isotope) { - delete p_psm_isotope; - } - else { - delete p_psm; - } - - - } - -} diff --git a/src/gui/peptide_detail_view/spectrum_widget/spectrumpainter.h b/src/gui/peptide_detail_view/spectrum_widget/spectrumpainter.h deleted file mode 100644 index 6d4b6f8a997d1b538439704cb6cfbc906cc33f4b..0000000000000000000000000000000000000000 --- a/src/gui/peptide_detail_view/spectrum_widget/spectrumpainter.h +++ /dev/null @@ -1,119 +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 SPECTRUMPAINTER_H -#define SPECTRUMPAINTER_H - -#include <QPainter> -#include <QPointF> -#include <pappsomspp/peptide/peptide.h> -#include <pappsomspp/spectrum/spectrum.h> -#include <pappsomspp/peptide/peptidefragmentionlistbase.h> -#include <pappsomspp/peptide/peptidenaturalisotopeaverage.h> -#include <pappsomspp/psm/peptidespectrummatch.h> -#include <pappsomspp/psm/peptideisotopespectrummatch.h> -#include <pappsomspp/spectrum/qualifiedspectrum.h> - -using namespace pappso; - -class SpectrumPainter -{ -public: - SpectrumPainter(); - ~SpectrumPainter(); - - void setPeptideSp(const pappso::PeptideSp & peptide_sp); - void setSpectrumSp(const pappso::SpectrumSp & spectrum_sp); - void setParentIonCharge(unsigned int parent_ion_charge); - void setIonList(const list< PeptideIon > & ion_list); - void setPrecision(PrecisionP precision); - void setPeptideFragmentIonList(const std::vector<PeptideFragmentIonSp> & peptide_fragment_ion_list, const std::vector<unsigned int> & peptide_fragment_ion_charge_list); - void setPeptideFragmentIonIsotopeList(const std::vector<PeptideNaturalIsotopeAverageSp> & peptide_fragment_ion_isotope_list, const std::vector<PeptideFragmentIonSp> & peptide_fragment_ion_list); - - - void setIsotopeMassList(std::vector<pappso::PeptideNaturalIsotopeAverageSp> & isotopeMassList); - - mz getMzFromLocalPosX(pappso_double x) const; - pappso_double getIntensityFromLocalPosY(pappso_double y) const; - int getLocalPosYFromIntensity(pappso_double intensity) const; - - void paint(QPainter & painter, pappso_double width, pappso_double height); - void setMarginLeft(pappso_double margin); - void setFontPointSize(int point_size); - void setMarginBottom(pappso_double margin); - void setMarginTop(pappso_double margin); - - pappso_double getCanvasWidth() const { - return _canvas_width; - }; - pappso_double getMarginLeft() const { - return _margin_left; - }; - void setMinMz(mz mzX) { - _min_mz = mzX; - }; - void setMaxMz(mz mzX) { - _max_mz = mzX; - }; - void setMaxIntensity(pappso_double max_intensity) { - _max_int = max_intensity; - } - void setQualifiedSpectrum(pappso::QualifiedSpectrum & spectrum); - -private : - PrecisionP _p_precision = pappso::Precision::getDaltonInstance(0.5); - std::list< PeptideIon > _ion_list; - unsigned int _parent_ion_charge=3; - SpectrumSp _spectrum_sp; - PeptideSp _peptide_sp; - std::vector<PeptideFragmentIonSp> _peptide_fragment_ion_list; - std::vector<unsigned int> _peptide_fragment_ion_charge_list; - std::vector<PeptideNaturalIsotopeAverageSp> _peptide_fragment_ion_isotope_list; - std::vector< PeptideNaturalIsotopeAverageSp > _isotope_mass_list; - -private : - - bool _is_isotope = false; - pappso_double _min_mz=0 ; - pappso_double _max_mz=0 ; - pappso_double _max_int = -1; - pappso_double _canvas_height; - pappso_double _canvas_width; - pappso_double _spectrum_height = 500; - pappso_double _spectrum_width = 1200; - pappso_double _margin_top = 10; - pappso_double _margin_bottom = 10; - pappso_double _margin_left = 10; - pappso_double _padding = 5; - int _font_point_size = 12; - unsigned int _ms_level; - - -private : - pappso_double getX(pappso_double x) const; - pappso_double getY(pappso_double x) const; - bool peakInPsm(pappso::PeptideSpectrumMatch* p_psm, pappso::PeptideIsotopeSpectrumMatch* p_psm_isotope, mz mz); - void convertPsmToSpectrum(Spectrum * spectrum_text_draw, pappso::PeptideSpectrumMatch* p_psm, pappso::PeptideIsotopeSpectrumMatch* p_psm_isotope); -}; - -#endif // SPECTRUMPAINTER_H - diff --git a/src/gui/project_view/projectwindow.cpp b/src/gui/project_view/projectwindow.cpp index 939827d94caadc3a9b2bc7f1bc93275792099b72..55fe94e8de38647a09496b3315e062a36d8dffec 100644 --- a/src/gui/project_view/projectwindow.cpp +++ b/src/gui/project_view/projectwindow.cpp @@ -35,7 +35,7 @@ #include <numeric> #include "../workerthread.h" #include "../../core/labeling/labelingmethod.h" -#include "../../../utils/utils.h" +#include "../../utils/utils.h" #include <qcustomplot.h>