⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dropnnw.c

📁 序列对齐 Compare a protein sequence to a protein sequence database or a DNA sequence to a DNA sequenc
💻 C
📖 第 1 页 / 共 2 页
字号:
/* copyright (c) 1996,2007 William R. Pearson *//* $Name: fa35_03_06 $ - $Id: dropnnw.c,v 1.9 2008/02/19 08:50:13 wrp Exp $ *//* 4-April-2007 - convert to global alignment *//* 17-Aug-2006 - removed globals *sapp/last - alignment should be thread safe *//* 12-Oct-2005 - converted to use a_res and aln for alignment coordinates *//* 4-Nov-2004 - Diagonal Altivec Smith-Waterman included *//* 14-May-2003 - modified to return alignment start at 0, rather than   1, for begin:end alignments   25-Feb-2003 - modified to support Altivec parallel Smith-Waterman   22-Sep-2003 - removed Altivec support at request of Sencel lawyers*//* the do_walign() code in this file is not thread_safe *//* init_work(), do_work(), are thread safe *//* this code uses an implementation of the Smith-Waterman algorithm   designed by Phil Green, U. of Washington, that is 1.5 - 2X faster   than my Miller and Myers implementation. *//* the shortcuts used in this program prevent it from calculating scores   that are less than the gap penalty for the first residue in a gap. As   a result this code cannot be used with very large gap penalties, or   with very short sequences, and probably should not be used with prss3.*//* version 3.2 fixes a subtle bug that was encountered while running   do_walign() interspersed with do_work().  This happens only with -m   9 and pvcomplib.  The fix was to more explicitly zero-out ss[] at   the beginning of do_work.*/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#include <math.h>#include "defs.h"#include "param.h"static char *verstr="6.0 April 2007";#include "dropgsw2.h"#define DROP_INTERN#include "drop_func.h"struct swstr {int H, E;};extern void init_karlin(const unsigned char *aa0, int n0, struct pstruct *ppst,			double *aa0_f, double **kp);extern int do_karlin(const unsigned char *aa1, int n1,		     int **pam2, struct pstruct *ppst,		     double *aa0_f, double *kar_p, double *lambda, double *H);extern intNW_ALIGN(int IW, const unsigned char *B,      int M, int N,      int **W, int G, int H, int *res, int *nres,      struct f_struct *f_str);static intFGLOBAL_ALIGN(int *pwaa, const unsigned char *aa1,	      int n0, int n1,	      int GG,int HH,	      struct swstr *ss);static void DISPLAY(const unsigned char *A, const unsigned char *B, 	     int M, int N,	     int *S, int AP, int BP, char *sq);extern void aancpy(char *to, char *from, int count, struct pstruct *ppst);/* initialize for Smith-Waterman optimal score */voidinit_work (unsigned char *aa0, int n0,	   struct pstruct *ppst,	   struct f_struct **f_arg){  int maxn0, ip;  int *pwaa_s, *pwaa_a;  int e, f, i, j, l;  int *res;  struct f_struct *f_str;  int **pam2p;  struct swstr *ss;  int nsq;  if (ppst->ext_sq_set) {    nsq = ppst->nsqx; ip = 1;  }  else {    nsq = ppst->nsq; ip = 0;  }  /* initialize range of length appropriate */  if (ppst->n1_low == 0) ppst->n1_low = (int)(0.8 * (float)n0 + 0.5);#if defined(GLOBAL_GLOBAL) && !defined(GLOBAL0)  if (ppst->n1_high == BIGNUM) ppst->n1_high = (int)(1.25 * (float)n0 - 0.5);#else  ppst->n1_high = BIGNUM;#endif  /* allocate space for function globals */  f_str = (struct f_struct *)calloc(1,sizeof(struct f_struct));  if(ppst->zsflag == 6 || ppst->zsflag == 16) {    f_str->kar_p = NULL;    init_karlin(aa0, n0, ppst, &f_str->aa0_f[0], &f_str->kar_p);  }    /* allocate space for the scoring arrays */  if ((ss = (struct swstr *) calloc (n0+2, sizeof (struct swstr)))      == NULL) {    fprintf (stderr, "cannot allocate ss array %3d\n", n0);    exit (1);  }  ss++;  f_str->ss = ss;  /* initialize variable (-S) pam matrix */  if ((f_str->waa_s= (int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {    fprintf(stderr,"cannot allocate waa_s array %3d\n",nsq*n0);    exit(1);  }  /* initialize pam2p[1] pointers */  if ((f_str->pam2p[1]= (int **)calloc((n0+1),sizeof(int *))) == NULL) {    fprintf(stderr,"cannot allocate pam2p[1] array %3d\n",n0);    exit(1);  }  pam2p = f_str->pam2p[1];  if ((pam2p[0]=(int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {    fprintf(stderr,"cannot allocate pam2p[1][] array %3d\n",nsq*n0);    exit(1);  }  for (i=1; i<n0; i++) {    pam2p[i]= pam2p[0] + (i*(nsq+1));  }  /* initialize universal (alignment) matrix */  if ((f_str->waa_a= (int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {    fprintf(stderr,"cannot allocate waa_a struct %3d\n",nsq*n0);    exit(1);  }     /* initialize pam2p[0] pointers */  if ((f_str->pam2p[0]= (int **)calloc((n0+1),sizeof(int *))) == NULL) {    fprintf(stderr,"cannot allocate pam2p[1] array %3d\n",n0);    exit(1);  }  pam2p = f_str->pam2p[0];  if ((pam2p[0]=(int *)calloc((nsq+1)*(n0+1),sizeof(int))) == NULL) {    fprintf(stderr,"cannot allocate pam2p[1][] array %3d\n",nsq*n0);    exit(1);  }  for (i=1; i<n0; i++) {    pam2p[i]= pam2p[0] + (i*(nsq+1));  }  /*      pwaa effectively has a sequence profile --     pwaa[0..n0-1] has pam score for residue 0 (-BIGNUM)     pwaa[n0..2n0-1] has pam scores for residue 1 (A)     pwaa[2n0..3n-1] has pam scores for residue 2 (R), ...     thus: pwaa = f_str->waa_s + (*aa1p++)*n0; sets up pwaa so that     *pwaa++ rapidly moves though the scores of the aa1p[] position     without further indexing     For a real sequence profile, pwaa[0..n0-1] vs ['A'] could have     a different score in each position.  */  if (ppst->pam_pssm) {    pwaa_s = f_str->waa_s;    pwaa_a = f_str->waa_a;    for (e = 0; e <=nsq; e++)	{	/* for each residue in the alphabet */      for (f = 0; f < n0; f++) {	/* for each position in aa0 */	*pwaa_s++ = f_str->pam2p[ip][f][e] = ppst->pam2p[ip][f][e];	*pwaa_a++ = f_str->pam2p[0][f][e]  = ppst->pam2p[0][f][e];      }    }  }  else {	/* initialize scanning matrix */    pwaa_s = f_str->waa_s;    pwaa_a = f_str->waa_a;    for (e = 0; e <=nsq; e++)	/* for each residue in the alphabet */      for (f = 0; f < n0; f++)	{	/* for each position in aa0 */	*pwaa_s++ = f_str->pam2p[ip][f][e]= ppst->pam2[ip][aa0[f]][e];	*pwaa_a++ = f_str->pam2p[0][f][e] = ppst->pam2[0][aa0[f]][e];      }  }  /* these structures are used for producing alignments */  /* minimum allocation for alignment */  f_str->max_res = max(3*n0/2,MIN_RES);  *f_arg = f_str;}void close_work (const unsigned char *aa0, int n0,		 struct pstruct *ppst,		 struct f_struct **f_arg){  struct f_struct *f_str;  f_str = *f_arg;  if (f_str != NULL) {    if (f_str->kar_p !=NULL) free(f_str->kar_p);    f_str->ss--;    free(f_str->ss);    free(f_str->waa_a);    free(f_str->pam2p[0][0]);    free(f_str->pam2p[0]);    free(f_str->waa_s);    free(f_str->pam2p[1][0]);    free(f_str->pam2p[1]);#if defined(SW_ALTIVEC) || defined(SW_SSE2)    free(f_str->workspace_memory);    free(f_str->word_score_memory);    free(f_str->byte_score_memory);#endif    free(f_str);    *f_arg = NULL;  }}/* pstring1 is a message to the manager, currently 512 *//*void get_param(struct pstruct *pstr,char *pstring1)*/voidget_param (struct pstruct *ppst, char **pstring1, char *pstring2) {  char pg_str[120];  char psi_str[120];#ifdef NW_SSE2  char *pg_desc = "Needelman-Wunsch (SSE2, Michael Farrar 2006)";#else#if !defined(GLOBAL0) #if defined(GLOBAL_GLOBAL)   char *pg_desc = "Global/Global Needleman-Wunsch (2007)";#else  char *pg_desc = "Global/Local Needleman-Wunsch (2007)";#endif#else  char *pg_desc = "Global0/Local Needleman-Wunsch (2007)";#endif#endif  strncpy(pg_str, pg_desc,  sizeof(pg_str));  if (ppst->pam_pssm) { strncpy(psi_str,"-PSI",sizeof(psi_str));}  else { psi_str[0]='\0';}  sprintf (pstring1[0], "%s (%s)", pg_str, verstr);  sprintf (pstring1[1], #ifdef OLD_FASTA_GAP	   "%s matrix%s (%d:%d)%s, gap-penalty: %d/%d",#else	   "%s matrix%s (%d:%d)%s, open/ext: %d/%d",#endif	   ppst->pamfile, psi_str, ppst->pam_h,ppst->pam_l, 	   (ppst->ext_sq_set)?"xS":"\0", ppst->gdelval, ppst->ggapval);   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",#else     sprintf(pstring2,"; pg_name: %s\n; pg_ver: %s\n; pg_matrix: %s (%d:%d)%s\n; pg_open-ext: %d %d\n",#endif	     pg_str,verstr,psi_str,ppst->pam_h,ppst->pam_l, 	     (ppst->ext_sq_set)?"xS":"\0",ppst->gdelval,ppst->ggapval);   }}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     score;  double lambda, H;  int i;    score = FGLOBAL_ALIGN(f_str->waa_s,aa1,n0,n1,#ifdef OLD_FASTA_GAP                       -(ppst->gdelval - ppst->ggapval),#else                       -ppst->gdelval,#endif                       -ppst->ggapval,f_str->ss);  rst->score[0] = score;  if(( ppst->zsflag == 6 || ppst->zsflag == 16) &&

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -