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

📄 pgsql_lib.c

📁 序列对齐 Compare a protein sequence to a protein sequence database or a DNA sequence to a DNA sequenc
💻 C
📖 第 1 页 / 共 2 页
字号:
    /* have get_desc, copy it */    else {      strcpy(m_fptr->sql_getdesc,bps);      *bp=';'; /* replace ; */      bps = bp+1;      while(isspace(*bps)) bps++;    }  }  else {    fprintf(stderr," cannot find getdesc field:\n%s\n",tmp_str);    goto error_r;  }  if ((bp=strchr(bps,';'))!=NULL) { *bp='\0';}  if ((m_fptr->sql_getseq=calloc(strlen(bps)+1,sizeof(char)))==NULL) {    fprintf(stderr, " cannot allocate space for database name [%d], %s\n",	    strlen(bps),bps);    goto error_r;  }  if (strlen(bps) > 0) {    strcpy(m_fptr->sql_getseq,bps);  }  else {    fprintf(stderr," cannot find getseq field:\n%s\n",tmp_str);    return NULL;  }  if (bp!=NULL) *bp=';';  /* now do the fetch */  res = PQexec(m_fptr->pgsql_conn,"BEGIN;");  if (PQresultStatus(res) != PGRES_COMMAND_OK) {    fprintf(stderr,"*** Error %s - BEGIN failed:\n",	    PQerrorMessage(conn));    PQclear(res);    goto error_r;  }  PQclear(res);  res = PQexec(m_fptr->pgsql_conn, m_fptr->sql_query);  if (PQresultStatus(res) != PGRES_COMMAND_OK) {    fprintf(stderr,"*** Error %d:%s - query failed:\n%s\n",	    PQresultStatus(res),PQerrorMessage(conn), m_fptr->sql_query);    PQclear(res);    goto error_r;  }  PQclear(res);  m_fptr->pgsql_res=NULL;  return m_fptr; error_r:  free(m_fptr->sql_getseq);  free(m_fptr->sql_getdesc);  free(m_fptr->sql_query);  free(m_fptr);  free(sql_db);  return NULL;}struct lmf_str *pgsql_reopen(struct lmf_str *m_fptr) {  m_fptr->sql_reopen = 1;  return m_fptr;}voidpgsql_closelib(struct lmf_str *m_fptr) {  if (m_fptr == NULL) return;  if (m_fptr->pgsql_res != NULL) PQclear(m_fptr->pgsql_res);  PQfinish(m_fptr->pgsql_conn);  m_fptr->sql_reopen=0;}/*static char *sql_seq = NULL, *sql_seqp;static int sql_seq_len;*/intpgsql_getlib( unsigned char *seq,	      int maxs,	      char *libstr,	      int n_libstr,	      fseek_t *libpos,	      int *lcont,	      struct lmf_str *lm_fd,	      long *l_off){  register unsigned char *cp, *seqp;  register int *ap;  unsigned char *seqm, *seqm1;  PGresult *res;  char *bp;  /*   int l_start, l_stop, len; */  seqp = seq;  seqm = &seq[maxs-9];  seqm1 = seqm-1;  ap = lm_fd->sascii;#ifdef SUPERFAMNUM  sfnum[0]=nsfnum = 0;#endif  if (*lcont==0) {    /* get a row, with UID, sequence */    *l_off = 1;    /* check to see if we already have a valid result */    if (lm_fd->pgsql_res==NULL) {      res = PQexec(lm_fd->pgsql_conn,"FETCH next_seq");      if (PQresultStatus(res) != PGRES_TUPLES_OK) {	fprintf(stderr,"*** Error %s - getlib FETCH failed:\n%s\n",		PQerrorMessage(lm_fd->pgsql_conn), lm_fd->sql_query);	PQclear(res);	lm_fd->pgsql_res = NULL;	*lcont = 0;	*seqp = EOSEQ;	return -1;      }    }    else {res = lm_fd->pgsql_res;}    if (PQntuples(res)>0) {      lm_fd->pgsql_res = res;      *libpos=(fseek_t)atol(PQgetvalue(res,0,0));	      *l_off = 1;      if (PQnfields(res) > 2 && (bp=strchr(PQgetvalue(res,0,2),'@'))!=NULL &&	  !strncmp(bp+1,"C:",2)) sscanf(bp+3,"%ld",l_off);      lm_fd->sql_seqp = PQgetvalue(res,0,1);          /* because of changes in pgsql_ranlib(), it is essential that         libstr return the unique identifier; thus we must use         sql_row[0], not sql_row[2]. Using libstr as the UID allows         one to use any UID, not just numeric ones.  *libpos is not         used for pgsql libraries.      */      if (n_libstr <= MAX_UID) {	/* the normal case returns only GID/sequence */	strncpy(libstr,PQgetvalue(res,0,0),MAX_UID-1);	libstr[MAX_UID-1]='\0';      }      else {	/* here we do not use the UID in libstr, because we are not           going back into the db */	/* the PVM case also returns a long description */	if (PQnfields(res)>2) {	  strncpy(libstr,PQgetvalue(res,0,2),n_libstr-1);	}	else {	  strncpy(libstr,PQgetvalue(res,0,0),n_libstr-1);	}	libstr[n_libstr-1]='\0';      }    }    else {      PQclear(lm_fd->pgsql_res);      lm_fd->pgsql_res=NULL;      *lcont = 0;      *seqp = EOSEQ;      return -1;    }  }  for (cp=(unsigned char *)lm_fd->sql_seqp; seqp<seqm1 && *cp; ) {    if ((*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA &&	(*seqp++=ap[*cp++])<NA) continue;    --seqp;    if (*(cp-1)==0) break;  }  lm_fd->sql_seqp = (char *)cp;  if (seqp>=seqm1) (*lcont)++;  else {    *lcont=0;    PQclear(lm_fd->pgsql_res);    lm_fd->pgsql_res = NULL;  }  *seqp = EOSEQ;  /*   if ((int)(seqp-seq)==0) return 1; */  return (int)(seqp-seq);}voidpgsql_ranlib(char *str,	     int cnt,	     fseek_t libpos,	     char *libstr,	     struct lmf_str *lm_fd	     ){  char tmp_query[1024], tmp_val[20];  PGresult *res;  char *bp;  str[0]='\0';  /* put the UID into the query string - cannot use sprintf because of     "%' etc */  /*   sprintf(tmp_query,lm_fd->sql_getdesc,libpos); */  if ((bp=strchr(lm_fd->sql_getdesc,'#'))==NULL) {    fprintf(stderr, "no KEY position in %s\n",lm_fd->sql_getdesc);    goto next1;  }  else {    *bp = '\0';    strncpy(tmp_query,lm_fd->sql_getdesc,sizeof(tmp_query));    tmp_query[sizeof(tmp_query)-1]='\0';    /*    sprintf(tmp_val,"%ld",(long)libpos); */    strncat(tmp_query,libstr,sizeof(tmp_query)-1);    strncat(tmp_query,bp+1,sizeof(tmp_query)-1);    *bp='#';    lm_fd->lpos = libpos;  }  /*  fprintf(stderr," requesting: %s\n",tmp_query); */  if (lm_fd->pgsql_res !=NULL) {    PQclear(lm_fd->pgsql_res);    lm_fd->pgsql_res = NULL;  }  res = PQexec(lm_fd->pgsql_conn,tmp_query);  if (PQresultStatus(res) != PGRES_TUPLES_OK) {    lm_fd->pgsql_res = NULL;    sprintf(str,"gi|%ld ***Error - query failed***",(long)libpos);    fprintf(stderr,"*** Error %s - ranlib DESC failed:\n%s\n",	    PQerrorMessage(lm_fd->pgsql_conn), tmp_query);    PQclear(res);    goto next1;  }  if (PQntuples(res)<=0) {/*     fprintf(stderr,"*** Error = use result failed\n%s\n", 	   pgsql_error(lm_fd->pgsql_conn)); */    sprintf(str,"gi|%ld ***use result failed***",(long)libpos);    goto next0;  }  if (PQgetvalue(res,0,1)!= NULL) strncpy(str,PQgetvalue(res,0,1),cnt-1);  else strncpy(str,PQgetvalue(res,0,0),cnt-1);  str[cnt-1]='\0';  /* change this later to support multiple row returns */  /*  while (strlen(str) < cnt-1 &&	 (lm_fd->sql_row = pgsql_fetch_row(lm_fd->pgsql_res))!=NULL) {    strncat(str," ",cnt-2-strlen(str));    if (lm_fd->sql_row[1]!=NULL)       strncat(str,lm_fd->sql_row[1],cnt-2-strlen(str));    else break;  }  */  str[cnt-1]='\0';  if ((bp = strchr(str,'\r'))!=NULL) *bp='\0';  if ((bp = strchr(str,'\n'))!=NULL) *bp='\0'; next0:  PQclear(res); next1:   lm_fd->pgsql_res = NULL;  /* get the sequence, set up for pgsql_getseq() */  /* put the UID into the query string */  if ((bp=strchr(lm_fd->sql_getseq,'#'))==NULL) {    fprintf(stderr, "no GID position in %s\n",lm_fd->sql_getseq);    return;  }  else {    *bp = '\0';    strncpy(tmp_query,lm_fd->sql_getseq,sizeof(tmp_query));    tmp_query[sizeof(tmp_query)-1]='\0';    /*    sprintf(tmp_val,"%ld",(long)libpos); */    strncat(tmp_query,libstr,sizeof(tmp_query));    strncat(tmp_query,bp+1,sizeof(tmp_query));    *bp='#';  }  res = PQexec(lm_fd->pgsql_conn,tmp_query);  if (PQresultStatus(res) != PGRES_TUPLES_OK) {    PQclear(res);    lm_fd->pgsql_res = NULL;    fprintf(stderr,"*** Error - ranlib SEQ failed:\n%s\n%s\n",tmp_query,	    PQerrorMessage(lm_fd->pgsql_conn));    exit(1);  }  else {    lm_fd->pgsql_res = res;  }}

⌨️ 快捷键说明

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