diff options
author | Alexandre Mestiashvili <alex@biotec.tu-dresden.de> | 2014-03-07 08:44:16 +0100 |
---|---|---|
committer | Alexandre Mestiashvili <alex@biotec.tu-dresden.de> | 2014-03-07 08:44:16 +0100 |
commit | 89ac339b1c8a2a8335b9478033531f75e30e5860 (patch) | |
tree | cf5d6f8ce8d72e2aaed237cd39dc15105baa97e6 /bt2_io.cpp | |
parent | 706918cb26f1f3f89ae41b4011aa5c5b16659d9f (diff) |
Imported Upstream version 2.2.1
Diffstat (limited to 'bt2_io.cpp')
-rw-r--r-- | bt2_io.cpp | 82 |
1 files changed, 28 insertions, 54 deletions
@@ -57,25 +57,6 @@ void Ebwt::readIntoMemory( cerr << " About to open input files: "; logTime(cerr); } -#ifdef BOWTIE_MM - // Initialize our primary and secondary input-stream fields - if(_in1 != -1) close(_in1); - if(_verbose || startVerbose) { - cerr << "Opening \"" << _in1Str.c_str() << "\"" << endl; - } - if((_in1 = open(_in1Str.c_str(), O_RDONLY)) < 0) { - cerr << "Could not open index file " << _in1Str.c_str() << endl; - } - if(loadSASamp) { - if(_in2 != -1) close(_in2); - if(_verbose || startVerbose) { - cerr << "Opening \"" << _in2Str.c_str() << "\"" << endl; - } - if((_in2 = open(_in2Str.c_str(), O_RDONLY)) < 0) { - cerr << "Could not open index file " << _in2Str.c_str() << endl; - } - } -#else // Initialize our primary and secondary input-stream fields if(_in1 != NULL) fclose(_in1); if(_verbose || startVerbose) cerr << "Opening \"" << _in1Str.c_str() << "\"" << endl; @@ -89,7 +70,6 @@ void Ebwt::readIntoMemory( cerr << "Could not open index file " << _in2Str.c_str() << endl; } } -#endif if(_verbose || startVerbose) { cerr << " Finished opening input files: "; logTime(cerr); @@ -98,7 +78,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM if(_useMm /*&& !justHeader*/) { const char *names[] = {_in1Str.c_str(), _in2Str.c_str()}; - int fds[] = { _in1, _in2 }; + int fds[] = { fileno(_in1), fileno(_in2) }; for(int i = 0; i < (loadSASamp ? 2 : 1); i++) { if(_verbose || startVerbose) { cerr << " Memory-mapping input file " << (i+1) << ": "; @@ -267,7 +247,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _plen.init((TIndexOffU*)(mmFile[0] + bytesRead), _nPat, false); bytesRead += _nPat*OFF_SIZE; - MM_SEEK(_in1, _nPat*OFF_SIZE, SEEK_CUR); + fseeko(_in1, _nPat*OFF_SIZE, SEEK_CUR); #endif } else { try { @@ -281,8 +261,8 @@ void Ebwt::readIntoMemory( plen()[i] = readU<TIndexOffU>(_in1, switchEndian); } } else { - MM_READ_RET r = MM_READ(_in1, (void*)(plen()), _nPat*OFF_SIZE); - if(r != (MM_READ_RET)(_nPat*OFF_SIZE)) { + size_t r = MM_READ(_in1, (void*)(plen()), _nPat*OFF_SIZE); + if(r != (size_t)(_nPat*OFF_SIZE)) { cerr << "Error reading _plen[] array: " << r << ", " << _nPat*OFF_SIZE << endl; throw 1; } @@ -315,7 +295,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _rstarts.init((TIndexOffU*)(mmFile[0] + bytesRead), _nFrag*3, false); bytesRead += this->_nFrag*OFF_SIZE*3; - MM_SEEK(_in1, this->_nFrag*OFF_SIZE*3, SEEK_CUR); + fseeko(_in1, this->_nFrag*OFF_SIZE*3, SEEK_CUR); #endif } else { _rstarts.init(new TIndexOffU[_nFrag*3], _nFrag*3, true); @@ -328,8 +308,8 @@ void Ebwt::readIntoMemory( this->rstarts()[i+2] = readU<TIndexOffU>(_in1, switchEndian); } } else { - MM_READ_RET r = MM_READ(_in1, (void *)rstarts(), this->_nFrag*OFF_SIZE*3); - if(r != (MM_READ_RET)(this->_nFrag*OFF_SIZE*3)) { + size_t r = MM_READ(_in1, (void *)rstarts(), this->_nFrag*OFF_SIZE*3); + if(r != (size_t)(this->_nFrag*OFF_SIZE*3)) { cerr << "Error reading _rstarts[] array: " << r << ", " << (this->_nFrag*OFF_SIZE*3) << endl; throw 1; } @@ -339,7 +319,7 @@ void Ebwt::readIntoMemory( // Skip em assert(rstarts() == NULL); bytesRead += this->_nFrag*OFF_SIZE*3; - MM_SEEK(_in1, this->_nFrag*OFF_SIZE*3, SEEK_CUR); + fseeko(_in1, this->_nFrag*OFF_SIZE*3, SEEK_CUR); } _ebwt.reset(); @@ -347,7 +327,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _ebwt.init((uint8_t*)(mmFile[0] + bytesRead), eh->_ebwtTotLen, false); bytesRead += eh->_ebwtTotLen; - MM_SEEK(_in1, eh->_ebwtTotLen, SEEK_CUR); + fseek(_in1, eh->_ebwtTotLen, SEEK_CUR); #endif } else { // Allocate ebwt (big allocation) @@ -381,7 +361,7 @@ void Ebwt::readIntoMemory( char *pebwt = (char*)this->ebwt(); while (bytesLeft>0){ - MM_READ_RET r = MM_READ(_in1, (void *)pebwt, bytesLeft); + size_t r = MM_READ(_in1, (void *)pebwt, bytesLeft); if(MM_IS_IO_ERR(_in1,r,bytesLeft)) { cerr << "Error reading _ebwt[] array: " << r << ", " << bytesLeft << gLastIOErrMsg << endl; @@ -404,7 +384,7 @@ void Ebwt::readIntoMemory( #endif } else { // Seek past the data and wait until master is finished - MM_SEEK(_in1, eh->_ebwtTotLen, SEEK_CUR); + fseeko(_in1, eh->_ebwtTotLen, SEEK_CUR); #ifdef BOWTIE_SHARED_MEM if(useShmem_) WAIT_SHARED(ebwt(), eh->_ebwtTotLen); #endif @@ -424,7 +404,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _fchr.init((TIndexOffU*)(mmFile[0] + bytesRead), 5, false); bytesRead += 5*OFF_SIZE; - MM_SEEK(_in1, 5*OFF_SIZE, SEEK_CUR); + fseek(_in1, 5*OFF_SIZE, SEEK_CUR); #endif } else { _fchr.init(new TIndexOffU[5], 5, true); @@ -450,7 +430,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _ftab.init((TIndexOffU*)(mmFile[0] + bytesRead), eh->_ftabLen, false); bytesRead += eh->_ftabLen*OFF_SIZE; - MM_SEEK(_in1, eh->_ftabLen*OFF_SIZE, SEEK_CUR); + fseeko(_in1, eh->_ftabLen*OFF_SIZE, SEEK_CUR); #endif } else { _ftab.init(new TIndexOffU[eh->_ftabLen], eh->_ftabLen, true); @@ -458,8 +438,8 @@ void Ebwt::readIntoMemory( for(TIndexOffU i = 0; i < eh->_ftabLen; i++) this->ftab()[i] = readU<TIndexOffU>(_in1, switchEndian); } else { - MM_READ_RET r = MM_READ(_in1, (void *)ftab(), eh->_ftabLen*OFF_SIZE); - if(r != (MM_READ_RET)(eh->_ftabLen*OFF_SIZE)) { + size_t r = MM_READ(_in1, (void *)ftab(), eh->_ftabLen*OFF_SIZE); + if(r != (size_t)(eh->_ftabLen*OFF_SIZE)) { cerr << "Error reading _ftab[] array: " << r << ", " << (eh->_ftabLen*OFF_SIZE) << endl; throw 1; } @@ -480,7 +460,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _eftab.init((TIndexOffU*)(mmFile[0] + bytesRead), eh->_eftabLen, false); bytesRead += eh->_eftabLen*OFF_SIZE; - MM_SEEK(_in1, eh->_eftabLen*OFF_SIZE, SEEK_CUR); + fseeko(_in1, eh->_eftabLen*OFF_SIZE, SEEK_CUR); #endif } else { _eftab.init(new TIndexOffU[eh->_eftabLen], eh->_eftabLen, true); @@ -488,8 +468,8 @@ void Ebwt::readIntoMemory( for(TIndexOffU i = 0; i < eh->_eftabLen; i++) this->eftab()[i] = readU<TIndexOffU>(_in1, switchEndian); } else { - MM_READ_RET r = MM_READ(_in1, (void *)this->eftab(), eh->_eftabLen*OFF_SIZE); - if(r != (MM_READ_RET)(eh->_eftabLen*OFF_SIZE)) { + size_t r = MM_READ(_in1, (void *)this->eftab(), eh->_eftabLen*OFF_SIZE); + if(r != (size_t)(eh->_eftabLen*OFF_SIZE)) { cerr << "Error reading _eftab[] array: " << r << ", " << (eh->_eftabLen*OFF_SIZE) << endl; throw 1; } @@ -507,10 +487,10 @@ void Ebwt::readIntoMemory( assert(eftab() == NULL); // Skip ftab bytesRead += eh->_ftabLen*OFF_SIZE; - MM_SEEK(_in1, eh->_ftabLen*OFF_SIZE, SEEK_CUR); + fseeko(_in1, eh->_ftabLen*OFF_SIZE, SEEK_CUR); // Skip eftab bytesRead += eh->_eftabLen*OFF_SIZE; - MM_SEEK(_in1, eh->_eftabLen*OFF_SIZE, SEEK_CUR); + fseeko(_in1, eh->_eftabLen*OFF_SIZE, SEEK_CUR); } } catch(bad_alloc& e) { cerr << "Out of memory allocating fchr[], ftab[] or eftab[] arrays for the Bowtie index." << endl @@ -523,7 +503,7 @@ void Ebwt::readIntoMemory( if(loadNames) { while(true) { char c = '\0'; - if(MM_READ(_in1, (void *)(&c), (size_t)1) != (MM_READ_RET)1) break; + if(MM_READ(_in1, (void *)(&c), (size_t)1) != (size_t)1) break; bytesRead++; if(c == '\0') break; else if(c == '\n') { @@ -582,8 +562,8 @@ void Ebwt::readIntoMemory( } for(TIndexOffU i = 0; i < offsLen; i += blockMaxSzU) { TIndexOffU block = min<TIndexOffU>(blockMaxSzU, offsLen - i); - MM_READ_RET r = MM_READ(_in2, (void *)buf, block << (OFF_SIZE/4 + 1)); - if(r != (MM_READ_RET)(block << (OFF_SIZE/4 + 1))) { + size_t r = MM_READ(_in2, (void *)buf, block << (OFF_SIZE/4 + 1)); + if(r != (size_t)(block << (OFF_SIZE/4 + 1))) { cerr << "Error reading block of _offs[] array: " << r << ", " << (block << (OFF_SIZE/4 + 1)) << endl; throw 1; } @@ -603,9 +583,7 @@ void Ebwt::readIntoMemory( #ifdef BOWTIE_MM _offs.init((TIndexOffU*)(mmFile[1] + bytesRead), offsLen, false); bytesRead += offsSz; - // Argument to lseek can be 64 bits if compiled with - // _FILE_OFFSET_BITS - MM_SEEK(_in2, offsSz, SEEK_CUR); + fseeko(_in2, offsSz, SEEK_CUR); #endif } else { // Workaround for small-index mode where MM_READ may @@ -615,7 +593,7 @@ void Ebwt::readIntoMemory( char *offs = (char *)this->offs(); while(bytesLeft > 0) { - MM_READ_RET r = MM_READ(_in2, (void*)offs, bytesLeft); + size_t r = MM_READ(_in2, (void*)offs, bytesLeft); if(MM_IS_IO_ERR(_in2,r,bytesLeft)) { cerr << "Error reading block of _offs[] array: " << r << ", " << bytesLeft << gLastIOErrMsg << endl; @@ -631,7 +609,7 @@ void Ebwt::readIntoMemory( #endif } else { // Not the shmem leader - MM_SEEK(_in2, offsLenSampled*OFF_SIZE, SEEK_CUR); + fseeko(_in2, offsLenSampled*OFF_SIZE, SEEK_CUR); #ifdef BOWTIE_SHARED_MEM if(useShmem_) WAIT_SHARED(offs(), offsLenSampled*OFF_SIZE); #endif @@ -650,12 +628,8 @@ done: // Exit hatch for both justHeader and !justHeader // Be kind if(deleteEh) delete eh; -#ifdef BOWTIE_MM - MM_SEEK(_in1, 0, SEEK_SET); - MM_SEEK(_in2, 0, SEEK_SET); -#else - rewind(_in1); rewind(_in2); -#endif + rewind(_in1); + rewind(_in2); } /** |