From f254484afa4ff3e9cda1d4f30fb17c88a910b9c6 Mon Sep 17 00:00:00 2001 From: marco <marco@5a81b35b-ba03-0410-adc8-b2c5c5119f08> Date: Thu, 22 Apr 2010 08:51:09 +0000 Subject: [PATCH] sequences are now generic property containers git-svn-id: https://dng.biozentrum.unibas.ch/svn/openstructure/trunk@2101 5a81b35b-ba03-0410-adc8-b2c5c5119f08 --- modules/base/src/CMakeLists.txt | 2 +- .../export_helper}/generic_property_def.hh | 30 ++-- modules/base/src/generic_property.hh | 128 ++++++++------- modules/mol/base/pymod/export_atom.cc | 3 +- modules/mol/base/pymod/export_bond.cc | 4 +- modules/mol/base/pymod/export_chain.cc | 4 +- modules/mol/base/pymod/export_entity.cc | 2 +- modules/mol/base/pymod/export_residue.cc | 7 +- modules/mol/base/src/atom_base.hh | 2 +- modules/mol/base/src/bond_handle.hh | 2 +- modules/mol/base/src/chain_base.hh | 2 +- modules/mol/base/src/entity_base.hh | 2 +- modules/mol/base/src/residue_base.hh | 2 +- modules/seq/base/pymod/export_sequence.cc | 74 +++++---- modules/seq/base/src/impl/sequence_impl.hh | 4 +- modules/seq/base/src/sequence_handle.cc | 154 +++++++++++++++++- modules/seq/base/src/sequence_handle.hh | 97 ++++++++++- 17 files changed, 382 insertions(+), 137 deletions(-) rename modules/{mol/base/pymod => base/src/export_helper}/generic_property_def.hh (89%) diff --git a/modules/base/src/CMakeLists.txt b/modules/base/src/CMakeLists.txt index 5dbc9b808..b30a8312b 100644 --- a/modules/base/src/CMakeLists.txt +++ b/modules/base/src/CMakeLists.txt @@ -31,7 +31,7 @@ fixed_string.hh ) module(NAME base SOURCES ${OST_BASE_SOURCES} - HEADERS ${OST_BASE_HEADERS} + HEADERS generic_property_def.hh IN_DIR export_helper ${OST_BASE_HEADERS} DEPENDS_ON geom HEADER_OUTPUT_DIR ost) diff --git a/modules/mol/base/pymod/generic_property_def.hh b/modules/base/src/export_helper/generic_property_def.hh similarity index 89% rename from modules/mol/base/pymod/generic_property_def.hh rename to modules/base/src/export_helper/generic_property_def.hh index fbed012fb..4b8241be7 100644 --- a/modules/mol/base/pymod/generic_property_def.hh +++ b/modules/base/src/export_helper/generic_property_def.hh @@ -24,8 +24,8 @@ Author: Marco Biasini */ -template <typename C> -void generic_prop_def(class_<C>& bp_class) +template <typename C, typename O> +void const_generic_prop_def(O& bp_class) { bool (C::*get_bool1)(const String&, bool) const=&C::GetGenericBoolProperty; bool (C::*get_bool2)(const String&) const=&C::GetGenericBoolProperty; @@ -40,6 +40,24 @@ void generic_prop_def(class_<C>& bp_class) String (C::*get_str2)(const String&) const=&C::GetGenericStringProperty; bp_class .def("HasGenericProperty", &C::HasGenericProperty) + .def("GetGenericPropertyStringRepresentation", + &C::GetGenericPropertyStringRepresentation) + .def("GetGenericBoolProperty", get_bool1) + .def("GetGenericBoolProperty", get_bool2) + .def("GetGenericFloatProperty", get_float1) + .def("GetGenericFloatProperty", get_float2) + .def("GetGenericIntProperty", get_int1) + .def("GetGenericIntProperty", get_int2) + .def("GetGenericStringProperty", get_str1) + .def("GetGenericStringProperty", get_str2) + ; +} + +template <typename C, typename O> +void generic_prop_def(O& bp_class) +{ + const_generic_prop_def<C, O>(bp_class); + bp_class .def("SetGenericBoolProperty", &C::SetGenericBoolProperty) .def("ClearGenericProperties", @@ -52,14 +70,6 @@ void generic_prop_def(class_<C>& bp_class) &C::SetGenericIntProperty) .def("SetGenericStringProperty", &C::SetGenericStringProperty) - .def("GetGenericBoolProperty", get_bool1) - .def("GetGenericBoolProperty", get_bool2) - .def("GetGenericFloatProperty", get_float1) - .def("GetGenericFloatProperty", get_float2) - .def("GetGenericIntProperty", get_int1) - .def("GetGenericIntProperty", get_int2) - .def("GetGenericStringProperty", get_str1) - .def("GetGenericStringProperty", get_str2) ; } diff --git a/modules/base/src/generic_property.hh b/modules/base/src/generic_property.hh index 66c9212ad..3fe6f037a 100644 --- a/modules/base/src/generic_property.hh +++ b/modules/base/src/generic_property.hh @@ -127,11 +127,11 @@ public: private: mutable PropertyMap* map_; }; - -/// \brief base class for the handler classes + template <typename H> -class TEMPLATE_EXPORT GenericPropertyContainer -{ +class TEMPLATE_EXPORT ConstGenericPropertyContainer { +protected: + template<typename T> T gp_get(const String& key) const { if(HasGenericProperty(key)) { @@ -150,19 +150,21 @@ class TEMPLATE_EXPORT GenericPropertyContainer } return def; } + GenericPropertyContainerImpl* GetImpl() + { + return static_cast<H*>(this)->GpImpl(); + } - + const GenericPropertyContainerImpl* GetImpl() const + { + return static_cast<const H*>(this)->GpImpl(); + } public: /// \brief checks existence of property bool HasGenericProperty(const String& key) const { - return GetImpl()->HasGenericProperty(key); + return this->GetImpl()->HasGenericProperty(key); } - - void ClearGenericProperties() - { - GetImpl()->ClearGenericProperties(); - } - + /// \brief returns a String representation of stored value /// /// returns the String representation of this property, or the empty String if @@ -174,50 +176,25 @@ public: { if(!HasGenericProperty(key)) return ""; std::ostringstream rep(""); - rep << GetImpl()->GenericProperty(key); + rep << this->GetImpl()->GenericProperty(key); return rep.str(); - } - - /// \brief sets String property - void SetGenericStringProperty(const String& key, const String& value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \brief sets floating point property - void SetGenericFloatProperty(const String& key, Real value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \brief sets integer property - void SetGenericIntProperty(const String& key, int value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \ brief sets boolean property - void SetGenericBoolProperty(const String& key, bool value) - { - GetImpl()->GenericProperty(key)=value; - } - - /// \brief returns String property, raises an exception if it does not exist - String GetGenericStringProperty(const String& key) const - { - return gp_get<String>(key); - } + } + /// \brief returns String property, raises an exception if it does not exist + String GetGenericStringProperty(const String& key) const + { + return this->gp_get<String>(key); + } /// \brief returns floating point property, raises an exception if it does /// not exist Real GetGenericFloatProperty(const String& key) const { if(HasGenericProperty(key)) { - GenericPropertyValue value=GetImpl()->GenericProperty(key); + GenericPropertyValue value=this->GetImpl()->GenericProperty(key); if (value.which()==1) { - return boost::get<Real>(GetImpl()->GenericProperty(key)); + return boost::get<Real>(this->GetImpl()->GenericProperty(key)); } else if (value.which()==2) { - return boost::get<int>(GetImpl()->GenericProperty(key)); + return boost::get<int>(this->GetImpl()->GenericProperty(key)); } std::ostringstream m(""); m << "property '" << key << "' is not numeric"; @@ -229,29 +206,30 @@ public: } } + /// \brief returns integer property, raises an exception if it does not exist int GetGenericIntProperty(const String& key) const { - return gp_get<int>(key); + return this->gp_get<int>(key); } /// \brief returns boolean property, raises an exception if it does not exist bool GetGenericBoolProperty(const String& key) const { - return gp_get<bool>(key); + return this->gp_get<bool>(key); } /// \brief returns String property, or the given default if it does not exist String GetGenericStringProperty(const String& key, const String& def) const { - return gp_get<String>(key,def); + return this->gp_get<String>(key,def); } /// \brief returns floating point property, or the given default if it does /// not exist Real GetGenericFloatProperty(const String& key, Real def) const { - if(HasGenericProperty(key)) { + if(this->HasGenericProperty(key)) { GenericPropertyValue value=GetImpl()->GenericProperty(key); if (value.which()==1) { return boost::get<Real>(GetImpl()->GenericProperty(key)); @@ -269,29 +247,55 @@ public: /// \brief returns integer property, or the given default if it does not exist int GetGenericIntProperty(const String& key, int def) const { - return gp_get<int>(key, def); + return this->gp_get<int>(key, def); } /// \brief returns boolean property, or the given default if it does not exist bool GetGenericBoolProperty(const String& key, bool def) const { - return gp_get<bool>(key, def); + return this->gp_get<bool>(key, def); } - + std::map<String,GenericPropertyValue> GetGenericPropertyMap() const { - return GetImpl()->GetGenericPropertyMap(); - } -protected: - GenericPropertyContainerImpl* GetImpl() + return this->GetImpl()->GetGenericPropertyMap(); + } +}; + +/// \brief base class for the handler classes +template <typename H> +class TEMPLATE_EXPORT GenericPropertyContainer : + public ConstGenericPropertyContainer<H> +{ +public: + void ClearGenericProperties() { - return static_cast<H*>(this)->GpImpl(); + this->GetImpl()->ClearGenericProperties(); } - const GenericPropertyContainerImpl* GetImpl() const + /// \brief sets String property + void SetGenericStringProperty(const String& key, const String& value) { - return static_cast<const H*>(this)->GpImpl(); - } + this->GetImpl()->GenericProperty(key)=value; + } + + /// \brief sets floating point property + void SetGenericFloatProperty(const String& key, Real value) + { + this->GetImpl()->GenericProperty(key)=value; + } + + /// \brief sets integer property + void SetGenericIntProperty(const String& key, int value) + { + this->GetImpl()->GenericProperty(key)=value; + } + + /// \ brief sets boolean property + void SetGenericBoolProperty(const String& key, bool value) + { + this->GetImpl()->GenericProperty(key)=value; + } }; diff --git a/modules/mol/base/pymod/export_atom.cc b/modules/mol/base/pymod/export_atom.cc index ccebbfb0a..bb8c9fe31 100644 --- a/modules/mol/base/pymod/export_atom.cc +++ b/modules/mol/base/pymod/export_atom.cc @@ -26,7 +26,8 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> + void export_Atom() { class_<AtomBase> atom_base("AtomBase", no_init); diff --git a/modules/mol/base/pymod/export_bond.cc b/modules/mol/base/pymod/export_bond.cc index e22adf98e..ddfde4721 100644 --- a/modules/mol/base/pymod/export_bond.cc +++ b/modules/mol/base/pymod/export_bond.cc @@ -26,8 +26,8 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> + void export_Bond() { void (BondHandle::* apply1)(EntityVisitor&) = &BondHandle::Apply; diff --git a/modules/mol/base/pymod/export_chain.cc b/modules/mol/base/pymod/export_chain.cc index 71896935b..57e717eba 100644 --- a/modules/mol/base/pymod/export_chain.cc +++ b/modules/mol/base/pymod/export_chain.cc @@ -24,9 +24,7 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" - -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> namespace { typedef void (ChainHandle::*RnumMethod)(const ResNum&); diff --git a/modules/mol/base/pymod/export_entity.cc b/modules/mol/base/pymod/export_entity.cc index a3624877a..733c867d6 100644 --- a/modules/mol/base/pymod/export_entity.cc +++ b/modules/mol/base/pymod/export_entity.cc @@ -28,7 +28,7 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> namespace { EntityHandle create1() { return CreateEntity(); } diff --git a/modules/mol/base/pymod/export_residue.cc b/modules/mol/base/pymod/export_residue.cc index 1ff735cf6..66214c7d4 100644 --- a/modules/mol/base/pymod/export_residue.cc +++ b/modules/mol/base/pymod/export_residue.cc @@ -25,9 +25,8 @@ using namespace boost::python; using namespace ost; using namespace ost::mol; -#include "generic_property_def.hh" -#include "generic_property_def.hh" +#include <ost/export_helper/generic_property_def.hh> namespace { typedef EntityView (ResidueHandle::*QueryMethod)(const Query&, uint) const; @@ -118,9 +117,7 @@ void export_Residue() return_value_policy<copy_const_reference>())) .add_property("qualified_name", &ResidueBase::GetQualifiedName) ; - generic_prop_def(residue_base); - - generic_prop_def(residue_base); + generic_prop_def<ResidueBase>(residue_base); class_<ResidueHandle, bases<ResidueBase> >("ResidueHandle", init<>()) .def("GetChain",&ResidueHandle::GetChain) diff --git a/modules/mol/base/src/atom_base.hh b/modules/mol/base/src/atom_base.hh index 3b10fb8ca..71ec8dbe8 100644 --- a/modules/mol/base/src/atom_base.hh +++ b/modules/mol/base/src/atom_base.hh @@ -49,7 +49,7 @@ public: AtomBase(); AtomBase(const impl::AtomImplPtr& impl); public: - friend class GenericPropertyContainer<AtomBase>; + friend class ConstGenericPropertyContainer<AtomBase>; ///\brief Get atom name. /// /// In Python the atom name may also be accesssed over the property \c Name diff --git a/modules/mol/base/src/bond_handle.hh b/modules/mol/base/src/bond_handle.hh index b23ca0679..114e033a6 100644 --- a/modules/mol/base/src/bond_handle.hh +++ b/modules/mol/base/src/bond_handle.hh @@ -34,7 +34,7 @@ namespace ost { namespace mol { class DLLEXPORT_OST_MOL BondHandle: public GenericPropertyContainer<BondHandle> { public: - friend class GenericPropertyContainer<BondHandle>; + friend class ConstGenericPropertyContainer<BondHandle>; /// necessary dummy ctor, creates invalid handle BondHandle(); /// ctor for internal use, in public interface for convenience purposes diff --git a/modules/mol/base/src/chain_base.hh b/modules/mol/base/src/chain_base.hh index 4e27e79ed..c8de6551b 100644 --- a/modules/mol/base/src/chain_base.hh +++ b/modules/mol/base/src/chain_base.hh @@ -42,7 +42,7 @@ public: // constructors ChainBase(); ChainBase(const impl::ChainImplPtr& impl); public: - friend class GenericPropertyContainer<ChainBase>; + friend class ConstGenericPropertyContainer<ChainBase>; String GetName() const; /// \name Handle validity //@{ diff --git a/modules/mol/base/src/entity_base.hh b/modules/mol/base/src/entity_base.hh index 9cb68a0c8..05228c56f 100644 --- a/modules/mol/base/src/entity_base.hh +++ b/modules/mol/base/src/entity_base.hh @@ -30,7 +30,7 @@ namespace ost { namespace mol { class DLLEXPORT_OST_MOL EntityBase: public GenericPropertyContainer<EntityBase> { public: - friend class GenericPropertyContainer<EntityBase>; + friend class ConstGenericPropertyContainer<EntityBase>; EntityBase(const impl::EntityImplPtr& impl); EntityBase(); diff --git a/modules/mol/base/src/residue_base.hh b/modules/mol/base/src/residue_base.hh index da5cd0525..0aabe77a3 100644 --- a/modules/mol/base/src/residue_base.hh +++ b/modules/mol/base/src/residue_base.hh @@ -63,7 +63,7 @@ public: ResidueBase(const impl::ResidueImplPtr& impl); ResidueBase(const ResidueBase& rhs); public: - friend class GenericPropertyContainer<ResidueBase>; + friend class ConstGenericPropertyContainer<ResidueBase>; /// \brief return residue number const ResNum& GetNumber() const; diff --git a/modules/seq/base/pymod/export_sequence.cc b/modules/seq/base/pymod/export_sequence.cc index ce05be244..60947f4cb 100644 --- a/modules/seq/base/pymod/export_sequence.cc +++ b/modules/seq/base/pymod/export_sequence.cc @@ -22,6 +22,8 @@ #include <boost/python/suite/indexing/vector_indexing_suite.hpp> using namespace boost::python; +#include <ost/generic_property.hh> +#include <ost/export_helper/generic_property_def.hh> #include <ost/info/info.hh> #include <ost/mol/mol.hh> #include <ost/seq/sequence_handle.hh> @@ -145,46 +147,54 @@ RevRegionRangeIter iter_range3(AlignedRegion& aln_region) return RevRegionRangeIter(aln_region.begin(), aln_region.end()); } -} - -void export_sequence() +template <typename C, typename O> +void const_seq_handle_def(O& bp_class) { - class_<ConstSequenceHandle>("ConstSequenceHandle", init<>()) - .def("GetResidueIndex", &ConstSequenceHandle::GetResidueIndex) - .def("GetPos", &ConstSequenceHandle::GetPos) - .def("GetLength", &ConstSequenceHandle::GetLength) - .def("GetResidue", &ConstSequenceHandle::GetResidue) - .def("GetOneLetterCode", &ConstSequenceHandle::GetOneLetterCode) - .def("__getitem__", &ConstSequenceHandle::GetOneLetterCode) - .def("GetSequenceOffset", &ConstSequenceHandle::GetSequenceOffset) - .def("Copy", &ConstSequenceHandle::Copy) - .def("GetFirstNonGap", &ConstSequenceHandle::GetFirstNonGap) - .def("GetLastNonGap", &ConstSequenceHandle::GetLastNonGap) - .add_property("first_non_gap", &SequenceHandle::GetFirstNonGap) - .add_property("last_non_gap", &SequenceHandle::GetLastNonGap) - .def("GetAttachedView", &ConstSequenceHandle::GetAttachedView) - .def("GetGaplessString", &ConstSequenceHandle::GetGaplessString) - .def("GetString", &ConstSequenceHandle::GetString, + bp_class + .def("GetResidueIndex", &C::GetResidueIndex) + .def("GetPos", &C::GetPos) + .def("GetLength", &C::GetLength) + .def("GetResidue", &C::GetResidue) + .def("GetOneLetterCode", &C::GetOneLetterCode) + .def("__getitem__", &C::GetOneLetterCode) + .def("GetSequenceOffset", &C::GetSequenceOffset) + .def("Copy", &C::Copy) + .def("GetFirstNonGap", &C::GetFirstNonGap) + .def("GetLastNonGap", &C::GetLastNonGap) + .add_property("first_non_gap", &C::GetFirstNonGap) + .add_property("last_non_gap", &C::GetLastNonGap) + .def("GetAttachedView", &C::GetAttachedView) + .def("GetGaplessString", &C::GetGaplessString) + .def("GetString", &C::GetString, return_value_policy<copy_const_reference>()) - .def("GetName", &ConstSequenceHandle::GetName, + .def("GetName", &C::GetName, return_value_policy<copy_const_reference>()) - .def("HasAttachedView", &ConstSequenceHandle::HasAttachedView) - .def("__len__", &SequenceHandle::GetLength) - .add_property("length", &SequenceHandle::GetLength) - .add_property("attached_view", &ConstSequenceHandle::GetAttachedView) + .def("HasAttachedView", &C::HasAttachedView) + .def("__len__", &C::GetLength) + .add_property("length", &C::GetLength) + .add_property("attached_view", &C::GetAttachedView) .add_property("name", - make_function(&ConstSequenceHandle::GetName, + make_function(&C::GetName, return_value_policy<copy_const_reference>())) - .add_property("sequence_offset", &ConstSequenceHandle::GetSequenceOffset) - .add_property("gapless_string", &ConstSequenceHandle::GetGaplessString) + .add_property("sequence_offset", &C::GetSequenceOffset) + .add_property("gapless_string", &C::GetGaplessString) .add_property("string", - make_function(&ConstSequenceHandle::GetString, + make_function(&C::GetString, return_value_policy<copy_const_reference>())) - .def("__str__", &ConstSequenceHandle::GetString, + .def("__str__", &C::GetString, return_value_policy<copy_const_reference>()) ; +} - class_<SequenceHandle, bases<ConstSequenceHandle> >("SequenceHandle", init<>()) +} + +void export_sequence() +{ + class_<ConstSequenceHandle> const_seq("ConstSequenceHandle", init<>()); + const_seq_handle_def<ConstSequenceHandle>(const_seq); + const_generic_prop_def<ConstSequenceHandle>(const_seq); + class_<SequenceHandle> seq_handle("SequenceHandle", init<>()); + seq_handle .def("SetSequenceOffset", &SequenceHandle::SetSequenceOffset) .def("AttachView", attach_one) .def("AttachView", attach_two) @@ -201,6 +211,10 @@ void export_sequence() .add_property("sequence_offset", &SequenceHandle::GetSequenceOffset, &SequenceHandle::SetSequenceOffset) ; + const_seq_handle_def<SequenceHandle>(seq_handle); + generic_prop_def<SequenceHandle>(seq_handle); + implicitly_convertible<SequenceHandle, ConstSequenceHandle>(); + def("CreateSequence", &CreateSequence); /*class_<SequenceHandleList>("SequenceHandleList", init<>()) .def(vector_indexing_suite<SequenceHandleList>()) diff --git a/modules/seq/base/src/impl/sequence_impl.hh b/modules/seq/base/src/impl/sequence_impl.hh index 033bf50bf..6ac241970 100644 --- a/modules/seq/base/src/impl/sequence_impl.hh +++ b/modules/seq/base/src/impl/sequence_impl.hh @@ -26,7 +26,7 @@ #include <list> #include <boost/shared_ptr.hpp> - +#include <ost/generic_property.hh> #include <ost/info/info_fw.hh> #include <ost/mol/residue_prop.hh> #include <ost/mol/entity_view.hh> @@ -43,7 +43,7 @@ class SequenceImpl; typedef boost::shared_ptr<SequenceImpl> SequenceImplPtr; /// \internal -class DLLEXPORT_OST_SEQ SequenceImpl { +class DLLEXPORT_OST_SEQ SequenceImpl : public GenericPropertyContainerImpl { public: /// \brief Construct new sequence object from sequence_string. static SequenceImplPtr FromString(const String& seq_name, diff --git a/modules/seq/base/src/sequence_handle.cc b/modules/seq/base/src/sequence_handle.cc index d24fff1ae..60216f9ae 100644 --- a/modules/seq/base/src/sequence_handle.cc +++ b/modules/seq/base/src/sequence_handle.cc @@ -32,7 +32,7 @@ ConstSequenceHandle::ConstSequenceHandle() { } SequenceHandle::SequenceHandle(const impl::SequenceImplPtr& impl): - ConstSequenceHandle(impl) + impl_(impl) { } ConstSequenceHandle::ConstSequenceHandle(const impl::SequenceImplPtr& impl): @@ -75,10 +75,6 @@ SequenceHandle CreateSequence(const String& name, const String& seq) return SequenceHandle(impl::SequenceImpl::FromString(name, seq)); } -SequenceHandle::SequenceHandle(): - ConstSequenceHandle() -{ } - String ConstSequenceHandle::GetGaplessString() const { @@ -175,8 +171,6 @@ void SequenceHandle::SetName(const String& name) return Impl()->SetName(name); } - - void SequenceHandle::SetString(const String& seq) { this->CheckValidity(); @@ -228,4 +222,150 @@ std::ostream& operator<<(std::ostream& os, const ConstSequenceHandle& sequence) return os; } +bool SequenceHandle::operator==(const SequenceHandle& rhs) const +{ + return impl_==rhs.impl_; +} + +bool SequenceHandle::operator!=(const SequenceHandle& rhs) const +{ + return impl_!=rhs.impl_; +} + + +void SequenceHandle::CheckValidity() const +{ + if (!impl_) { + throw InvalidHandle(); + } +} + +bool SequenceHandle::IsValid() const +{ + return impl_.get()!=0; +} + +impl::SequenceImplPtr& SequenceHandle::Impl() const +{ + return impl_; +} + + +SequenceHandle::SequenceHandle(): + impl_() +{ } + + +String SequenceHandle::GetGaplessString() const +{ + this->CheckValidity(); + return Impl()->GetGaplessString(); +} + +int SequenceHandle::GetSequenceOffset() const +{ + this->CheckValidity(); + return Impl()->GetSequenceOffset(); +} + +SequenceHandle::operator ConstSequenceHandle() const +{ + return ConstSequenceHandle(impl_); +} + +int SequenceHandle::GetLength() const +{ + this->CheckValidity(); + return Impl()->GetLength(); +} + + +char SequenceHandle::GetOneLetterCode(int position) const +{ + this->CheckValidity(); + return Impl()->GetOneLetterCode(position); +} + +mol::ResidueView SequenceHandle::GetResidue(int position) const +{ + this->CheckValidity(); + return Impl()->GetResidue(position); +} + +mol::EntityView SequenceHandle::GetAttachedView() const +{ + this->CheckValidity(); + return Impl()->GetAttachedView(); +} + +SequenceHandle SequenceHandle::Copy() const +{ + this->CheckValidity(); + return Impl()->Copy(); +} + +bool SequenceHandle::HasAttachedView() const +{ + this->CheckValidity(); + return Impl()->HasAttachedView(); +} + + +int SequenceHandle::GetResidueIndex(int pos) const +{ + this->CheckValidity(); + return Impl()->GetResidueIndex(pos); +} + +int SequenceHandle::GetPos(int residue_index) const +{ + this->CheckValidity(); + return Impl()->GetPos(residue_index); +} + + +int SequenceHandle::GetFirstNonGap() const +{ + this->CheckValidity(); + return Impl()->GetFirstNonGap(); +} + + +int SequenceHandle::GetLastNonGap() const +{ + this->CheckValidity(); + return Impl()->GetLastNonGap(); +} + +const String& SequenceHandle::GetName() const +{ + this->CheckValidity(); + return Impl()->GetName(); +} + +const String& SequenceHandle::GetString() const +{ + this->CheckValidity(); + return Impl()->GetString(); +} + +GenericPropertyContainerImpl* ConstSequenceHandle::GpImpl() +{ + return Impl().get(); +} + +const GenericPropertyContainerImpl* ConstSequenceHandle::GpImpl() const +{ + return Impl().get(); +} + +GenericPropertyContainerImpl* SequenceHandle::GpImpl() +{ + return Impl().get(); +} + +const GenericPropertyContainerImpl* SequenceHandle::GpImpl() const +{ + return Impl().get(); +} }} diff --git a/modules/seq/base/src/sequence_handle.hh b/modules/seq/base/src/sequence_handle.hh index ba9b2eabe..c76c3298c 100644 --- a/modules/seq/base/src/sequence_handle.hh +++ b/modules/seq/base/src/sequence_handle.hh @@ -24,6 +24,7 @@ */ #include <ost/base.hh> +#include <ost/generic_property.hh> #include <ost/info/info_fw.hh> #include <ost/seq/module_config.hh> @@ -41,8 +42,10 @@ class AlignmentHandle; /// /// The ConstSequenceHandle provides all read-only methods of the /// \ref SequenceHandle "sequence handle". -class DLLEXPORT_OST_SEQ ConstSequenceHandle { +class DLLEXPORT_OST_SEQ ConstSequenceHandle : + public ConstGenericPropertyContainer<ConstSequenceHandle> { public: + friend class ConstGenericPropertyContainer<ConstSequenceHandle>; friend class AlignmentHandle; friend class ConstSequenceList; friend class SequenceList; @@ -116,14 +119,15 @@ public: /// \brief whether the sequence is valid bool IsValid() const; /// \internal +protected: + GenericPropertyContainerImpl* GpImpl(); + + const GenericPropertyContainerImpl* GpImpl() const; public: ConstSequenceHandle(const impl::SequenceImplPtr& impl); impl::SequenceImplPtr& Impl() const; -protected: - void CheckValidity() const; - - private: + void CheckValidity() const; mutable impl::SequenceImplPtr impl_; }; @@ -149,12 +153,80 @@ private: /// /// Sequences IO is dealt with in the sequence module. For more information, /// consult \ref module_seq "this page". -class DLLEXPORT_OST_SEQ SequenceHandle : public ConstSequenceHandle { +class DLLEXPORT_OST_SEQ SequenceHandle : + public GenericPropertyContainer<SequenceHandle> { public: - friend class ConstSequenceHandle; + friend class GenericPropertyContainer<SequenceHandle>; friend class SequenceList; + friend class AlignmentHandle; + friend class ConstSequenceList; + /// \brief Get residue index corresponding to given sequence position + /// \param pos zero-based index + /// \throws out_of_range if pos is not in [0, length-1]. + int GetResidueIndex(int pos) const; + + /// \brief Get zero-based index for given residue number. + /// \throws out_of_range, if number is not included in sequence. + int GetPos(int residue_index) const; + + /// \brief Get position of first non-gap character in sequence + int GetFirstNonGap() const; + + /// \brief Get position of last non-gap character in sequence + int GetLastNonGap() const; + + /// \brief Get name of sequence + /// + /// \sa SequenceHandle::GetName() + const String& GetName() const; + + /// \brief get sequence as a string, including all the gaps + /// + /// \sa GetGaplessString() + const String& GetString() const; + + /// \brief Get sequence as string ignoring gaps + String GetGaplessString() const; + + /// \brief Get sequence offset from N-terminus + /// + /// \sa SequenceHandle::SetSequenceOffset + int GetSequenceOffset() const; + + /// \brief Get lenght of sequence, including gaps. + int GetLength() const; + + /// \brief get one letter code of residue at position + char GetOneLetterCode(int position) const; + + /// \brief get residue at position + /// + /// will return the residue view at the given sequence position or an invalid + /// residue view when no view is attached, the index is out of bounds or the + /// position contains a gap. + mol::ResidueView GetResidue(int position) const; + + /// \brief get attached view. may be an invalid entity view + /// \sa SequenceHandle::AttachView(const mol::EntityView&, const String&) + mol::EntityView GetAttachedView() const; + + /// \brief create copy sequence + /// The newly created sequence has the same attached view. + SequenceHandle Copy() const; + + /// \brief whether the sequence has an attached view + /// + /// \sa SequenceHandle::AttachView(const mol::EntityView&, const String&) + bool HasAttachedView() const; + + bool operator==(const SequenceHandle& rhs) const; + bool operator!=(const SequenceHandle& rhs) const; + + /// \brief whether the sequence is valid + bool IsValid() const; + /// \brief create invalid sequence handle /// /// \sa IsValid() @@ -178,7 +250,7 @@ public: /// \throw IntegrityError when the view contains more than one chain void AttachView(const mol::EntityView& view); - + operator ConstSequenceHandle() const; /// \brief attach entity view to sequence /// /// The sequence is mapped onto the chain with given name @@ -186,6 +258,15 @@ public: /// \internal SequenceHandle(const impl::SequenceImplPtr& impl); + + impl::SequenceImplPtr& Impl() const; + + GenericPropertyContainerImpl* GpImpl(); + + const GenericPropertyContainerImpl* GpImpl() const; +private: + void CheckValidity() const; + mutable impl::SequenceImplPtr impl_; }; SequenceHandle DLLEXPORT_OST_SEQ CreateSequence(const String& name, -- GitLab