/* This program retrieves one (or actually a few) records from a GenBank * file. */ #include "common.h" #include "linefile.h" void usage() /* Explain usage and exit. */ { errAbort( "gbOneAcc - retrieve one or a few records from a GenBank flat file.\n" "usage:\n" " gbOneAcc gbFile acc(s)\n" "The output will be printed to standard out"); } void unexpectedEof(struct lineFile *lf) /* Complain about unexpected EOF and die. */ { errAbort("Unexpected end of file line %d of %s", lf->lineIx, lf->fileName); } void extractAccFromGb( char *gbName, char **accNames, int accCount) /* Parse records of genBank file and print ones that match accession names. */ { struct lineFile *lf = lineFileOpen(gbName, TRUE); FILE *out = stdout; enum {maxHeadLines=200, headLineSize=256 }; char *headLines[maxHeadLines]; /* Store stuff between locus and accession. */ char *line; int lineSize; int i; for (i=0; i= headLineSize) errAbort("Line too long (%d chars) line %d of %s", lineSize, lf->lineIx, lf->fileName); strcpy(headLines[i], line); if (!lineFileNext(lf, &line, &lineSize)) unexpectedEof(lf); if (startsWith("ACCESSION", line)) { gotAcc = TRUE; break; } } if (!gotAcc) { errAbort("LOCUS without ACCESSION in %d lines at line %d of %s", maxHeadLines, lf->lineIx, lf->fileName); } for (i=0; i