NCBI C++ ToolKit
sls_alp.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: sls_alp.hpp 44808 2010-02-18 16:10:58Z boratyng $
2 * ===========================================================================
3 *
4 * PUBLIC DOMAIN NOTICE
5 * National Center for Biotechnology Information
6 *
7 * This software/database is a "United States Government Work" under the
8 * terms of the United States Copyright Act. It was written as part of
9 * the author's offical duties as a United States Government employee and
10 * thus cannot be copyrighted. This software/database is freely available
11 * to the public for use. The National Library of Medicine and the U.S.
12 * Government have not placed any restriction on its use or reproduction.
13 *
14 * Although all reasonable efforts have been taken to ensure the accuracy
15 * and reliability of the software and data, the NLM and the U.S.
16 * Government do not and cannot warrant the performance or results that
17 * may be obtained by using this software or data. The NLM and the U.S.
18 * Government disclaim all warranties, express or implied, including
19 * warranties of performance, merchantability or fitness for any particular
20 * purpose.
21 *
22 * Please cite the author in any work or product based on this material.
23 *
24 * ===========================================================================*/
25 
26 /*****************************************************************************
27 
28 File name: sls_alp.hpp
29 
30 Author: Sergey Sheetlin
31 
32 Contents: Ascending ladder points simulation
33 
34 ******************************************************************************/
35 
36 #ifndef ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_SLS_ALP
37 #define ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_SLS_ALP
38 
39 #include <complex>
40 #include <iostream>
41 #include <map>
42 #include <vector>
43 #include <fstream>
44 #include <float.h>
45 
46 #include <corelib/ncbistl.hpp>
47 
48 #include "sls_alp_data.hpp"
49 #include "sls_alp_regression.hpp"
50 
51 
53 BEGIN_SCOPE(blast)
54 
55 BEGIN_SCOPE(Sls)
56 
57  const double DBL_MAX1=DBL_MAX/10.0;
58 
59  class state//struct to save a state of calculation
60  {
61  public:
62  state();
63 
64  public:
66 
71 
76 
81 
83 
85 
88 
89  };
90 
91 
92  class alp{
93 
94 
95 
96  public:
97 
98 
99  alp(//constructor
100  alp_data *alp_data_
101  );
102 
103 
104  ~alp();//destructor
105 
106  Int4 random_AA1();//generates random AA for the sequence 1
107  Int4 random_AA2();//generates random AA for the sequence 2
108 
110  Int4 d_dim1_,
111  Int4 d_dim2_);
112 
113  void increment_sequences();
114 
115  void increment_W_matrix();
116  void increment_H_matrix();
117 
118  void increment_W_weights();
119  //the function calculates weigths for d_W_matr_len increased by 1
120  //assumes that letters are defined for d_W_matr_len
121 
122  void increment_H_weights();
123  //the function calculates alignment scores for d_H_matr_len increased by 1
124  //assumes that letters are defined for d_H_matr_len
125 
127  Int4 diff_opt_);
128  //the function calculates alignment scores for d_H_matr_len increased by 1
129  //assumes that letters are defined for d_H_matr_len
130  //uses sentinels
131 
132 
133  void simulate_next_alp();//simulates next ALP
134 
135  void simulate_alp_upto_the_given_number(//simulates ALP upto the given number nalp_ including
136  Int4 nalp_);
137 
138  void simulate_alp_upto_the_given_level(//simulates ALP upto the given level M_min_ including
139  Int4 M_min_);
140 
141 
142 
143 
144  template<typename T>
145  inline void swap(
146  T& a1_,
147  T& a2_)
148  {
149  T tmp=a1_;
150  a1_=a2_;
151  a2_=tmp;
152  };
153 
154  static double degree(//returns x_^n_
155  double x_,
156  double n_);
157 
158 
160  Int4 length_);//calculation of weigths for the importance sampling
161 
162  void save_state(
163  state * &state_);
164 
165  void restore_state(
166  Int4 nalp_,
167  state * &state_);
168 
169  void kill_upto_level(
170  Int4 M_min_,
171  Int4 M_level_);
172 
173  void check_time_function(
174  Int4 ff_=0);
175 
176  template<typename T>
178  T *&pointer_,
179  Int4 dim_)
180  {
181  if(pointer_==NULL)
182  {
183  return;
184  };
185  delete[]pointer_;pointer_=NULL;
186  if(d_alp_data)
187  {
188  d_alp_data->d_memory_size_in_MB-=(double)(sizeof(T)*dim_)/mb_bytes;
189  };
190 
191  };
192 
193 
194  template<typename T>
196  T *&pointer_)
197  {
198  if(pointer_==NULL)
199  {
200  return;
201  };
202  delete pointer_;pointer_=NULL;
203  if(d_alp_data)
204  {
205  d_alp_data->d_memory_size_in_MB-=(double)(sizeof(T))/mb_bytes;
206  };
207 
208  };
209 
211 
212 
213 
214 
215 
216 
217 
218  public:
219 
220 
221 
222  alp_data *d_alp_data;//initial data
223  Int4 d_a_step;//increment for sequence length during memory allocation
224 
225 
226  bool d_is_now;//true if the importance sampling is being used
227 
228 
229 
230 
231 
232  //alignment data
233 
234  Int4 d_seqi_len;//current length of sequence 1
235  Int4 d_seqj_len;//current length of sequence 2
236 
237 
238  Int4 d_seq_a_len;//current length for memory allocation for the sequences
239  Int4 d_H_matr_a_len;//current length for memory allocation for the matrices H
240  Int4 d_W_matr_a_len;//current length for memory allocation for the matrices W
241 
242  Int4 *d_seqi;//AA from sequence 1 for the next step
243  Int4 *d_seqj;//AA from sequence 2 for the next step
244 
245  Int4 d_H_matr_len;//length of the matrices H currently calculated
246  Int4 d_W_matr_len;//length of the matrices W currently calculated
247 
248  //the importance sampling weights
252 
256 
260 
264 
265  double d_WS_ij_pred;
266  double d_WI_ij_pred;
267  double d_WD_ij_pred;
268 
269  double d_WS_ij_next;
270  double d_WI_ij_next;
271  double d_WD_ij_next;
272 
273 
274  //alignment matrix
279 
284 
289 
294 
299 
304 
305  bool d_success;
306 
307  //statistics
310 
314 
317 
320 
322 
324 
327 
330 
333 
337 
339 
340 
341 
342  //for the importance sampling
344 
345 
346 
347 
348 
349 
350 
351  };
352 
353 END_SCOPE(Sls)
354 
355 END_SCOPE(blast)
357 
358 #endif //! ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_SLS_ALP
double d_memory_size_in_MB
Definition: sls_alp.hpp:92
static double degree(double x_, double n_)
Definition: sls_alp.cpp:1116
Int4 * d_HD_i_const_next
Definition: sls_alp.hpp:282
double John2_weight_calculation(Int4 length_)
Definition: sls_alp.cpp:1819
void release_and_calculate_memory(T *&pointer_, Int4 dim_)
Definition: sls_alp.hpp:177
Int4 * d_HI_j_const_pred
Definition: sls_alp.hpp:286
double * d_WD_j_const_next
Definition: sls_alp.hpp:263
Int4 * d_H_i_const_next
Definition: sls_alp.hpp:283
Int4 * d_HS_i_const_pred
Definition: sls_alp.hpp:275
Int4 * d_H_i_const_pred
Definition: sls_alp.hpp:278
Int4 d_seq_a_len
Definition: sls_alp.hpp:238
double * d_WS_j_const_next
Definition: sls_alp.hpp:261
Int4 d_sentinel_i_pred
Definition: sls_alp.hpp:328
Int4 d_HI_ij_pred
Definition: sls_alp.hpp:296
bool d_time_limit_flag
Definition: sls_alp.hpp:336
alp(alp_data *alp_data_)
Definition: sls_alp.cpp:46
Int4 d_W_matr_a_len
Definition: sls_alp.hpp:240
Int4 * d_seqi
Definition: sls_alp.hpp:242
void increment_sequences()
Definition: sls_alp.cpp:585
Int4 d_H_ij_pred
Definition: sls_alp.hpp:298
double * d_WD_i_const_next
Definition: sls_alp.hpp:255
void simulate_alp_upto_the_given_level(Int4 M_min_)
Definition: sls_alp.cpp:1980
void increment_H_weights_with_sentinels(Int4 diff_opt_)
Definition: sls_alp.cpp:1346
void partially_release_memory()
Definition: sls_alp.cpp:357
array_positive< Int4 > * d_alp_pos
Definition: sls_alp.hpp:318
Int4 * d_HI_i_const_pred
Definition: sls_alp.hpp:276
array_positive< Int4 > * d_H_J
Definition: sls_alp.hpp:316
array_positive< Int4 > * d_alp
Definition: sls_alp.hpp:313
void save_state(state *&state_)
Definition: sls_alp.cpp:1649
Int4 * d_H_j_const_pred
Definition: sls_alp.hpp:288
Int4 d_a_step
Definition: sls_alp.hpp:223
Int4 d_seqj_len
Definition: sls_alp.hpp:235
void kill_upto_level(Int4 M_min_, Int4 M_level_)
Definition: sls_alp.cpp:1744
Int4 * d_HS_j_const_pred
Definition: sls_alp.hpp:285
double * d_WS_j_const_pred
Definition: sls_alp.hpp:257
double * d_WS_i_const_next
Definition: sls_alp.hpp:253
double d_WS_ij_next
Definition: sls_alp.hpp:269
Int4 d_sentinel_j_next
Definition: sls_alp.hpp:326
double d_WI_ij_next
Definition: sls_alp.hpp:270
Int4 * d_H_edge_max
Definition: sls_alp.hpp:308
void increment_H_matrix()
Definition: sls_alp.cpp:817
Int4 d_nalp
Definition: sls_alp.hpp:311
bool d_success
Definition: sls_alp.hpp:305
double d_WD_ij_next
Definition: sls_alp.hpp:271
Int4 * d_H_j_const_next
Definition: sls_alp.hpp:293
double * d_WI_j_const_pred
Definition: sls_alp.hpp:258
Int4 d_HS_ij_next
Definition: sls_alp.hpp:300
Int4 * d_HD_j_const_pred
Definition: sls_alp.hpp:287
Int4 * d_HI_j_const_next
Definition: sls_alp.hpp:291
void increment_W_matrix()
Definition: sls_alp.cpp:653
bool d_time_error_flag
Definition: sls_alp.hpp:335
Int4 * d_HD_j_const_next
Definition: sls_alp.hpp:292
Int4 d_HS_ij_pred
Definition: sls_alp.hpp:295
Int4 d_sentinel_j_pred
Definition: sls_alp.hpp:329
bool d_sentinels_flag
Definition: sls_alp.hpp:332
double * d_WI_i_const_pred
Definition: sls_alp.hpp:250
Int4 d_H_matr_a_len
Definition: sls_alp.hpp:239
Int4 d_nalp_killing
Definition: sls_alp.hpp:312
array_positive< double > * d_alp_weights
Definition: sls_alp.hpp:319
void check_time_function(Int4 ff_=0)
Definition: sls_alp.cpp:1317
bool d_check_time_flag
Definition: sls_alp.hpp:334
Int4 * d_seqj
Definition: sls_alp.hpp:243
Int4 d_HD_ij_next
Definition: sls_alp.hpp:302
Int4 d_sentinel_i_next
Definition: sls_alp.hpp:325
bool d_is_now
Definition: sls_alp.hpp:226
Int4 * d_HI_i_const_next
Definition: sls_alp.hpp:281
bool one_step_of_importance_sampling_without_weight_calculation(Int4 d_dim1_, Int4 d_dim2_)
Definition: sls_alp.cpp:468
Int4 d_H_ij_next
Definition: sls_alp.hpp:303
Int4 d_seqi_len
Definition: sls_alp.hpp:234
void swap(T &a1_, T &a2_)
Definition: sls_alp.hpp:145
array_positive< state * > * d_alp_states
Definition: sls_alp.hpp:323
bool d_single_realiztion_calculation_flag
Definition: sls_alp.hpp:338
Int4 d_diff_opt
Definition: sls_alp.hpp:331
double * d_WI_j_const_next
Definition: sls_alp.hpp:262
Int4 random_AA1()
Definition: sls_alp.cpp:450
Int4 random_AA2()
Definition: sls_alp.cpp:459
char d_IS_state
Definition: sls_alp.hpp:343
void restore_state(Int4 nalp_, state *&state_)
Definition: sls_alp.cpp:1579
void simulate_next_alp()
Definition: sls_alp.cpp:1903
Int4 d_H_matr_len
Definition: sls_alp.hpp:245
double d_WI_ij_pred
Definition: sls_alp.hpp:266
array< Int4 > * d_cells_counts
Definition: sls_alp.hpp:321
void release_and_calculate_memory(T *&pointer_)
Definition: sls_alp.hpp:195
Int4 d_HI_ij_next
Definition: sls_alp.hpp:301
double d_WD_ij_pred
Definition: sls_alp.hpp:267
void increment_H_weights()
Definition: sls_alp.cpp:1141
double * d_WI_i_const_next
Definition: sls_alp.hpp:254
double d_WS_ij_pred
Definition: sls_alp.hpp:265
alp_data * d_alp_data
Definition: sls_alp.hpp:222
array_positive< Int4 > * d_H_I
Definition: sls_alp.hpp:315
Int4 * d_HS_j_const_next
Definition: sls_alp.hpp:290
Int4 * d_HD_i_const_pred
Definition: sls_alp.hpp:277
void increment_W_weights()
Definition: sls_alp.cpp:1021
Int4 d_M
Definition: sls_alp.hpp:309
~alp()
Definition: sls_alp.cpp:207
double * d_WS_i_const_pred
Definition: sls_alp.hpp:249
double * d_WD_j_const_pred
Definition: sls_alp.hpp:259
void simulate_alp_upto_the_given_number(Int4 nalp_)
Definition: sls_alp.cpp:1966
Int4 d_W_matr_len
Definition: sls_alp.hpp:246
Int4 * d_HS_i_const_next
Definition: sls_alp.hpp:280
double * d_WD_i_const_pred
Definition: sls_alp.hpp:251
Int4 d_HD_ij_pred
Definition: sls_alp.hpp:297
Int4 d_sentinel_i_next
Definition: sls_alp.hpp:86
Int4 d_HD_ij_next
Definition: sls_alp.hpp:79
Int4 * d_HI_i_const_next
Definition: sls_alp.hpp:68
Int4 * d_HI_j_const_next
Definition: sls_alp.hpp:73
Int4 d_M
Definition: sls_alp.hpp:84
Int4 d_sentinel_j_next
Definition: sls_alp.hpp:87
Int4 * d_HD_j_const_next
Definition: sls_alp.hpp:74
Int4 d_H_ij_next
Definition: sls_alp.hpp:80
Int4 * d_HD_i_const_next
Definition: sls_alp.hpp:69
array< Int4 > * d_cells_counts
Definition: sls_alp.hpp:65
Int4 * d_H_i_const_next
Definition: sls_alp.hpp:70
Int4 * d_HS_j_const_next
Definition: sls_alp.hpp:72
Int4 * d_HS_i_const_next
Definition: sls_alp.hpp:67
Int4 d_HI_ij_next
Definition: sls_alp.hpp:78
Int4 d_HS_ij_next
Definition: sls_alp.hpp:77
Int4 * d_H_j_const_next
Definition: sls_alp.hpp:75
Int4 d_H_matr_len
Definition: sls_alp.hpp:82
#define T(s)
Definition: common.h:230
static char tmp[3200]
Definition: utf8.c:42
#define NULL
Definition: ncbistd.hpp:225
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
The NCBI C++/STL use hints.
const double DBL_MAX1
Definition: sls_alp.hpp:57
const double mb_bytes
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:48 2024 by modify_doxy.py rev. 669887