Victor
 All Data Structures Functions Variables Friends Pages
LoopTable.h
1 /* This file is part of Victor.
2 
3  Victor is free software: you can redistribute it and/or modify
4  it under the terms of the GNU General Public License as published by
5  the Free Software Foundation, either version 3 of the License, or
6  (at your option) any later version.
7 
8  Victor is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  GNU General Public License for more details.
12 
13  You should have received a copy of the GNU General Public License
14  along with Victor. If not, see <http://www.gnu.org/licenses/>.
15  */
16 
17 
18 #ifndef _LOOPTABLE_H_
19 #define _LOOPTABLE_H_
20 
21 // Includes:
22 #include <string>
23 #include <vector3.h>
24 #include <matrix3.h>
25 #include <Debug.h>
26 #include <RamachandranData.h>
27 #include <LoopTableEntry.h>
28 #include <queue>
29 
30 namespace Victor { namespace Lobo {
31 
32  // Global constants, typedefs, etc. (to avoid):
33 
38  double dev;
39  unsigned int index1, index2;
40 
41  bool operator<(const solutionQueueElem& _sqe) const {
42  return (_sqe.dev < dev);
43  }
44  };
45 
51  class LoopTable {
52  public:
53 
54  // CONSTRUCTORS/DESTRUCTOR:
55  LoopTable();
56  LoopTable(const LoopTable& orig);
57  virtual ~LoopTable();
58 
59  // PREDICATES:
63  virtual unsigned int size();
64  unsigned int getLength();
65  unsigned int getMaxBins();
66  void showDistribution();
67  virtual LoopTableEntry getClosest(const LoopTableEntry& le,
68  unsigned int currentSelection = 1);
69  virtual vector<LoopTableEntry> getNClosest(const LoopTableEntry& le,
70  unsigned int num, unsigned int nAmino);
71 
72  // MODIFIERS:
73  void setRama(RamachandranData* r);
74  void setLength(unsigned int l);
75 
76  void copy(const LoopTable& orig);
77 
78  // initializes the table for nAminoAcid = 1
79  void setToSingleAminoAcid();
80 
81  // concatenates two tables
82  void concatenate(LoopTable&, LoopTable&, unsigned long, unsigned long);
83 
84 
85  virtual void adjustTable();
86  virtual void read(const string&);
87  virtual void cluster(double cutoff);
88  virtual void write(const string&);
89  void writeASCII(const string&, unsigned long num = 0,
90  unsigned int wEntry = 0, unsigned int wDim = 0);
91 
92  // OPERATORS:
93  LoopTable& operator=(const LoopTable& orig);
94  virtual LoopTableEntry& operator[](unsigned int n);
95  virtual const LoopTableEntry& operator[](unsigned int n) const;
96 
97 
98  // TESTERS:
99  void printTable(unsigned int);
100 
101  static unsigned int MAX_FACTOR;
102 
103  protected:
104 
105  // HELPERS:
106  double pEstimateSimilarityCutoff(const LoopTableEntry& le,
107  unsigned int num);
108 
109  virtual void store(const LoopTableEntry&);
110  void pInsertElem(LoopTableEntry& elem,
111  vector<vector<LoopTableEntry> >& table);
112  unsigned int pGetBin(const vgVector3<float>& e);
113  void pAddToSolutionQueue(unsigned int offset,
114  priority_queue<solutionQueueElem>& solutionQueue,
115  const LoopTableEntry& dest);
116 
117  //methods used to concatenate two tables:
118  void initOccurrence(const unsigned long);
120 
121  //methods used to compress and uncompress a table:
122  unsigned short code(const double, const double, const double);
123  double decode(const unsigned short, const double, const double);
124 
125 
126  private:
127 
128  // ATTRIBUTES:
129  RamachandranData* rama;
130 
131  // number of amino acids represented by this table, ie. chain segment length
132  unsigned int nAminoAcid;
133 
134 
135  // table of (sorted) bins containing the chain information
136  vector<vector<LoopTableEntry> > entry;
137 
138 
139  double lowerLimit; // information about the lower and
140  double upperLimit; // upper bin limits
141  double stepLimit; // bin step size
142 
143  LoopTableEntry max, min; // min and max values for each coordinate
144 
145  // constant expression required for selectOccurrence:
146  vgVector3<float> psiNormal;
147 
148  unsigned long nextIndex; // data required for SuS selection of
149  unsigned long stepWidth; // next occurrence
150 
151  static unsigned int MAX_BINS;
152  static double BOND_ANGLE_AT_CPRIME_TO_N;
153  static double BOND_LENGTH_N_TO_CALPHA;
154  static double BOND_ANGLE_AT_N_TO_CALPHA;
155 
156  };
157 
158  void printTable(LoopTable&, int num = -1);
159 
160  // ---------------------------------------------------------------------------
161  // LoopTable
162  // -----------------x-------------------x-------------------x-----------------
163 
164 
165  // PREDICATES:
166 
173  return min;
174  }
175 
182  return max;
183  }
184 
191  return rama;
192  }
193 
199  inline unsigned int LoopTable::size() {
200  unsigned int count = 0;
201  for (unsigned int i = 0; i < entry.size(); i++)
202  count += entry[i].size();
203  return count;
204  }
205 
211  inline unsigned int LoopTable::getLength() {
212  return nAminoAcid;
213  }
214 
220  inline unsigned int LoopTable::getMaxBins() {
221  return MAX_BINS;
222  }
223 
224  // MODIFIERS:
225 
232  rama = r;
233  }
234 
240  inline void LoopTable::setLength(unsigned int l) {
241  nAminoAcid = l;
242  }
243 
244 
245  // OPERATORS:
251  inline LoopTableEntry& LoopTable::operator[](unsigned int n) {
252 
253  unsigned int count = MAX_BINS + 1;
254  for (unsigned int i = 0; i < entry.size(); i++) {
255  if (n >= entry[i].size())
256  n -= entry[i].size();
257  else {
258  count = i;
259  break;
260  }
261  }
262 
263  if ((count >= MAX_BINS + 1) || (entry.size() == 0))
264  ERROR("LoopTable::operator[] : Argument out of scope.", exception);
265 
266  return entry[count][n];
267  }
273  inline const LoopTableEntry& LoopTable::operator[](unsigned int n) const {
274  unsigned int count = MAX_BINS + 1;
275  for (unsigned int i = 0; i < entry.size(); i++) {
276  if (n >= entry[i].size())
277  n -= entry[i].size();
278  else {
279  count = i;
280  break;
281  }
282  }
283  if ((count >= MAX_BINS + 1) || (entry.size() == 0))
284  ERROR("LoopTable::operator[] : Argument out of scope.", exception);
285  return entry[count][n];
286  }
287 
288 
289  // HELPERS:
290 
296  inline void LoopTable::pInsertElem(LoopTableEntry& elem, vector<vector<LoopTableEntry> >& table) {
297  unsigned int numBin = pGetBin(elem.endPoint);
298  if (numBin >= MAX_BINS)
299  ERROR("LoopTable::pInsertElem : element out of scope.", exception);
300 
301  table[numBin].push_back(elem);
302  }
303 
309  inline unsigned int LoopTable::pGetBin(const vgVector3<float>& e) {
310  double dist = sqrt(sqr(e.x) + sqr(e.y) + sqr(e.z));
311  if (dist < lowerLimit)
312  return 0;
313  if (dist >= upperLimit)
314  return MAX_BINS - 1;
315 
316  return static_cast<unsigned int> ((dist - lowerLimit) / stepLimit);
317  }
318 
325  inline void LoopTable::pAddToSolutionQueue(unsigned int offset,
326  priority_queue<solutionQueueElem>& solutionQueue, const LoopTableEntry& dest) {
327  solutionQueueElem sqe;
328  for (unsigned int i = 0; i < entry[offset].size(); i++) {
329  sqe.dev = entry[offset][i].calculateDeviation(dest, nAminoAcid);
330  sqe.index1 = offset;
331  sqe.index2 = i;
332  solutionQueue.push(sqe);
333  }
334  }
335 
336 }} // namespace
337 
338 #endif //_LOOPTABLE_H_
339 
340 
void writeASCII(const string &, unsigned long num=0, unsigned int wEntry=0, unsigned int wDim=0)
Definition: LoopTable.cc:455
virtual LoopTableEntry & operator[](unsigned int n)
Definition: LoopTable.h:251
void pAddToSolutionQueue(unsigned int offset, priority_queue< solutionQueueElem > &solutionQueue, const LoopTableEntry &dest)
Definition: LoopTable.h:325
LoopTableEntry getMin()
Definition: LoopTable.h:172
Struct that contains a queue element.
Definition: LoopTable.h:37
void concatenate(LoopTable &, LoopTable &, unsigned long, unsigned long)
Definition: LoopTable.cc:245
LoopTable()
Definition: LoopTable.cc:61
void setToSingleAminoAcid()
Definition: LoopTable.cc:230
Defines a table of possible amino chain end points and end directions after k amino acids have been c...
Definition: LoopTable.h:51
void showDistribution()
Definition: LoopTable.cc:101
unsigned short code(const double, const double, const double)
Definition: LoopTable.cc:620
double decode(const unsigned short, const double, const double)
Definition: LoopTable.cc:641
LoopTable & operator=(const LoopTable &orig)
Definition: LoopTable.cc:497
void setRama(RamachandranData *r)
Definition: LoopTable.h:231
unsigned int pGetBin(const vgVector3< float > &e)
Definition: LoopTable.h:309
double pEstimateSimilarityCutoff(const LoopTableEntry &le, unsigned int num)
Definition: LoopTable.cc:511
RamachandranData * getRama()
Definition: LoopTable.h:190
void initOccurrence(const unsigned long)
Definition: LoopTable.cc:559
void pInsertElem(LoopTableEntry &elem, vector< vector< LoopTableEntry > > &table)
Definition: LoopTable.h:296
LoopTableEntry getMax()
Definition: LoopTable.h:181
virtual vector< LoopTableEntry > getNClosest(const LoopTableEntry &le, unsigned int num, unsigned int nAmino)
Definition: LoopTable.cc:147
virtual ~LoopTable()
Definition: LoopTable.cc:90
Implements an entry for the loop table (equivalent to the old "ProteinTableEntry" from the previous v...
Definition: LoopTableEntry.h:41
virtual void cluster(double cutoff)
Definition: LoopTable.cc:366
virtual unsigned int size()
Definition: LoopTable.h:199
virtual LoopTableEntry getClosest(const LoopTableEntry &le, unsigned int currentSelection=1)
Definition: LoopTable.cc:116
virtual void store(const LoopTableEntry &)
Definition: LoopTable.cc:533
unsigned int getMaxBins()
Definition: LoopTable.h:220
void copy(const LoopTable &orig)
Definition: LoopTable.cc:203
This struct implements the container for ramachandran plot-like phi/psi angle combinations for the Lo...
Definition: RamachandranData.h:42
LoopTableEntry selectOccurrence()
Definition: LoopTable.cc:575
unsigned int getLength()
Definition: LoopTable.h:211
virtual void write(const string &)
Definition: LoopTable.cc:406
virtual void adjustTable()
Definition: LoopTable.cc:274
void setLength(unsigned int l)
Definition: LoopTable.h:240
virtual void read(const string &)
Definition: LoopTable.cc:295
void printTable(unsigned int)
Definition: LoopTable.cc:657