// Marth Lab, Department of Biology, Boston College\r
// All rights reserved.\r
// ---------------------------------------------------------------------------\r
-// Last modified: 29 March 2010 (DB)\r
+// Last modified: 30 March 2010 (DB)\r
// ---------------------------------------------------------------------------\r
// Provides the basic constants, data structures, etc. for using BAM files\r
// ***************************************************************************\r
}\r
\r
// swaps endianness of 16-bit value 'in place'\r
+inline void SwapEndian_16(int16_t& x) {\r
+ x = ((x >> 8) | (x << 8));\r
+}\r
+\r
inline void SwapEndian_16(uint16_t& x) {\r
x = ((x >> 8) | (x << 8));\r
}\r
\r
// swaps endianness of 32-bit value 'in-place'\r
-inline void SwapEndian_32(uint32_t& value) {\r
+inline void SwapEndian_32(int32_t& x) {\r
+ x = ( (x >> 24) | \r
+ ((x << 8) & 0x00FF0000) | \r
+ ((x >> 8) & 0x0000FF00) | \r
+ (x << 24)\r
+ );\r
+}\r
+\r
+inline void SwapEndian_32(uint32_t& x) {\r
x = ( (x >> 24) | \r
((x << 8) & 0x00FF0000) | \r
((x >> 8) & 0x0000FF00) | \r
}\r
\r
// swaps endianness of 64-bit value 'in-place'\r
-inline void SwapEndian_64(uint64_t& value) {\r
+inline void SwapEndian_64(int64_t& x) {\r
+ x = ( (x >> 56) | \r
+ ((x << 40) & 0x00FF000000000000ll) |\r
+ ((x << 24) & 0x0000FF0000000000ll) |\r
+ ((x << 8) & 0x000000FF00000000ll) |\r
+ ((x >> 8) & 0x00000000FF000000ll) |\r
+ ((x >> 24) & 0x0000000000FF0000ll) |\r
+ ((x >> 40) & 0x000000000000FF00ll) |\r
+ (x << 56)\r
+ );\r
+}\r
+\r
+inline void SwapEndian_64(uint64_t& x) {\r
x = ( (x >> 56) | \r
- ((x << 40) & 0x00FF000000000000) |\r
- ((x << 24) & 0x0000FF0000000000) |\r
- ((x << 8) & 0x000000FF00000000) |\r
- ((x >> 8) & 0x00000000FF000000) |\r
- ((x >> 24) & 0x0000000000FF0000) |\r
- ((x >> 40) & 0x000000000000FF00) |\r
+ ((x << 40) & 0x00FF000000000000ll) |\r
+ ((x << 24) & 0x0000FF0000000000ll) |\r
+ ((x << 8) & 0x000000FF00000000ll) |\r
+ ((x >> 8) & 0x00000000FF000000ll) |\r
+ ((x >> 24) & 0x0000000000FF0000ll) |\r
+ ((x >> 40) & 0x000000000000FF00ll) |\r
(x << 56)\r
);\r
}\r
// Marth Lab, Department of Biology, Boston College\r
// All rights reserved.\r
// ---------------------------------------------------------------------------\r
-// Last modified: 29 March 2010 (DB)\r
+// Last modified: 30 March 2010 (DB)\r
// ---------------------------------------------------------------------------\r
// Uses BGZF routines were adapted from the bgzf.c code developed at the Broad\r
// Institute.\r
bool GetNextAlignment(BamAlignment& bAlignment);\r
\r
// access auxiliary data\r
- const string GetHeaderText(void) const;\r
- const int GetReferenceCount(void) const;\r
- const RefVector GetReferenceData(void) const;\r
- const int GetReferenceID(const string& refName) const;\r
+ int GetReferenceID(const string& refName) const;\r
\r
// index operations\r
bool CreateIndex(void);\r
bool BamReader::GetNextAlignment(BamAlignment& bAlignment) { return d->GetNextAlignment(bAlignment); }\r
\r
// access auxiliary data\r
-const string BamReader::GetHeaderText(void) const { return d->HeaderText; }\r
-const int BamReader::GetReferenceCount(void) const { return d->References.size(); }\r
+const string BamReader::GetHeaderText(void) const { return d->HeaderText; }\r
+int BamReader::GetReferenceCount(void) const { return d->References.size(); }\r
const RefVector BamReader::GetReferenceData(void) const { return d->References; }\r
-const int BamReader::GetReferenceID(const string& refName) const { return d->GetReferenceID(refName); }\r
+int BamReader::GetReferenceID(const string& refName) const { return d->GetReferenceID(refName); }\r
\r
// index operations\r
bool BamReader::CreateIndex(void) { return d->CreateIndex(); }\r
}\r
\r
// returns RefID for given RefName (returns References.size() if not found)\r
-const int BamReader::BamReaderPrivate::GetReferenceID(const string& refName) const {\r
+int BamReader::BamReaderPrivate::GetReferenceID(const string& refName) const {\r
\r
// retrieve names from reference data\r
vector<string> refNames;\r
int bytesRead = 4;\r
\r
// read in core alignment data, make sure the right size of data was read\r
- uint32_t x[8];\r
+ char x[BAM_CORE_SIZE];\r
if ( mBGZF.Read(x, BAM_CORE_SIZE) != BAM_CORE_SIZE ) { return false; }\r
bytesRead += BAM_CORE_SIZE;\r
\r
if ( IsBigEndian ) {\r
- for ( int i = 0; i < 8; ++i ) { \r
- SwapEndian_32(x[i]); \r
+ for ( int i = 0; i < BAM_CORE_SIZE; i+=sizeof(uint32_t) ) { \r
+ SwapEndian_32p(&x[i]); \r
}\r
}\r
\r
unsigned int querySequenceLength;\r
\r
bAlignment.RefID = BgzfData::UnpackSignedInt(&x[0]); \r
- bAlignment.Position = BgzfData::UnpackSignedInt(&x[1]);\r
+ bAlignment.Position = BgzfData::UnpackSignedInt(&x[4]);\r
\r
- tempValue = BgzfData::UnpackUnsignedInt(&x[2]);\r
+ tempValue = BgzfData::UnpackUnsignedInt(&x[8]);\r
bAlignment.Bin = tempValue >> 16;\r
bAlignment.MapQuality = tempValue >> 8 & 0xff;\r
queryNameLength = tempValue & 0xff;\r
\r
- tempValue = BgzfData::UnpackUnsignedInt(&x[3]);\r
+ tempValue = BgzfData::UnpackUnsignedInt(&x[12]);\r
bAlignment.AlignmentFlag = tempValue >> 16;\r
numCigarOperations = tempValue & 0xffff;\r
\r
- querySequenceLength = BgzfData::UnpackUnsignedInt(&x[4]);\r
- bAlignment.MateRefID = BgzfData::UnpackSignedInt(&x[5]);\r
- bAlignment.MatePosition = BgzfData::UnpackSignedInt(&x[6]);\r
- bAlignment.InsertSize = BgzfData::UnpackSignedInt(&x[7]);\r
+ querySequenceLength = BgzfData::UnpackUnsignedInt(&x[16]);\r
+ bAlignment.MateRefID = BgzfData::UnpackSignedInt(&x[20]);\r
+ bAlignment.MatePosition = BgzfData::UnpackSignedInt(&x[24]);\r
+ bAlignment.InsertSize = BgzfData::UnpackSignedInt(&x[28]);\r
\r
// calculate lengths/offsets\r
const unsigned int dataLength = blockLength - BAM_CORE_SIZE;\r
bytesRead += dataLength;\r
\r
// clear out any previous string data\r
- bAlignment.Name.clear(;)\r
+ bAlignment.Name.clear();\r
bAlignment.QueryBases.clear();\r
bAlignment.Qualities.clear();\r
bAlignment.AlignedBases.clear();\r
// -----------------------\r
if ( IsBigEndian ) {\r
int i = 0;\r
- while ( i < tagDataLen ) {\r
+ while ( (unsigned int)i < tagDataLen ) {\r
\r
i += 2; // skip tag type (e.g. "RG", "NM", etc)\r
uint8_t type = toupper(tagData[i]); // lower & upper case letters have same meaning \r
// ***************************************************************************\r
-// BamReader.h (c) 2009 Derek Barnett, Michael Strömberg\r
+// BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg\r
// Marth Lab, Department of Biology, Boston College\r
// All rights reserved.\r
// ---------------------------------------------------------------------------\r
-// Last modified: 8 December 2009 (DB)\r
+// Last modified: 30 March 2010 (DB)\r
// ---------------------------------------------------------------------------\r
// Uses BGZF routines were adapted from the bgzf.c code developed at the Broad\r
// Institute.\r
// returns SAM header text\r
const std::string GetHeaderText(void) const;\r
// returns number of reference sequences\r
- const int GetReferenceCount(void) const;\r
+ int GetReferenceCount(void) const;\r
// returns vector of reference objects\r
const BamTools::RefVector GetReferenceData(void) const;\r
// returns reference id (used for BamReader::Jump()) for the given reference name\r
- const int GetReferenceID(const std::string& refName) const;\r
+ int GetReferenceID(const std::string& refName) const;\r
\r
// ----------------------\r
// BAM index operations\r
// Marth Lab, Department of Biology, Boston College\r
// All rights reserved.\r
// ---------------------------------------------------------------------------\r
-// Last modified: 29 March 2010 (DB)\r
+// Last modified: 30 March 2010 (DB)\r
// ---------------------------------------------------------------------------\r
// Uses BGZF routines were adapted from the bgzf.c code developed at the Broad\r
// Institute.\r
\r
for (unsigned int i = 0; i < packedCigarLen; ++i) {\r
if ( IsBigEndian ) { \r
- SwapEndian_32(cigarData[i]); \r
+ SwapEndian_32p(&cigarData[i]); \r
}\r
}\r
\r
memcpy(tagData, al.TagData.data(), tagDataLength);\r
\r
int i = 0;\r
- while ( i < tagDataLength ) {\r
+ while ( (unsigned int)i < tagDataLength ) {\r
\r
i += 2; // skip tag type (e.g. "RG", "NM", etc)\r
uint8_t type = toupper(tagData[i]); // lower & upper case letters have same meaning \r