From: derek Date: Mon, 3 Oct 2011 20:50:56 +0000 (-0400) Subject: merge conflict X-Git-Url: https://git.donarmstrong.com/?p=bamtools.git;a=commitdiff_plain;h=1a93ff03d7e40d97c32e6f5966045ceaeb2f038a merge conflict --- 1a93ff03d7e40d97c32e6f5966045ceaeb2f038a diff --cc src/api/BamMultiReader.cpp index 8543451,35e6758..0079871 --- a/src/api/BamMultiReader.cpp +++ b/src/api/BamMultiReader.cpp @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // BamMultiReader.cpp (c) 2010 Erik Garrison, Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 15 March 2011 (DB) + // Last modified: 1 October 2011 (DB) // --------------------------------------------------------------------------- // Convenience class for reading multiple BAM files. // diff --cc src/api/BamMultiReader.h index 561ce7a,43ef56a..959048c --- a/src/api/BamMultiReader.h +++ b/src/api/BamMultiReader.h @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // BamMultiReader.h (c) 2010 Erik Garrison, Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 15 March 2011 (DB) + // Last modified: 1 October 2011 (DB) // --------------------------------------------------------------------------- // Convenience class for reading multiple BAM files. // *************************************************************************** diff --cc src/api/SamReadGroupDictionary.cpp index f243f92,af4e341..4dcaa3b --- a/src/api/SamReadGroupDictionary.cpp +++ b/src/api/SamReadGroupDictionary.cpp @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // SamReadGroupDictionary.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 18 April 2011 (DB) + // Last modified: 1 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamReadGroup entries. // *************************************************************************** diff --cc src/api/SamReadGroupDictionary.h index 328763a,3d5ff2d..89f23e0 --- a/src/api/SamReadGroupDictionary.h +++ b/src/api/SamReadGroupDictionary.h @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // SamReadGroupDictionary.h (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 18 April 2011 (DB) + // Last modified: 1 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamReadGroup entries. // *************************************************************************** diff --cc src/api/SamSequenceDictionary.cpp index 10d0437,0c92581..34cf328 --- a/src/api/SamSequenceDictionary.cpp +++ b/src/api/SamSequenceDictionary.cpp @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // SamSequenceDictionary.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 18 April 2011 (DB) + // Last modified: 1 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamSequence entries. // ************************************************************************* diff --cc src/api/SamSequenceDictionary.h index 76bd45a,d488e14..8e2401e --- a/src/api/SamSequenceDictionary.h +++ b/src/api/SamSequenceDictionary.h @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // SamSequenceDictionary.h (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 18 April 2011 + // Last modified: 1 October 2011 // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamSequence entries. // *************************************************************************** diff --cc src/api/internal/BamMultiMerger_p.h index b279611,bd596ef..9248df0 --- a/src/api/internal/BamMultiMerger_p.h +++ b/src/api/internal/BamMultiMerger_p.h @@@ -1,8 -1,8 +1,8 @@@ // *************************************************************************** // BamMultiMerger_p.h (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 28 September 2011 (DB) ++// Last modified: 3 October 2011 (DB) // --------------------------------------------------------------------------- // Provides merging functionality for BamMultiReader. At this point, supports // sorting results by (refId, position) or by read name. diff --cc src/api/internal/BamMultiReader_p.cpp index 189f0ec,a5c7ca6..bacc449 --- a/src/api/internal/BamMultiReader_p.cpp +++ b/src/api/internal/BamMultiReader_p.cpp @@@ -431,15 -365,11 +365,14 @@@ bool BamMultiReaderPrivate::LocateIndex // opens BAM files bool BamMultiReaderPrivate::Open(const vector& filenames) { - // create alignment cache if neccessary - if ( m_alignments == 0 ) { - m_alignments = CreateMergerForCurrentSortOrder(); - if ( m_alignments == 0 ) return false; - } + bool openedOk = true; + + // put all current readers back at beginning + openedOk &= Rewind(); + // put all current readers back at beginning (refreshes alignment cache) + Rewind(); + // iterate over filenames vector::const_iterator filenameIter = filenames.begin(); vector::const_iterator filenameEnd = filenames.end(); @@@ -507,80 -447,35 +450,63 @@@ bool BamMultiReaderPrivate::OpenIndexes return result; } - ReaderAlignment BamMultiReaderPrivate::OpenReader(const string& filename, bool* ok) { + - // clear status flag - *ok = false; - - // create new BamReader & BamAlignment - BamReader* reader = new BamReader; - BamAlignment* alignment = new BamAlignment; + bool BamMultiReaderPrivate::PopNextCachedAlignment(BamAlignment& al, const bool needCharData) { - // if reader opens OK - if ( reader->Open(filename) ) { + // skip if no alignments available + if ( m_alignmentCache == 0 || m_alignmentCache->IsEmpty() ) + return false; - // if first alignment reads OK - if ( LoadNextAlignment(reader, alignment) ) { - *ok = true; - return make_pair(reader, alignment); - } + // pop next merge item entry from cache + MergeItem item = m_alignmentCache->TakeFirst(); + BamReader* reader = item.Reader; + BamAlignment* alignment = item.Alignment; + if ( reader == 0 || alignment == 0 ) + return false; - // could not read alignment - else { - cerr << "BamMultiReader WARNING: Could not read first alignment from " - << filename << ", ignoring file" << endl; - } + // set char data if requested + if ( needCharData ) { + alignment->BuildCharData(); + alignment->Filename = reader->GetFilename(); } - // reader could not open - else { - cerr << "BamMultiReader WARNING: Could not open " - << filename << ", ignoring file" << endl; - } + // store cached alignment into destination parameter (by copy) + al = *alignment; - // if we get here, there was a problem with this BAM file (opening or reading) - // clean up memory allocation & return null pointer - delete reader; - delete alignment; - return ReaderAlignment(); - } + // load next alignment from reader & store in cache + SaveNextAlignment(reader, alignment); - // print associated filenames to stdout - void BamMultiReaderPrivate::PrintFilenames(void) const { - const vector& filenames = Filenames(); - vector::const_iterator filenameIter = filenames.begin(); - vector::const_iterator filenameEnd = filenames.end(); - for ( ; filenameIter != filenameEnd; ++filenameIter ) - cout << (*filenameIter) << endl; + // return success + return true; } +bool BamMultiReaderPrivate::PopNextCachedAlignment(BamAlignment& al, const bool needCharData) { + + // bail out if no more data to process + if ( !HasAlignmentData() ) + return false; + + // pop next reader/alignment pair + ReaderAlignment nextReaderAlignment = m_alignments->TakeFirst(); + BamReader* reader = nextReaderAlignment.first; + BamAlignment* alignment = nextReaderAlignment.second; + + // store cached alignment into destination parameter (by copy) + al = *alignment; + + // set char data if requested + if ( needCharData ) { + al.BuildCharData(); + al.Filename = reader->GetFilename(); + } + + // load next alignment from reader & store in cache + SaveNextAlignment(reader, alignment); + + // return success + return true; +} + // returns BAM file pointers to beginning of alignment data & resets alignment cache bool BamMultiReaderPrivate::Rewind(void) { diff --cc src/api/internal/BamMultiReader_p.h index 33048eb,70640a3..4c4e5ea --- a/src/api/internal/BamMultiReader_p.h +++ b/src/api/internal/BamMultiReader_p.h @@@ -28,14 -29,8 +29,12 @@@ namespace BamTools { namespace Internal { - class IBamMultiMerger; - class BamMultiReaderPrivate { + // typedefs + public: + typedef std::pair ReaderAlignment; + // constructor / destructor public: BamMultiReaderPrivate(void); @@@ -78,11 -71,7 +75,8 @@@ // 'internal' methods public: - IBamMultiMerger* CreateMergerForCurrentSortOrder(void) const; - const std::string ExtractReadGroup(const std::string& headerLine) const; - bool HasAlignmentData(void) const; - bool LoadNextAlignment(BamReader* reader, BamAlignment* alignment); - ReaderAlignment OpenReader(const std::string& filename, bool* ok); ++ + IMultiMerger* CreateAlignmentCache(void) const; bool PopNextCachedAlignment(BamAlignment& al, const bool needCharData); bool RewindReaders(void); void SaveNextAlignment(BamReader* reader, BamAlignment* alignment); diff --cc src/toolkit/bamtools_sort.cpp index ad0e4f0,37a74e5..f495058 --- a/src/toolkit/bamtools_sort.cpp +++ b/src/toolkit/bamtools_sort.cpp @@@ -1,8 -1,9 +1,8 @@@ // *************************************************************************** // bamtools_sort.cpp (c) 2010 Derek Barnett, Erik Garrison // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- - // Last modified: 28 September 2011 (DB) + // Last modified: 3 October 2011 (DB) // --------------------------------------------------------------------------- // Sorts an input BAM file // ***************************************************************************