diff --git a/config.h b/config.h index 84e03c5..ac61c73 100644 --- a/config.h +++ b/config.h @@ -135,7 +135,7 @@ typedef struct { FILE *unsortedLcp; // if !NULL file containing unsorted LCP values FILE *unsortedLcp_size; // if !NULL file containing the size of sorted blocks in unsorted_Lcp bool smallAlpha; // the alphabet is small - int extMem; // run in external memory: if ==1 only keep BWTs in external memory + bool extMem; // if true run in external memory int algorithm; // preferred algorithm to use: gap8 gap16 gap128 gap256, if!=8,16,128,256 then use gap bool mmapZ; // mmap Z arrays bool mmapB; // mmap B array diff --git a/gap.c b/gap.c index 1ac8ba8..ce04021 100644 --- a/gap.c +++ b/gap.c @@ -61,8 +61,8 @@ int main(int argc, char *argv[]) { bool hm = false; g.unsortedLcp = NULL; g.outPath = NULL; - g.extMem = g.algorithm = 0; - g.smallAlpha=g.mmapZ=g.mmapBWT=g.mmapB= g.lcpMerge = g.lcpCompute = false; + g.algorithm = 0; + g.extMem = g.smallAlpha=g.mmapZ=g.mmapBWT=g.mmapB= g.lcpMerge = g.lcpCompute = false; g.outputDA = 0; g.dbOrder = 0; // order for deBruijn graph int num_threads = 0; @@ -103,8 +103,7 @@ int main(int argc, char *argv[]) { num_threads = atoi(optarg); // number of consumer threads break; case 'E': - g.extMem++; - break; // use external memory (see mergegap.c) + g.extMem=true; break; // use external memory (see mergegap.c) case 'Z': g.mmapZ=true; break; // mmap merge and newmerge case 'B': @@ -117,6 +116,20 @@ int main(int argc, char *argv[]) { exit(EXIT_FAILURE); } } + if(g.dbOrder<0 || g.dbOrder==1) { // illegal order + printf("dbOrder must be al least 2\n"); + exit(EXIT_FAILURE); + } + if(g.dbOrder>1) { // valid order !=0 + if(!g.extMem) { + printf("Option -D forces option -E\n"); + g.extMem = true; + } + if(g.algorithm!=128) { + printf("Option -D forces option -A 128\n"); + g.algorithm = 128; + } + } if(num_threads <0) { printf("Invalid number of threads, must be non negative\n"); exit(EXIT_FAILURE); diff --git a/io.c b/io.c index bca0f48..04bbbb8 100644 --- a/io.c +++ b/io.c @@ -181,12 +181,11 @@ void bitfile_flush(bitfile *b) // init a bitfile: opening file and filling it with size zero bits // if temp==true the file is anonymous and immediately deleted, otherwise // the file has .bitfile extension and maintained after the end of the computation -void bitfile_create(bitfile *b, size_t size, char *path, bool temp) { +void bitfile_create(bitfile *b, size_t size, char *path, int order) { // create local copy of template - char s[strlen(path)+11]; - if(temp) { // if this is a temp file create unique name + char s[Filename_size]; + if(order==0) { // if this is a temp file create unique name sprintf(s,"%s.bitXXXXXX",path); - assert(strlen(s)==strlen(path) + 10); // get file descriptor for tmp file fill it with 0s and delete file b->fd = mkstemp(s); if(b->fd == -1) die("bitfile_create: Tempfile creation failed"); @@ -196,11 +195,10 @@ void bitfile_create(bitfile *b, size_t size, char *path, bool temp) { if(e!=0) die("bitfile_create: Tempfile unlink failed"); } else { // we keep this file (to compute the DB-graph) - sprintf(s,"%s.bitfile1",path); - assert(strlen(s)==strlen(path) + 9); + sprintf(s,"%s.%d.lcpbit1",path,order); // get file descriptor for bitfile fill it with 0s b->fd = open(s,O_RDWR|O_CREAT|O_TRUNC, 0666); - if(b->fd == -1) die("bitfile_create: bitfileq creation failed"); + if(b->fd == -1) die("bitfile_create: bitfile creation failed"); int e = ftruncate(b->fd,(size+7)/8); // fill with size 0 bits if(e!=0) die("bitfile_create: bitfile ftruncate failed"); } @@ -281,12 +279,12 @@ off_t bitfile_tell(bitfile *b) { // save hi bit of name to bitfile0 // used for extracting info for dbGraph -void extract_bitfile(char *name, size_t size, char *outpath) +void extract_bitfile(char *name, size_t size, char *outpath, int order) { FILE *f = fopen(name,"rb"); if(f==NULL) die("extract_bitfile: unable to open input file"); - char s[strlen(outpath) + 10]; - sprintf(s,"%s.bitfile0",outpath); + char s[Filename_size]; + sprintf(s,"%s.%d.lcpbit0",outpath,order); assert(strlen(s)==strlen(outpath) + 9); FILE *g = fopen(s,"wb"); if(f==NULL) die("extract_bitfile: unable to open output file"); diff --git a/io.h b/io.h index 221c41e..d09b5b4 100644 --- a/io.h +++ b/io.h @@ -37,7 +37,7 @@ typedef struct{ } bitfile; void bitfile_flush(bitfile *b); -void bitfile_create(bitfile *b, size_t size, char *path, bool); +void bitfile_create(bitfile *b, size_t size, char *path, int); void bitfile_destroy(bitfile *b); void bitfile_rewind(bitfile *b); bool bitfile_read_or_write(bitfile *b, bool new); @@ -45,7 +45,7 @@ void bitfile_skip(bitfile *b, uint64_t s); off_t bitfile_tell(bitfile *b); // used for extract hi bit from mergefile for later dbGraph construction -void extract_bitfile(char *name, size_t size, char *outpath); +void extract_bitfile(char *name, size_t size, char *outpath, int order); #endif diff --git a/merge128ext.h b/merge128ext.h index 77ea37a..384e86d 100644 --- a/merge128ext.h +++ b/merge128ext.h @@ -205,8 +205,7 @@ void gap128ext(g_data *g, bool lastRound) { open_bw_files(g); // create 0 initialized bitfile (reading and writing using bitfile_* functions) bitfile b; - if(g->dbOrder>1) bitfile_create(&b,g->mergeLen,g->outPath,false); - else bitfile_create(&b,g->mergeLen,g->outPath,true); + bitfile_create(&b,g->mergeLen,g->outPath,g->dbOrder); // allocate Z (merge) Znew (reading only Z, writing only newZ) alloc_merge_arrays(g); @@ -248,7 +247,7 @@ void gap128ext(g_data *g, bool lastRound) { // update solid block files: rewind(ibList->fout); ibList->fin = ibList->fout; - } while(!merge_completed && (prefixLength!=g->dbOrder+1)); // end main loop + } while(!merge_completed && (prefixLength!=g->dbOrder)); // end main loop if(ibList->fin!=NULL) fclose(ibList->fin); if (g->verbose>0) { @@ -270,7 +269,7 @@ void gap128ext(g_data *g, bool lastRound) { // for dbGraph info we need to extract the hi bit from the merge arrray if(g->dbOrder>1) - extract_bitfile(g->merge_fname, g->mergeLen, g->outPath); + extract_bitfile(g->merge_fname, g->mergeLen, g->outPath, g->dbOrder); // computation complete, do the merging. // The following call writes the merged BWT back to file g->bwfname diff --git a/util.c b/util.c index 8a007c2..3d15ff8 100644 --- a/util.c +++ b/util.c @@ -331,7 +331,6 @@ void mergeBWT128ext(g_data *g, bool lastRound) if(sizeof(symbol)>sizeof(palette)) die("Sorry, alphabet is too large (mergeBWT128ext"); assert(!g->lcpMerge && g->extMem && g->numBwt<=128); FILE *daOutFile=NULL; - check_g_data(g); array_clear(g->inCnt,g->numBwt,0); if(g->outputDA && lastRound) @@ -377,8 +376,7 @@ void mergeBWT128ext(g_data *g, bool lastRound) g->inCnt[currentColor]++; // one more char read from currentColor BWT } close_bw_files(g); - if(g->outputDA) - close_da_files(g); + if(g->outputDA && lastRound) close_da_files(g); // final check on the merging for(int i=0;inumBwt;i++) assert(g->inCnt[i]==g->bwtLen[i]);