Skip to content

Commit

Permalink
lcpbit file creationi completed
Browse files Browse the repository at this point in the history
  • Loading branch information
giovmanz committed Jan 11, 2019
1 parent 9b0876f commit 9a8e9cc
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 17 additions & 4 deletions gap.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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':
Expand All @@ -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);
Expand Down
18 changes: 8 additions & 10 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
Expand Down Expand Up @@ -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");
Expand Down
4 changes: 2 additions & 2 deletions io.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ 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);
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
7 changes: 3 additions & 4 deletions merge128ext.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
4 changes: 1 addition & 3 deletions util.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;i<g->numBwt;i++) assert(g->inCnt[i]==g->bwtLen[i]);

Expand Down

0 comments on commit 9a8e9cc

Please sign in to comment.