From: Erik Garrison Date: Wed, 8 Sep 2010 19:36:39 +0000 (-0400) Subject: Merge branch 'master' of git://github.com/pezmaster31/bamtools X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=90bb3691f9aa2a2e8a4dd906c2439c7bc434eb78;hp=1d03f81d725ffedeac9d9d73a2058f00cfc0b0e4;p=bamtools.git Merge branch 'master' of git://github.com/pezmaster31/bamtools Conflicts: src/api/BamReader.cpp --- diff --git a/src/api/BGZF.cpp b/src/api/BGZF.cpp index 92afb96..2b74343 100644 --- a/src/api/BGZF.cpp +++ b/src/api/BGZF.cpp @@ -34,7 +34,7 @@ BgzfData::BgzfData(void) CompressedBlock = new char[CompressedBlockSize]; UncompressedBlock = new char[UncompressedBlockSize]; } catch( std::bad_alloc& ba ) { - printf("BGZF ERROR: unable to allocate memory for our BGZF object.\n"); + fprintf(stderr, "BGZF ERROR: unable to allocate memory for our BGZF object.\n"); exit(1); } } @@ -103,7 +103,7 @@ int BgzfData::DeflateBlock(void) { // initialize the zlib compression algorithm if ( deflateInit2(&zs, compressionLevel, Z_DEFLATED, GZIP_WINDOW_BITS, Z_DEFAULT_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK ) { - printf("BGZF ERROR: zlib deflate initialization failed.\n"); + fprintf(stderr, "BGZF ERROR: zlib deflate initialization failed.\n"); exit(1); } @@ -117,26 +117,26 @@ int BgzfData::DeflateBlock(void) { if ( status == Z_OK ) { inputLength -= 1024; if( inputLength < 0 ) { - printf("BGZF ERROR: input reduction failed.\n"); + fprintf(stderr, "BGZF ERROR: input reduction failed.\n"); exit(1); } continue; } - printf("BGZF ERROR: zlib::deflateEnd() failed.\n"); + fprintf(stderr, "BGZF ERROR: zlib::deflateEnd() failed.\n"); exit(1); } // finalize the compression routine if ( deflateEnd(&zs) != Z_OK ) { - printf("BGZF ERROR: zlib::deflateEnd() failed.\n"); + fprintf(stderr, "BGZF ERROR: zlib::deflateEnd() failed.\n"); exit(1); } compressedLength = zs.total_out; compressedLength += BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH; if ( compressedLength > MAX_BLOCK_SIZE ) { - printf("BGZF ERROR: deflate overflow.\n"); + fprintf(stderr, "BGZF ERROR: deflate overflow.\n"); exit(1); } @@ -156,7 +156,7 @@ int BgzfData::DeflateBlock(void) { int remaining = BlockOffset - inputLength; if ( remaining > 0 ) { if ( remaining > inputLength ) { - printf("BGZF ERROR: after deflate, remainder too large.\n"); + fprintf(stderr, "BGZF ERROR: after deflate, remainder too large.\n"); exit(1); } memcpy(UncompressedBlock, UncompressedBlock + inputLength, remaining); @@ -179,7 +179,7 @@ void BgzfData::FlushBlock(void) { int numBytesWritten = fwrite(CompressedBlock, 1, blockLength, Stream); if ( numBytesWritten != blockLength ) { - printf("BGZF ERROR: expected to write %u bytes during flushing, but wrote %u bytes.\n", blockLength, numBytesWritten); + fprintf(stderr, "BGZF ERROR: expected to write %u bytes during flushing, but wrote %u bytes.\n", blockLength, numBytesWritten); exit(1); } @@ -201,20 +201,20 @@ int BgzfData::InflateBlock(const int& blockLength) { int status = inflateInit2(&zs, GZIP_WINDOW_BITS); if ( status != Z_OK ) { - printf("BGZF ERROR: could not decompress block - zlib::inflateInit() failed\n"); + fprintf(stderr, "BGZF ERROR: could not decompress block - zlib::inflateInit() failed\n"); return -1; } status = inflate(&zs, Z_FINISH); if ( status != Z_STREAM_END ) { inflateEnd(&zs); - printf("BGZF ERROR: could not decompress block - zlib::inflate() failed\n"); + fprintf(stderr, "BGZF ERROR: could not decompress block - zlib::inflate() failed\n"); return -1; } status = inflateEnd(&zs); if ( status != Z_OK ) { - printf("BGZF ERROR: could not decompress block - zlib::inflateEnd() failed\n"); + fprintf(stderr, "BGZF ERROR: could not decompress block - zlib::inflateEnd() failed\n"); return -1; } @@ -230,7 +230,7 @@ bool BgzfData::Open(const string& filename, const char* mode, bool isWriteUncomp else if ( strcmp(mode, "wb") == 0) IsWriteOnly = true; else { - printf("BGZF ERROR: unknown file mode: %s\n", mode); + fprintf(stderr, "BGZF ERROR: unknown file mode: %s\n", mode); return false; } @@ -251,7 +251,7 @@ bool BgzfData::Open(const string& filename, const char* mode, bool isWriteUncomp Stream = freopen(NULL, mode, stdout); if ( !Stream ) { - printf("BGZF ERROR: unable to open file %s\n", filename.c_str() ); + fprintf(stderr, "BGZF ERROR: unable to open file %s\n", filename.c_str() ); return false; } @@ -308,12 +308,12 @@ bool BgzfData::ReadBlock(void) { } if ( count != sizeof(header) ) { - printf("BGZF ERROR: read block failed - could not read block header\n"); + fprintf(stderr, "BGZF ERROR: read block failed - could not read block header\n"); return false; } if ( !BgzfData::CheckBlockHeader(header) ) { - printf("BGZF ERROR: read block failed - invalid block header\n"); + fprintf(stderr, "BGZF ERROR: read block failed - invalid block header\n"); return false; } @@ -324,13 +324,13 @@ bool BgzfData::ReadBlock(void) { count = fread(&compressedBlock[BLOCK_HEADER_LENGTH], 1, remaining, Stream); if ( count != remaining ) { - printf("BGZF ERROR: read block failed - could not read data from block\n"); + fprintf(stderr, "BGZF ERROR: read block failed - could not read data from block\n"); return false; } count = InflateBlock(blockLength); if ( count < 0 ) { - printf("BGZF ERROR: read block failed - could not decompress block data\n"); + fprintf(stderr, "BGZF ERROR: read block failed - could not decompress block data\n"); return false; } @@ -351,7 +351,7 @@ bool BgzfData::Seek(int64_t position) { int64_t blockAddress = (position >> 16) & 0xFFFFFFFFFFFFLL; if ( fseek64(Stream, blockAddress, SEEK_SET) != 0 ) { - printf("BGZF ERROR: unable to seek in file\n"); + fprintf(stderr, "BGZF ERROR: unable to seek in file\n"); return false; } diff --git a/src/api/BamAux.h b/src/api/BamAux.h index 25f4538..7a7fb1c 100644 --- a/src/api/BamAux.h +++ b/src/api/BamAux.h @@ -790,12 +790,12 @@ bool BamAlignment::GetTag(const std::string& tag, uint32_t& destination) const { case 'f': case 'Z': case 'H': - printf("ERROR: Cannot store tag of type %c in integer destination\n", type); + fprintf(stderr, "ERROR: Cannot store tag of type %c in integer destination\n", type); return false; // unknown tag type default: - printf("ERROR: Unknown tag storage class encountered: [%c]\n", type); + fprintf(stderr, "ERROR: Unknown tag storage class encountered: [%c]\n", type); return false; } @@ -858,12 +858,12 @@ bool BamAlignment::GetTag(const std::string& tag, float& destination) const { // unsupported type (var-length strings) case 'Z': case 'H': - printf("ERROR: Cannot store tag of type %c in integer destination\n", type); + fprintf(stderr, "ERROR: Cannot store tag of type %c in integer destination\n", type); return false; // unknown tag type default: - printf("ERROR: Unknown tag storage class encountered: [%c]\n", type); + fprintf(stderr, "ERROR: Unknown tag storage class encountered: [%c]\n", type); return false; } @@ -985,7 +985,7 @@ bool BamAlignment::SkipToNextTag(const char storageType, char* &pTagData, unsign default: // error case - printf("ERROR: Unknown tag storage class encountered: [%c]\n", storageType); + fprintf(stderr, "ERROR: Unknown tag storage class encountered: [%c]\n", storageType); return false; } diff --git a/src/api/BamIndex.cpp b/src/api/BamIndex.cpp index cad9d71..59a1c9c 100644 --- a/src/api/BamIndex.cpp +++ b/src/api/BamIndex.cpp @@ -211,8 +211,8 @@ bool BamStandardIndex::Build(void) { // if lastCoordinate greater than BAM position - file not sorted properly else if ( lastCoordinate > bAlignment.Position ) { - printf("BAM file not properly sorted:\n"); - printf("Alignment %s : %d > %d on reference (id = %d)", bAlignment.Name.c_str(), lastCoordinate, bAlignment.Position, bAlignment.RefID); + fprintf(stderr, "BAM file not properly sorted:\n"); + fprintf(stderr, "Alignment %s : %d > %d on reference (id = %d)", bAlignment.Name.c_str(), lastCoordinate, bAlignment.Position, bAlignment.RefID); exit(1); } @@ -253,7 +253,7 @@ bool BamStandardIndex::Build(void) { // make sure that current file pointer is beyond lastOffset if ( m_BGZF->Tell() <= (int64_t)lastOffset ) { - printf("Error in BGZF offsets.\n"); + fprintf(stderr, "Error in BGZF offsets.\n"); exit(1); } @@ -396,7 +396,7 @@ bool BamStandardIndex::Load(const string& filename) { // open index file, abort on error FILE* indexStream = fopen(filename.c_str(), "rb"); if( !indexStream ) { - printf("ERROR: Unable to open the BAM index file %s for reading.\n", filename.c_str()); + fprintf(stderr, "ERROR: Unable to open the BAM index file %s for reading.\n", filename.c_str()); return false; } @@ -407,7 +407,7 @@ bool BamStandardIndex::Load(const string& filename) { char magic[4]; elementsRead = fread(magic, 1, 4, indexStream); if ( strncmp(magic, "BAI\1", 4) ) { - printf("Problem with index file - invalid format.\n"); + fprintf(stderr, "Problem with index file - invalid format.\n"); fclose(indexStream); return false; } @@ -578,7 +578,7 @@ bool BamStandardIndex::Write(const std::string& bamFilename) { string indexFilename = bamFilename + ".bai"; FILE* indexStream = fopen(indexFilename.c_str(), "wb"); if ( indexStream == 0 ) { - printf("ERROR: Could not open file to save index.\n"); + fprintf(stderr, "ERROR: Could not open file to save index.\n"); return false; } @@ -808,7 +808,7 @@ bool BamToolsIndex::Load(const string& filename) { // open index file, abort on error FILE* indexStream = fopen(filename.c_str(), "rb"); if( !indexStream ) { - printf("ERROR: Unable to open the BAM index file %s for reading.\n", filename.c_str()); + fprintf(stderr, "ERROR: Unable to open the BAM index file %s for reading.\n", filename.c_str()); return false; } @@ -819,7 +819,7 @@ bool BamToolsIndex::Load(const string& filename) { char magic[4]; elementsRead = fread(magic, 1, 4, indexStream); if ( strncmp(magic, "BTI\1", 4) ) { - printf("Problem with index file - invalid format.\n"); + fprintf(stderr, "Problem with index file - invalid format.\n"); fclose(indexStream); return false; } @@ -874,7 +874,7 @@ bool BamToolsIndex::Write(const std::string& bamFilename) { string indexFilename = bamFilename + ".bti"; FILE* indexStream = fopen(indexFilename.c_str(), "wb"); if ( indexStream == 0 ) { - printf("ERROR: Could not open file to save index.\n"); + fprintf(stderr, "ERROR: Could not open file to save index.\n"); return false; } diff --git a/src/api/BamReader.cpp b/src/api/BamReader.cpp index 98ea758..93a991b 100644 --- a/src/api/BamReader.cpp +++ b/src/api/BamReader.cpp @@ -282,7 +282,7 @@ bool BamReader::BamReaderPrivate::BuildCharData(BamAlignment& bAlignment) { break; // for 'H' - hard clip, do nothing to AlignedBases, move to next op default: - printf("ERROR: Invalid Cigar op type\n"); // shouldn't get here + fprintf(stderr, "ERROR: Invalid Cigar op type\n"); // shouldn't get here exit(1); } } @@ -330,7 +330,7 @@ bool BamReader::BamReaderPrivate::BuildCharData(BamAlignment& bAlignment) { break; default : - printf("ERROR: Invalid tag value type\n"); // shouldn't get here + fprintf(stderr, "ERROR: Invalid tag value type\n"); // shouldn't get here exit(1); } } @@ -520,7 +520,7 @@ bool BamReader::BamReaderPrivate::Jump(int refID, int position) { // determine possible offsets vector offsets; if ( !NewIndex->GetOffsets(Region, IsRightBoundSpecified, offsets) ) { - printf("ERROR: Could not jump: unable to calculate offset for specified region.\n"); + fprintf(stderr, "ERROR: Could not jump: unable to calculate offset for specified region.\n"); return false; } @@ -550,12 +550,12 @@ void BamReader::BamReaderPrivate::LoadHeaderData(void) { // check to see if proper BAM header char buffer[4]; if (mBGZF.Read(buffer, 4) != 4) { - printf("Could not read header type\n"); + fprintf(stderr, "Could not read header type\n"); exit(1); } if (strncmp(buffer, "BAM\001", 4)) { - printf("wrong header type!\n"); + fprintf(stderr, "wrong header type!\n"); exit(1); } diff --git a/src/api/BamWriter.cpp b/src/api/BamWriter.cpp index f83ff1c..2be38bb 100644 --- a/src/api/BamWriter.cpp +++ b/src/api/BamWriter.cpp @@ -131,7 +131,7 @@ void BamWriter::BamWriterPrivate::CreatePackedCigar(const vector& cigar cigarOp = BAM_CPAD; break; default: - printf("ERROR: Unknown cigar operation found: %c\n", coIter->Type); + fprintf(stderr, "ERROR: Unknown cigar operation found: %c\n", coIter->Type); exit(1); } @@ -182,7 +182,7 @@ void BamWriter::BamWriterPrivate::EncodeQuerySequence(const string& query, strin break; default: - printf("ERROR: Only the following bases are supported in the BAM format: {=, A, C, G, T, N}. Found [%c]\n", *pQuery); + fprintf(stderr, "ERROR: Only the following bases are supported in the BAM format: {=, A, C, G, T, N}. Found [%c]\n", *pQuery); exit(1); } @@ -417,7 +417,7 @@ void BamWriter::BamWriterPrivate::SaveAlignment(const BamAlignment& al) { break; default : - printf("ERROR: Invalid tag value type\n"); // shouldn't get here + fprintf(stderr, "ERROR: Invalid tag value type\n"); // shouldn't get here free(tagData); exit(1); }