// Marth Lab, Department of Biology, Boston College\r
// All rights reserved.\r
// ---------------------------------------------------------------------------\r
-// Last modified: 27 July 2010 (DB)\r
+// Last modified: 15 September 2010 (DB)\r
// ---------------------------------------------------------------------------\r
// Provides the basic constants, data structures, etc. for using BAM files\r
// ***************************************************************************\r
\r
// C++ includes\r
#include <exception>\r
+#include <fstream>\r
+#include <iostream>\r
#include <map>\r
#include <string>\r
#include <utility>\r
\r
// Additional data access methods\r
public:\r
- int GetEndPosition(bool usePadded = false) const; // calculates alignment end position, based on starting position and CIGAR operations\r
+ // calculates alignment end position, based on starting position and CIGAR operations\r
+ // @zeroBased - if true, returns 0-based coordinate; else returns 1-based\r
+ int GetEndPosition(bool usePadded = false, bool zeroBased = true) const; \r
\r
// 'internal' utility methods \r
private:\r
, RightRefID(rightID)\r
, RightPosition(rightPos)\r
{ }\r
+ \r
+ // member functions\r
+ void clear(void) { LeftRefID = -1; LeftPosition = -1; RightRefID = -1; RightPosition = -1; }\r
+ bool isLeftBoundSpecified(void) const { return ( LeftRefID != -1 && LeftPosition != -1 ); }\r
+ bool isNull(void) const { return ( !isLeftBoundSpecified() && !isRightBoundSpecified() ); }\r
+ bool isRightBoundSpecified(void) const { return ( RightRefID != -1 && RightPosition != -1 ); }\r
};\r
\r
// ----------------------------------------------------------------\r
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
\r
// calculates alignment end position, based on starting position and CIGAR operations\r
inline \r
-int BamAlignment::GetEndPosition(bool usePadded) const {\r
+int BamAlignment::GetEndPosition(bool usePadded, bool zeroBased) const {\r
\r
// initialize alignment end to starting position\r
int alignEnd = Position;\r
alignEnd += (*cigarIter).Length;\r
}\r
}\r
- return alignEnd;\r
+ \r
+ // adjust for zeroBased, if necessary\r
+ if (zeroBased) \r
+ return alignEnd - 1;\r
+ else \r
+ return alignEnd;\r
}\r
\r
inline\r
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
// 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
\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