Next version of JABA
[jabaws.git] / binaries / src / fasta34 / sc_to_e.c
1
2 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
3    U. of Virginia */
4
5 /* $Name: fa_34_26_5 $ - $Id: sc_to_e.c,v 1.2 2006/04/12 18:00:02 wrp Exp $ */
6
7 /* sc_to_e  uses statistical parameters from search and
8             score, length, and database size to calculate E()
9 */
10
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <math.h>
14
15 double mean_var, mu, rho;
16
17 main(argc, argv)
18      int argc; char **argv;
19 {
20   char line[128];
21   int score, length, db_size;
22   double z_val, s_to_zv(), zv_to_E();
23
24   if (argc == 4) {
25     sscanf(argv[1],"%lf",&rho);
26     sscanf(argv[2],"%lf",&mu);
27     sscanf(argv[3],"%lf",&mean_var);
28   }
29   else {
30     fprintf(stderr," enter rho mu mean_var: ");
31     fgets(line,sizeof(line),stdin);
32     sscanf(line,"%lf %lf %lf",&rho, &mu, &mean_var);
33   }
34
35   while (1) {
36     fprintf(stderr," enter score length db_size: ");
37     if (fgets(line,sizeof(line),stdin)==NULL) exit(0);
38     if (line[0]=='\n') exit(0);
39     sscanf(line,"%d %d %d",&score, &length, &db_size);
40     if (db_size < 1) db_size = 50000;
41
42     z_val = s_to_zv(score, length);
43
44     printf(" s: %d (%d) E(%d): %4.2g\n",score,length,db_size,zv_to_E(z_val,db_size));
45   }
46 }
47
48 double s_to_zv(int score, int length)
49 {
50   return ((double)score - rho * log((double)length) - mu)/sqrt(mean_var);
51 }
52
53 double zv_to_E(double zv, int db_size)
54 {
55   double e;
56
57   e = exp(-1.282554983 * zv - .577216);
58   return (double)db_size * (e > .01 ? 1.0 - exp(-e) : e);
59 }