// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 5 April 2011 (DB)
+// Last modified: 10 May 2011 (DB)
// ---------------------------------------------------------------------------
// Provides the basic functionality for reading BAM files
// ***************************************************************************
Close();
// attempt to open BgzfStream for reading
- if ( !m_stream.Open(filename, "rb") )
+ if ( !m_stream.Open(filename, "rb") ) {
+ cerr << "BamReader ERROR: Could not open BGZF stream for " << filename << endl;
return false;
+ }
// attempt to load header data
- if ( !LoadHeaderData() )
+ if ( !LoadHeaderData() ) {
+ cerr << "BamReader ERROR: Could not load header data for " << filename << endl;
+ Close();
return false;
+ }
// attempt to load reference data
- if ( !LoadReferenceData() )
+ if ( !LoadReferenceData() ) {
+ cerr << "BamReader ERROR: Could not load reference data for " << filename << endl;
+ Close();
return false;
+ }
// if all OK, store filename & offset of first alignment
m_filename = filename;
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 27 April 2011 (DB)
+// Last modified: 10 May 2011 (DB)
// ---------------------------------------------------------------------------
// Provides index operations for the standardized BAM index format (".bai")
// ***************************************************************************
// store alignment chunk's start offset
// if its stop offset is larger than our 'minOffset'
- if ( chunkStop > minOffset )
+ if ( chunkStop >= minOffset )
offsets.push_back(chunkStart);
}
// set up region boundaries based on actual BamReader data
uint32_t begin;
uint32_t end;
- if ( !AdjustRegion(region, begin, end) )
+ if ( !AdjustRegion(region, begin, end) ) {
+ cerr << "BamStandardIndex ERROR: cannot calculate offsets on invalid region" << endl;
return false;
+ }
// retrieve all candidate bin IDs for region
set<uint16_t> candidateBins;
const uint64_t& minOffset = CalculateMinOffset(refSummary, begin);
// attempt to use reference summary, minOffset, & candidateBins to calculate offsets
- if ( !CalculateCandidateOffsets(refSummary, minOffset, candidateBins, offsets) )
+ if ( !CalculateCandidateOffsets(refSummary, minOffset, candidateBins, offsets) ) {
+ cerr << "Could not caluclate candidate offsets for region" << endl;
return false;
+ }
// ensure that offsets are sorted before returning
sort( offsets.begin(), offsets.end() );
// create new alignment chunk
BaiAlignmentChunk newChunk(currentOffset, lastOffset);
+
+
// if no entry exists yet for this bin, create one and store alignment chunk
BaiBinMap::iterator binIter = binMap.find(currentBin);
if ( binIter == binMap.end() ) {
}
bool BamStandardIndex::SummarizeReference(BaiReferenceSummary& refSummary) {
+
bool loadedOk = true;
loadedOk &= SummarizeBins(refSummary);
loadedOk &= SummarizeLinearOffsets(refSummary);
// Marth Lab, Department of Biology, Boston College
// All rights reserved.
// ---------------------------------------------------------------------------
-// Last modified: 19 April 2011 (DB)
+// Last modified: 10 May 2011 (DB)
// ---------------------------------------------------------------------------
// Provides the basic functionality for producing BAM files
// ***************************************************************************
// write the base qualities
char* pBaseQualities = (char*)al.Qualities.data();
- for ( unsigned int i = 0; i < queryLength; i++ )
+ for ( unsigned int i = 0; i < queryLength; ++i )
pBaseQualities[i] -= 33; // FASTQ conversion
m_stream.Write(pBaseQualities, queryLength);