00001 //------------------------------------------------------------------------------ 00002 // This file is part of the OpenStructure project <www.openstructure.org> 00003 // 00004 // Copyright (C) 2008-2011 by the OpenStructure authors 00005 // 00006 // This library is free software; you can redistribute it and/or modify it under 00007 // the terms of the GNU Lesser General Public License as published by the Free 00008 // Software Foundation; either version 3.0 of the License, or (at your option) 00009 // any later version. 00010 // This library is distributed in the hope that it will be useful, but WITHOUT 00011 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 00012 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 00013 // details. 00014 // 00015 // You should have received a copy of the GNU Lesser General Public License 00016 // along with this library; if not, write to the Free Software Foundation, Inc., 00017 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00018 //------------------------------------------------------------------------------ 00019 #ifndef OST_SEQ_SEQUENCE_HANDLE_HH 00020 #define OST_SEQ_SEQUENCE_HANDLE_HH 00021 00022 /* 00023 Author: Marco Biasini 00024 */ 00025 00026 #include <ost/base.hh> 00027 #include <ost/generic_property.hh> 00028 #include <ost/config.hh> 00029 #if(OST_INFO_ENABLED) 00030 #include <ost/info/info_fw.hh> 00031 #endif 00032 #include <ost/seq/module_config.hh> 00033 00034 #include <ost/mol/residue_view.hh> 00035 #include <ost/mol/entity_view.hh> 00036 00037 #include <ost/seq/impl/sequence_impl_fw.hh> 00038 00039 namespace ost { namespace seq { 00040 00041 class SequenceHandle; 00042 class AlignmentHandle; 00043 00048 class DLLEXPORT_OST_SEQ ConstSequenceHandle : 00049 public ConstGenericPropContainer<ConstSequenceHandle> { 00050 public: 00051 friend class ConstGenericPropContainer<ConstSequenceHandle>; 00052 friend class AlignmentHandle; 00053 friend class ConstSequenceList; 00054 friend class SequenceList; 00055 00056 typedef String::const_iterator iterator; 00057 00061 ConstSequenceHandle(); 00062 00066 int GetResidueIndex(int pos) const; 00067 00070 int GetPos(int residue_index) const; 00071 00073 int GetFirstNonGap() const; 00074 00076 int GetLastNonGap() const; 00077 00081 const String& GetName() const; 00082 00086 const String& GetString() const; 00087 00089 String GetGaplessString() const; 00090 00094 int GetOffset() const; 00095 00097 int GetLength() const; 00098 00100 int GetIndex(const String& substr) const; 00101 00103 char GetOneLetterCode(int position) const; 00104 00110 mol::ResidueView GetResidue(int position) const; 00111 00114 mol::EntityView GetAttachedView() const; 00115 00118 SequenceHandle Copy() const; 00119 00123 bool HasAttachedView() const; 00124 00125 const String& GetRole() const; 00126 00127 bool operator==(const ConstSequenceHandle& rhs) const; 00128 bool operator!=(const ConstSequenceHandle& rhs) const; 00129 00130 char operator[](int index) const; 00131 00132 iterator begin() const { return this->GetString().begin(); } 00133 iterator end() const { return this->GetString().end(); } 00134 00136 bool IsValid() const; 00138 protected: 00139 GenericPropContainerImpl* GpImpl(); 00140 00141 const GenericPropContainerImpl* GpImpl() const; 00142 public: 00143 ConstSequenceHandle(const impl::SequenceImplPtr& impl); 00144 impl::SequenceImplPtr& Impl() const; 00145 private: 00146 void CheckValidity() const; 00147 mutable impl::SequenceImplPtr impl_; 00148 }; 00149 00163 // 00172 class DLLEXPORT_OST_SEQ SequenceHandle : 00173 public GenericPropContainer<SequenceHandle> { 00174 public: 00175 typedef String::const_iterator iterator; 00176 friend class GenericPropContainer<SequenceHandle>; 00177 friend class SequenceList; 00178 00179 friend class AlignmentHandle; 00180 friend class ConstSequenceList; 00181 00185 int GetResidueIndex(int pos) const; 00186 00189 int GetPos(int residue_index) const; 00190 00192 int GetFirstNonGap() const; 00193 00195 int GetLastNonGap() const; 00196 00200 const String& GetName() const; 00201 00205 const String& GetString() const; 00206 00208 String GetGaplessString() const; 00209 00213 int GetOffset() const; 00214 00216 int GetLength() const; 00217 00219 char GetOneLetterCode(int position) const; 00220 00222 int GetIndex(const String& substr) const; 00223 00229 mol::ResidueView GetResidue(int position) const; 00230 00233 mol::EntityView GetAttachedView() const; 00234 00237 void Normalise(); 00238 00241 SequenceHandle Copy() const; 00242 00246 bool HasAttachedView() const; 00247 00248 bool operator==(const SequenceHandle& rhs) const; 00249 bool operator!=(const SequenceHandle& rhs) const; 00250 00252 bool IsValid() const; 00253 00257 SequenceHandle(); 00258 00260 void SetName(const String& name); 00261 00263 void SetString(const String& seq); 00264 00270 void SetOffset(int offset); 00271 00275 void AttachView(const mol::EntityView& view); 00276 00277 void SetOneLetterCode(int position, char new_char); 00278 00279 char operator[](size_t index) const; 00280 00281 iterator begin() const { return this->GetString().begin(); } 00282 iterator end() const { return this->GetString().end(); } 00283 00284 void Append(char olc); 00285 00286 operator ConstSequenceHandle() const; 00290 void AttachView(const mol::EntityView& view, const String& chain_name); 00291 00293 SequenceHandle(const impl::SequenceImplPtr& impl); 00294 00295 const String& GetRole() const; 00296 00297 void SetRole(const String& role) const; 00298 00299 impl::SequenceImplPtr& Impl() const; 00300 00301 GenericPropContainerImpl* GpImpl(); 00302 00303 const GenericPropContainerImpl* GpImpl() const; 00304 private: 00305 void CheckValidity() const; 00306 mutable impl::SequenceImplPtr impl_; 00307 }; 00308 00309 SequenceHandle DLLEXPORT_OST_SEQ CreateSequence(const String& name, 00310 const String& seq, 00311 const String& role="UNKNOWN"); 00312 #if(OST_INFO_ENABLED) 00314 void DLLEXPORT_OST_SEQ SequenceToInfo(const ConstSequenceHandle& sequence, 00315 info::InfoGroup& group); 00316 00318 SequenceHandle DLLEXPORT_OST_SEQ SequenceFromInfo(info::InfoGroup& group); 00319 #endif 00320 00321 00322 DLLEXPORT_OST_SEQ std::ostream& operator<<(std::ostream& os, 00323 const ConstSequenceHandle& sequence); 00324 00325 bool DLLEXPORT_OST_SEQ Match(const ConstSequenceHandle& s1, 00326 const ConstSequenceHandle& s2); 00327 00328 bool DLLEXPORT_OST_SEQ Match(const String& s1, 00329 const String& s2); 00330 }} 00331 00332 #endif