From: derek Date: Fri, 14 Oct 2011 16:42:15 +0000 (-0400) Subject: Fixed regression: improper @SQ line ordering in SamHeader output X-Git-Url: https://git.donarmstrong.com/?p=bamtools.git;a=commitdiff_plain;h=af6a3d8491e485969d2df306e41cb9439dec4039 Fixed regression: improper @SQ line ordering in SamHeader output --- diff --git a/CMakeLists.txt b/CMakeLists.txt index 31bc980..bcbdb3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ ensure_out_of_source_build (" # set BamTools version information set (BamTools_VERSION_MAJOR 2) set (BamTools_VERSION_MINOR 0) -set (BamTools_VERSION_BUILD 2) +set (BamTools_VERSION_BUILD 3) # set our library and executable destination dirs set (EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin") diff --git a/docs/Doxyfile b/docs/Doxyfile index da1bf4e..6e882dd 100644 --- a/docs/Doxyfile +++ b/docs/Doxyfile @@ -31,7 +31,7 @@ PROJECT_NAME = BamTools # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 2.0.2 +PROJECT_NUMBER = 2.0.3 # The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute) # base path where the generated documentation will be put. diff --git a/src/api/CMakeLists.txt b/src/api/CMakeLists.txt index bee347b..3e2ddd5 100644 --- a/src/api/CMakeLists.txt +++ b/src/api/CMakeLists.txt @@ -49,7 +49,7 @@ set( BamToolsAPISources # create main BamTools API shared library add_library( BamTools SHARED ${BamToolsAPISources} ) -set_target_properties( BamTools PROPERTIES SOVERSION "2.0.2" ) +set_target_properties( BamTools PROPERTIES SOVERSION "2.0.3" ) set_target_properties( BamTools PROPERTIES OUTPUT_NAME "bamtools" ) # create main BamTools API static library diff --git a/src/api/SamReadGroupDictionary.cpp b/src/api/SamReadGroupDictionary.cpp index 7b8fad0..7e36a15 100644 --- a/src/api/SamReadGroupDictionary.cpp +++ b/src/api/SamReadGroupDictionary.cpp @@ -2,7 +2,7 @@ // SamReadGroupDictionary.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 (DB) +// Last modified: 14 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamReadGroup entries. // *************************************************************************** @@ -19,32 +19,6 @@ using namespace std; Provides methods for operating on a collection of SamReadGroup entries. */ -/*! \typedef BamTools::SamReadGroupIterator - \brief mutable iterator for SamReadGroupDictionary data - - \note This iterator, dereferenced, actually points to a - std::pair, NOT a "plain old" SamReadGroup. - To retrieve the read group object: - - \code - SamReadGroupIterator iter; - SamReadGroup& rg = (*iter).second // OR iter->second; - \endcode -*/ - -/*! \typedef BamTools::SamReadGroupConstIterator - \brief const iterator for SamReadGroupDictionary data - - \note This iterator, dereferenced, actually points to a - std::pair, NOT a "plain old" SamReadGroup. - To retrieve the read group object: - - \code - SamReadGroupConstIterator iter; - const SamReadGroup& sq = (*iter).second // OR iter->second; - \endcode -*/ - /*! \fn SamReadGroupDictionary::SamReadGroupDictionary(void) \brief constructor */ @@ -55,6 +29,7 @@ SamReadGroupDictionary::SamReadGroupDictionary(void) { } */ SamReadGroupDictionary::SamReadGroupDictionary(const SamReadGroupDictionary& other) : m_data(other.m_data) + , m_lookupData(other.m_lookupData) { } /*! \fn SamReadGroupDictionary::~SamReadGroupDictionary(void) @@ -70,8 +45,10 @@ SamReadGroupDictionary::~SamReadGroupDictionary(void) { } \param[in] readGroup entry to be added */ void SamReadGroupDictionary::Add(const SamReadGroup& readGroup) { - if ( IsEmpty() || !Contains(readGroup) ) - m_data[readGroup.ID] = readGroup; + if ( IsEmpty() || !Contains(readGroup) ) { + m_data.push_back(readGroup); + m_lookupData[readGroup.ID] = readGroup; + } } /*! \fn void SamReadGroupDictionary::Add(const std::string& readGroupId) @@ -98,7 +75,7 @@ void SamReadGroupDictionary::Add(const SamReadGroupDictionary& readGroups) { SamReadGroupConstIterator rgIter = readGroups.ConstBegin(); SamReadGroupConstIterator rgEnd = readGroups.ConstEnd(); for ( ; rgIter != rgEnd; ++rgIter ) - Add(rgIter->second); + Add(*rgIter); } /*! \fn void SamReadGroupDictionary::Add(const std::vector& readGroups) @@ -155,6 +132,7 @@ SamReadGroupConstIterator SamReadGroupDictionary::Begin(void) const { */ void SamReadGroupDictionary::Clear(void) { m_data.clear(); + m_lookupData.clear(); } /*! \fn SamReadGroupConstIterator SamReadGroupDictionary::ConstBegin(void) const @@ -180,7 +158,7 @@ SamReadGroupConstIterator SamReadGroupDictionary::ConstEnd(void) const { \return \c true if dictionary contains a read group with this ID */ bool SamReadGroupDictionary::Contains(const std::string& readGroupId) const { - return ( m_data.find(readGroupId) != m_data.end() ); + return ( m_lookupData.find(readGroupId) != m_lookupData.end() ); } /*! \fn bool SamReadGroupDictionary::Contains(const SamReadGroup& readGroup) const @@ -240,7 +218,17 @@ void SamReadGroupDictionary::Remove(const SamReadGroup& readGroup) { \sa Remove() */ void SamReadGroupDictionary::Remove(const std::string& readGroupId) { - m_data.erase(readGroupId); + + SamReadGroupIterator rgIter = Begin(); + SamReadGroupIterator rgEnd = End(); + for ( size_t i = 0 ; rgIter != rgEnd; ++rgIter, ++i ) { + SamReadGroup& rg = (*rgIter); + if( rg.ID == readGroupId ) { + m_data.erase( Begin() + i ); + } + } + + m_lookupData.erase(readGroupId); } /*! \fn void SamReadGroupDictionary::Remove(const std::vector& readGroups) @@ -292,7 +280,10 @@ int SamReadGroupDictionary::Size(void) const { \return a modifiable reference to the SamReadGroup associated with the ID */ SamReadGroup& SamReadGroupDictionary::operator[](const std::string& readGroupId) { - if ( !Contains(readGroupId) ) - m_data[readGroupId] = SamReadGroup(readGroupId); - return m_data[readGroupId]; + if ( !Contains(readGroupId) ) { + SamReadGroup rg(readGroupId); + m_data.push_back(rg); + m_lookupData[readGroupId] = rg; + } + return m_lookupData[readGroupId]; } diff --git a/src/api/SamReadGroupDictionary.h b/src/api/SamReadGroupDictionary.h index 5aa44ab..c66c6d5 100644 --- a/src/api/SamReadGroupDictionary.h +++ b/src/api/SamReadGroupDictionary.h @@ -2,7 +2,7 @@ // SamReadGroupDictionary.h (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 (DB) +// Last modified: 14 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamReadGroup entries. // *************************************************************************** @@ -18,7 +18,7 @@ namespace BamTools { -typedef std::map SamReadGroupContainer; +typedef std::vector SamReadGroupContainer; typedef SamReadGroupContainer::iterator SamReadGroupIterator; typedef SamReadGroupContainer::const_iterator SamReadGroupConstIterator; @@ -77,6 +77,7 @@ class API_EXPORT SamReadGroupDictionary { // data members private: SamReadGroupContainer m_data; + std::map m_lookupData; }; } // namespace BamTools diff --git a/src/api/SamSequenceDictionary.cpp b/src/api/SamSequenceDictionary.cpp index 80042d6..25694f3 100644 --- a/src/api/SamSequenceDictionary.cpp +++ b/src/api/SamSequenceDictionary.cpp @@ -2,7 +2,7 @@ // SamSequenceDictionary.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 (DB) +// Last modified: 14 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamSequence entries. // ************************************************************************* @@ -19,30 +19,6 @@ using namespace std; Provides methods for operating on a collection of SamSequence entries. */ -/*! \typedef BamTools::SamSequenceIterator - \brief mutable iterator for SamSequenceDictionary data - - \note This iterator, dereferenced, points to a std::pair, NOT - a "plain old" SamSequence. To retrieve the sequence: - - \code - SamSequenceIterator iter; - SamSequence& sq = (*iter).second // OR iter->second; - \endcode -*/ - -/*! \typedef BamTools::SamSequenceConstIterator - \brief const iterator for SamSequenceDictionary data - - \note This iterator, dereferenced, points to a std::pair, NOT - a "plain old" SamSequence. To retrieve the sequence: - - \code - SamSequenceConstIterator iter; - const SamSequence& sq = (*iter).second // OR iter->second; - \endcode -*/ - /*! \fn SamSequenceDictionary::SamSequenceDictionary(void) \brief constructor */ @@ -53,6 +29,7 @@ SamSequenceDictionary::SamSequenceDictionary(void) { } */ SamSequenceDictionary::SamSequenceDictionary(const SamSequenceDictionary& other) : m_data(other.m_data) + , m_lookupData(other.m_lookupData) { } /*! \fn SamSequenceDictionary::~SamSequenceDictionary(void) @@ -68,8 +45,10 @@ SamSequenceDictionary::~SamSequenceDictionary(void) { } \param[in] sequence entry to be added */ void SamSequenceDictionary::Add(const SamSequence& sequence) { - if ( IsEmpty() || !Contains(sequence) ) - m_data[sequence.Name] = sequence; + if ( IsEmpty() || !Contains(sequence) ) { + m_data.push_back(sequence); + m_lookupData[sequence.Name] = sequence; + } } /*! \fn void SamSequenceDictionary::Add(const std::string& name, const int& length) @@ -97,7 +76,7 @@ void SamSequenceDictionary::Add(const SamSequenceDictionary& sequences) { SamSequenceConstIterator seqIter = sequences.ConstBegin(); SamSequenceConstIterator seqEnd = sequences.ConstEnd(); for ( ; seqIter != seqEnd; ++seqIter ) - Add(seqIter->second); + Add(*seqIter); } /*! \fn void SamSequenceDictionary::Add(const std::vector& sequences) @@ -157,6 +136,7 @@ SamSequenceConstIterator SamSequenceDictionary::Begin(void) const { */ void SamSequenceDictionary::Clear(void) { m_data.clear(); + m_lookupData.clear(); } /*! \fn SamSequenceConstIterator SamSequenceDictionary::ConstBegin(void) const @@ -182,7 +162,7 @@ SamSequenceConstIterator SamSequenceDictionary::ConstEnd(void) const { \return \c true if dictionary contains a sequence with this name */ bool SamSequenceDictionary::Contains(const std::string& sequenceName) const { - return ( m_data.find(sequenceName) != m_data.end() ); + return ( m_lookupData.find(sequenceName) != m_lookupData.end() ); } /*! \fn bool SamSequenceDictionary::Contains(const SamSequence& sequence) const @@ -242,7 +222,17 @@ void SamSequenceDictionary::Remove(const SamSequence& sequence) { \sa Remove() */ void SamSequenceDictionary::Remove(const std::string& sequenceName) { - m_data.erase(sequenceName); + + SamSequenceIterator seqIter = Begin(); + SamSequenceIterator seqEnd = End(); + for ( size_t i = 0 ; seqIter != seqEnd; ++seqIter, ++i ) { + SamSequence& seq = (*seqIter); + if( seq.Name == sequenceName ) { + m_data.erase( Begin() + i ); + } + } + + m_lookupData.erase(sequenceName); } /*! \fn void SamSequenceDictionary::Remove(const std::vector& sequences) @@ -294,7 +284,10 @@ int SamSequenceDictionary::Size(void) const { \return a modifiable reference to the SamSequence associated with the name */ SamSequence& SamSequenceDictionary::operator[](const std::string& sequenceName) { - if ( !Contains(sequenceName) ) - m_data[sequenceName] = SamSequence(sequenceName, 0); - return m_data[sequenceName]; + if ( !Contains(sequenceName) ) { + SamSequence seq(sequenceName, 0); + m_data.push_back(seq); + m_lookupData[sequenceName] = seq; + } + return m_lookupData[sequenceName]; } diff --git a/src/api/SamSequenceDictionary.h b/src/api/SamSequenceDictionary.h index a583f04..cf7c2f3 100644 --- a/src/api/SamSequenceDictionary.h +++ b/src/api/SamSequenceDictionary.h @@ -2,7 +2,7 @@ // SamSequenceDictionary.h (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 +// Last modified: 14 October 2011 // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamSequence entries. // *************************************************************************** @@ -18,7 +18,7 @@ namespace BamTools { -typedef std::map SamSequenceContainer; +typedef std::vector SamSequenceContainer; typedef SamSequenceContainer::iterator SamSequenceIterator; typedef SamSequenceContainer::const_iterator SamSequenceConstIterator; @@ -77,6 +77,7 @@ class API_EXPORT SamSequenceDictionary { // data members private: SamSequenceContainer m_data; + std::map m_lookupData; }; } // namespace BamTools diff --git a/src/api/internal/SamFormatPrinter_p.cpp b/src/api/internal/SamFormatPrinter_p.cpp index a5b61a0..f9a118e 100644 --- a/src/api/internal/SamFormatPrinter_p.cpp +++ b/src/api/internal/SamFormatPrinter_p.cpp @@ -2,7 +2,7 @@ // SamFormatPrinter.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 (DB) +// Last modified: 14 October 2011 (DB) // --------------------------------------------------------------------------- // Provides functionality for printing formatted SAM header to string // *************************************************************************** @@ -81,7 +81,7 @@ void SamFormatPrinter::PrintSQ(std::stringstream& out) const { SamSequenceConstIterator seqIter = m_header.Sequences.ConstBegin(); SamSequenceConstIterator seqEnd = m_header.Sequences.ConstEnd(); for ( ; seqIter != seqEnd; ++seqIter ) { - const SamSequence& seq = seqIter->second; + const SamSequence& seq = (*seqIter); // @SQ SN: LN: out << Constants::SAM_SQ_BEGIN_TOKEN @@ -115,7 +115,7 @@ void SamFormatPrinter::PrintRG(std::stringstream& out) const { SamReadGroupConstIterator rgIter = m_header.ReadGroups.ConstBegin(); SamReadGroupConstIterator rgEnd = m_header.ReadGroups.ConstEnd(); for ( ; rgIter != rgEnd; ++rgIter ) { - const SamReadGroup& rg = rgIter->second; + const SamReadGroup& rg = (*rgIter); // @RG ID: out << Constants::SAM_RG_BEGIN_TOKEN diff --git a/src/api/internal/SamHeaderValidator_p.cpp b/src/api/internal/SamHeaderValidator_p.cpp index 9d7f6d4..c76fff9 100644 --- a/src/api/internal/SamHeaderValidator_p.cpp +++ b/src/api/internal/SamHeaderValidator_p.cpp @@ -2,7 +2,7 @@ // SamHeaderValidator.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 (DB) +// Last modified: 14 October 2011 (DB) // --------------------------------------------------------------------------- // Provides functionality for validating SamHeader data // *************************************************************************** @@ -244,7 +244,7 @@ bool SamHeaderValidator::ValidateSequenceDictionary(void) { SamSequenceConstIterator seqIter = sequences.ConstBegin(); SamSequenceConstIterator seqEnd = sequences.ConstEnd(); for ( ; seqIter != seqEnd; ++seqIter ) { - const SamSequence& seq = seqIter->second; + const SamSequence& seq = (*seqIter); isValid &= ValidateSequence(seq); } @@ -264,7 +264,7 @@ bool SamHeaderValidator::ContainsUniqueSequenceNames(void) { SamSequenceConstIterator seqIter = sequences.ConstBegin(); SamSequenceConstIterator seqEnd = sequences.ConstEnd(); for ( ; seqIter != seqEnd; ++seqIter ) { - const SamSequence& seq = seqIter->second; + const SamSequence& seq = (*seqIter); // lookup sequence name const string& name = seq.Name; @@ -348,7 +348,7 @@ bool SamHeaderValidator::ValidateReadGroupDictionary(void) { SamReadGroupConstIterator rgIter = readGroups.ConstBegin(); SamReadGroupConstIterator rgEnd = readGroups.ConstEnd(); for ( ; rgIter != rgEnd; ++rgIter ) { - const SamReadGroup& rg = rgIter->second; + const SamReadGroup& rg = (*rgIter); isValid &= ValidateReadGroup(rg); } @@ -370,7 +370,7 @@ bool SamHeaderValidator::ContainsUniqueIDsAndPlatformUnits(void) { SamReadGroupConstIterator rgIter = readGroups.ConstBegin(); SamReadGroupConstIterator rgEnd = readGroups.ConstEnd(); for ( ; rgIter != rgEnd; ++rgIter ) { - const SamReadGroup& rg = rgIter->second; + const SamReadGroup& rg = (*rgIter); // -------------------------------- // check for unique ID diff --git a/src/toolkit/bamtools_resolve.cpp b/src/toolkit/bamtools_resolve.cpp index cdf53ee..cb42f5b 100644 --- a/src/toolkit/bamtools_resolve.cpp +++ b/src/toolkit/bamtools_resolve.cpp @@ -2,7 +2,7 @@ // bamtools_resolve.cpp (c) 2011 // Marth Lab, Department of Biology, Boston College // --------------------------------------------------------------------------- -// Last modified: 12 October 2011 +// Last modified: 14 October 2011 // --------------------------------------------------------------------------- // Resolves paired-end reads (marking the IsProperPair flag as needed). // *************************************************************************** @@ -1029,7 +1029,7 @@ void ResolveTool::ResolveToolPrivate::ParseHeader(const SamHeader& header) { SamReadGroupConstIterator rgIter = header.ReadGroups.ConstBegin(); SamReadGroupConstIterator rgEnd = header.ReadGroups.ConstEnd(); for ( ; rgIter != rgEnd; ++rgIter ) { - const SamReadGroup& rg = rgIter->second; + const SamReadGroup& rg = (*rgIter); m_readGroups.insert( make_pair(rg.ID, ReadGroupResolver()) ); } }