static EmbPEntry dbiblast_nextblastentry(PBlastDb db, ajint ifile, const AjPStr idformat, AjBool systemsort, AjPStr const * fields, ajint * maxFieldLen, ajuint* maxidlen, ajuint* countfield, AjPFile elistfile, AjPFile * alistfile) { ajint i; static ajint lastfile = -1; static ajint iparser = -1; static ajint called = 0; static ajuint tabhdr[TABLESIZE]; static ajint iload = TABLESIZE-1; static ajint irest = 0; static ajint ipos = 0; static ajint jpos = 0; ajint ir; ajint j; static ajint is = 0; char* token; static ajint nfields; ajint ifield; if(!called) { for(i=0; parser[i].Name; i++) if(ajStrMatchC(idformat, parser[i].Name)) { iparser = i; break; } if(iparser < 0) ajFatal("idformat '%S' unknown", idformat); ajDebug("idformat '%S' Parser %d\n", idformat, iparser); ajStrSetRes(&id, HDRSIZE); ajStrSetRes(&acc, HDRSIZE); ajStrSetRes(&hline, HDRSIZE); called = 1; } if(!fdl) { nfields=0; while(fields[nfields]) nfields++; if(nfields) AJCNEW(fdl, nfields); for(i=0; i < nfields; i++) fdl[i] = ajListNew(); } if(lastfile != ifile) { lastfile = ifile; ipos = 1; /* isize = 0;*/ irest = 0; iload = TABLESIZE-1; } if(!dbiblastEntry || !systemsort) dbiblastEntry = embDbiEntryNew(nfields); /* pick up the next entry, parse it and dump it */ if(ipos > db->Size) return NULL; if( ipos >= irest) { ajDebug("ipos: %d iload: %d irest: %d\n", ipos, iload, irest); irest = ipos + TABLESIZE - 2; if(irest > db->Size) { iload = db->Size - ipos + 1; irest = db->Size; } jpos=0; j = dbiblast_loadtable(tabhdr, iload, db, db->TopHdr, ipos-1); if(!j) ajDebug("No elements read"); } j = dbiblast_ncblreadhdr(&hline, db, tabhdr[jpos], tabhdr[jpos+1]); if(!parser[iparser].Parser(hline, alistfile, systemsort, fields, maxFieldLen, countfield, &id, fdl)) ajFatal("failed to parse '%S'", hline); ir = ipos; if(ajStrGetLen(id) > *maxidlen) *maxidlen = ajStrGetLen(id); if(systemsort) ajFmtPrintF(elistfile, "%S %d %d %d\n", id, ir, is, ifile+1); else { dbiblastEntry->entry = ajCharNewS(id); dbiblastEntry->rpos = ir; dbiblastEntry->spos = is; dbiblastEntry->filenum = ifile+1; /* field tokens as list, then move to dbiblastEntry->field */ for(ifield=0; ifield < nfields; ifield++) { dbiblastEntry->nfield[ifield] = ajListGetLength(fdl[ifield]); if(dbiblastEntry->nfield[ifield]) { AJCNEW(dbiblastEntry->field[ifield], dbiblastEntry->nfield[ifield]); i = 0; while(ajListPop(fdl[ifield], (void**) &token)) dbiblastEntry->field[ifield][i++] = token; } else dbiblastEntry->field[ifield] = NULL; } } ipos++; jpos++; return dbiblastEntry; }
static EmbPEntry dbifasta_NextFlatEntry(AjPFile libr, ajint ifile, AjPRegexp idexp, ajuint type, AjBool systemsort, AjPStr const * fields, ajint* maxFieldLen, ajuint* maxidlen, ajuint* countfield, AjPFile elistfile, AjPFile* alistfile) { ajint ir; ajint is = 0; char* token; ajint i; static ajint nfields; ajint ifield; if(!dbifastaGFdl) { nfields = 0; while(fields[nfields]) nfields++; if(nfields) AJCNEW(dbifastaGFdl, nfields); for(i=0; i < nfields; i++) { dbifastaGFdl[i] = ajListNew(); } } if(!dbifastaGEntry || !systemsort) dbifastaGEntry = embDbiEntryNew(nfields); if(!dbifasta_ParseFasta(libr, &ir, maxFieldLen, countfield, idexp, type, alistfile, systemsort, fields)) return NULL; /* id to dbifastaGEntry->entry */ if(ajStrGetLen(dbifastaGTmpId) > *maxidlen) *maxidlen = ajStrGetLen(dbifastaGTmpId); if(systemsort) ajFmtPrintF(elistfile, "%S %d %d %d\n", dbifastaGTmpId, ir, is, ifile+1); else { dbifastaGEntry->entry = ajCharNewS(dbifastaGTmpId); dbifastaGEntry->rpos = ir; dbifastaGEntry->spos = is; dbifastaGEntry->filenum = ifile+1; /* field tokens as list, then move to ret->field */ for(ifield=0; ifield < nfields; ifield++) { dbifastaGEntry->nfield[ifield] = (ajuint) ajListGetLength(dbifastaGFdl[ifield]); if(dbifastaGEntry->nfield[ifield]) { AJCNEW(dbifastaGEntry->field[ifield], dbifastaGEntry->nfield[ifield]); i = 0; while(ajListPop(dbifastaGFdl[ifield], (void**) &token)) dbifastaGEntry->field[ifield][i++] = token; } else dbifastaGEntry->field[ifield] = NULL; } } return dbifastaGEntry; }