]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/BamAux.h
Merge branch 'master' of git://github.com/pezmaster31/bamtools
[bamtools.git] / src / api / BamAux.h
index 73e88381b695751473eba93098f4f3cdea5192e5..7a7fb1c00ab96299eb378dccfa6952aaeb5e9d24 100644 (file)
@@ -3,7 +3,7 @@
 // Marth Lab, Department of Biology, Boston College\r
 // All rights reserved.\r
 // ---------------------------------------------------------------------------\r
-// Last modified: 27 July 2010 (DB)\r
+// Last modified: 3 September 2010 (DB)\r
 // ---------------------------------------------------------------------------\r
 // Provides the basic constants, data structures, etc. for using BAM files\r
 // ***************************************************************************\r
@@ -19,6 +19,8 @@
 \r
 // C++ includes\r
 #include <exception>\r
+#include <fstream>\r
+#include <iostream>\r
 #include <map>\r
 #include <string>\r
 #include <utility>\r
@@ -350,6 +352,11 @@ inline void SwapEndian_64p(char* data) {
     SwapEndian_64(value);\r
 }\r
 \r
+inline bool FileExists(const std::string& filename) {\r
+    std::ifstream f(filename.c_str(), std::ifstream::in);\r
+    return !f.fail();\r
+}\r
+\r
 // ----------------------------------------------------------------\r
 // BamAlignment member methods\r
 \r
@@ -783,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
@@ -851,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
@@ -978,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