From: barnett Date: Thu, 23 Apr 2009 20:26:30 +0000 (+0000) Subject: Removed assertion in GetOffset(), now returns -1 if regionChunks == 0. Jump() then... X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=855e80b994faaf1cc12bbb62b314e4b08ef65f3d;p=bamtools.git Removed assertion in GetOffset(), now returns -1 if regionChunks == 0. Jump() then returns false if offset = -1, else tries to Jump git-svn-id: svn+ssh://gene.bc.edu/home/subversion/Derek/BamTools/trunk@17 9efb377e-2e27-44b9-b91a-ec4abb80ed8b --- diff --git a/BamReader.cpp b/BamReader.cpp index 4b50d7e..ad584a2 100644 --- a/BamReader.cpp +++ b/BamReader.cpp @@ -2,7 +2,7 @@ // Derek Barnett // Marth Lab, Boston College -// Last modified: 6 April 2009 +// Last modified: 23 April 2009 #include "BamReader.h" #include @@ -153,7 +153,10 @@ bool BamReader::Jump(int refID, unsigned int left) { m_currentRefID = refID; m_currentLeft = left; m_isRegionSpecified = true; - return ( bam_seek(m_file, GetOffset(m_currentRefID, m_currentLeft), SEEK_SET) == 0 ); + + int64_t offset = GetOffset(m_currentRefID, m_currentLeft); + if ( offset == -1 ) { return false; } + else { return ( bam_seek(m_file, offset, SEEK_SET) == 0 ); } } return false; } @@ -238,7 +241,7 @@ uint32_t BamReader::CalculateAlignmentEnd(const unsigned int& position, const ve return alignEnd; } -uint64_t BamReader::GetOffset(int refID, unsigned int left) { +int64_t BamReader::GetOffset(int refID, unsigned int left) { // make space for bins uint16_t* bins = (uint16_t*)calloc(MAX_BIN, 2); @@ -298,7 +301,7 @@ uint64_t BamReader::GetOffset(int refID, unsigned int left) { free(bins); // there should be at least 1 - assert(regionChunks.size() > 0); + if(regionChunks.size() > 0) { return -1; } // sort chunks by start position sort ( regionChunks.begin(), regionChunks.end(), LookupKeyCompare() ); @@ -323,7 +326,7 @@ uint64_t BamReader::GetOffset(int refID, unsigned int left) { } // return beginning file offset of first chunk for region - return regionChunks.at(0).first; + return (int64_t)regionChunks.at(0).first; } bool BamReader::IsOverlap(BamAlignment& bAlignment) { diff --git a/BamReader.h b/BamReader.h index 7748afa..e2b4598 100644 --- a/BamReader.h +++ b/BamReader.h @@ -33,7 +33,7 @@ // Derek Barnett // Marth Lab, Boston College -// Last modified: 6 April 2009 +// Last modified: 23 April 2009 #ifndef BAMREADER_H #define BAMREADER_H @@ -205,7 +205,7 @@ class BamReader { private: int BinsFromRegion(int, unsigned int, uint16_t[MAX_BIN]); uint32_t CalculateAlignmentEnd(const unsigned int&, const vector&); - uint64_t GetOffset(int, unsigned int); + int64_t GetOffset(int, unsigned int); bool IsOverlap(BamAlignment&); bool LoadHeader(void); bool LoadIndex(void);