diff --git a/ebwt_search.cpp b/ebwt_search.cpp index 2de2d0b..c6ae53f 100644 --- a/ebwt_search.cpp +++ b/ebwt_search.cpp @@ -136,6 +136,7 @@ static const char * refMapFile = NULL; // file containing a map from index coo static const char * annotMapFile= NULL; // file containing a map from reference coordinates to annotations static size_t fastaContLen = 0; static size_t fastaContFreq = 0; +static bool hadoopOut = false; // print Hadoop status and summary messages // mating constraints @@ -212,7 +213,8 @@ enum { ARG_CHAININ, ARG_REFMAP, ARG_ANNOTMAP, - ARG_REPORTSE + ARG_REPORTSE, + ARG_HADOOPOUT }; static struct option long_options[] = { @@ -316,6 +318,7 @@ static struct option long_options[] = { {(char*)"refmap", required_argument, 0, ARG_REFMAP}, {(char*)"annotmap", required_argument, 0, ARG_ANNOTMAP}, {(char*)"reportse", no_argument, 0, ARG_REPORTSE}, + {(char*)"hadoopout", no_argument, 0, ARG_HADOOPOUT}, {(char*)0, 0, 0, 0} // terminator }; @@ -1448,6 +1451,7 @@ static void parseOptions(int argc, char **argv) { #endif } case ARG_MMSWEEP: mmSweep = true; break; + case ARG_HADOOPOUT: hadoopOut = true; break; case ARG_DUMP_NOHIT: dumpNoHits = new ofstream(".nohits.dump"); break; case ARG_DUMP_HHHIT: dumpHHHits = new ofstream(".hhhits.dump"); break; case ARG_AL: dumpAlBase = optarg; break; @@ -4484,7 +4488,7 @@ static void driver(const char * type, delete ebwtBw; } if(!quiet) { - sink->finish(); // end the hits section of the hit file + sink->finish(hadoopOut); // end the hits section of the hit file } if(dumpHHHits != NULL) dumpHHHits->close(); if(dumpNoHits != NULL) dumpNoHits->close(); diff --git a/hit.h b/hit.h index 15a7da7..353b1f9 100644 --- a/hit.h +++ b/hit.h @@ -588,7 +588,7 @@ class HitSink { * Called when all alignments are complete. It is assumed that no * synchronization is necessary. */ - void finish() { + void finish(bool hadoopOut) { // Close output streams closeOuts(); if(!quiet_) { @@ -634,6 +634,13 @@ class HitSink { << " singleton alignments to " << _outs.size() << " output stream(s)" << endl; } + if(hadoopOut) { + cerr << "reporter:counter:Bowtie,reads_with_at_least_1_alignment," << numAligned_ << endl; + cerr << "reporter:counter:Bowtie,reads_with_no_alignments," << numUnaligned_ << endl; + cerr << "reporter:counter:Bowtie,reads_over_dash_m_limit," << numMaxed_ << endl; + cerr << "reporter:counter:Bowtie,unpaired_alignments_reported," << numReported_ << endl; + cerr << "reporter:counter:Bowtie,paired_alignments_reported," << numReportedPaired_ << endl; + } } // Print the recalibration table. if(recalTable_ != NULL) { diff --git a/shmem.cpp b/shmem.cpp index e0cdc7b..49fdc9d 100644 --- a/shmem.cpp +++ b/shmem.cpp @@ -16,6 +16,9 @@ using namespace std; +#define SHMEM_UNINIT 0xafba4242 +#define SHMEM_INIT 0xffaa6161 + /** * Tries to allocate a shared-memory chunk for a given file of a given size. */ @@ -95,14 +98,15 @@ bool allocSharedMem(string fname, } } // while(true) *dst = ptr; - if(ds.shm_cpid == getpid()) { + bool initid = (((volatile uint32_t*)((char*)ptr + len))[0] == SHMEM_INIT); + if(ds.shm_cpid == getpid() && !initid) { if(verbose) { cerr << " I (pid = " << getpid() << ") created the " << "shared memory for " << memName << endl; } // Set this value just off the end of the chunk to // indicate that the data hasn't been read yet. - ((volatile uint32_t*)((char*)ptr + len))[0] = 0xffffffff; + ((volatile uint32_t*)((char*)ptr + len))[0] = SHMEM_UNINIT; return true; } else { if(verbose) { @@ -119,7 +123,7 @@ bool allocSharedMem(string fname, * finished initializing it. */ void notifySharedMem(void *mem, size_t len) { - ((volatile uint32_t*)((char*)mem + len))[0] = 0x0f0f0f0f; + ((volatile uint32_t*)((char*)mem + len))[0] = SHMEM_INIT; } /** @@ -127,8 +131,8 @@ void notifySharedMem(void *mem, size_t len) { * initializing it. */ void waitSharedMem(void *mem, size_t len) { - while(((volatile uint32_t*)((char*)mem + len))[0] != 0x0f0f0f0f) { - // spin + while(((volatile uint32_t*)((char*)mem + len))[0] != SHMEM_INIT) { + sleep(1); } } diff --git a/str_util.h b/str_util.h index 00e84d4..8587ff1 100644 --- a/str_util.h +++ b/str_util.h @@ -13,7 +13,14 @@ hash_string(const std::string& s) { int b = 378551; for(size_t i = 0; i < s.length(); i++) { ret = (ret * a) + (int)s[i]; - a *= b; + if(a == 0) { + a += b; + } else { + a *= b; + } + if(a == 0) { + a += b; + } } return ret; }