NCBI C++ ToolKit
sls_pvalues.cpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: sls_pvalues.cpp 62325 2014-04-01 19:20:49Z 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_pvalues.cpp
29 
30 Author: Sergey Sheetlin
31 
32 Contents: Calculation of P-values using precalculated Gumbel parameters
33 
34 ******************************************************************************/
35 
36 #include <ncbi_pch.hpp>
37 
38 #include "sls_pvalues.hpp"
39 #include "sls_alp_data.hpp"
40 
41 
43 USING_SCOPE(blast);
45 
46 const bool read_Sbs_par_flag=true;
47 
48 
49 
50 double pvalues::error_of_the_sum(//v1_+v2_
51 double v1_,
52 double v1_error_,
53 double v2_,
54 double v2_error_)
55 {
56  if(v1_error_>=1e100||v2_error_>=1e100)
57  {
58  return 1e100;
59  };
60 
61  return sqrt(v1_error_*v1_error_+v2_error_*v2_error_);
62 };
63 
65 double v1_,
66 double v1_error_,
67 double v2_,
68 double v2_error_)
69 {
70  if(v1_error_>=1e100||v2_error_>=1e100)
71  {
72  return 1e100;
73  };
74 
75  double a1=(v1_+v1_error_)*(v2_+v2_error_);
76  double a2=(v1_-v1_error_)*(v2_+v2_error_);
77  double a3=(v1_+v1_error_)*(v2_-v2_error_);
78  double a4=(v1_-v1_error_)*(v2_-v2_error_);
79 
80  double a=v1_*v2_;
81 
82  return alp_data::Tmax(fabs(a1-a),fabs(a2-a),fabs(a3-a),fabs(a4-a));
83 
84 };
85 
86 
87 double pvalues::error_of_the_sqrt(//sqrt(v1_)
88 double v1_,
89 double v1_error_)
90 {
91  if(v1_error_>=1e100||v1_<0)
92  {
93  return 1e100;
94  };
95 
96  double s=sqrt(v1_);
97  double s1=sqrt(alp_data::Tmax(0.0,v1_-v1_error_));
98  double s2=sqrt(alp_data::Tmax(0.0,v1_+v1_error_));
99 
100  return alp_data::Tmax(fabs(s-s1),fabs(s-s2));
101 };
102 
104 double v1_,
105 double v1_error_,
106 double v2_,
107 double v2_error_)
108 {
109  if(v1_error_>=1e100||v2_error_>=1e100)
110  {
111  return 1e100;
112  };
113 
114 
115  if(v2_==0)
116  {
117  return 1e100;
118  };
119 
120  if(v1_==0&&v1_error_==0)
121  {
122  return 0.0;
123  };
124 
125  double a=v1_/v2_;
126 
127 
128  if(((v2_+v2_error_)*v2_<=0))
129  {
130  double a3=(v1_+v1_error_)/(v2_-v2_error_);
131  double a4=(v1_-v1_error_)/(v2_-v2_error_);
132  return alp_data::Tmax(fabs(a-a3),fabs(a-a4));
133  };
134 
135  if(((v2_-v2_error_)*v2_<=0))
136  {
137  double a1=(v1_+v1_error_)/(v2_+v2_error_);
138  double a2=(v1_-v1_error_)/(v2_+v2_error_);
139  return alp_data::Tmax(fabs(a-a1),fabs(a-a2));
140  };
141 
142 
143  double a1=(v1_+v1_error_)/(v2_+v2_error_);
144  double a2=(v1_-v1_error_)/(v2_+v2_error_);
145  double a3=(v1_+v1_error_)/(v2_-v2_error_);
146  double a4=(v1_-v1_error_)/(v2_-v2_error_);
147 
148  return alp_data::Tmax(fabs(a-a1),fabs(a-a2),fabs(a-a3),fabs(a-a4));
149 };
150 
151 
152 
153 
155 double y_)
156 {
157  if(fabs(y_)>1e-8)
158  {
159  return 1.0-exp(y_);
160  }
161  else
162  {
163  return -(y_+y_*y_/2.0+y_*y_*y_/6.0+y_*y_*y_*y_/24.0);
164  };
165 };
166 
168 double x_,
169 double eps_)
170 {
171 
172  double pi=3.1415926535897932384626433832795;
173  if(x_==0)
174  {
175  return 0.5;
176  };
177 
178 
179  eps_=alp_data::Tmin(1.0,eps_);
180 
181  double x_max=10*eps_+sqrt(alp_data::Tmax(0.0,-2*log(eps_)));
182 
183 
184  if(x_>=x_max)
185  {
186  double x=x_/sqrt(2.0);
187  return 1-0.5*exp(-x*x)/(x*sqrt(pi))*(1-1.0/(2*x*2*x));
188  };
189 
190  if(x_<=-x_max)
191  {
192  double x=x_/sqrt(2.0);
193  return 0.5*exp(-x*x)/(-x*sqrt(pi))*(1-1.0/(2*x*2*x));
194  };
195 
196 
197  double const_val=1/sqrt(2.0*pi);
198 
199 
200 
201 
202  Int4 N=(Int4)alp_data::round(fabs(x_)/eps_)+1;
203  double h=x_/(double)N;
204 
205 
206 
207  double res=0;
208  Int4 i;
209  for(i=0;i<=N;i++)
210  {
211  double y=h*i;
212  double tmp=exp(-0.5*y*y);
213  if(i==0||i==N)
214  {
215  res+=0.5*tmp;
216  }
217  else
218  {
219  res+=tmp;
220  };
221  };
222 
223  res*=h;
224 
225  return 0.5+const_val*(res);
226 };
227 
229 double a_,
230 double b_,
231 double h_,
232 Int4 N_,
233 double *p_,
234 double x_,
235 double eps_)
236 {
237  if(x_<a_||x_>b_)
238  {
239  return normal_probability(x_,eps_);
240  };
241 
242  Int4 x_n=(Int4)floor((x_-a_)/h_);
243  x_n=alp_data::Tmin(N_-1,x_n);
244  return p_[x_n]+(p_[x_n+1]-p_[x_n])*(x_-(h_*x_n+a_))/h_;
245 };
246 
248 double val_)
249 {
250  if(val_>1e-8)
251  {
252  return log(1-val_);
253  };
254 
255  return -val_-val_*val_/2.0-val_*val_*val_/3.0;
256 };
257 
258 
259 
261 set_of_parameters &par_,
262 bool blast_,
263 double y_,
264 Int4 m_,
265 Int4 n_,
266 
267 double &P_,
268 double &P_error_,
269 
270 double &area_,
271 
272 double a_normal_,
273 double b_normal_,
274 double h_normal_,
275 Int4 N_normal_,
276 double *p_normal_,
277 
278 bool &area_is_1_flag_)
279 {
280 
281 
282  double lambda_=par_.lambda;
283  double lambda_error_=par_.lambda_error;
284  double k_=par_.K;
285  double k_error_=par_.K_error;
286 
287  double ai_hat_=par_.a_I;
288  double ai_hat_error_=par_.a_I_error;
289  double bi_hat_=2.0*par_.G*(par_.gapless_a-par_.a_I);
290  double bi_hat_error_=2.0*par_.G*error_of_the_sum(par_.gapless_a,par_.gapless_a_error,par_.a_I,par_.a_I_error);
291  double alphai_hat_=par_.alpha_I;
292  double alphai_hat_error_=par_.alpha_I_error;
293  double betai_hat_=2.0*par_.G*(par_.gapless_alpha-par_.alpha_I);
294  double betai_hat_error_=2.0*par_.G*error_of_the_sum(par_.gapless_alpha,par_.gapless_alpha_error,par_.alpha_I,par_.alpha_I_error);
295 
296  double aj_hat_=par_.a_J;
297  double aj_hat_error_=par_.a_J_error;
298  double bj_hat_=2.0*par_.G*(par_.gapless_a-par_.a_J);
299  double bj_hat_error_=2.0*par_.G*error_of_the_sum(par_.gapless_a,par_.gapless_a_error,par_.a_J,par_.a_J_error);
300  double alphaj_hat_=par_.alpha_J;
301  double alphaj_hat_error_=par_.alpha_J_error;
302  double betaj_hat_=2.0*par_.G*(par_.gapless_alpha-par_.alpha_J);
303  double betaj_hat_error_=2.0*par_.G*error_of_the_sum(par_.gapless_alpha,par_.gapless_alpha_error,par_.alpha_J,par_.alpha_J_error);
304 
305  double sigma_hat_=par_.sigma;
306  double sigma_hat_error_=par_.sigma_error;
307  double tau_hat_=2.0*par_.G*(par_.gapless_alpha-par_.sigma);
308  double tau_hat_error_=2.0*par_.G*error_of_the_sum(par_.gapless_alpha,par_.gapless_alpha_error,par_.sigma,par_.sigma_error);
309 
310 
311  bool where_it_is_works_flag=false;
312  bool negative_flag=false;
313 
314 
315  if(blast_)
316  {
317  alphai_hat_=0;
318  alphai_hat_error_=0;
319  betai_hat_=0;
320  betai_hat_error_=0;
321 
322  alphaj_hat_=0;
323  alphaj_hat_error_=0;
324  betaj_hat_=0;
325  betaj_hat_error_=0;
326 
327  sigma_hat_=0;
328  sigma_hat_error_=0;
329  tau_hat_=0;
330  tau_hat_error_=0;
331  };
332 
333  double const_val=1/sqrt(2.0*3.1415926535897932384626433832795);
334  double eps=0.000001;
335 
336 
337 
338  double m_li_y_error = 0.0;
339  double m_li_y = 0.0;
340 
341  bool flag_Mi=true;
342 
343  if(flag_Mi||blast_)
344  {
345  double tmp=alp_data::Tmax(0.0,(ai_hat_*y_+bi_hat_));
346  if(where_it_is_works_flag)
347  {
348  if(ai_hat_*y_+bi_hat_<0)
349  {
350  negative_flag=true;
351  };
352  };
353  m_li_y_error=error_of_the_sum(y_*ai_hat_,fabs(y_)*ai_hat_error_,bi_hat_,bi_hat_error_);
354  m_li_y=m_-tmp;
355  };
356 
357  double vi_y_error = 0.0;
358  double vi_y = 0.0;
359 
360  bool flag_Mii=true;
361 
362  if(flag_Mii||blast_)
363  {
364  vi_y_error=error_of_the_sum(y_*alphai_hat_,fabs(y_)*alphai_hat_error_,betai_hat_,betai_hat_error_);
365  vi_y=alp_data::Tmax(0.0,alphai_hat_*y_+betai_hat_);
366  if(where_it_is_works_flag)
367  {
368  if(alphai_hat_*y_+betai_hat_<0)
369  {
370  negative_flag=true;
371  };
372  };
373  };
374 
375  double sqrt_vi_y_error=error_of_the_sqrt(vi_y,vi_y_error);
376  double sqrt_vi_y=sqrt(vi_y);
377 
378  double m_F;
379  double m_F_error;
380 
381  if(sqrt_vi_y==0.0||blast_)
382  {
383  m_F=1e100;
384  m_F_error=0.0;
385  }
386  else
387  {
388  m_F_error=error_of_the_ratio(m_li_y,m_li_y,sqrt_vi_y,sqrt_vi_y_error);
389  m_F=m_li_y/sqrt_vi_y;
390  };
391 
392 
393  double P_m_F=normal_probability(a_normal_,b_normal_,h_normal_,N_normal_,p_normal_,m_F,eps);
394  double P_m_F_error=const_val*exp(-0.5*m_F*m_F)*m_F_error;
395 
396  double E_m_F=-const_val*exp(-0.5*m_F*m_F);
397  double E_m_F_error=fabs(-E_m_F*m_F)*m_F_error;
398 
399  double m_li_y_P_m_F_error=error_of_the_product(m_li_y,m_li_y_error,P_m_F,P_m_F_error);
400  double m_li_y_P_m_F=m_li_y*P_m_F;
401 
402  double sqrt_vi_y_E_m_F_error=error_of_the_product(sqrt_vi_y,sqrt_vi_y_error,E_m_F,E_m_F_error);
403  double sqrt_vi_y_E_m_F=sqrt_vi_y*E_m_F;
404 
405  double p1_error=error_of_the_sum(m_li_y_P_m_F,m_li_y_P_m_F_error,sqrt_vi_y_E_m_F,sqrt_vi_y_E_m_F_error);
406  double p1=m_li_y_P_m_F-sqrt_vi_y_E_m_F;
407 
408 
409  double n_lj_y_error = 0.0;
410  double n_lj_y = 0.0;
411 
412  bool flag_Mj=true;
413 
414  if(flag_Mj||blast_)
415  {
416  double tmp=alp_data::Tmax(0.0,(aj_hat_*y_+bj_hat_));
417  n_lj_y_error=error_of_the_sum(y_*aj_hat_,fabs(y_)*aj_hat_error_,bj_hat_,bj_hat_error_);
418  n_lj_y=n_-tmp;
419 
420  if(where_it_is_works_flag)
421  {
422  if(aj_hat_*y_+bj_hat_<0)
423  {
424  negative_flag=true;
425  };
426  };
427 
428  };
429 
430  double vj_y_error = 0.0;
431  double vj_y = 0.0;
432 
433  bool flag_Mjj=true;
434 
435  if(flag_Mjj||blast_)
436  {
437  vj_y_error=error_of_the_sum(y_*alphaj_hat_,fabs(y_)*alphaj_hat_error_,betaj_hat_,betaj_hat_error_);
438  vj_y=alp_data::Tmax(0.0,alphaj_hat_*y_+betaj_hat_);
439 
440  if(where_it_is_works_flag)
441  {
442  if(alphaj_hat_*y_+betaj_hat_<0)
443  {
444  negative_flag=true;
445  };
446  };
447 
448  };
449 
450 
451 
452  double sqrt_vj_y_error=error_of_the_sqrt(vj_y,vj_y_error);
453  double sqrt_vj_y=sqrt(vj_y);
454 
455  double n_F;
456  double n_F_error;
457 
458  if(sqrt_vj_y==0.0||blast_)
459  {
460  n_F=1e100;
461  n_F_error=0.0;
462  }
463  else
464  {
465  n_F_error=error_of_the_ratio(n_lj_y,n_lj_y,sqrt_vj_y,sqrt_vj_y_error);
466  n_F=n_lj_y/sqrt_vj_y;
467  };
468 
469  double P_n_F=normal_probability(a_normal_,b_normal_,h_normal_,N_normal_,p_normal_,n_F,eps);
470  double P_n_F_error=const_val*exp(-0.5*n_F*n_F)*n_F_error;
471 
472  double E_n_F=-const_val*exp(-0.5*n_F*n_F);
473  double E_n_F_error=fabs(-E_n_F*n_F)*n_F_error;
474 
475  double n_lj_y_P_n_F_error=error_of_the_product(n_lj_y,n_lj_y_error,P_n_F,P_n_F_error);
476  double n_lj_y_P_n_F=n_lj_y*P_n_F;
477 
478  double sqrt_vj_y_E_n_F_error=error_of_the_product(sqrt_vj_y,sqrt_vj_y_error,E_n_F,E_n_F_error);
479  double sqrt_vj_y_E_n_F=sqrt_vj_y*E_n_F;
480 
481  double p2_error=error_of_the_sum(n_lj_y_P_n_F,n_lj_y_P_n_F_error,sqrt_vj_y_E_n_F,sqrt_vj_y_E_n_F_error);
482  double p2=n_lj_y_P_n_F-sqrt_vj_y_E_n_F;
483 
484 
485 
486 
487  double c_y_error = 0.0;
488  double c_y = 0.0;
489 
490  bool flag_Mij=true;
491 
492  if(flag_Mij||blast_)
493  {
494  c_y_error=error_of_the_sum(sigma_hat_*y_,sigma_hat_error_*y_,tau_hat_,tau_hat_error_);
495  c_y=alp_data::Tmax(0.0,sigma_hat_*y_+tau_hat_);
496 
497  if(where_it_is_works_flag)
498  {
499  if(sigma_hat_*y_+tau_hat_<0)
500  {
501  negative_flag=true;
502  };
503  };
504 
505  };
506 
507  double P_m_F_P_n_F_error=error_of_the_product(P_m_F,P_m_F_error,P_n_F,P_n_F_error);
508  double P_m_F_P_n_F=P_m_F*P_n_F;
509 
510  double c_y_P_m_F_P_n_F_error=error_of_the_product(c_y,c_y_error,P_m_F_P_n_F,P_m_F_P_n_F_error);
511  double c_y_P_m_F_P_n_F=c_y*P_m_F_P_n_F;
512 
513  double p1_p2_error=error_of_the_product(p1,p1_error,p2,p2_error);
514  double p1_p2=p1*p2;
515 
516  p1_p2=alp_data::Tmax(0.0,p1_p2);
517 
518 
519  double area_error=error_of_the_sum(p1_p2,p1_p2_error,c_y_P_m_F_P_n_F,c_y_P_m_F_P_n_F_error);
520  double area=p1_p2+c_y_P_m_F_P_n_F;
521 
522 
523 
524 
525  if(!blast_)
526  {
527  area=alp_data::Tmax(area,1.0);
528  }
529  else
530  {
531  if(area<=1.0)
532  {
533  area_is_1_flag_=true;
534  };
535 
536  if(area_is_1_flag_)
537  {
538  area=1.0;
539  };
540  };
541 
542  if(negative_flag&&where_it_is_works_flag)
543  {
544  area=0;
545  };
546 
547 
548 
549  double exp_lambda_y_error=fabs(lambda_error_*y_*exp(-lambda_*y_));
550  double exp_lambda_y=exp(-lambda_*y_);
551 
552  double area_k_error=error_of_the_product(area,area_error,k_,k_error_);
553  double area_k=area*k_;
554 
555  double area_k_exp_lambda_y_error=error_of_the_product(area_k,area_k_error,exp_lambda_y,exp_lambda_y_error);
556  double area_k_exp_lambda_y=-area_k*exp_lambda_y;
557 
558  P_error_=exp(area_k_exp_lambda_y)*area_k_exp_lambda_y_error;
559 
560  P_=one_minus_exp_function(area_k_exp_lambda_y);
561 // P_=1-exp(-k_*area*exp(-lambda_*y_));
562 
563  area_=area;
564 
565 
566 
567 
568 };
569 
570 
571 
573 set_of_parameters &par_,
574 bool blast_,
575 double y_,
576 Int4 m_,
577 Int4 n_,
578 
579 double &P_,
580 double &P_error_,
581 
582 double &area_,
583 
584 double a_normal_,
585 double b_normal_,
586 double h_normal_,
587 Int4 N_normal_,
588 double *p_normal_,
589 
590 bool &area_is_1_flag_)
591 {
592 
593 
594 
595  double lambda_=par_.lambda;
596  double k_=par_.K;
597 
598  double ai_hat_=par_.a_I;
599  double bi_hat_=2.0*par_.G*(par_.gapless_a-par_.a_I);
600  double alphai_hat_=par_.alpha_I;
601  double betai_hat_=2.0*par_.G*(par_.gapless_alpha-par_.alpha_I);
602 
603  double aj_hat_=par_.a_J;
604  double bj_hat_=2.0*par_.G*(par_.gapless_a-par_.a_J);
605  double alphaj_hat_=par_.alpha_J;
606  double betaj_hat_=2.0*par_.G*(par_.gapless_alpha-par_.alpha_J);
607 
608  double sigma_hat_=par_.sigma;
609  double tau_hat_=2.0*par_.G*(par_.gapless_alpha-par_.sigma);
610 
611 
612  bool where_it_is_works_flag=false;
613  bool negative_flag=false;
614 
615 
616  if(blast_)
617  {
618  alphai_hat_=0;
619  betai_hat_=0;
620 
621  alphaj_hat_=0;
622  betaj_hat_=0;
623 
624  sigma_hat_=0;
625  tau_hat_=0;
626  };
627 
628  double const_val=1/sqrt(2.0*3.1415926535897932384626433832795);
629  double eps=0.000001;
630 
631 
632  double m_li_y = 0.0;
633 
634  bool flag_Mi=true;
635 
636  if(flag_Mi||blast_)
637  {
638  double tmp=alp_data::Tmax(0.0,(ai_hat_*y_+bi_hat_));
639  if(where_it_is_works_flag)
640  {
641  if(ai_hat_*y_+bi_hat_<0)
642  {
643  negative_flag=true;
644  };
645  };
646  m_li_y=m_-tmp;
647  };
648 
649  double vi_y = 0.0;
650 
651  bool flag_Mii=true;
652 
653  if(flag_Mii||blast_)
654  {
655  vi_y=alp_data::Tmax(0.0,alphai_hat_*y_+betai_hat_);
656  if(where_it_is_works_flag)
657  {
658  if(alphai_hat_*y_+betai_hat_<0)
659  {
660  negative_flag=true;
661  };
662  };
663  };
664 
665  double sqrt_vi_y=sqrt(vi_y);
666 
667  double m_F;
668 
669  if(sqrt_vi_y==0.0||blast_)
670  {
671  m_F=1e100;
672  }
673  else
674  {
675  m_F=m_li_y/sqrt_vi_y;
676  };
677 
678 
679  double P_m_F=normal_probability(a_normal_,b_normal_,h_normal_,N_normal_,p_normal_,m_F,eps);
680 
681  double E_m_F=-const_val*exp(-0.5*m_F*m_F);
682 
683  double m_li_y_P_m_F=m_li_y*P_m_F;
684 
685  double sqrt_vi_y_E_m_F=sqrt_vi_y*E_m_F;
686 
687  double p1=m_li_y_P_m_F-sqrt_vi_y_E_m_F;
688 
689 
690  double n_lj_y = 0.0;
691 
692  bool flag_Mj=true;
693 
694  if(flag_Mj||blast_)
695  {
696  double tmp=alp_data::Tmax(0.0,(aj_hat_*y_+bj_hat_));
697  n_lj_y=n_-tmp;
698 
699  if(where_it_is_works_flag)
700  {
701  if(aj_hat_*y_+bj_hat_<0)
702  {
703  negative_flag=true;
704  };
705  };
706 
707  };
708 
709  double vj_y = 0.0;
710 
711  bool flag_Mjj=true;
712 
713  if(flag_Mjj||blast_)
714  {
715  vj_y=alp_data::Tmax(0.0,alphaj_hat_*y_+betaj_hat_);
716 
717  if(where_it_is_works_flag)
718  {
719  if(alphaj_hat_*y_+betaj_hat_<0)
720  {
721  negative_flag=true;
722  };
723  };
724 
725  };
726 
727 
728 
729  double sqrt_vj_y=sqrt(vj_y);
730 
731  double n_F;
732 
733  if(sqrt_vj_y==0.0||blast_)
734  {
735  n_F=1e100;
736  }
737  else
738  {
739  n_F=n_lj_y/sqrt_vj_y;
740  };
741 
742  double P_n_F=normal_probability(a_normal_,b_normal_,h_normal_,N_normal_,p_normal_,n_F,eps);
743 
744  double E_n_F=-const_val*exp(-0.5*n_F*n_F);
745 
746  double n_lj_y_P_n_F=n_lj_y*P_n_F;
747 
748  double sqrt_vj_y_E_n_F=sqrt_vj_y*E_n_F;
749 
750  double p2=n_lj_y_P_n_F-sqrt_vj_y_E_n_F;
751 
752 
753 
754 
755  double c_y = 0.0;
756 
757  bool flag_Mij=true;
758 
759  if(flag_Mij||blast_)
760  {
761  c_y=alp_data::Tmax(0.0,sigma_hat_*y_+tau_hat_);
762 
763  if(where_it_is_works_flag)
764  {
765  if(sigma_hat_*y_+tau_hat_<0)
766  {
767  negative_flag=true;
768  };
769  };
770 
771  };
772 
773  double P_m_F_P_n_F=P_m_F*P_n_F;
774 
775  double c_y_P_m_F_P_n_F=c_y*P_m_F_P_n_F;
776 
777  double p1_p2=p1*p2;
778 
779  p1_p2=alp_data::Tmax(0.0,p1_p2);
780 
781 
782  double area=p1_p2+c_y_P_m_F_P_n_F;
783 
784 
785 
786 
787  if(!blast_)
788  {
789  area=alp_data::Tmax(area,1.0);
790  }
791  else
792  {
793  if(area<=1.0)
794  {
795  area_is_1_flag_=true;
796  };
797 
798  if(area_is_1_flag_)
799  {
800  area=1.0;
801  };
802  };
803 
804  if(negative_flag&&where_it_is_works_flag)
805  {
806  area=0;
807  };
808 
809 
810 
811  double exp_lambda_y=exp(-lambda_*y_);
812 
813  double area_k=area*k_;
814 
815  double area_k_exp_lambda_y=-area_k*exp_lambda_y;
816 
817  P_=one_minus_exp_function(area_k_exp_lambda_y);
818 // P_=1-exp(-k_*area*exp(-lambda_*y_));
819 
820  area_=area;
821 
822 };
823 
825 set_of_parameters &par_,
826 bool blast_,
827 double y_,
828 Int4 m_,
829 Int4 n_,
830 
831 double &P_,
832 double &P_error_,
833 
834 double &area_,
835 
836 double a_normal_,
837 double b_normal_,
838 double h_normal_,
839 Int4 N_normal_,
840 double *p_normal_,
841 
842 bool &area_is_1_flag_)
843 {
844  Int4 dim=par_.m_LambdaSbs.size();
845  if(dim==0)
846  {
847  throw error("Unexpected error in get_P_error_using_splitting_method\n",1);
848  };
849 
850  P_=0;
851  P_error_=0;
852 
853 
854  vector<double> P_values(dim);
855 
856  Int4 i;
857  for(i=0;i<dim;i++)
858  {
859  set_of_parameters par_tmp;
860 
861  par_tmp.a_I=par_.m_AISbs[i];
862  par_tmp.a_I_error=0;
863 
864  par_tmp.a_J=par_.m_AJSbs[i];
865  par_tmp.a_J_error=0;
866 
867 
868 
869  par_tmp.gapless_a=par_.gapless_a;
870  par_tmp.gapless_a_error=par_.gapless_a_error;
871 
872  par_tmp.a=0.5*(par_tmp.a_I+par_tmp.a_J);
873  par_tmp.a_error=0;
874 
875 
876  par_tmp.sigma=par_.m_SigmaSbs[i];
877  par_tmp.sigma_error=0;
878 
879  par_tmp.gapless_alpha=par_.gapless_alpha;
881 
882 
883  par_tmp.C=par_.m_CSbs[i];
884  par_tmp.C_error=0;
885 
886  par_tmp.K=par_.m_KSbs[i];
887  par_tmp.K_error=0;
888 
889 
890  par_tmp.lambda=par_.m_LambdaSbs[i];
891  par_tmp.lambda_error=0;
892 
893  par_tmp.alpha_I=par_.m_AlphaISbs[i];
894  par_tmp.alpha_I_error=0;
895 
896  par_tmp.alpha_J=par_.m_AlphaJSbs[i];
897  par_tmp.alpha_J_error=0;
898 
899  par_tmp.alpha=0.5*(par_tmp.alpha_I+par_tmp.alpha_J);
900  par_tmp.alpha_error=0;
901 
902  par_tmp.G=par_.G;
903 
904  double P_tmp,P_tmp_error,area_tmp;
905 
907  par_tmp,
908  blast_,
909  y_,
910  m_,
911  n_,
912 
913  P_tmp,
914  P_tmp_error,
915 
916  area_tmp,
917 
918  a_normal_,
919  b_normal_,
920  h_normal_,
921  N_normal_,
922  p_normal_,
923 
924  area_is_1_flag_);
925 
926  P_values[i]=P_tmp;
927 
928  P_+=P_tmp;
929 
930  };
931 
932  if(dim<=1)
933  {
934  return;
935  };
936 
937 
938  if(P_<=0)
939  {
940  return;
941  };
942 
943  P_/=(double)dim;
944 
945  for(i=0;i<dim;i++)
946  {
947  double tmp=P_values[i]/P_;
948  P_error_+=tmp*tmp;
949  };
950 
951  P_error_/=(double)dim;
952  P_error_-=1;
953 
954 
955 
956  P_error_=P_*alp_reg::sqrt_for_errors(P_error_/(double)dim);
957 
958 };
959 
960 
962 {
963  bool ee_error_flag=false;
964  error ee_error("",0);
965 
966  p_normal=NULL;
967 
968  try
969  {
970  try
971  {
972 
973  blast=false;
974  eps=0.0001;
975  a_normal=-10;
976  b_normal=10;
980 
981  }
982  catch (error er)
983  {
984  ee_error_flag=true;
985  ee_error=er;
986  };
987  }
988  catch (...)
989  {
990  ee_error_flag=true;
991  ee_error=error("Internal error in the program\n",1);
992  };
993 
994  //memory release
995 
996  if(ee_error_flag)
997  {
998  this->~pvalues();
999  throw error(ee_error.st,ee_error.error_code);
1000  };
1001 
1002 
1003 };
1004 
1005 
1007 {
1008 
1009 };
1010 
1012 Int4 Score1,
1013 Int4 Score2,
1014 Int4 Seq1Len,
1015 Int4 Seq2Len,
1016 set_of_parameters &ParametersSet,
1017 vector<double> &P_values,
1018 vector<double> &P_values_errors)
1019 {
1020  if(Score2<Score1)
1021  {
1022  throw error("Error - Score2<Score1\n",2);
1023  };
1024 
1025  if(Seq1Len<=0||Seq2Len<=0)
1026  {
1027  throw error("Error - Seq1Len<=0||Seq2Len<=0\n",2);
1028  };
1029 
1030  Int4 ymin_=Score1;//calculation of P-values in the range [ymin_,ymax_]
1031  Int4 ymax_=Score2;
1032  Int4 m_=Seq1Len;//length of the first sequence
1033  Int4 n_=Seq2Len;//length of the second sequence
1034  set_of_parameters &par_=ParametersSet;
1035 
1036  P_values.resize(ymax_-ymin_+1);
1037  P_values_errors.resize(ymax_-ymin_+1);
1038 
1039 
1040 
1041  Int4 y;
1042  for(y=ymin_;y<=ymax_;y++)
1043  {
1044 
1045  double P;
1046  double P_error;
1047  double area;
1048  bool area_is_1_flag=false;
1049 
1050 
1051  if(read_Sbs_par_flag)
1052  {
1053 
1054 
1056  par_,
1057  blast,
1058  (double)y,
1059  m_,
1060  n_,
1061 
1062  P,
1063  P_error,
1064 
1065  area,
1066  a_normal,
1067  b_normal,
1068  h_normal,
1069  N_normal,
1070  p_normal,
1071  area_is_1_flag);
1072 
1073 
1074 
1075  double P_tmp,area_tmp;
1076 
1077  if(par_.m_LambdaSbs.size()>0)
1078  {
1080  par_,
1081  blast,
1082  (double)y,
1083  m_,
1084  n_,
1085 
1086  P_tmp,
1087  P_error,
1088 
1089  area_tmp,
1090  a_normal,
1091  b_normal,
1092  h_normal,
1093  N_normal,
1094  p_normal,
1095  area_is_1_flag);
1096 
1097 
1098  if(P_tmp>0)
1099  {
1100  P_error=P_error/P_tmp*P;
1101  };
1102 
1103  P_values_errors[y-ymin_]=P_error;
1104  }
1105  else
1106  {
1107  P_values_errors[y-ymin_]=-DBL_MAX;
1108  };
1109 
1110 
1111 
1112  }
1113  else
1114  {
1116  par_,
1117  blast,
1118  (double)y,
1119  m_,
1120  n_,
1121 
1122  P,
1123  P_error,
1124 
1125  area,
1126  a_normal,
1127  b_normal,
1128  h_normal,
1129  N_normal,
1130  p_normal,
1131  area_is_1_flag);
1132 
1133  P_values_errors[y-ymin_]=P_error;
1134  };
1135 
1136 
1137 
1138  P_values[y-ymin_]=P;
1139 
1140 
1141 
1142  };
1143 
1144 };
1145 
static double round(const double &x_)
static T Tmax(T i_, T j_)
static T Tmin(T i_, T j_)
static double sqrt_for_errors(double x_)
static double ln_one_minus_val(double val_)
double * p_normal
static double one_minus_exp_function(double y_)
static void get_appr_tail_prob_with_cov(set_of_parameters &par_, bool blast_, double y_, Int4 m_, Int4 n_, double &P_, double &P_error_, double &area_, double a_normal_, double b_normal_, double h_normal_, Int4 N_normal_, double *p_normal_, bool &area_is_1_flag_)
static double error_of_the_ratio(double v1_, double v1_error_, double v2_, double v2_error_)
bool blast
static double normal_probability(double x_, double eps_)
static double error_of_the_product(double v1_, double v1_error_, double v2_, double v2_error_)
Definition: sls_pvalues.cpp:64
double b_normal
static void get_P_error_using_splitting_method(set_of_parameters &par_, bool blast_, double y_, Int4 m_, Int4 n_, double &P_, double &P_error_, double &area_, double a_normal_, double b_normal_, double h_normal_, Int4 N_normal_, double *p_normal_, bool &area_is_1_flag_)
static double error_of_the_sum(double v1_, double v1_error_, double v2_, double v2_error_)
Definition: sls_pvalues.cpp:50
double eps
static double error_of_the_sqrt(double v1_, double v1_error_)
Definition: sls_pvalues.cpp:87
double h_normal
Int4 N_normal
static void get_appr_tail_prob_with_cov_without_errors(set_of_parameters &par_, bool blast_, double y_, Int4 m_, Int4 n_, double &P_, double &P_error_, double &area_, double a_normal_, double b_normal_, double h_normal_, Int4 N_normal_, double *p_normal_, bool &area_is_1_flag_)
double a_normal
void calculate_P_values(Int4 Score1, Int4 Score2, Int4 Seq1Len, Int4 Seq2Len, set_of_parameters &ParametersSet, std::vector< double > &P_values, std::vector< double > &P_values_errors)
#define P(a, b)
Definition: sqlwparams.h:19
static char tmp[3200]
Definition: utf8.c:42
#define NULL
Definition: ncbistd.hpp:225
const float pi
Definition: math.hpp:54
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
int i
#define fabs(v)
Definition: ncbi_dispd.c:46
unsigned int a
Definition: ncbi_localip.c:102
#define NORMAL_DISTR_ARRAY_DIM
double * GetNormalDistrArrayForPvaluesCalculation(void)
const bool read_Sbs_par_flag
Definition: sls_pvalues.cpp:46
USING_SCOPE(blast)
USING_NCBI_SCOPE
Definition: sls_pvalues.cpp:42
std::string st
std::vector< double > m_KSbs
std::vector< double > m_SigmaSbs
std::vector< double > m_AlphaJSbs
std::vector< double > m_CSbs
std::vector< double > m_AlphaISbs
std::vector< double > m_AJSbs
std::vector< double > m_LambdaSbs
std::vector< double > m_AISbs
double gapless_alpha_error
Definition: sls_pvalues.hpp:97
#define N
Definition: crc32.c:57
Modified on Sun Jun 23 05:15:09 2024 by modify_doxy.py rev. 669887