📄 dropfz2.c
字号:
lkt = i0+ktup; continue; } hv = (hv << f_str->kshft) + hsq[aa0[i0]]; phv += ppst->pam2[ip][aa0[i0]][aa0[i0]]*ktup; } } if (i0 >= n0) break; hv = ((hv & f_str->hmask) << f_str->kshft) + ppst->hsq[aa0[i0]]; f_str->link[i0] = f_str->harr[hv]; f_str->harr[hv] = i0; if (pamfact) { f_str->pamh2[hv] = (phv += ppst->pam2[ip][aa0[i0]][aa0[i0]] * ktup); if (hsq[aa0[i0-kt1]] < NMAP) phv -= ppst->pam2[ip][aa0[i0 - kt1]][aa0[i0 - kt1]] * ktup; } else f_str->pamh2[hv] = fact * ktup; }/* this has been modified from 0..<ppst->nsq to 1..<=ppst->nsq because the pam2[0][0] is now undefined for consistency with blast*/ if (pamfact) for (i0 = 1; i0 <= ppst->nsq; i0++) f_str->pamh1[i0] = ppst->pam2[ip][i0][i0] * ktup; else for (i0 = 1; i0 <= ppst->nsq; i0++) f_str->pamh1[i0] = fact; f_str->ndo = 0; /* used to save time on diagonals with long queries */#ifndef ALLOCN0 if ((f_str->diag = (struct dstruct *) calloc ((size_t)MAXDIAG, sizeof (struct dstruct)))==NULL) { fprintf (stderr," cannot allocate diagonal arrays: %lu\n", MAXDIAG *sizeof (struct dstruct)); exit (1); };#else if ((f_str->diag = (struct dstruct *) calloc ((size_t)n0, sizeof (struct dstruct)))==NULL) { fprintf (stderr," cannot allocate diagonal arrays: %ld\n", (long)n0*sizeof (struct dstruct)); exit (1); };#endif#ifndef TFAST /* done hashing, now switch aa0, aa0x back */ fs = aa0; aa0 = aa0x; aa0x = fs;#else if ((f_str->aa1x =(unsigned char *)calloc((size_t)ppst->maxlen+4, sizeof(unsigned char))) == NULL) { fprintf (stderr, "cannot allocate aa1x array %d\n", ppst->maxlen+4); exit (1); } f_str->aa1x++; if ((f_str->aa1v =(unsigned char *)calloc((size_t)ppst->maxlen+4, sizeof(unsigned char))) == NULL) { fprintf (stderr, "cannot allocate aa1v array %d\n", ppst->maxlen+4); exit (1); } f_str->aa1v++;#endif if ((waa= (int *)malloc (sizeof(int)*(ppst->nsq+1)*n0)) == NULL) { fprintf(stderr,"cannot allocate waa struct %3d\n",ppst->nsq*n0); exit(1); } pwaa = waa; for (i=0; i<=ppst->nsq; i++) { for (j=0;j<n0; j++) { *pwaa = ppst->pam2[ip][i][aa0[j]]; pwaa++; } } f_str->waa = waa;#ifndef TFAST maxn0 = max(2*n0,MIN_RES);#else maxn0 = max(4*n0,MIN_RES);#endif if ((res = (int *)calloc((size_t)maxn0,sizeof(int)))==NULL) { fprintf(stderr,"cannot allocate alignment results array %d\n",maxn0); exit(1); } f_str->res = res; f_str->max_res = maxn0; *f_arg = f_str;}/* pstring1 is a message to the manager, currently 512 *//* pstring2 is the same information, but in a markx==10 format */voidget_param (struct pstruct *ppst, char **pstring1, char *pstring2){#ifndef TFAST char *pg_str="FASTY";#else char *pg_str="TFASTY";#endif if (!ppst->param_u.fa.optflag) sprintf (pstring1[0], "%s (%s)",pg_str, verstr); else sprintf (pstring1[0], "%s (%s) [optimized]",pg_str, verstr); sprintf (pstring1[1], #ifdef OLD_FASTA_GAP "%s matrix (%d:%d)%s ktup: %d\n join: %d, opt: %d, gap-pen: %3d/%3d shift: %3d, subs: %3d width: %3d",#else "%s matrix (%d:%d)%s ktup: %d\n join: %d, opt: %d, open/ext: %3d/%3d shift: %3d, subs: %3d width: %3d",#endif ppst->pamfile, ppst->pam_h,ppst->pam_l, (ppst->ext_sq_set) ? "xS":"\0", ppst->param_u.fa.ktup, ppst->param_u.fa.cgap, ppst->param_u.fa.optcut, ppst->gdelval, ppst->ggapval, ppst->gshift,ppst->gsubs,ppst->param_u.fa.optwid); if (ppst->param_u.fa.iniflag) strcat(pstring1[0]," init1"); if (pstring2 != NULL) {#ifdef OLD_FASTA_GAP sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n\; pg_gap-pen: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",#else sprintf (pstring2, "; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n\; pg_open-ext: %d %d\n; pg_ktup: %d\n; pg_optcut: %d\n; pg_cgap: %d\n",#endif pg_str,verstr,ppst->pamfile, ppst->pam_h,ppst->pam_l, (ppst->ext_sq_set) ? "xS":"\0", ppst->gdelval, ppst->ggapval,ppst->param_u.fa.ktup,ppst->param_u.fa.optcut, ppst->param_u.fa.cgap); }}voidclose_work (const unsigned char *aa0, int n0, struct pstruct *ppst, struct f_struct **f_arg){ struct f_struct *f_str; int naat; f_str = *f_arg; if (f_str != NULL) { if (ppst->ext_sq_set) naat = MAXLC; else naat = MAXUC; free_weights(&f_str->weight0,&f_str->weight1,&f_str->weight_c,naat); free(f_str->cur);#ifndef TFAST f_str->aa0v--; free(f_str->aa0v); f_str->aa0x--; free(f_str->aa0x);#else /* TFAST */ f_str->aa1x--; free(f_str->aa1x); f_str->aa1v--; free(f_str->aa1v);#endif free(f_str->res); free(f_str->waa); free(f_str->diag); free(f_str->link); free(f_str->pamh2); free(f_str->pamh1); free(f_str->harr); free(f_str); *f_arg = NULL; }}void do_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; int i; register struct dstruct *dptr; register int tscor; int xdebug = 0;#ifndef ALLOCN0 register struct dstruct *diagp;#else register int dpos; int lposn0;#endif struct dstruct *dpmax; register int lpos; int tpos; struct savestr *vmptr; int scor, tmp; int im, ib, nsave; int ktup, kt1, *hsq, ip, lkt;#ifndef TFAST int n0x31, n0x32; n0x31 = (n0-2)/3; n0x32 = n0x31+1+(n0-n0x31-1)/2;#else unsigned char *fs, *fd; int n1x31, n1x32, last_n1, itemp; n1x31 = (n1-2)/3; n1x32 = n1x31+1+(n1-n1x31-1)/2;#endif if (ppst->ext_sq_set) { ip = 1; hsq = ppst->hsqx; } else { ip = 0; hsq = ppst->hsq; } 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; } f_str->noff = n0 - 1;#ifdef ALLOCN0 nd = n0;#endif#ifndef ALLOCN0 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; if (n1 > 1000 && aa1[0]==23 && aa1[100]==23 && aa1[1400]==23 && aa1[1401]!=23) { xdebug = 1; } else xdebug = 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) + ppst->hsq[aa1[lpos]]; }#ifndef ALLOCN0 diagp = &f_str->diag[f_str->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) + ppst->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 = f_str->noff + lpos; for (; lpos < n1; lpos++, lposn0++) { if (hsq[aa1[lpos]]>=NMAP) {lhval = 0; goto loopl;} lhval = ((lhval & f_str->hmask) << f_str->kshft) + ppst->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 = f_str->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]*/ /* if (xdebug) fprintf(stderr,"n0: %d; noff: %d; n1: %d; n1x31: %d n1x32 %d\n", n0, f_str->noff,n1,n1x31,n1x32); */ for (nsave = 0, vmptr = f_str->vmax; vmptr < &f_str->vmax[MAXSAV]; vmptr++) { /* if (xdebug) fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", f_str->noff+vmptr->start-vmptr->dp, f_str->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[0], f_str); f_str->vptr[nsave++] = vmptr; } } if (nsave <= 0) { rst->score[0] = rst->score[1] = rst->score[2] = 0; return; } #ifndef TFAST /* FASTX code here to modify the start, stop points for the three phases of the translated protein sequence */ /* fprintf(stderr,"n0x: %d; n0x31:%d; n0x32: %d\n",n0,n0x31,n0x32); for (ib=0; ib<nsave; ib++) { fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp, f_str->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"); */ for (ib=0; ib<nsave; ib++) { if (f_str->noff-f_str->vptr[ib]->dp+f_str->vptr[ib]->start >= n0x32) f_str->vptr[ib]->dp += n0x32; if (f_str->noff-f_str->vptr[ib]->dp +f_str->vptr[ib]->start >= n0x31) f_str->vptr[ib]->dp += n0x31; } /* for (ib=0; ib<nsave; ib++) { fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp, f_str->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); } */#else /* TFAST code here to modify the start, stop points for the three phases of the translated protein sequence TFAST modifies library start points, rather than query start points */ /* fprintf(stderr,"n0: %d; noff: %d; n1: %d; n1x31: %d n1x32 %d\n",n0, f_str->noff,n1,n1x31,n1x32); for (ib=0; ib<nsave; ib++) { fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp, f_str->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"); */ for (ib=0; ib<nsave; ib++) { if (f_str->vptr[ib]->start >= n1x32) { f_str->vptr[ib]->start -= n1x32; f_str->vptr[ib]->stop -= n1x32; f_str->vptr[ib]->dp -= n1x32; } if (f_str->vptr[ib]->start >= n1x31) { f_str->vptr[ib]->start -= n1x31; f_str->vptr[ib]->stop -= n1x31; f_str->vptr[ib]->dp -= n1x31; } } /* for (ib=0; ib<nsave; ib++) { fprintf(stderr,"0: %4d-%4d 1: %4d-%4d dp: %d score: %d\n", f_str->noff+f_str->vptr[ib]->start-f_str->vptr[ib]->dp, f_str->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); } */#endif /* TFAST */ scor = sconn (f_str->vptr, nsave, ppst->param_u.fa.cgap, ppst->param_u.fa.pgap, f_str); 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) {#ifndef TFAST rst->score[2] = dmatchx(aa0, n0,aa1,n1,*hoff=f_str->noff - vmptr->dp, ppst->param_u.fa.optwid, ppst->pam2[0], ppst->gdelval,ppst->ggapval,ppst->gshift,f_str);#else /* TFAST */ /* generate f_str->aa1x *//* for (i=0; i<n1; i++) { fputc(ppst->sq[aa1[i]],stderr); if (i%60==59) fputc('\n',stderr); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -