-
Olivier Langella authoredOlivier Langella authored
ptmislandtablemodel.cpp 7.10 KiB
/**
* \file gui/ptm_island_list_window/ptmislandtablemodel.h
* \date 30/5/2017
* \author Olivier Langella
* \brief display all ptm islands
*/
/*******************************************************************************
* 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 "ptmislandtablemodel.h"
#include "ptmislandlistwindow.h"
PtmIslandTableModel::columnMap PtmIslandTableModel::_column_assignment = {
(std::int8_t)PtmIslandListColumn::ptm_island_id,
(std::int8_t)PtmIslandListColumn::accession,
(std::int8_t)PtmIslandListColumn::description,
(std::int8_t)PtmIslandListColumn::spectrum,
(std::int8_t)PtmIslandListColumn::sequence,
(std::int8_t)PtmIslandListColumn::ptm_position_list,
(std::int8_t)PtmIslandListColumn::multiptm,
(std::int8_t)PtmIslandListColumn::ptm_island_start,
(std::int8_t)PtmIslandListColumn::ptm_island_length
};
PtmIslandTableModel::PtmIslandTableModel(PtmIslandListWindow * p_ptm_island_list_window)
{
}
PtmIslandTableModel::~PtmIslandTableModel()
{
}
const QString PtmIslandTableModel::getTitle(std::int8_t column) const {
switch (column) {
case (std::int8_t) PtmIslandListColumn::spectrum:
return "spectrum";
break;
case (std::int8_t) PtmIslandListColumn::description:
return "description";
break;
case (std::int8_t) PtmIslandListColumn::multiptm:
return "multi PTM";
break;
case (std::int8_t) PtmIslandListColumn::sequence:
return "sequence";
break;
case (std::int8_t) PtmIslandListColumn::ptm_island_id:
return "PTM island ID";
break;
case (std::int8_t) PtmIslandListColumn::accession:
return "accession";
break;
case (std::int8_t) PtmIslandListColumn::ptm_position_list:
return "ptm positions";
break;
case (std::int8_t) PtmIslandListColumn::ptm_island_start:
return "start";
break;
case (std::int8_t) PtmIslandListColumn::ptm_island_length:
return "length";
}
return "";
}
void PtmIslandTableModel::setIdentificationGroup(IdentificationGroup * p_identification_group) {
qDebug() << "PtmIslandTableModel::setIdentificationGroup begin ";
beginResetModel();
_p_identification_group = p_identification_group;
//emit headerDataChanged(Qt::Horizontal, 0,11);
//refresh();
qDebug() << "PtmIslandTableModel::setIdentificationGroup end ";
endResetModel();
}
const PtmGroupingExperiment * PtmIslandTableModel::getPtmGroupingExperiment() const {
if (_p_identification_group == nullptr) {
return nullptr;
}
return _p_identification_group->getPtmGroupingExperiment();
}
int PtmIslandTableModel::rowCount(const QModelIndex &parent ) const {
//qDebug() << "ProteinTableModel::rowCount begin ";
if (getPtmGroupingExperiment() != nullptr) {
//qDebug() << "ProteinTableModel::rowCount(const QModelIndex &parent ) " << _p_identification_group->getProteinMatchList().size();
return (int) getPtmGroupingExperiment()->getPtmIslandList().size();
}
return 0;
}
int PtmIslandTableModel::columnCount(const QModelIndex &parent ) const {
//qDebug() << "ProteinTableModel::columnCount begin ";
if (getPtmGroupingExperiment() != nullptr) {
return 9;
}
return 0;
}
QVariant PtmIslandTableModel::headerData(int section, Qt::Orientation orientation, int role) const
{
if (getPtmGroupingExperiment() == nullptr) return QVariant();
if (orientation == Qt::Horizontal)
{
if (role == Qt::DisplayRole)
{
return QVariant(getTitle(_column_assignment [section]));
}
}
return QVariant();
}
QVariant PtmIslandTableModel::data(const QModelIndex &index, int role ) const {
// generate a log message when this method gets called
if (getPtmGroupingExperiment() == nullptr) return QVariant();
int row = index.row();
int col = index.column();
switch(role) {
case Qt::DisplayRole:
if (_p_identification_group == nullptr) {
return QVariant();
}
switch (_column_assignment [col]) {
case (std::int8_t) PtmIslandListColumn::spectrum:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->getPtmIslandSubroup()->countSampleScan());
break;
case (std::int8_t) PtmIslandListColumn::description:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->getProteinMatch()->getProteinXtpSp().get()->getDescription());
break;
case (std::int8_t) PtmIslandListColumn::multiptm:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->countSampleScanMultiPtm(getPtmGroupingExperiment()));
break;
case (std::int8_t) PtmIslandListColumn::sequence:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->countSequence());
break;
case (std::int8_t) PtmIslandListColumn::ptm_island_id:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->getGroupingId());
break;
case (std::int8_t) PtmIslandListColumn::accession:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->getProteinMatch()->getProteinXtpSp().get()->getAccession());
break;
case (std::int8_t) PtmIslandListColumn::ptm_island_start:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->getStart());
break;
case (std::int8_t) PtmIslandListColumn::ptm_island_length:
return QVariant(getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->size());
break;
case (std::int8_t) PtmIslandListColumn::ptm_position_list:
QStringList position_list;
for (unsigned int position :getPtmGroupingExperiment()->getPtmIslandList().at(row).get()->getPositionList()) {
position_list << QString("%1").arg(position+1);
}
return QVariant(position_list.join(" "));
}
}
return QVariant();
}
void PtmIslandTableModel::onPtmIslandDataChanged() {
qDebug() << "PtmIslandTableModel::onPtmIslandDataChanged begin " << rowCount();
emit layoutAboutToBeChanged();
emit layoutChanged();
}