1 /****************************************************************************
3 AGETBLOC - a routine to read an AMPS block file
5 Copyright: Geoffrey J. Barton (1992,1997)
9 Please see README for conditions of use.
11 ****************************************************************************
15 15th November 1992 - ANSI C version - also uses GJ... routines.
16 This version adapted with error messages for alscript.
19 Agetbloc: like getbloc, but does not require that every character read into
20 the seqs structure is an alphabetic character. Also does not contain the
21 option to convert the "sequences" read in into integer format
23 getbloc: Read an AMPS style block file into the seqs array
24 the nbloc aligned sequences are stored in positions 1-nbloc.
26 This is a straight-ish translation of the fortran routine fbloc.f, hence
27 the non-C like goto's...
29 Sequence lengths are actual length +1 + 1. This allows position 0 to
30 be reserved for future use, and preserves the '\0' for output.
32 18/Feb/1993:Fix (i) to (i+1) in realloc. Spotted by RBR.
34 $Id: agetbloc.c,v 1.2 1998/09/17 16:54:58 geoff Exp $
36 Revision 1.2 1998/09/17 16:54:58 geoff
37 Check consistency with archive
50 int Agetbloc(FILE *bfile,struct seqdat *bloc,int *nbloc)
54 extern int MAXnseq, MAXslen, MAXilen, MAXtlen, MAXnbloc;
56 extern FILE *std_in,*std_out,*std_err;
58 char *idstart, *idend, *bstart, sident = 0;
59 int idlen,totseq = 0,k,j;
61 buff = (char *) GJmalloc(sizeof(char) * MAXtlen);
64 buff = fgets(buff,MAXtlen,bfile);
66 fprintf(std_err,"Premature end of BLOCK FILE\n");
69 if((idstart = strchr(buff,'>')) != NULL){
70 if(++totseq == MAXnbloc){
72 "Max Number of block file sequences exceeded: %d\n",
74 fprintf(std_err,"Use MAX_NSEQ command to increase value");
78 idend = strchr(idstart,' ');
80 idend = strchr(idstart,'\0');
83 fprintf(std_err,"Error reading identifier:%s\n",idstart);
86 idlen = (idend - idstart) + 1;
87 bloc[totseq].id = (char *) malloc(sizeof(char) * idlen);
88 bloc[totseq].id = GJstrblank(bloc[totseq].id,idlen);
89 strncpy(bloc[totseq].id,idstart+1,idlen-1); /* don't copy the ">" symbol */
90 bloc[totseq].ilen = idlen-1;
91 bloc[totseq].id[idlen-1] = '\0';
93 bloc[totseq].tlen = strlen(idend)+1;
94 bloc[totseq].title = (char *) GJmalloc(sizeof(char) * bloc[totseq].tlen);
95 bloc[totseq].title = GJstrblank(bloc[totseq].title,bloc[totseq].tlen);
96 strcpy(bloc[totseq].title,idend);
98 bloc[totseq].seq = (char *) GJmalloc(sizeof(char) * MAXslen);
99 bloc[totseq].seq[0] = ' ';
102 if((idstart = strchr(buff,'*')) != NULL){
104 while((buff = fgets(buff,MAXtlen,bfile)) != NULL){
106 /* fprintf(stdout,"Blocfile read: Length: %d\n",i);*/
108 for(k=1;k<totseq+1;++k){
110 bloc[k].seq[i] = '\0';
111 bloc[k].seq = (char *) realloc(bloc[k].seq,sizeof(char)*(i+1)); /*i+1 fix suggested by rbr*/
119 if(i==MAXslen)error("Max Sequence length exceeded - use MAX_SEQ_LEN command to increase",1);
120 for(j=1;j<totseq+1;++j){
121 /*cope with short lines */
122 /* if(!isalnum(*bstart)) *bstart = ' '; */
123 bloc[j].seq[i] = *bstart++;
126 fprintf(std_err,"No terminating * in blocfile\n");