libpappsomspp
Library for mass spectrometry
Loading...
Searching...
No Matches
obolistmodel.cpp
Go to the documentation of this file.
1/**
2 * \file pappsomspp/widget/obo/obolistwidget/obolistmodel.h
3 * \date 19/04/2021
4 * \author Olivier Langella
5 * \brief MVC model of OBO term list
6 */
7
8
9/*******************************************************************************
10 * Copyright (c) 2021 Olivier Langella
11 *<Olivier.Langella@universite-paris-saclay.fr>.
12 *
13 * This file is part of the PAPPSOms++ library.
14 *
15 * PAPPSOms++ is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation, either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * PAPPSOms++ is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with PAPPSOms++. If not, see <http://www.gnu.org/licenses/>.
27 *
28 ******************************************************************************/
29
30#include "obolistmodel.h"
33#include "obolistwidget.h"
36
37#include <QColor>
38#include <QDebug>
39
40using namespace pappso;
41
42OboListModel::OboListModel(QObject *parent) : QStringListModel(parent)
43{
44}
45
49
54
58
59void
61{
62 mp_parent->m_oboPsiModTermList.push_back(term);
63}
64
65
66void
68{
69 OboPsiModHandler handler(this);
70 OboPsiMod reader(handler);
71 OboUnimod unimod_reader(handler);
72
73
74 // https://pubchem.ncbi.nlm.nih.gov/compound/640368
75 OboPsiModTerm term;
76 term.setAccession("USER:2-Ethynylbenzaldehyde");
77 term.m_diffFormula = "H 4 C 9 O 0"; // C9H6O
78 term.m_name = "2-Ethynylbenzaldehyde";
79 ChemicalFormula formula;
80 formula.setOboPsiModTerm(term);
81 term.m_diffMono = formula.getMass();
82
83 m_oboPsiModTermList.push_back(term);
84
85 qDebug() << m_oboPsiModTermList.size();
86}
87
88QVariant
89pappso::OboListModel::data(const QModelIndex &index, int role) const
90{
91
92 // generate a log message when this method gets called
93 std::size_t row = index.row();
94 // int col = index.column();
95 // qDebug() << QString("row %1, col%2, role %3")
96 // .arg(row).arg(col).arg(role);
97 if(row < m_oboPsiModTermList.size())
98 {
99
100 switch(role)
101 {
102 case Qt::CheckStateRole:
103
104 break;
105 case Qt::BackgroundRole:
106 // return QVariant(QColor("grey"));
107 break;
108 case Qt::SizeHintRole:
109 // qDebug() << "ProteinTableModel::headerData " <<
110 // ProteinTableModel::getColumnWidth(section);
111 // return QSize(PeptideTableModel::getColumnWidth(col), 30);
112 break;
113 case Qt::ToolTipRole:
114 break;
115 case Qt::DisplayRole:
116 return QVariant(QString("%1 %2 %3")
117 .arg(m_oboPsiModTermList[row].getAccession())
118 .arg(m_oboPsiModTermList[row].m_diffMono)
119 .arg(m_oboPsiModTermList[row].m_name));
120 break;
121 case Qt::UserRole:
122 QVariant value;
123 value.setValue(m_oboPsiModTermList[row]);
124 return value;
125 break;
126 }
127 }
128 return QVariant();
129}
130
131int
132pappso::OboListModel::rowCount(const QModelIndex &parent [[maybe_unused]]) const
133{
134 return (int)m_oboPsiModTermList.size();
135}
136
139{
140 if(row < (int)m_oboPsiModTermList.size())
141 {
142 return m_oboPsiModTermList[row];
143 }
144 else
145 {
146 throw pappso::ExceptionNotFound(tr("OBO term not found"));
147 }
148}
void setOboPsiModTerm(const OboPsiModTerm &term)
get formula from an Obo term
void setOboPsiModTerm(const OboPsiModTerm &term) override
triggered function on each obo term when parsing obo file
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
const OboPsiModTerm & getOboPsiModTerm(int row) const
OboListModel(QObject *parent=nullptr)
std::vector< OboPsiModTerm > m_oboPsiModTermList
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void setAccession(const QString &accession)
tries to keep as much as possible monoisotopes, removing any possible C13 peaks and changes multichar...
Definition aa.cpp:39