2 /* copyright (c) 1996, 1997, 1998, 1999 William R. Pearson and the
5 /* $Name: fa_34_26_5 $ - $Id: last_tat.c,v 1.8 2006/04/12 18:00:02 wrp Exp $ */
23 void do_stage2(struct beststr **bptr, int nbest, struct mngmsg m_msg0,
24 int s_func, struct qmng_str *qm_msp);
28 extern int (*ranlib) (char *str, int cnt,
29 fseek_t libpos, char *libstr,
30 struct lmf_str *lm_fd);
32 #define RANLIB (m_fptr->ranlib)
37 re_getlib(unsigned char *, int, int, int, int, int, long *, long *,
38 struct lmf_str *m_fptr);
41 do_work(unsigned char *aa0, int n0, unsigned char *aa1, int n1, int frame,
42 struct pstruct *ppst, void *f_str, int qr_flg, struct rstruct *rst);
45 do_opt (unsigned char *aa0, int n0, unsigned char *aa1, int n1,
46 int frame, struct pstruct *pst, void *f_str,
49 struct lmf_str *re_openlib(struct lmf_str *, int outtty);
51 void sortbestz (struct beststr **bptr, int nbest);
53 double zs_to_E(double zs,int n1, int isdna, long entries, struct db_str db);
55 double scale_one_score(int ipos, double escore, struct db_str db, void *rs_str);
57 void sortbests (struct beststr **bptr, int nbest)
62 for (gap = nbest/2; gap > 0; gap /= 2)
63 for (i = gap; i < nbest; i++)
64 for (j = i - gap; j >= 0; j-= gap) {
65 if (bptr[j]->score[0] >= bptr[j + gap]->score[0]) break;
67 bptr[j] = bptr[j + gap];
75 unsigned char **aa0, unsigned char *aa1, int maxn,
77 struct beststr **bptr, int nbest,
78 struct mngmsg m_msg, struct pstruct *ppst
80 , struct qmng_str *qm_msp
91 struct lmf_str *m_fptr;
93 int tat_samp, tat_inc, loop_cnt, i;
94 double min_escore, ess;
98 sortbestz(bptr,nbest);
102 if (zs_to_E(bptr[0]->zscore,bptr[0]->n1,0,ppst->zdb_size,m_msg.db)/
103 zs_to_E(bptr[nbest-1]->zscore,bptr[nbest-1]->n1,0,ppst->zdb_size,m_msg.db)
104 < 1e-20) { tat_inc /= 4 ;}
107 /* || (zs_to_E(bptr[0]->zscore,bptr[0]->n1,0,ppst->zdb_size,m_msg.db)< 1e-5); */
110 for (loop_cnt = 0; loop_cnt < 5; loop_cnt++) {
112 nopt = min(nbest,tat_samp);
113 min_escore = 1000000.0;
115 for ( ; ib<nopt; ib++) {
118 if (bbp->score[0] < 0) break;
120 if ((m_fptr=re_openlib(bbp->m_file_p,!m_msg.quiet))==NULL) {
121 fprintf(stderr,"*** cannot re-open %s\n",bbp->m_file_p->lb_name);
124 RANLIB(bline,sizeof(bline),bbp->lseek,bbp->libstr,m_fptr);
126 n1 = re_getlib(aa1,maxn,m_msg.maxt3,m_msg.loff,bbp->cont,m_msg.term_code,
127 &loffset,&l_off,bbp->m_file_p);
129 do_opt(aa0[bbp->frame],m_msg.n0,aa1,n1,bbp->frame,ppst,
130 f_str[bbp->frame],&rst);
131 bbp->score[0]=rst.score[0];
132 bbp->score[1]=rst.score[1];
133 bbp->score[2]=rst.score[2];
134 bbp->escore=rst.escore;
135 bbp->segnum = rst.segnum;
136 bbp->seglen = rst.seglen;
138 if ((ess=scale_one_score(ib, bbp->escore, m_msg.db, rstat_str)) <
139 min_escore) { min_escore = ess;}
141 fprintf(stderr,"%d: %4d %2d %3d %.4g %.4g\n",
142 ib, bbp->score[0], bbp->segnum,bbp->seglen,bbp->escore, ess);
146 do_stage2(&bptr[ib], nopt-ib, m_msg, DO_CALC_FLG, qm_msp);
148 for ( ; ib < nopt; ib++) {
149 if ((ess=scale_one_score(ib, bptr[ib]->escore, m_msg.db, rstat_str)) <
150 min_escore) { min_escore = ess;}
152 fprintf(stderr, "%d: %4d %2d %3d %.4g %.4g\n",
153 ib,bptr[ib]->score[0],bptr[ib]->segnum,bptr[ib]->seglen,bptr[ib]->escore,ess);
159 if (min_escore > m_msg.e_cut) return ib;