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-2020 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/config.hh>
29 #if(OST_INFO_ENABLED)
30 #include <ost/info/info_fw.hh>
31 #endif
32 #include <ost/seq/module_config.hh>
33 
34 #include <ost/mol/residue_view.hh>
35 #include <ost/mol/entity_view.hh>
36 
38 
39 namespace ost { namespace seq {
40 
41 class SequenceHandle;
42 class AlignmentHandle;
43 
49  public ConstGenericPropContainer<ConstSequenceHandle> {
50 public:
52  friend class AlignmentHandle;
53  friend class ConstSequenceList;
54  friend class SequenceList;
55 
56  typedef String::const_iterator iterator;
57 
62 
66  int GetResidueIndex(int pos) const;
67 
70  int GetPos(int residue_index) const;
71 
73  int GetFirstNonGap() const;
74 
76  int GetLastNonGap() const;
77 
81  const String& GetName() const;
82 
86  const String& GetString() const;
87 
90 
94  int GetOffset() const;
95 
97  int GetLength() const;
98 
100  int GetIndex(const String& substr) const;
101 
103  char GetOneLetterCode(int position) const;
104 
110  mol::ResidueView GetResidue(int position) const;
111 
115 
119 
123  bool HasAttachedView() const;
124 
125  const String& GetRole() const;
126 
127  bool operator==(const ConstSequenceHandle& rhs) const;
128  bool operator!=(const ConstSequenceHandle& rhs) const;
129 
130  char operator[](int index) const;
131 
132  iterator begin() const { return this->GetString().begin(); }
133  iterator end() const { return this->GetString().end(); }
134 
136  bool IsValid() const;
138 protected:
140 
142 public:
145 private:
146  void CheckValidity() const;
147  mutable impl::SequenceImplPtr impl_;
148 };
149 
163 //
173  public GenericPropContainer<SequenceHandle> {
174 public:
175  typedef String::const_iterator iterator;
176  friend class GenericPropContainer<SequenceHandle>;
177  friend class SequenceList;
178 
179  friend class AlignmentHandle;
180  friend class ConstSequenceList;
181 
185  int GetResidueIndex(int pos) const;
186 
189  int GetPos(int residue_index) const;
190 
192  int GetFirstNonGap() const;
193 
195  int GetLastNonGap() const;
196 
200  const String& GetName() const;
201 
205  const String& GetString() const;
206 
209 
213  int GetOffset() const;
214 
216  int GetLength() const;
217 
219  char GetOneLetterCode(int position) const;
220 
222  int GetIndex(const String& substr) const;
223 
229  mol::ResidueView GetResidue(int position) const;
230 
234 
237  void Normalise();
238 
242 
246  bool HasAttachedView() const;
247 
248  bool operator==(const SequenceHandle& rhs) const;
249  bool operator!=(const SequenceHandle& rhs) const;
250 
252  bool IsValid() const;
253 
258 
260  void SetName(const String& name);
261 
263  void SetString(const String& seq);
264 
270  void SetOffset(int offset);
271 
275  void AttachView(const mol::EntityView& view);
276 
277  void SetOneLetterCode(int position, char new_char);
278 
279  char operator[](size_t index) const;
280 
281  iterator begin() const { return this->GetString().begin(); }
282  iterator end() const { return this->GetString().end(); }
283 
284  void Append(char olc);
285 
286  operator ConstSequenceHandle() const;
290  void AttachView(const mol::EntityView& view, const String& chain_name);
291 
294 
295  const String& GetRole() const;
296 
297  void SetRole(const String& role) const;
298 
300 
302 
304 private:
305  void CheckValidity() const;
306  mutable impl::SequenceImplPtr impl_;
307 };
308 
310  const String& seq,
311  const String& role="UNKNOWN");
312 #if(OST_INFO_ENABLED)
314 void DLLEXPORT_OST_SEQ SequenceToInfo(const ConstSequenceHandle& sequence,
315  info::InfoGroup& group);
316 
318 SequenceHandle DLLEXPORT_OST_SEQ SequenceFromInfo(info::InfoGroup& group);
319 #endif
320 
321 
322 DLLEXPORT_OST_SEQ std::ostream& operator<<(std::ostream& os,
323  const ConstSequenceHandle& sequence);
324 
326  const ConstSequenceHandle& s2);
327 
329  const String& s2);
330 }}
331 
332 #endif
base class for the handler classes
base class for the implementation
definition of EntityView
Definition: entity_view.hh:86
representation of a multiple sequence alignemnt consisting of two or more sequences
int GetIndex(const String &substr) const
get index of substring
SequenceHandle Copy() const
create copy sequence The newly created sequence has the same attached view.
char operator[](int index) const
String::const_iterator iterator
int GetFirstNonGap() const
Get position of first non-gap character in sequence.
int GetOffset() const
Get sequence offset from N-terminus.
bool HasAttachedView() const
whether the sequence has an attached view
bool operator!=(const ConstSequenceHandle &rhs) const
ConstSequenceHandle(const impl::SequenceImplPtr &impl)
int GetLastNonGap() const
Get position of last non-gap character in sequence.
impl::SequenceImplPtr & Impl() const
int GetLength() const
Get lenght of sequence, including gaps.
int GetPos(int residue_index) const
Get zero-based index for given residue number.
GenericPropContainerImpl * GpImpl()
ConstSequenceHandle()
create invalid sequence handle
mol::EntityView GetAttachedView() const
get attached view. may be an invalid entity view
bool operator==(const ConstSequenceHandle &rhs) const
bool IsValid() const
whether the sequence is valid
const GenericPropContainerImpl * GpImpl() const
int GetResidueIndex(int pos) const
Get residue index corresponding to given sequence position.
const String & GetString() const
get sequence as a string, including all the gaps
const String & GetName() const
Get name of sequence.
const String & GetRole() const
char GetOneLetterCode(int position) const
get one letter code of residue at position
String GetGaplessString() const
Get sequence as string ignoring gaps.
mol::ResidueView GetResidue(int position) const
get residue at position
list of immutable sequences.
mutable sequence handle.
int GetIndex(const String &substr) const
get index of substring
SequenceHandle Copy() const
create copy sequence The newly created sequence has the same attached view.
bool operator==(const SequenceHandle &rhs) const
void SetString(const String &seq)
Set sequence String.
String::const_iterator iterator
int GetFirstNonGap() const
Get position of first non-gap character in sequence.
int GetOffset() const
Get sequence offset from N-terminus.
bool HasAttachedView() const
whether the sequence has an attached view
char operator[](size_t index) const
SequenceHandle()
create invalid sequence handle
bool operator!=(const SequenceHandle &rhs) const
int GetLastNonGap() const
Get position of last non-gap character in sequence.
impl::SequenceImplPtr & Impl() const
int GetLength() const
Get lenght of sequence, including gaps.
void SetRole(const String &role) const
SequenceHandle(const impl::SequenceImplPtr &impl)
int GetPos(int residue_index) const
Get zero-based index for given residue number.
void SetOneLetterCode(int position, char new_char)
GenericPropContainerImpl * GpImpl()
void Normalise()
remove '.', '-' as gaps and make sequence all-uppercase Changes happen in place.
mol::EntityView GetAttachedView() const
get attached view. may be an invalid entity view
bool IsValid() const
whether the sequence is valid
const GenericPropContainerImpl * GpImpl() const
void SetName(const String &name)
set name of sequence
void AttachView(const mol::EntityView &view)
attach entity view to sequence
int GetResidueIndex(int pos) const
Get residue index corresponding to given sequence position.
void SetOffset(int offset)
Set sequence offset.
const String & GetString() const
get sequence as a string, including all the gaps
const String & GetName() const
Get name of sequence.
void AttachView(const mol::EntityView &view, const String &chain_name)
attach entity view to sequence
const String & GetRole() const
char GetOneLetterCode(int position) const
get one letter code of residue at position
String GetGaplessString() const
Get sequence as string ignoring gaps.
mol::ResidueView GetResidue(int position) const
get residue at position
list of sequences.
std::string String
Definition: base.hh:54
boost::shared_ptr< SequenceImpl > SequenceImplPtr
SequenceHandle DLLEXPORT_OST_SEQ CreateSequence(const String &name, const String &seq, const String &role="UNKNOWN")
bool DLLEXPORT_OST_SEQ Match(const ConstSequenceHandle &s1, const ConstSequenceHandle &s2)
DLLEXPORT_OST_SEQ std::ostream & operator<<(std::ostream &os, const AlignedColumn &col)
Definition: base.dox:1
#define DLLEXPORT_OST_SEQ