/* bwtFind - Figure out if a string is in bwt transformed text.. */ #include "common.h" #include "linefile.h" #include "hash.h" #include "options.h" #include "obscure.h" void usage() /* Explain usage and exit. */ { errAbort( "bwtFind - Figure out if a string is in bwt transformed text.\n" "usage:\n" " bwtFind text.bwt string\n" "options:\n" " -xxx=XXX\n" ); } static struct optionSpec options[] = { {NULL, 0}, }; int _findOcc(UBYTE *bwt, UBYTE c, bits32 *occ, bits32 *counts, int pos) /* Use occ array to help find the number of characters c that * occur in bwt before position. */ { if (pos <= 0) return -1; if (counts[c] == 0) return 0; while (pos > 0) { if (bwt[pos] == c) return occ[pos]; --pos; } return 0; } int findOcc(UBYTE *bwt, UBYTE c, int pos) { if (pos < 0) return 0; int i; int count = 0; for (i=0; i<=pos; ++i) if (bwt[i] == c) ++count; return count; } int bwtSearch(UBYTE *bwt, bits32 size, char *string) /* Reverse Burrows Wheeler transform of string. */ { /* Empty case is easy here (and a pain if we have to deal with it later) */ if (size == 0) return 0; /* Make array that will store the count of occurences of each character up to a given position. */ bits32 *occ; AllocArray(occ, size+1); /* Count up occurences of all characters into offset array. */ bits32 i, counts[256], offsets[256]; for (i=0; i<256; ++i) counts[i] = 0; for (i=0; i