// ***************************************************************************
// BgzfStream_p.cpp (c) 2011 Derek Barnett
// Marth Lab, Department of Biology, Boston College
-// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 21 March 2011(DB)
+// Last modified: 2 September 2011(DB)
// ---------------------------------------------------------------------------
// Based on BGZF routines developed at the Broad Institute.
// Provides the basic functionality for reading & writing BGZF files
}
// open BGZF stream on a file
- if ( (filename != "stdin") && (filename != "stdout") )
+ if ( (filename != "stdin") && (filename != "stdout") && (filename != "-"))
Stream = fopen(filename.c_str(), mode);
// open BGZF stream on stdin
- else if ( (filename == "stdin") && (strcmp(mode, "rb") == 0 ) )
+ else if ( (filename == "stdin" || filename == "-") && (strcmp(mode, "rb") == 0 ) )
Stream = freopen(NULL, mode, stdin);
// open BGZF stream on stdout
- else if ( (filename == "stdout") && (strcmp(mode, "wb") == 0) )
+ else if ( (filename == "stdout" || filename == "-") && (strcmp(mode, "wb") == 0) )
Stream = freopen(NULL, mode, stdout);
if ( !Stream ) {
}
// seek to position in BGZF file
-bool BgzfStream::Seek(int64_t position) {
+bool BgzfStream::Seek(const int64_t& position) {
// skip if not open
if ( !IsOpen ) return false;
return false;
}
- // update block data
+ // update block data & return success
BlockLength = 0;
BlockAddress = blockAddress;
BlockOffset = blockOffset;
-
- // return success
return true;
}
}
// get file position in BGZF file
-int64_t BgzfStream::Tell(void) {
-
- // skip if file not open
- if ( !IsOpen ) return false;
-
- // otherwise return file pointer position
+int64_t BgzfStream::Tell(void) const {
+ if ( !IsOpen )
+ return 0;
return ( (BlockAddress << 16) | (BlockOffset & 0xFFFF) );
}