From 5ccdabf3912d6468bbd907442a6ab5b1da858c34 Mon Sep 17 00:00:00 2001 From: barnett Date: Tue, 30 Mar 2010 15:36:55 +0000 Subject: [PATCH] Had some typos in last commit. Fixed. git-svn-id: svn+ssh://gene.bc.edu/home/subversion/Derek/BamTools/trunk@41 9efb377e-2e27-44b9-b91a-ec4abb80ed8b --- BamAux.h | 42 +++++++++++++++++++++++++++++++++--------- BamReader.cpp | 39 ++++++++++++++++++--------------------- BamReader.h | 8 ++++---- BamWriter.cpp | 6 +++--- 4 files changed, 58 insertions(+), 37 deletions(-) diff --git a/BamAux.h b/BamAux.h index ea70927..089700a 100644 --- a/BamAux.h +++ b/BamAux.h @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 29 March 2010 (DB) +// Last modified: 30 March 2010 (DB) // --------------------------------------------------------------------------- // Provides the basic constants, data structures, etc. for using BAM files // *************************************************************************** @@ -341,12 +341,24 @@ inline bool SystemIsBigEndian(void) { } // swaps endianness of 16-bit value 'in place' +inline void SwapEndian_16(int16_t& x) { + x = ((x >> 8) | (x << 8)); +} + inline void SwapEndian_16(uint16_t& x) { x = ((x >> 8) | (x << 8)); } // swaps endianness of 32-bit value 'in-place' -inline void SwapEndian_32(uint32_t& value) { +inline void SwapEndian_32(int32_t& x) { + x = ( (x >> 24) | + ((x << 8) & 0x00FF0000) | + ((x >> 8) & 0x0000FF00) | + (x << 24) + ); +} + +inline void SwapEndian_32(uint32_t& x) { x = ( (x >> 24) | ((x << 8) & 0x00FF0000) | ((x >> 8) & 0x0000FF00) | @@ -355,14 +367,26 @@ inline void SwapEndian_32(uint32_t& value) { } // swaps endianness of 64-bit value 'in-place' -inline void SwapEndian_64(uint64_t& value) { +inline void SwapEndian_64(int64_t& x) { + x = ( (x >> 56) | + ((x << 40) & 0x00FF000000000000ll) | + ((x << 24) & 0x0000FF0000000000ll) | + ((x << 8) & 0x000000FF00000000ll) | + ((x >> 8) & 0x00000000FF000000ll) | + ((x >> 24) & 0x0000000000FF0000ll) | + ((x >> 40) & 0x000000000000FF00ll) | + (x << 56) + ); +} + +inline void SwapEndian_64(uint64_t& x) { x = ( (x >> 56) | - ((x << 40) & 0x00FF000000000000) | - ((x << 24) & 0x0000FF0000000000) | - ((x << 8) & 0x000000FF00000000) | - ((x >> 8) & 0x00000000FF000000) | - ((x >> 24) & 0x0000000000FF0000) | - ((x >> 40) & 0x000000000000FF00) | + ((x << 40) & 0x00FF000000000000ll) | + ((x << 24) & 0x0000FF0000000000ll) | + ((x << 8) & 0x000000FF00000000ll) | + ((x >> 8) & 0x00000000FF000000ll) | + ((x >> 24) & 0x0000000000FF0000ll) | + ((x >> 40) & 0x000000000000FF00ll) | (x << 56) ); } diff --git a/BamReader.cpp b/BamReader.cpp index c29b14c..2d43e39 100644 --- a/BamReader.cpp +++ b/BamReader.cpp @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 29 March 2010 (DB) +// Last modified: 30 March 2010 (DB) // --------------------------------------------------------------------------- // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -70,10 +70,7 @@ struct BamReader::BamReaderPrivate { bool GetNextAlignment(BamAlignment& bAlignment); // access auxiliary data - const string GetHeaderText(void) const; - const int GetReferenceCount(void) const; - const RefVector GetReferenceData(void) const; - const int GetReferenceID(const string& refName) const; + int GetReferenceID(const string& refName) const; // index operations bool CreateIndex(void); @@ -144,10 +141,10 @@ bool BamReader::Rewind(void) { return d->Rewind(); } bool BamReader::GetNextAlignment(BamAlignment& bAlignment) { return d->GetNextAlignment(bAlignment); } // access auxiliary data -const string BamReader::GetHeaderText(void) const { return d->HeaderText; } -const int BamReader::GetReferenceCount(void) const { return d->References.size(); } +const string BamReader::GetHeaderText(void) const { return d->HeaderText; } +int BamReader::GetReferenceCount(void) const { return d->References.size(); } const RefVector BamReader::GetReferenceData(void) const { return d->References; } -const int BamReader::GetReferenceID(const string& refName) const { return d->GetReferenceID(refName); } +int BamReader::GetReferenceID(const string& refName) const { return d->GetReferenceID(refName); } // index operations bool BamReader::CreateIndex(void) { return d->CreateIndex(); } @@ -375,7 +372,7 @@ bool BamReader::BamReaderPrivate::CreateIndex(void) { } // returns RefID for given RefName (returns References.size() if not found) -const int BamReader::BamReaderPrivate::GetReferenceID(const string& refName) const { +int BamReader::BamReaderPrivate::GetReferenceID(const string& refName) const { // retrieve names from reference data vector refNames; @@ -717,13 +714,13 @@ bool BamReader::BamReaderPrivate::LoadNextAlignment(BamAlignment& bAlignment) { int bytesRead = 4; // read in core alignment data, make sure the right size of data was read - uint32_t x[8]; + char x[BAM_CORE_SIZE]; if ( mBGZF.Read(x, BAM_CORE_SIZE) != BAM_CORE_SIZE ) { return false; } bytesRead += BAM_CORE_SIZE; if ( IsBigEndian ) { - for ( int i = 0; i < 8; ++i ) { - SwapEndian_32(x[i]); + for ( int i = 0; i < BAM_CORE_SIZE; i+=sizeof(uint32_t) ) { + SwapEndian_32p(&x[i]); } } @@ -734,21 +731,21 @@ bool BamReader::BamReaderPrivate::LoadNextAlignment(BamAlignment& bAlignment) { unsigned int querySequenceLength; bAlignment.RefID = BgzfData::UnpackSignedInt(&x[0]); - bAlignment.Position = BgzfData::UnpackSignedInt(&x[1]); + bAlignment.Position = BgzfData::UnpackSignedInt(&x[4]); - tempValue = BgzfData::UnpackUnsignedInt(&x[2]); + tempValue = BgzfData::UnpackUnsignedInt(&x[8]); bAlignment.Bin = tempValue >> 16; bAlignment.MapQuality = tempValue >> 8 & 0xff; queryNameLength = tempValue & 0xff; - tempValue = BgzfData::UnpackUnsignedInt(&x[3]); + tempValue = BgzfData::UnpackUnsignedInt(&x[12]); bAlignment.AlignmentFlag = tempValue >> 16; numCigarOperations = tempValue & 0xffff; - querySequenceLength = BgzfData::UnpackUnsignedInt(&x[4]); - bAlignment.MateRefID = BgzfData::UnpackSignedInt(&x[5]); - bAlignment.MatePosition = BgzfData::UnpackSignedInt(&x[6]); - bAlignment.InsertSize = BgzfData::UnpackSignedInt(&x[7]); + querySequenceLength = BgzfData::UnpackUnsignedInt(&x[16]); + bAlignment.MateRefID = BgzfData::UnpackSignedInt(&x[20]); + bAlignment.MatePosition = BgzfData::UnpackSignedInt(&x[24]); + bAlignment.InsertSize = BgzfData::UnpackSignedInt(&x[28]); // calculate lengths/offsets const unsigned int dataLength = blockLength - BAM_CORE_SIZE; @@ -772,7 +769,7 @@ bool BamReader::BamReaderPrivate::LoadNextAlignment(BamAlignment& bAlignment) { bytesRead += dataLength; // clear out any previous string data - bAlignment.Name.clear(;) + bAlignment.Name.clear(); bAlignment.QueryBases.clear(); bAlignment.Qualities.clear(); bAlignment.AlignedBases.clear(); @@ -875,7 +872,7 @@ bool BamReader::BamReaderPrivate::LoadNextAlignment(BamAlignment& bAlignment) { // ----------------------- if ( IsBigEndian ) { int i = 0; - while ( i < tagDataLen ) { + while ( (unsigned int)i < tagDataLen ) { i += 2; // skip tag type (e.g. "RG", "NM", etc) uint8_t type = toupper(tagData[i]); // lower & upper case letters have same meaning diff --git a/BamReader.h b/BamReader.h index 6332cde..8047d7a 100644 --- a/BamReader.h +++ b/BamReader.h @@ -1,9 +1,9 @@ // *************************************************************************** -// BamReader.h (c) 2009 Derek Barnett, Michael Strömberg +// BamReader.h (c) 2009 Derek Barnett, Michael Str�mberg // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 8 December 2009 (DB) +// Last modified: 30 March 2010 (DB) // --------------------------------------------------------------------------- // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -59,11 +59,11 @@ class BamReader { // returns SAM header text const std::string GetHeaderText(void) const; // returns number of reference sequences - const int GetReferenceCount(void) const; + int GetReferenceCount(void) const; // returns vector of reference objects const BamTools::RefVector GetReferenceData(void) const; // returns reference id (used for BamReader::Jump()) for the given reference name - const int GetReferenceID(const std::string& refName) const; + int GetReferenceID(const std::string& refName) const; // ---------------------- // BAM index operations diff --git a/BamWriter.cpp b/BamWriter.cpp index 075989a..2cd2742 100644 --- a/BamWriter.cpp +++ b/BamWriter.cpp @@ -3,7 +3,7 @@ // Marth Lab, Department of Biology, Boston College // All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 29 March 2010 (DB) +// Last modified: 30 March 2010 (DB) // --------------------------------------------------------------------------- // Uses BGZF routines were adapted from the bgzf.c code developed at the Broad // Institute. @@ -305,7 +305,7 @@ void BamWriter::BamWriterPrivate::SaveAlignment(const BamAlignment& al) { for (unsigned int i = 0; i < packedCigarLen; ++i) { if ( IsBigEndian ) { - SwapEndian_32(cigarData[i]); + SwapEndian_32p(&cigarData[i]); } } @@ -332,7 +332,7 @@ void BamWriter::BamWriterPrivate::SaveAlignment(const BamAlignment& al) { memcpy(tagData, al.TagData.data(), tagDataLength); int i = 0; - while ( i < tagDataLength ) { + while ( (unsigned int)i < tagDataLength ) { i += 2; // skip tag type (e.g. "RG", "NM", etc) uint8_t type = toupper(tagData[i]); // lower & upper case letters have same meaning -- 2.39.5