]> git.donarmstrong.com Git - bamtools.git/commitdiff
Merge branch 'master' of git://github.com/pezmaster31/bamtools
authorErik Garrison <erik.garrison@bc.edu>
Wed, 8 Sep 2010 19:36:39 +0000 (15:36 -0400)
committerErik Garrison <erik.garrison@bc.edu>
Wed, 8 Sep 2010 19:36:39 +0000 (15:36 -0400)
Conflicts:
src/api/BamReader.cpp

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 25f4538982b8393ac74cdd1bb7aa3943ea21a2f8..7a7fb1c00ab96299eb378dccfa6952aaeb5e9d24 100644 (file)
@@ -790,12 +790,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
@@ -858,12 +858,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
@@ -985,7 +985,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 cad9d71da539b8ad8dea7112da2194813764cb28..59a1c9ca9e8c4de8d4e1e2c5f6ae307188c68b34 100644 (file)
@@ -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;
     }
 
index 98ea7589f664de056f5138593e24454480bd26c7..93a991bd77f942becb85fa505dba8b6334a15be1 100644 (file)
@@ -282,7 +282,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
@@ -330,7 +330,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
@@ -520,7 +520,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
@@ -550,12 +550,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
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