Skip to content
Snippets Groups Projects
Commit ef98debe authored by stefan's avatar stefan
Browse files

New SequenceViewer, coloring by conservation

git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2310 5a81b35b-ba03-0410-adc8-b2c5c5119f08
parent 0a452e94
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,7 @@ set(OST_GUI_SEQUENCE_VIEW_HEADERS
align_properties_painter.hh
base_row.hh
background_painter.hh
conservation_painter.hh
painter.hh
secstr_row.hh
seq_secstr_painter.hh
......@@ -218,6 +219,7 @@ sequence_viewer/sequence_search_bar.cc
sequence/align_properties_painter.cc
sequence/base_row.cc
sequence/background_painter.cc
sequence/conservation_painter.cc
sequence/secstr_row.cc
sequence/seq_secstr_painter.cc
sequence/seq_selection_painter.cc
......@@ -352,6 +354,7 @@ sequence_viewer/sequence_search_bar.hh
sequence/align_properties_painter.hh
sequence/background_painter.hh
sequence/base_row.hh
sequence/conservation_painter.hh
sequence/painter.hh
sequence/secstr_row.hh
sequence/seq_secstr_painter.hh
......
......@@ -27,6 +27,8 @@
#include <ost/mol/mol.hh>
#include <ost/mol/view_op.hh>
#include <ost/seq/aligned_region.hh>
#include "sequence_row.hh"
#include "secstr_row.hh"
......@@ -40,12 +42,114 @@
namespace ost { namespace gui {
AlignmentViewObject::AlignmentViewObject(const seq::AlignmentHandle& alignment, QObject* parent): SequenceViewObject(parent)
namespace {
QMap<QString,int> GetGroupMap(){
QMap<QString,int> map;
map["G"]=1;
map["A"]=1;
map["V"]=1;
map["L"]=1;
map["I"]=1;
map["F"]=2;
map["Y"]=2;
map["W"]=2;
map["C"]=3;
map["M"]=3;
map["S"]=4;
map["T"]=4;
map["K"]=5;
map["R"]=5;
map["H"]=5;
map["D"]=6;
map["E"]=6;
map["N"]=6;
map["Q"]=6;
map["P"]=7;
return map;
}
QColor GetColor(int cons){
int color = 255 - int((float(cons) / 100) * 255);
return QColor(color,color,color);
}
QColor GetForeGroundColor(QColor background){
if(background == Qt::transparent){
return Qt::black;
}
int gray = 255 - background.red();
return QColor(gray,gray,gray);
}
}
QMap<QString,int> AlignmentViewObject::group_map_ = GetGroupMap();
AlignmentViewObject::AlignmentViewObject(const seq::AlignmentHandle& alignment, QObject* parent): SequenceViewObject(parent), alignment_(alignment)
{
for(int i=0; i<alignment.GetCount();i++){
for(int i=0; i<alignment.GetCount(); i++){
seq::SequenceHandle seq_handle = alignment.GetSequence(i).Copy();
this->AddSequence(seq_handle, seq_handle.GetName().c_str());
}
for(int j=0; j<alignment.GetLength(); j++){
int group = 0;
QString element = "";
for(int i=0; i<alignment.GetCount();i++){
QString code = QString(alignment.GetOneLetterCode(i,j));
if(element.size()==0){
element = code;
}
else if (element != code){
element = " ";
}
if(group_map_.contains(code) && group>=0){
if(group == 0) {
group = group_map_[code];
}
else if(group_map_[code] != group){
group = -1;
}
}
else{
group = -1;
}
}
if(element.size()==1){
conservation_[j] = GetColor(100);
}
else if(group > 0){
conservation_[j] = GetColor(70);
}
else{
conservation_[j] = Qt::transparent;
}
}
}
QVariant AlignmentViewObject::GetData(int row, int column, int role)
{
if(column > 0 && column <= alignment_.GetLength()){
if(role == Qt::UserRole+3 ){
if(column -1 < conservation_.size()){
return QVariant(conservation_[column-1]);
}
return QVariant(Qt::transparent);
}
if(role == Qt::ForegroundRole){
if(column -1 < conservation_.size()){
return QVariant(GetForeGroundColor(conservation_[column-1]));
}
return QVariant(Qt::transparent);
}
}
return BaseViewObject::GetData(row,column,role);
}
}}
......@@ -35,6 +35,14 @@ class AlignmentViewObject : public SequenceViewObject
public:
AlignmentViewObject(const seq::AlignmentHandle& alignment, QObject* parent = 0);
QVariant GetData(int row, int column, int role);
private:
seq::AlignmentHandle alignment_;
QMap<int, QColor> conservation_;
static QMap<QString,int> group_map_;
};
......
......@@ -45,11 +45,11 @@ public:
int GetRowCount();
int GetMaxColumnCount() const;
void SetSelection(int row, const QSet<int>& added, const QSet<int>& removed);
virtual void SetSelection(int row, const QSet<int>& added, const QSet<int>& removed);
QVariant GetData(int row, int column, int role);
bool SetData(int row, int column, const QVariant& value, int role);
Qt::ItemFlags Flags(int row, int column) const;
virtual QVariant GetData(int row, int column, int role);
virtual bool SetData(int row, int column, const QVariant& value, int role);
virtual Qt::ItemFlags Flags(int row, int column) const;
void DoubleClicked(int row, int column);
void ZoomIn();
......
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library 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 Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
/*
Author: Stefan Scheuber
*/
#include <QtGui>
#include "conservation_painter.hh"
namespace ost { namespace gui {
ConservationPainter::ConservationPainter(QObject* parent)
: Painter(parent)
{}
void ConservationPainter::Paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index){
painter->save();
if (index.column()>0){
QColor cons = index.data(Qt::UserRole+3).value<QColor>();
painter->fillRect(option.rect, cons);
}
painter->restore();
}
}}
//------------------------------------------------------------------------------
// This file is part of the OpenStructure project <www.openstructure.org>
//
// Copyright (C) 2008-2010 by the OpenStructure authors
//
// This library is free software; you can redistribute it and/or modify it under
// the terms of the GNU Lesser General Public License as published by the Free
// Software Foundation; either version 3.0 of the License, or (at your option)
// any later version.
// This library 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 Lesser General Public License for more
// details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with this library; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//------------------------------------------------------------------------------
#ifndef OST_SEQUENCE_VIEWER_CONSERVATION_PAINTER
#define OST_SEQUENCE_VIEWER_CONSERVATION_PAINTER
/*
Author: Stefan Scheuber
*/
#include <QObject>
#include "painter.hh"
namespace ost { namespace gui {
class ConservationPainter : public Painter
{
Q_OBJECT
public:
ConservationPainter(QObject* parent = 0);
void Paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index);
};
}}
#endif
......@@ -34,7 +34,7 @@ SeqTextPainter::SeqTextPainter(QObject* parent)
void SeqTextPainter::Paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index){
painter->save();
painter->setPen(QPen(Qt::black));
painter->setPen(index.data(Qt::ForegroundRole).value<QColor>());
QVariant value = index.data(Qt::DisplayRole);
if (value.isValid()){
QString text = value.toString();
......
......@@ -31,6 +31,7 @@
#include "secstr_row.hh"
#include "align_properties_painter.hh"
#include "conservation_painter.hh"
#include "painter.hh"
#include "background_painter.hh"
#include "seq_secstr_painter.hh"
......@@ -85,10 +86,12 @@ void SequenceViewObject::AddSequence(seq::SequenceHandle& sequence, const QStrin
new_row->InsertPainter(p);
p = new AlignPropertiesPainter(this);
new_row->InsertPainter(p);
p = new SeqSelectionPainter(this);
p = new ConservationPainter(this);
new_row->InsertPainter(p);
p = new SeqTextPainter(this);
new_row->InsertPainter(p);
p = new SeqSelectionPainter(this);
new_row->InsertPainter(p);
rows_.append(new_row);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment