📄 dropnfa.c
字号:
int **pam2p, int, int q, int r, int *res, int *nc);static intLOCAL_ALIGN(const unsigned char *, const unsigned char *, int, int, int, int, int **, int, int, int *, int *, int *, int *, int, struct f_struct *);static intB_ALIGN(const unsigned char *A, const unsigned char *B, int M, int N, int low, int up, int **W, int G, int H, int *S, int *nS, int MW, int MX, struct bdstr *bss);static voiddo_fasta (const unsigned char *aa0, int n0, const unsigned char *aa1, int n1, struct pstruct *ppst, struct f_struct *f_str, struct rstruct *rst, int *hoff){ int nd; /* diagonal array size */ int lhval; int kfact; register struct dstruct *dptr; register int tscor;#ifndef ALLOCN0 register struct dstruct *diagp;#else register int dpos; int lposn0;#endif int noff; struct dstruct *dpmax; register int lpos; int tpos; struct savestr *vmptr; int scor, ib, nsave; int xdrop, do_extend; int ktup, kt1, lkt, *hsq, ip; if (ppst->ext_sq_set) { ip = 1; hsq = ppst->hsqx; } else { ip = 0; hsq = ppst->hsq; } xdrop = -ppst->pam_l; /* do extended alignment in spam iff protein or short sequences */ do_extend = !ppst->nt_align || (n0 < 50) || (n1 < 50); ktup = ppst->param_u.fa.ktup; kt1 = ktup-1; if (n1 < ktup) { rst->score[0] = rst->score[1] = rst->score[2] = 0; return; } if (n0+n1+1 >= MAXDIAG) { fprintf(stderr,"n0,n1 too large: %d, %d\n",n0,n1); rst->score[0] = rst->score[1] = rst->score[2] = -1; return; }#ifdef ALLOCN0 nd = n0;#else nd = n0 + n1;#endif dpmax = &f_str->diag[nd]; for (dptr = &f_str->diag[f_str->ndo]; dptr < dpmax;) { dptr->stop = -1; dptr->dmax = NULL; dptr++->score = 0; } for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) vmptr->score = 0; f_str->lowmax = f_str->vmax; f_str->lowscor = 0; /* start hashing */ lhval = 0; lkt = kt1; for (lpos = 0; (lpos < lkt || hsq[aa1[lpos]]>=NMAP) && lpos <n1; lpos++) { /* restart lhval calculation */ if (hsq[aa1[lpos]]>=NMAP) { lhval = 0; lkt = lpos + ktup; continue; } lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]]; } noff = f_str->noff;#ifndef ALLOCN0 diagp = &f_str->diag[noff + lkt]; for (; lpos < n1; lpos++, diagp++) { if (hsq[aa1[lpos]]>=NMAP) { lpos++ ; diagp++; while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; diagp++;} if (lpos >= n1) break; lhval = 0; } lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]]; for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) { if ((tscor = (dptr = &diagp[-tpos])->stop) >= 0) {#else lposn0 = noff + lpos; for (; lpos < n1; lpos++, lposn0++) { if (hsq[aa1[lpos]]>=NMAP) {lhval = 0; goto loopl;} /* if (hsq[aa1[lpos]]>=NMAP) { lpos++; lposn0++; while (lpos < n1 && hsq[aa1[lpos]]>=NMAP) {lpos++; lposn0++;} } */ lhval = ((lhval & f_str->hmask) << f_str->kshft) + hsq[aa1[lpos]]; for (tpos = f_str->harr[lhval]; tpos >= 0; tpos = f_str->link[tpos]) { dpos = lposn0 - tpos; if ((tscor = (dptr = &f_str->diag[dpos % nd])->stop) >= 0) {#endif tscor += ktup; if ((tscor -= lpos) <= 0) { scor = dptr->score; if ((tscor += (kfact = f_str->pamh2[lhval])) < 0 && f_str->lowscor < scor)#ifdef ALLOCN0 savemax (dptr, dpos, f_str);#else savemax (dptr, f_str);#endif if ((tscor += scor) >= kfact) { dptr->score = tscor; dptr->stop = lpos; } else { dptr->score = kfact; dptr->start = (dptr->stop = lpos) - kt1; } } else { dptr->score += f_str->pamh1[aa0[tpos]]; dptr->stop = lpos; } } else { dptr->score = f_str->pamh2[lhval]; dptr->start = (dptr->stop = lpos) - kt1; } } /* end tpos */#ifdef ALLOCN0 /* reinitialize diag structure */ loopl: if ((dptr = &f_str->diag[lpos % nd])->score > f_str->lowscor) savemax (dptr, lpos, f_str); dptr->stop = -1; dptr->dmax = NULL; dptr->score = 0;#endif } /* end lpos */#ifdef ALLOCN0 for (tpos = 0, dpos = noff + n1 - 1; tpos < n0; tpos++, dpos--) { if ((dptr = &f_str->diag[dpos % nd])->score > f_str->lowscor) savemax (dptr, dpos, f_str); }#else for (dptr = f_str->diag; dptr < dpmax;) { if (dptr->score > f_str->lowscor) savemax (dptr, f_str); dptr->stop = -1; dptr->dmax = NULL; dptr++->score = 0; } f_str->ndo = nd;#endif/* at this point all of the elements of aa1[lpos] have been searched for elements of aa0[tpos] with the results in diag[dpos]*/ for (nsave = 0, vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) { /* fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", noff+vmptr->start-vmptr->dp, noff+vmptr->stop-vmptr->dp, vmptr->start,vmptr->stop, vmptr->dp,vmptr->score); */ if (vmptr->score > 0) { vmptr->score = spam (aa0, aa1, vmptr, ppst->pam2[ip], xdrop, noff,do_extend); f_str->vptr[nsave++] = vmptr; } } if (nsave <= 0) { rst->score[0] = rst->score[1] = rst->score[2] = 0; return; } /* fprintf(stderr,"n0: %d; n1: %d; noff: %d\n",n0,n1,noff); for (ib=0; ib<nsave; ib++) { fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp, noff+f_str->vptr[ib]->stop-f_str->vptr[ib]->dp, f_str->vptr[ib]->start,f_str->vptr[ib]->stop, f_str->vptr[ib]->dp,f_str->vptr[ib]->score); } fprintf(stderr,"---\n"); */ scor = sconn (f_str->vptr, nsave, ppst->param_u.fa.cgap, ppst->param_u.fa.pgap, noff); for (vmptr=f_str->vptr[0],ib=1; ib<nsave; ib++) if (f_str->vptr[ib]->score > vmptr->score) vmptr=f_str->vptr[ib];/* kssort (f_str->vptr, nsave); */ rst->score[1] = vmptr->score; rst->score[0] = max (scor, vmptr->score); rst->score[2] = rst->score[0]; /* initn */ if (ppst->param_u.fa.optflag) { if (rst->score[0] > ppst->param_u.fa.optcut) rst->score[2] = dmatch (aa0, n0, aa1, n1, *hoff=noff - vmptr->dp, ppst->param_u.fa.optwid, ppst->pam2[ip], ppst->gdelval,ppst->ggapval,f_str); }}void do_work (const unsigned char *aa0, int n0, const unsigned char *aa1, int n1, int frame, struct pstruct *ppst, struct f_struct *f_str, int qr_flg, struct rstruct *rst){ int hoff, n10; double lambda, H; rst->score[0] = rst->score[1] = rst->score[2] = 0; rst->escore = 1.0; rst->segnum = rst->seglen = 1; if (n1 < ppst->param_u.fa.ktup) return;#ifdef TFASTA n10=aatran(aa1,f_str->aa1x,n1,frame); do_fasta (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff);#else /* FASTA */ do_fasta (aa0, n0, aa1, n1, ppst, f_str, rst, &hoff);#endif#ifndef TFASTA if((ppst->zsflag%10) == 6 && (do_karlin(aa1, n1, ppst->pam2[0], ppst,f_str->aa0_f, f_str->kar_p, &lambda, &H)>0)) { rst->comp = 1.0/lambda; rst->H = H; } else {rst->comp = rst->H = -1.0;}#else rst->comp = rst->H = -1.0;#endif}void do_opt (const unsigned char *aa0, int n0, const unsigned char *aa1, int n1, int frame, struct pstruct *ppst, struct f_struct *f_str, struct rstruct *rst){ int optflag, tscore, hoff, n10; optflag = ppst->param_u.fa.optflag; ppst->param_u.fa.optflag = 1;#ifdef TFASTA n10=aatran(aa1,f_str->aa1x,n1,frame); do_fasta (aa0, n0, f_str->aa1x, n10, ppst, f_str, rst, &hoff);#else /* FASTA */ do_fasta(aa0,n0,aa1,n1,ppst,f_str,rst, &hoff);#endif ppst->param_u.fa.optflag = optflag;}#ifdef ALLOCN0voidsavemax (dptr, dpos, f_str) register struct dstruct *dptr; int dpos; struct f_struct *f_str;{ register struct savestr *vmptr; register int i;#elsevoid savemax (dptr, f_str) register struct dstruct *dptr; struct f_struct *f_str;{ register int dpos; register struct savestr *vmptr; register int i; dpos = (int) (dptr - f_str->diag);#endif/* check to see if this is the continuation of a run that is already saved */ if ((vmptr = dptr->dmax) != NULL && vmptr->dp == dpos && vmptr->start == dptr->start) { vmptr->stop = dptr->stop; if ((i = dptr->score) <= vmptr->score) return; vmptr->score = i; if (vmptr != f_str->lowmax) return; } else { i = f_str->lowmax->score = dptr->score; f_str->lowmax->dp = dpos; f_str->lowmax->start = dptr->start; f_str->lowmax->stop = dptr->stop; dptr->dmax = f_str->lowmax; } for (vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) if (vmptr->score < i) { i = vmptr->score; f_str->lowmax = vmptr; } f_str->lowscor = i;}int spam (const unsigned char *aa0, const unsigned char *aa1, struct savestr *dmax, int **pam2, int xdrop, int noff, int do_extend){ register int lpos, tot; register const unsigned char *aa0p, *aa1p; int drop_thresh; struct { int start, stop, score; } curv, maxv; aa1p = &aa1[lpos= dmax->start]; /* get the start of lib seq */ aa0p = &aa0[lpos - dmax->dp + noff]; /* start of query */#ifdef DEBUG /* also add check in calling routine */ if (aa0p < aa0) { return -99; }#endif curv.start = lpos; /* start index in lib seq */ tot = curv.score = maxv.score = 0; for (; lpos <= dmax->stop; lpos++) { tot += pam2[*aa0p++][*aa1p++]; if (tot > curv.score) { /* update current score */ curv.stop = lpos; curv.score = tot; } else if (tot < 0) { if (curv.score > maxv.score) { /* save score, start, stop */ maxv.start = curv.start; maxv.stop = curv.stop; maxv.score = curv.score; } tot = curv.score = 0; /* reset running score */ curv.start = lpos+1; /* reset start */ if(lpos >= dmax->stop) break; /* if the zero is beyond stop, quit */ } } if (curv.score > maxv.score) { maxv.start = curv.start; maxv.stop = curv.stop; maxv.score = curv.score; }#ifndef NOSPAM_EXT /* now check to see if the score gets better by extending */ if (do_extend && maxv.score > xdrop) { if (maxv.stop == dmax->stop) { tot = maxv.score; drop_thresh = maxv.score - xdrop; aa1p = &aa1[lpos= dmax->stop]; aa0p = &aa0[lpos - dmax->dp + noff]; while (tot > drop_thresh ) { ++lpos; tot += pam2[*(++aa0p)][*(++aa1p)]; if (tot > maxv.score) { maxv.start = lpos; maxv.score = tot; drop_thresh = tot - xdrop; } } } /* scan backwards now */ if (maxv.start == dmax->start) { tot = maxv.score; drop_thresh = maxv.score - xdrop; aa1p = &aa1[lpos= dmax->start]; aa0p = &aa0[lpos - dmax->dp + noff]; while (tot > drop_thresh) { --lpos; tot += pam2[*(--aa0p)][*(--aa1p)]; if (tot > maxv.score) { maxv.start = lpos; maxv.score = tot; drop_thresh = tot - xdrop; } } } }#endif/* if (maxv.start != dmax->start || maxv.stop != dmax->stop) printf(" new region: %3d %3d %3d %3d\n",maxv.start, dmax->start,maxv.stop,dmax->stop);*/ dmax->start = maxv.start; dmax->stop = maxv.stop; return maxv.score;}int sconn (struct savestr **v, int n, int cgap, int pgap, int noff){ int i, si; struct slink { int score; struct savestr *vp; struct slink *next; } *start, *sl, *sj, *so, sarr[MAXSAV]; int lstart, tstart, plstop, ptstop;/* sort the score left to right in lib pos */ kpsort (v, n); start = NULL;/* for the remaining runs, see if they fit */ for (i = 0, si = 0; i < n; i++) {/* if the score is less than the gap penalty, it never helps */ if (v[i]->score < cgap) continue; lstart = v[i]->start; tstart = lstart - v[i]->dp + noff;/* put the run in the group */ sarr[si].vp = v[i]; sarr[si].score = v[i]->score; sarr[si].next = NULL;/* if it fits, then increase the score */ for (sl = start; sl != NULL; sl = sl->next) { plstop = sl->vp->stop; ptstop = plstop - sl->vp->dp + noff; if (plstop < lstart && ptstop < tstart) { sarr[si].score = sl->score + v[i]->score + pgap;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -