ACNUC C API example

/*

SIMPLE EXAMPLE OF ACCESS TO SEQUENCES AND THEIR ANNOTATION WITH THE C ACNUC API

PROGRAMME EXECUTION ENVIRONMENT
setenv acnuc pathname-of-dir-containing-acnuc-index-files
setenv gcgacnuc pathname-of-dir-containing-seq-data-files

*/

/* ALWAYS NECESSARY */
#include "dir_acnuc.h"

int main(void)
{
char name[WIDTH_MAX]; /* ENOUGH FOR SEQ NAMES */
char seq[10001], *p;
int tot, num, lseq, deb, div, i, frame, code;
off_t annot;

/* OPEN THE DATABASE */
acnucopen();  /* simpleopen() would be enough here */

do 	{
	printf("Sequence name? ");
	scanf("%s",name); /* case is ignored */

/* FROM NAME, GET THE ACNUC RANK (NUM), AND THE SEQUENCE LENGTH (LSEQ) */
	num=gsnuml(name,&lseq,NULL,NULL);
/* A RETURNED RANK OF 0 MEANS THAT SEQUENCE DOES NOT EXIST */
	if(num==0)exit(0);

/* READING SEQ BY 60-BASE PIECES. READING BY SMALL OR BIG PIECES IS
POSSIBLE BECAUSE THERE IS AN INTERNAL BUFFER */
	for(deb=1; deb <= lseq; deb += 60) {
/* gfrag IS THE MAIN ACNUC SEQUENCE READING FUNCTION
1ST ARG: SEQ RANK; 2ND ARG: NUMBER IN SEQ OF THE FIRST DESIRED BASE OR AA;
3RD ARG: NUMBER OF DESIRED BASES OR AA; 
4TH ARG: RETURNED FILLED WITH READ BASES OR AA AND 0-TERMINATED
         SHOULD BE TRANSMITTED BY THE CALLER LARGE ENOUGH TO HOLD THESE DATA
RETURNED VALUE: NUMBER OF EFFECTIVELY RETURNED BASES OR AA */
		tot=gfrag(num,deb,60,seq);
		printf("%s\n",seq);
		}

	printf("\nTranslation of the first 60 bases:\n");
/* AA TRANSLATION:
FUNCTION GSNUML RETURNS ALSO THE READING FRAME (0,1 OR 2) AND THE 
GENETIC CODE ID (0 IS THE STANDARD CODE) */
	num=gsnuml(name,&lseq,&frame,&code);
/* SEE THE USE OF FRAME TO ACCESS THE CORRECT READING FRAME OF THE CODING SEQ*/
	tot=gfrag(num,frame+1,60,seq);
/* TRANSMIT TO FUNCTION CODAA SUCCESSIVE CODONS AND GET THE CORRESPONDING AA */
	for(i=0;i<tot-2;i+=3)
		printf("%c",codaa(seq+i,code));
	printf("\n");

/* ACCESS TO A SHORT DESCRIPTION OF A PARENT OR SUBSEQUENCE
1ST ARG: SEQ RANK; 2ND ARG: RETURNED FILLED WITH THE DESCRIPTION;
3RD ARG: MAX NUMBER OF CHARS TO FILL
RETURNED VALUE: POINTER TO 2ND ARG */
	printf("\nDescription:\n%s\n",short_descr(num,seq,80));

/* OTHER FORM OF BRIEF DESCRIPTION: SAME AS SHORT_DESCR FOR PARENT SEQUENCES;
THOSE OF THEIR PARENT FOR SUBSEQUENCES */
	printf("\nParent's description:\n%s\n",short_descr_p(num,seq,100));

/* PREPARE ACCESS TO THE FIRST LINE OF ANNOTATION ASSOCIATED 
TO A SEQ OF RANK NUM */
	seq_to_annots64(num, &annot, &div);

/* READ THIS FIRST LINE AND THE 9 FOLLOWING LINES 
THAT ARE GENERALLY <= 80 CHARS LONG */
	printf("\nBeginning of sequence's annotation:\n");
	p = read_annots64(annot, div);
	printf("%s\n",p);
	for(i=1;i<10;i++) {
		p = next_annots64(NULL);
		printf("%s\n",p);
		}
	}
while(1);
}