Skip to content
Snippets Groups Projects
proteinwindow.cpp 5.37 KiB
Newer Older

/*******************************************************************************
* Copyright (c) 2017 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 "proteinwindow.h"
#include "../project_view/projectwindow.h"
#include "ui_protein_detail_view.h"
#include <pappsomspp/pappsoexception.h>
#include <QMessageBox>
Olivier Langella's avatar
Olivier Langella committed
#include <QDesktopServices>
Olivier Langella's avatar
Olivier Langella committed
#include <cmath>
Olivier Langella's avatar
Olivier Langella committed

DbXrefButton::DbXrefButton(QWidget * parent, DbXref dbxref): QPushButton(parent) {
    _dbxref = dbxref;
#if QT_VERSION >= 0x050000
    // Qt5 code
Langella Olivier's avatar
Langella Olivier committed
    QObject::connect(this, &DbXrefButton::clicked,this, &DbXrefButton::clickedSlot);
Olivier Langella's avatar
Olivier Langella committed
#else
// Qt4 code
    QObject::connect(this, SIGNAL(clicked()),this, SLOT(clickedSlot()));
#endif
Langella Olivier's avatar
Langella Olivier committed

Olivier Langella's avatar
Olivier Langella committed
    setText(_dbxref.accession);
}

void DbXrefButton::clickedSlot() {
    qDebug() << "DbXrefButton::clickedSlot " << _dbxref.getUrl();
    QDesktopServices::openUrl (_dbxref.getUrl()) ;
}

ProteinWindow::ProteinWindow(ProjectWindow *parent):
    QMainWindow(parent),
    ui(new Ui::ProteinDetailView)
{
Olivier Langella's avatar
Olivier Langella committed
    _p_project_window = parent;
    ui->setupUi(this);
    /*
    */


#if QT_VERSION >= 0x050000
    // Qt5 code
Langella Olivier's avatar
Langella Olivier committed
    connect (_p_project_window, &ProjectWindow::identificationGroupGrouped, this,&ProteinWindow::doIdentificationGroupGrouped);
    connect (_p_project_window, &ProjectWindow::peptideMatchSelected, this,&ProteinWindow::doPeptideMatchSelected);
#else
// Qt4 code
Olivier Langella's avatar
Olivier Langella committed
    connect (_p_project_window, SIGNAL(identificationGroupGrouped(IdentificationGroup *)), this,SLOT(doIdentificationGroupGrouped(IdentificationGroup *)));
    connect (_p_project_window, SIGNAL(peptideMatchSelected(PeptideMatch*)), this,SLOT(doPeptideMatchSelected(PeptideMatch*)));
    //connect(_protein_table_model_p, SIGNAL(layoutChanged()), this, SLOT(updateStatusBar()));
#endif
}

ProteinWindow::~ProteinWindow()
{
Olivier Langella's avatar
Olivier Langella committed
    clearDbXrefLayout();
    delete ui;
}
Olivier Langella's avatar
Olivier Langella committed
void ProteinWindow::doIdentificationGroupGrouped(IdentificationGroup * p_identification_group) {
    updateDisplay();
}
void ProteinWindow::doPeptideMatchSelected(PeptideMatch * peptide_match) {
    if (_p_protein_match != nullptr) {
Olivier Langella's avatar
Olivier Langella committed
        ui->sequenceTextEdit->setText(_p_protein_match->getHtmlSequence(peptide_match));
Olivier Langella's avatar
Olivier Langella committed
void ProteinWindow::clearDbXrefLayout() {
    for (int i = 0; i < ui->dbxref_list_layout->count(); ++i)
Olivier Langella's avatar
Olivier Langella committed
    {
        delete ui->dbxref_list_layout->itemAt(i)->widget();
    }
Olivier Langella's avatar
Olivier Langella committed
}
Olivier Langella's avatar
Olivier Langella committed
void ProteinWindow::browseUrl(int i) {
Olivier Langella's avatar
Olivier Langella committed
}
Olivier Langella's avatar
Olivier Langella committed
void ProteinWindow::updateDisplay() {
Olivier Langella's avatar
Olivier Langella committed
        clearDbXrefLayout();
        ui->valid_checkbox->setCheckState(Qt::Unchecked);
        if (_p_protein_match->isValid()) ui->valid_checkbox->setCheckState(Qt::Checked);
        ui->decoy_checkbox->setCheckState(Qt::Unchecked);
        if (_p_protein_match->getProteinXtpSp().get()->isDecoy()) ui->decoy_checkbox->setCheckState(Qt::Checked);
        ui->accession_label->setText(_p_protein_match->getProteinXtpSp().get()->getAccession());
Olivier Langella's avatar
Olivier Langella committed
        for (const DbXref & dbxref:_p_protein_match->getProteinXtpSp().get()->getDbxrefList()) {
            QString accession = ui->accession_label->text().replace(dbxref.accession, QString("<span style=\"color:%2;\">%1</span>").arg(dbxref.accession).arg("blue"));
Olivier Langella's avatar
Olivier Langella committed
            ui->accession_label->setText(accession);
            qDebug() << "ProteinWindow::updateDisplay " << accession;
Olivier Langella's avatar
Olivier Langella committed

            DbXrefButton * dbxref_button = new DbXrefButton(this,dbxref);
Olivier Langella's avatar
Olivier Langella committed
            ui->dbxref_list_layout->addWidget(dbxref_button);
        }
Olivier Langella's avatar
Olivier Langella committed

        ui->button_layout->setVisible(true);
Olivier Langella's avatar
Olivier Langella committed
        if (ui->dbxref_list_layout->count() == 0) {
Olivier Langella's avatar
Olivier Langella committed
            ui->button_layout->setVisible(false);
Olivier Langella's avatar
Olivier Langella committed
        }
        ui->description_label->setText(_p_protein_match->getProteinXtpSp().get()->getDescription());
Olivier Langella's avatar
Olivier Langella committed
        ui->sequenceTextEdit->setText(_p_protein_match->getHtmlSequence());
        ui->coverage_label->setText(QString("%1 %").arg(_p_protein_match->getCoverage()*100));
        ui->mw_label->setText(QString("%1 kDa").arg(_p_protein_match->getProteinXtpSp().get()->getMass()/1000));
        ui->evalue_label->setText(QString("%1 (log10: %2)").arg(_p_protein_match->getEvalue()).arg(_p_protein_match->getLogEvalue()));
    }
    catch (pappso::PappsoException exception_pappso) {
        QMessageBox::warning(this,
                             tr("Unable to display protein details :"), exception_pappso.qwhat());
    }
    catch (std::exception exception_std) {
        QMessageBox::warning(this,
                             tr("Unable to display protein details :"), exception_std.what());
    }
Olivier Langella's avatar
Olivier Langella committed

}

void ProteinWindow::setProteinMatch(ProteinMatch * p_protein_match) {
    _p_protein_match = p_protein_match;
    updateDisplay();