OpenStructure
sequence_handle.hh
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // This file is part of the OpenStructure project <www.openstructure.org>
3 //
4 // Copyright (C) 2008-2011 by the OpenStructure authors
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License as published by the Free
8 // Software Foundation; either version 3.0 of the License, or (at your option)
9 // any later version.
10 // This library is distributed in the hope that it will be useful, but WITHOUT
11 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 // FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
13 // details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with this library; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 //------------------------------------------------------------------------------
19 #ifndef OST_SEQ_SEQUENCE_HANDLE_HH
20 #define OST_SEQ_SEQUENCE_HANDLE_HH
21 
22 /*
23  Author: Marco Biasini
24  */
25 
26 #include <ost/base.hh>
27 #include <ost/generic_property.hh>
28 #include <ost/info/info_fw.hh>
29 #include <ost/seq/module_config.hh>
30 
31 #include <ost/mol/residue_view.hh>
32 #include <ost/mol/entity_view.hh>
33 
35 
36 namespace ost { namespace seq {
37 
38 class SequenceHandle;
39 class AlignmentHandle;
40 
46  public ConstGenericPropContainer<ConstSequenceHandle> {
47 public:
49  friend class AlignmentHandle;
50  friend class ConstSequenceList;
51  friend class SequenceList;
52 
53  typedef String::const_iterator iterator;
54 
59 
63  int GetResidueIndex(int pos) const;
64 
67  int GetPos(int residue_index) const;
68 
70  int GetFirstNonGap() const;
71 
73  int GetLastNonGap() const;
74 
78  const String& GetName() const;
79 
83  const String& GetString() const;
84 
86  String GetGaplessString() const;
87 
91  int GetOffset() const;
92 
94  int GetLength() const;
95 
97  char GetOneLetterCode(int position) const;
98 
104  mol::ResidueView GetResidue(int position) const;
105 
108  mol::EntityView GetAttachedView() const;
109 
112  SequenceHandle Copy() const;
113 
117  bool HasAttachedView() const;
118 
119  bool operator==(const ConstSequenceHandle& rhs) const;
120  bool operator!=(const ConstSequenceHandle& rhs) const;
121 
122  char operator[](int index) const;
123 
124  iterator begin() const { return this->GetString().begin(); }
125  iterator end() const { return this->GetString().end(); }
126 
128  bool IsValid() const;
130 protected:
131  GenericPropContainerImpl* GpImpl();
132 
133  const GenericPropContainerImpl* GpImpl() const;
134 public:
136  impl::SequenceImplPtr& Impl() const;
137 private:
138  void CheckValidity() const;
139  mutable impl::SequenceImplPtr impl_;
140 };
141 
155 //
165  public GenericPropContainer<SequenceHandle> {
166 public:
167  typedef String::const_iterator iterator;
169  friend class SequenceList;
170 
171  friend class AlignmentHandle;
172  friend class ConstSequenceList;
173 
177  int GetResidueIndex(int pos) const;
178 
181  int GetPos(int residue_index) const;
182 
184  int GetFirstNonGap() const;
185 
187  int GetLastNonGap() const;
188 
192  const String& GetName() const;
193 
197  const String& GetString() const;
198 
200  String GetGaplessString() const;
201 
205  int GetOffset() const;
206 
208  int GetLength() const;
209 
211  char GetOneLetterCode(int position) const;
212 
218  mol::ResidueView GetResidue(int position) const;
219 
222  mol::EntityView GetAttachedView() const;
223 
226  SequenceHandle Copy() const;
227 
231  bool HasAttachedView() const;
232 
233  bool operator==(const SequenceHandle& rhs) const;
234  bool operator!=(const SequenceHandle& rhs) const;
235 
237  bool IsValid() const;
238 
242  SequenceHandle();
243 
245  void SetName(const String& name);
246 
248  void SetString(const String& seq);
249 
255  void SetOffset(int offset);
256 
260  void AttachView(const mol::EntityView& view);
261 
262  void SetOneLetterCode(int position, char new_char);
263 
264 
265  char operator[](size_t index) const;
266 
267  iterator begin() const { return this->GetString().begin(); }
268  iterator end() const { return this->GetString().end(); }
269 
270  operator ConstSequenceHandle() const;
274  void AttachView(const mol::EntityView& view, const String& chain_name);
275 
278 
279  impl::SequenceImplPtr& Impl() const;
280 
281  GenericPropContainerImpl* GpImpl();
282 
283  const GenericPropContainerImpl* GpImpl() const;
284 private:
285  void CheckValidity() const;
286  mutable impl::SequenceImplPtr impl_;
287 };
288 
289 SequenceHandle DLLEXPORT_OST_SEQ CreateSequence(const String& name,
290  const String& seq);
291 
293 void DLLEXPORT_OST_SEQ SequenceToInfo(const ConstSequenceHandle& sequence,
294  info::InfoGroup& group);
295 
297 SequenceHandle DLLEXPORT_OST_SEQ SequenceFromInfo(info::InfoGroup& group);
298 
299 DLLEXPORT_OST_SEQ std::ostream& operator<<(std::ostream& os,
300  const ConstSequenceHandle& sequence);
301 }}
302 
303 #endif