]> git.donarmstrong.com Git - bamtools.git/commitdiff
change printf's to fprint(stderr,
authorErik Garrison <erik.garrison@bc.edu>
Fri, 20 Aug 2010 16:22:34 +0000 (12:22 -0400)
committerErik Garrison <erik.garrison@bc.edu>
Fri, 20 Aug 2010 16:22:34 +0000 (12:22 -0400)
This pushes errors to the expected output, stderr, instead of mixing
them into the standard output stream.

src/api/BGZF.cpp
src/api/BamAux.h
src/api/BamIndex.cpp
src/api/BamReader.cpp
src/api/BamWriter.cpp

index 92afb96f83e058960aa4ebf0b2789de947944c0b..2b74343b1a79ef42fc33fa6806e8b6bc0218e43f 100644 (file)
@@ -34,7 +34,7 @@ BgzfData::BgzfData(void)
         CompressedBlock   = new char[CompressedBlockSize];\r
         UncompressedBlock = new char[UncompressedBlockSize];\r
     } catch( std::bad_alloc& ba ) {\r
-        printf("BGZF ERROR: unable to allocate memory for our BGZF object.\n");\r
+        fprintf(stderr, "BGZF ERROR: unable to allocate memory for our BGZF object.\n");\r
         exit(1);\r
     }\r
 }\r
@@ -103,7 +103,7 @@ int BgzfData::DeflateBlock(void) {
 \r
         // initialize the zlib compression algorithm\r
         if ( deflateInit2(&zs, compressionLevel, Z_DEFLATED, GZIP_WINDOW_BITS, Z_DEFAULT_MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK ) {\r
-            printf("BGZF ERROR: zlib deflate initialization failed.\n");\r
+            fprintf(stderr, "BGZF ERROR: zlib deflate initialization failed.\n");\r
             exit(1);\r
         }\r
 \r
@@ -117,26 +117,26 @@ int BgzfData::DeflateBlock(void) {
             if ( status == Z_OK ) {\r
                 inputLength -= 1024;\r
                 if( inputLength < 0 ) {\r
-                    printf("BGZF ERROR: input reduction failed.\n");\r
+                    fprintf(stderr, "BGZF ERROR: input reduction failed.\n");\r
                     exit(1);\r
                 }\r
                 continue;\r
             }\r
 \r
-            printf("BGZF ERROR: zlib::deflateEnd() failed.\n");\r
+            fprintf(stderr, "BGZF ERROR: zlib::deflateEnd() failed.\n");\r
             exit(1);\r
         }\r
 \r
         // finalize the compression routine\r
         if ( deflateEnd(&zs) != Z_OK ) {\r
-            printf("BGZF ERROR: zlib::deflateEnd() failed.\n");\r
+            fprintf(stderr, "BGZF ERROR: zlib::deflateEnd() failed.\n");\r
             exit(1);\r
         }\r
 \r
         compressedLength = zs.total_out;\r
         compressedLength += BLOCK_HEADER_LENGTH + BLOCK_FOOTER_LENGTH;\r
         if ( compressedLength > MAX_BLOCK_SIZE ) {\r
-            printf("BGZF ERROR: deflate overflow.\n");\r
+            fprintf(stderr, "BGZF ERROR: deflate overflow.\n");\r
             exit(1);\r
         }\r
 \r
@@ -156,7 +156,7 @@ int BgzfData::DeflateBlock(void) {
     int remaining = BlockOffset - inputLength;\r
     if ( remaining > 0 ) {\r
         if ( remaining > inputLength ) {\r
-            printf("BGZF ERROR: after deflate, remainder too large.\n");\r
+            fprintf(stderr, "BGZF ERROR: after deflate, remainder too large.\n");\r
             exit(1);\r
         }\r
         memcpy(UncompressedBlock, UncompressedBlock + inputLength, remaining);\r
@@ -179,7 +179,7 @@ void BgzfData::FlushBlock(void) {
         int numBytesWritten = fwrite(CompressedBlock, 1, blockLength, Stream);\r
 \r
         if ( numBytesWritten != blockLength ) {\r
-          printf("BGZF ERROR: expected to write %u bytes during flushing, but wrote %u bytes.\n", blockLength, numBytesWritten);\r
+          fprintf(stderr, "BGZF ERROR: expected to write %u bytes during flushing, but wrote %u bytes.\n", blockLength, numBytesWritten);\r
           exit(1);\r
         }\r
               \r
@@ -201,20 +201,20 @@ int BgzfData::InflateBlock(const int& blockLength) {
 \r
     int status = inflateInit2(&zs, GZIP_WINDOW_BITS);\r
     if ( status != Z_OK ) {\r
-        printf("BGZF ERROR: could not decompress block - zlib::inflateInit() failed\n");\r
+        fprintf(stderr, "BGZF ERROR: could not decompress block - zlib::inflateInit() failed\n");\r
         return -1;\r
     }\r
 \r
     status = inflate(&zs, Z_FINISH);\r
     if ( status != Z_STREAM_END ) {\r
         inflateEnd(&zs);\r
-        printf("BGZF ERROR: could not decompress block - zlib::inflate() failed\n");\r
+        fprintf(stderr, "BGZF ERROR: could not decompress block - zlib::inflate() failed\n");\r
         return -1;\r
     }\r
 \r
     status = inflateEnd(&zs);\r
     if ( status != Z_OK ) {\r
-        printf("BGZF ERROR: could not decompress block - zlib::inflateEnd() failed\n");\r
+        fprintf(stderr, "BGZF ERROR: could not decompress block - zlib::inflateEnd() failed\n");\r
         return -1;\r
     }\r
 \r
@@ -230,7 +230,7 @@ bool BgzfData::Open(const string& filename, const char* mode, bool isWriteUncomp
     else if ( strcmp(mode, "wb") == 0) \r
         IsWriteOnly = true;\r
     else {\r
-        printf("BGZF ERROR: unknown file mode: %s\n", mode);\r
+        fprintf(stderr, "BGZF ERROR: unknown file mode: %s\n", mode);\r
         return false; \r
     }\r
 \r
@@ -251,7 +251,7 @@ bool BgzfData::Open(const string& filename, const char* mode, bool isWriteUncomp
         Stream = freopen(NULL, mode, stdout);\r
 \r
     if ( !Stream ) {\r
-        printf("BGZF ERROR: unable to open file %s\n", filename.c_str() );\r
+        fprintf(stderr, "BGZF ERROR: unable to open file %s\n", filename.c_str() );\r
         return false;\r
     }\r
     \r
@@ -308,12 +308,12 @@ bool BgzfData::ReadBlock(void) {
     }\r
 \r
     if ( count != sizeof(header) ) {\r
-        printf("BGZF ERROR: read block failed - could not read block header\n");\r
+        fprintf(stderr, "BGZF ERROR: read block failed - could not read block header\n");\r
         return false;\r
     }\r
 \r
     if ( !BgzfData::CheckBlockHeader(header) ) {\r
-        printf("BGZF ERROR: read block failed - invalid block header\n");\r
+        fprintf(stderr, "BGZF ERROR: read block failed - invalid block header\n");\r
         return false;\r
     }\r
 \r
@@ -324,13 +324,13 @@ bool BgzfData::ReadBlock(void) {
 \r
     count = fread(&compressedBlock[BLOCK_HEADER_LENGTH], 1, remaining, Stream);\r
     if ( count != remaining ) {\r
-        printf("BGZF ERROR: read block failed - could not read data from block\n");\r
+        fprintf(stderr, "BGZF ERROR: read block failed - could not read data from block\n");\r
         return false;\r
     }\r
 \r
     count = InflateBlock(blockLength);\r
     if ( count < 0 ) { \r
-      printf("BGZF ERROR: read block failed - could not decompress block data\n");\r
+      fprintf(stderr, "BGZF ERROR: read block failed - could not decompress block data\n");\r
       return false;\r
     }\r
 \r
@@ -351,7 +351,7 @@ bool BgzfData::Seek(int64_t position) {
     int64_t blockAddress = (position >> 16) & 0xFFFFFFFFFFFFLL;\r
 \r
     if ( fseek64(Stream, blockAddress, SEEK_SET) != 0 ) {\r
-        printf("BGZF ERROR: unable to seek in file\n");\r
+        fprintf(stderr, "BGZF ERROR: unable to seek in file\n");\r
         return false;\r
     }\r
 \r
index 73e88381b695751473eba93098f4f3cdea5192e5..a39abb07da19a2cc2c6e8daabd7caa1c072a6f3b 100644 (file)
@@ -783,12 +783,12 @@ bool BamAlignment::GetTag(const std::string& tag, uint32_t& destination) const {
             case 'f':\r
             case 'Z':\r
             case 'H':\r
-                printf("ERROR: Cannot store tag of type %c in integer destination\n", type);\r
+                fprintf(stderr, "ERROR: Cannot store tag of type %c in integer destination\n", type);\r
                 return false;\r
 \r
             // unknown tag type\r
             default:\r
-                printf("ERROR: Unknown tag storage class encountered: [%c]\n", type);\r
+                fprintf(stderr, "ERROR: Unknown tag storage class encountered: [%c]\n", type);\r
                 return false;\r
         }\r
           \r
@@ -851,12 +851,12 @@ bool BamAlignment::GetTag(const std::string& tag, float& destination) const {
             // unsupported type (var-length strings)\r
             case 'Z':\r
             case 'H':\r
-                printf("ERROR: Cannot store tag of type %c in integer destination\n", type);\r
+                fprintf(stderr, "ERROR: Cannot store tag of type %c in integer destination\n", type);\r
                 return false;\r
 \r
             // unknown tag type\r
             default:\r
-                printf("ERROR: Unknown tag storage class encountered: [%c]\n", type);\r
+                fprintf(stderr, "ERROR: Unknown tag storage class encountered: [%c]\n", type);\r
                 return false;\r
         }\r
           \r
@@ -978,7 +978,7 @@ bool BamAlignment::SkipToNextTag(const char storageType, char* &pTagData, unsign
 \r
         default: \r
             // error case\r
-            printf("ERROR: Unknown tag storage class encountered: [%c]\n", storageType);\r
+            fprintf(stderr, "ERROR: Unknown tag storage class encountered: [%c]\n", storageType);\r
             return false;\r
     }\r
     \r
index d74e751cd902c546760afa42e3ba7c5bbe90b0ca..5f636d1282567e990e78f4edae019fcac2dda72e 100644 (file)
@@ -213,8 +213,8 @@ bool BamDefaultIndex::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);
         }
 
@@ -255,7 +255,7 @@ bool BamDefaultIndex::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);
         }
 
@@ -397,7 +397,7 @@ bool BamDefaultIndex::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;
     }
 
@@ -408,7 +408,7 @@ bool BamDefaultIndex::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 BamDefaultIndex::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;
     }
 
@@ -810,7 +810,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;
     }
 
@@ -821,7 +821,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;
     }
@@ -876,7 +876,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;
     }
 
index b1b1b5de2ab79a76416bd5267f6dc5cc1ecccd02..bb70f1fa159acb79110f0a4f1019561aad951430 100644 (file)
@@ -291,7 +291,7 @@ bool BamReader::BamReaderPrivate::BuildCharData(BamAlignment& bAlignment) {
                     break;  // for 'H' - hard clip, do nothing to AlignedBases, move to next op\r
                     \r
                 default:\r
-                    printf("ERROR: Invalid Cigar op type\n"); // shouldn't get here\r
+                    fprintf(stderr, "ERROR: Invalid Cigar op type\n"); // shouldn't get here\r
                     exit(1);\r
             }\r
         }\r
@@ -339,7 +339,7 @@ bool BamReader::BamReaderPrivate::BuildCharData(BamAlignment& bAlignment) {
                     break;\r
                 \r
                 default : \r
-                    printf("ERROR: Invalid tag value type\n"); // shouldn't get here\r
+                    fprintf(stderr, "ERROR: Invalid tag value type\n"); // shouldn't get here\r
                     exit(1);\r
             }\r
         }\r
@@ -525,7 +525,7 @@ bool BamReader::BamReaderPrivate::Jump(int refID, int position) {
     // determine possible offsets\r
     vector<int64_t> offsets;\r
     if ( !NewIndex->GetOffsets(Region, IsRightBoundSpecified, offsets) ) {\r
-        printf("ERROR: Could not jump: unable to calculate offset for specified region.\n");\r
+        fprintf(stderr, "ERROR: Could not jump: unable to calculate offset for specified region.\n");\r
         return false;\r
     }\r
       \r
@@ -555,12 +555,12 @@ void BamReader::BamReaderPrivate::LoadHeaderData(void) {
     // check to see if proper BAM header\r
     char buffer[4];\r
     if (mBGZF.Read(buffer, 4) != 4) {\r
-        printf("Could not read header type\n");\r
+        fprintf(stderr, "Could not read header type\n");\r
         exit(1);\r
     }\r
 \r
     if (strncmp(buffer, "BAM\001", 4)) {\r
-        printf("wrong header type!\n");\r
+        fprintf(stderr, "wrong header type!\n");\r
         exit(1);\r
     }\r
 \r
@@ -602,7 +602,7 @@ bool BamReader::BamReaderPrivate::LoadIndex(void) {
     \r
     // else unknown\r
     else {\r
-        printf("ERROR: Unknown index file extension.\n");\r
+        fprintf(stderr, "ERROR: Unknown index file extension.\n");\r
         return false;\r
     }\r
     \r
index f83ff1c3046ed46876c655b5b11f0535d634bda0..2be38bbe9d160668448c8d48a8e421025139f445 100644 (file)
@@ -131,7 +131,7 @@ void BamWriter::BamWriterPrivate::CreatePackedCigar(const vector<CigarOp>& cigar
                   cigarOp = BAM_CPAD;\r
                   break;\r
             default:\r
-                  printf("ERROR: Unknown cigar operation found: %c\n", coIter->Type);\r
+                  fprintf(stderr, "ERROR: Unknown cigar operation found: %c\n", coIter->Type);\r
                   exit(1);\r
         }\r
 \r
@@ -182,7 +182,7 @@ void BamWriter::BamWriterPrivate::EncodeQuerySequence(const string& query, strin
                 break;\r
             \r
             default:\r
-                printf("ERROR: Only the following bases are supported in the BAM format: {=, A, C, G, T, N}. Found [%c]\n", *pQuery);\r
+                fprintf(stderr, "ERROR: Only the following bases are supported in the BAM format: {=, A, C, G, T, N}. Found [%c]\n", *pQuery);\r
                 exit(1);\r
         }\r
 \r
@@ -417,7 +417,7 @@ void BamWriter::BamWriterPrivate::SaveAlignment(const BamAlignment& al) {
                         break;\r
                                 \r
                     default : \r
-                        printf("ERROR: Invalid tag value type\n"); // shouldn't get here\r
+                        fprintf(stderr, "ERROR: Invalid tag value type\n"); // shouldn't get here\r
                         free(tagData);\r
                         exit(1); \r
                 }\r