OpenStructure
sequence_impl.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_SEQUENCE_HH
20 #define OST_SEQUENCE_HH
21 
22 /*
23  Author: Marco Biasini
24  */
25 #include <ost/message.hh>
26 #include <list>
27 
28 #include <boost/shared_ptr.hpp>
29 #include <ost/generic_property.hh>
30 #include <ost/config.hh>
31 #if(OST_INFO_ENABLED)
32 #include <ost/info/info_fw.hh>
33 #endif
34 #include <ost/mol/residue_prop.hh>
35 #include <ost/mol/entity_view.hh>
36 #include <ost/mol/residue_view.hh>
37 
38 #include <ost/seq/module_config.hh>
40 namespace ost { namespace seq { namespace impl {
41 
43 class SequenceImpl;
44 
46 typedef boost::shared_ptr<SequenceImpl> SequenceImplPtr;
47 
50 public:
52  static SequenceImplPtr FromString(const String& seq_name,
53  const String& sequence_string,
54  const String& role="UNKNOWN");
55 
59  int GetResidueIndex(int pos) const;
60 
63  int GetPos(int residue_index) const;
64 
66  int GetFirstNonGap() const;
67 
69  int GetLastNonGap() const;
70 
71  const String& GetName() const;
72 
73  void SetName(const String& name);
74 
75  void Cut(int start, int n);
76 
77  void ShiftRegion(int start, int end, int amount);
78  const String& GetString() const {
79  return seq_string_;
80  }
82  void SetString(const String& seq);
83 
85  void Normalise();
86 
88  void Replace(const String& str,int start, int end);
89 
92 
96  int GetOffset() const;
97 
98  int GetIndex(const String& substr) const;
104  void SetOffset(int offset);
105 
107  int GetLength() const;
112  SequenceImpl(const String& seq_name, const String& sequence_string,
113  const String& role);
114 
116  char GetOneLetterCode(int position) const;
117 
118  void SetOneLetterCode(int position, char new_char);
124  mol::ResidueView GetResidue(int position) const;
125 
128 
132  void AttachView(const mol::EntityView& view);
133 
141  void AttachView(const mol::EntityView& view, const String& chain_name);
142 
144  bool HasAttachedView() const;
145 
146  void Append(char olc);
147 
148  char& operator[](size_t index)
149  {
150  return seq_string_[index];
151  }
152  char operator[](size_t index) const
153  {
154  return seq_string_[index];
155  }
156  const String& GetRole() const
157  {
158  return seq_role_;
159  }
160 
161  void SetRole(const String& role)
162  {
163  seq_role_=role;
164  }
165 private:
166 
172  void ShiftsFromSequence();
173 
174 
175  int GetPosNoBounds(int index) const;
176 
177  static bool IsSequenceStringSane(const String& seq_string);
178 
179  typedef struct {
180  int start;
181  int shift;
182  } Shift;
183  String seq_name_;
184  String seq_string_;
185  String seq_role_;
186  std::list<Shift> shifts_;
187  bool editing_;
188  int offset_;
189  mol::EntityView attached_view_;
190 };
191 
193 typedef std::vector<SequenceImplPtr> SequenceList;
194 
195 #if(OST_INFO_ENABLED)
197 SequenceImplPtr DLLEXPORT_OST_SEQ SequenceImplFromInfo(const info::InfoGroup& group);
198 
200 void DLLEXPORT_OST_SEQ SequenceImplToInfo(const SequenceImplPtr& sequence,
201  info::InfoGroup& group);
202 #endif
203 
204 
205 }}} //ns
206 #endif
207 
base class for the implementation
definition of EntityView
Definition: entity_view.hh:86
void ShiftRegion(int start, int end, int amount)
int GetIndex(const String &substr) const
void SetRole(const String &role)
void SetString(const String &seq)
Set sequence String.
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
SequenceImplPtr Copy() const
create copy sequence
int GetLastNonGap() const
Get position of last non-gap character in sequence.
SequenceImpl(const String &seq_name, const String &sequence_string, const String &role)
Construct new sequence object from sequence_string.
void Replace(const String &str, int start, int end)
replace substring starting from start to end
static SequenceImplPtr FromString(const String &seq_name, const String &sequence_string, const String &role="UNKNOWN")
Construct new sequence object from sequence_string.
char & operator[](size_t index)
int GetLength() const
Get lenght of sequence, including gaps.
int GetPos(int residue_index) const
Get zero-based index for given residue number.
void SetOneLetterCode(int position, char new_char)
void Normalise()
Remove everything 'unusual' from sequence.
mol::EntityView GetAttachedView() const
get attached view. may be an invalid entity view
void SetName(const String &name)
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.
void Cut(int start, int n)
const String & GetString() const
const String & GetName() const
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
std::string String
Definition: base.hh:54
ImageStateConstModOPAlgorithm< ShiftFnc > Shift
Definition: alg_shift.hh:73
pointer_it< T > end(const std::vector< T > &values)
std::vector< SequenceImplPtr > SequenceList
boost::shared_ptr< SequenceImpl > SequenceImplPtr
Definition: base.dox:1
#define DLLEXPORT_OST_SEQ