From 9fcb2f6dfc60526f2b2d00679431f8814ef10ba5 Mon Sep 17 00:00:00 2001 From: stefan <stefan@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Fri, 28 May 2010 15:09:35 +0000 Subject: [PATCH] New SequenceViewer, support for seq::AlignmentHandle git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2297 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/gui/pymod/export_sequence_viewerV2.cc | 2 + modules/gui/src/CMakeLists.txt | 3 ++ .../gui/src/sequence/alignment_view_object.cc | 51 +++++++++++++++++++ .../gui/src/sequence/alignment_view_object.hh | 43 ++++++++++++++++ modules/gui/src/sequence/sequence_model.cc | 18 +++++++ modules/gui/src/sequence/sequence_model.hh | 3 ++ .../gui/src/sequence/sequence_view_object.cc | 3 ++ .../gui/src/sequence/sequence_view_object.hh | 1 + modules/gui/src/sequence/sequence_viewer.cc | 12 +++++ modules/gui/src/sequence/sequence_viewer.hh | 5 ++ 10 files changed, 141 insertions(+) create mode 100644 modules/gui/src/sequence/alignment_view_object.cc create mode 100644 modules/gui/src/sequence/alignment_view_object.hh diff --git a/modules/gui/pymod/export_sequence_viewerV2.cc b/modules/gui/pymod/export_sequence_viewerV2.cc index cd010952f..0a744dccc 100644 --- a/modules/gui/pymod/export_sequence_viewerV2.cc +++ b/modules/gui/pymod/export_sequence_viewerV2.cc @@ -32,6 +32,8 @@ void export_SequenceViewerV2() class_<SequenceViewerV2, boost::noncopyable >("SequenceViewerV2",init<>()) .def("Show", &SequenceViewerV2::show) .def("Hide", &SequenceViewerV2::hide) + .def("AddAlignment", &SequenceViewerV2::AddAlignment) + .def("RemoveAlignment", &SequenceViewerV2::RemoveAlignment) .def("GetQObject",&get_py_qobject<SequenceViewerV2>) .add_property("qobject", &get_py_qobject<SequenceViewerV2>) ; diff --git a/modules/gui/src/CMakeLists.txt b/modules/gui/src/CMakeLists.txt index b4ca43ed3..36b468e63 100644 --- a/modules/gui/src/CMakeLists.txt +++ b/modules/gui/src/CMakeLists.txt @@ -36,6 +36,7 @@ sequence_table_view.hh sequence_viewer.hh tick_painter.hh title_row.hh +alignment_view_object.hh base_view_object.hh sequence_view_object.hh ) @@ -227,6 +228,7 @@ sequence/sequence_table_view.cc sequence/sequence_viewer.cc sequence/tick_painter.cc sequence/title_row.cc +sequence/alignment_view_object.cc sequence/base_view_object.cc sequence/sequence_view_object.cc gosty_app.cc @@ -360,6 +362,7 @@ sequence/sequence_table_view.hh sequence/sequence_viewer.hh sequence/tick_painter.hh sequence/title_row.hh +sequence/alignment_view_object.hh sequence/base_view_object.hh sequence/sequence_view_object.hh plot_viewer/plot_axis_base.hh diff --git a/modules/gui/src/sequence/alignment_view_object.cc b/modules/gui/src/sequence/alignment_view_object.cc new file mode 100644 index 000000000..bee250f9f --- /dev/null +++ b/modules/gui/src/sequence/alignment_view_object.cc @@ -0,0 +1,51 @@ +//------------------------------------------------------------------------------ +// 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 <ost/mol/mol.hh> +#include <ost/mol/view_op.hh> + +#include "sequence_row.hh" +#include "secstr_row.hh" + +#include "painter.hh" +#include "background_painter.hh" +#include "seq_secstr_painter.hh" +#include "seq_selection_painter.hh" +#include "seq_text_painter.hh" + +#include "alignment_view_object.hh" + +namespace ost { namespace gui { + +AlignmentViewObject::AlignmentViewObject(const seq::AlignmentHandle& alignment, QObject* parent): SequenceViewObject(parent) +{ + 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()); + } +} + +}} diff --git a/modules/gui/src/sequence/alignment_view_object.hh b/modules/gui/src/sequence/alignment_view_object.hh new file mode 100644 index 000000000..a75159c22 --- /dev/null +++ b/modules/gui/src/sequence/alignment_view_object.hh @@ -0,0 +1,43 @@ +//------------------------------------------------------------------------------ +// 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_ALIGNMENT_VIEW_OBJECT +#define OST_SEQUENCE_VIEWER_ALIGNMENT_VIEW_OBJECT + +/* + Author: Stefan Scheuber + */ + +#include <ost/seq/alignment_handle.hh> + +#include "sequence_view_object.hh" + +namespace ost { namespace gui { + +class AlignmentViewObject : public SequenceViewObject +{ + Q_OBJECT + +public: + AlignmentViewObject(const seq::AlignmentHandle& alignment, QObject* parent = 0); +}; + + +}} + +#endif diff --git a/modules/gui/src/sequence/sequence_model.cc b/modules/gui/src/sequence/sequence_model.cc index dc26ce348..e054a9046 100644 --- a/modules/gui/src/sequence/sequence_model.cc +++ b/modules/gui/src/sequence/sequence_model.cc @@ -26,6 +26,7 @@ #include <QtGui> +#include "alignment_view_object.hh" #include "sequence_view_object.hh" #include "title_row.hh" @@ -78,6 +79,19 @@ void SequenceModel::InsertChain(QString& name, mol::ChainView& view){ this->endInsertRows(); } +void SequenceModel::InsertAlignment(const seq::AlignmentHandle& alignment){ + int cols = this->columnCount(); + int new_cols = alignment.GetLength(); + this->beginInsertRows(QModelIndex(),this->rowCount(),this->rowCount()+alignment.GetCount()-1); + objects_.append(new AlignmentViewObject(alignment, this)); + if(new_cols > cols){ + this->max_columns = new_cols; + this->beginInsertColumns(QModelIndex(), cols, new_cols); + this->endInsertColumns(); + } + this->endInsertRows(); +} + void SequenceModel::InsertSequences(const QList<QString>& names, seq::SequenceList& list){ this->beginInsertRows(this->index(this->rowCount(),0),this->rowCount(),this->rowCount()+list.GetCount()); objects_.append(new SequenceViewObject(list, names, this)); @@ -116,6 +130,10 @@ void SequenceModel::RemoveGfxEntity(gfx::EntityP& entity){ } } +void SequenceModel::RemoveAlignment(const seq::AlignmentHandle& alignment){ + +} + int SequenceModel::GetColumnCount() const{ int cols = 0; for(int i = 0; i<objects_.size();i++){ diff --git a/modules/gui/src/sequence/sequence_model.hh b/modules/gui/src/sequence/sequence_model.hh index 98cbe3aa4..218dbb4c9 100644 --- a/modules/gui/src/sequence/sequence_model.hh +++ b/modules/gui/src/sequence/sequence_model.hh @@ -29,6 +29,7 @@ #include <ost/mol/chain_view.hh> #include <ost/seq/sequence_list.hh> +#include <ost/seq/alignment_handle.hh> #include <ost/gfx/entity.hh> @@ -44,11 +45,13 @@ class SequenceModel : public QAbstractTableModel public: SequenceModel(QObject *parent = 0); + void InsertAlignment(const seq::AlignmentHandle& alignment); void InsertGfxEntity(gfx::EntityP& entity); void InsertChain(QString& name, mol::ChainView& view); void InsertSequence(QString& name, seq::SequenceHandle& seq); void InsertSequences(const QList<QString>& names, seq::SequenceList& list); + void RemoveAlignment(const seq::AlignmentHandle& alignment); void RemoveGfxEntity(gfx::EntityP& entity); QModelIndexList GetModelIndexes(gfx::EntityP& entity, const mol::EntityView& view); diff --git a/modules/gui/src/sequence/sequence_view_object.cc b/modules/gui/src/sequence/sequence_view_object.cc index d3e53093a..b5a44c067 100644 --- a/modules/gui/src/sequence/sequence_view_object.cc +++ b/modules/gui/src/sequence/sequence_view_object.cc @@ -74,6 +74,9 @@ SequenceViewObject::SequenceViewObject(gfx::EntityP& entity, QObject* parent): B } } +SequenceViewObject::SequenceViewObject(QObject* parent): BaseViewObject(parent), entity_(gfx::EntityP()) +{ } + void SequenceViewObject::AddSequence(seq::SequenceHandle& sequence, const QString& name) { SequenceRow* new_row = new SequenceRow(name, sequence, this); diff --git a/modules/gui/src/sequence/sequence_view_object.hh b/modules/gui/src/sequence/sequence_view_object.hh index 9d85f85b8..9c443095f 100644 --- a/modules/gui/src/sequence/sequence_view_object.hh +++ b/modules/gui/src/sequence/sequence_view_object.hh @@ -43,6 +43,7 @@ public: SequenceViewObject(seq::SequenceHandle& sequence, const QString& name, QObject* parent = 0); SequenceViewObject(mol::ChainView& chain, const QString& name, QObject* parent = 0); SequenceViewObject(gfx::EntityP& entity, QObject* parent = 0); + SequenceViewObject(QObject* parent = 0); void AddSequence(seq::SequenceHandle& sequence, const QString& name=QString()); void AddChain(mol::ChainView& chain, const QString& name=QString()); diff --git a/modules/gui/src/sequence/sequence_viewer.cc b/modules/gui/src/sequence/sequence_viewer.cc index d00a1b07b..c73f0a51a 100644 --- a/modules/gui/src/sequence/sequence_viewer.cc +++ b/modules/gui/src/sequence/sequence_viewer.cc @@ -128,6 +128,18 @@ void SequenceViewerV2::NodeRemoved(const gfx::GfxNodeP& node) } } +void SequenceViewerV2::AddAlignment(const seq::AlignmentHandle& alignment) +{ + if(alignment.GetCount()>0 && alignment.GetLength()>0){ + model_->InsertAlignment(alignment); + } +} + +void SequenceViewerV2::RemoveAlignment(const seq::AlignmentHandle& alignment) +{ + model_->RemoveAlignment(alignment); +} + void SequenceViewerV2::UpdateSearchBar() { QStringList sequence_names_; diff --git a/modules/gui/src/sequence/sequence_viewer.hh b/modules/gui/src/sequence/sequence_viewer.hh index b04d242dc..b4134f1fe 100644 --- a/modules/gui/src/sequence/sequence_viewer.hh +++ b/modules/gui/src/sequence/sequence_viewer.hh @@ -25,6 +25,8 @@ #include <QWidget> +#include <ost/seq/alignment_handle.hh> + #include <ost/gfx/scene.hh> #include <ost/gfx/gfx_object.hh> @@ -49,6 +51,9 @@ public: virtual void NodeRemoved(const gfx::GfxNodeP& node); virtual void SelectionChanged(const gfx::GfxObjP& o, const mol::EntityView& view); + virtual void AddAlignment(const seq::AlignmentHandle& alignment); + virtual void RemoveAlignment(const seq::AlignmentHandle& alignment); + virtual bool Restore(const QString&){return true;}; virtual bool Save(const QString&){return true;}; -- GitLab