From: Derek Date: Tue, 17 Aug 2010 20:39:44 +0000 (-0400) Subject: Modified the way BGZF sets up uncompressed output. Modified BamWriter to support... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=2d6d143e041a08c2083a6857898ca36753317dad;p=bamtools.git Modified the way BGZF sets up uncompressed output. Modified BamWriter to support uncompressed option. --- diff --git a/BGZF.cpp b/BGZF.cpp index 600e075..92afb96 100644 --- a/BGZF.cpp +++ b/BGZF.cpp @@ -17,7 +17,7 @@ using namespace BamTools; using std::string; using std::min; -BgzfData::BgzfData(bool writeUncompressed) +BgzfData::BgzfData(void) : UncompressedBlockSize(DEFAULT_BLOCK_SIZE) , CompressedBlockSize(MAX_BLOCK_SIZE) , BlockLength(0) @@ -25,7 +25,7 @@ BgzfData::BgzfData(bool writeUncompressed) , BlockAddress(0) , IsOpen(false) , IsWriteOnly(false) - , IsWriteUncompressed(writeUncompressed) + , IsWriteUncompressed(false) , Stream(NULL) , UncompressedBlock(NULL) , CompressedBlock(NULL) @@ -62,6 +62,7 @@ void BgzfData::Close(void) { // flush and close fflush(Stream); fclose(Stream); + IsWriteUncompressed = false; IsOpen = false; } @@ -221,7 +222,7 @@ int BgzfData::InflateBlock(const int& blockLength) { } // opens the BGZF file for reading (mode is either "rb" for reading, or "wb" for writing) -bool BgzfData::Open(const string& filename, const char* mode) { +bool BgzfData::Open(const string& filename, const char* mode, bool isWriteUncompressed ) { // determine open mode if ( strcmp(mode, "rb") == 0 ) @@ -254,8 +255,9 @@ bool BgzfData::Open(const string& filename, const char* mode) { return false; } - // set flag, return success + // set flags, return success IsOpen = true; + IsWriteUncompressed = isWriteUncompressed; return true; } diff --git a/BGZF.h b/BGZF.h index c5cd60b..37bcff7 100644 --- a/BGZF.h +++ b/BGZF.h @@ -93,7 +93,7 @@ struct BgzfData { // constructor & destructor public: - BgzfData(bool writeUncompressed = false); + BgzfData(void); ~BgzfData(void); // main interface methods @@ -101,7 +101,7 @@ struct BgzfData { // closes BGZF file void Close(void); // opens the BGZF file (mode is either "rb" for reading, or "wb" for writing) - bool Open(const std::string& filename, const char* mode); + bool Open(const std::string& filename, const char* mode, bool isWriteUncompressed = false); // reads BGZF data into a byte buffer int Read(char* data, const unsigned int dataLength); // seek to position in BGZF file diff --git a/BamWriter.cpp b/BamWriter.cpp index 5052eaa..f83ff1c 100644 --- a/BamWriter.cpp +++ b/BamWriter.cpp @@ -35,7 +35,7 @@ struct BamWriter::BamWriterPrivate { // "public" interface void Close(void); - bool Open(const string& filename, const string& samHeader, const RefVector& referenceSequences); + bool Open(const string& filename, const string& samHeader, const RefVector& referenceSequences, bool isWriteUncompressed); void SaveAlignment(const BamAlignment& al); // internal methods @@ -65,8 +65,8 @@ void BamWriter::Close(void) { } // opens the alignment archive -bool BamWriter::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences) { - return d->Open(filename, samHeader, referenceSequences); +bool BamWriter::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences, bool isWriteUncompressed) { + return d->Open(filename, samHeader, referenceSequences, isWriteUncompressed); } // saves the alignment to the alignment archive @@ -202,10 +202,10 @@ void BamWriter::BamWriterPrivate::EncodeQuerySequence(const string& query, strin } // opens the alignment archive -bool BamWriter::BamWriterPrivate::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences) { +bool BamWriter::BamWriterPrivate::Open(const string& filename, const string& samHeader, const RefVector& referenceSequences, bool isWriteUncompressed) { // open the BGZF file for writing, return failure if error - if ( !mBGZF.Open(filename, "wb") ) + if ( !mBGZF.Open(filename, "wb", isWriteUncompressed) ) return false; // ================ diff --git a/BamWriter.h b/BamWriter.h index e8e7a14..b0cb6ce 100644 --- a/BamWriter.h +++ b/BamWriter.h @@ -34,7 +34,10 @@ class BamWriter { // closes the alignment archive void Close(void); // opens the alignment archive - bool Open(const std::string& filename, const std::string& samHeader, const BamTools::RefVector& referenceSequences); + bool Open(const std::string& filename, + const std::string& samHeader, + const BamTools::RefVector& referenceSequences, + bool writeUncompressed = false); // saves the alignment to the alignment archive void SaveAlignment(const BamTools::BamAlignment& al);