]> git.donarmstrong.com Git - bamtools.git/commitdiff
Fixed regression: improper @SQ line ordering in SamHeader output
authorderek <derekwbarnett@gmail.com>
Fri, 14 Oct 2011 16:42:15 +0000 (12:42 -0400)
committerderek <derekwbarnett@gmail.com>
Fri, 14 Oct 2011 16:42:15 +0000 (12:42 -0400)
CMakeLists.txt
docs/Doxyfile
src/api/CMakeLists.txt
src/api/SamReadGroupDictionary.cpp
src/api/SamReadGroupDictionary.h
src/api/SamSequenceDictionary.cpp
src/api/SamSequenceDictionary.h
src/api/internal/SamFormatPrinter_p.cpp
src/api/internal/SamHeaderValidator_p.cpp
src/toolkit/bamtools_resolve.cpp

index 31bc9806969270a47d412bb8fc70f6ccc68b1691..bcbdb3f493c2602a2bd55cb8049a7354e4475e13 100644 (file)
@@ -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")
index da1bf4ed6b70b524546eaefef5e57ddbcbb4b0e4..6e882dd5cead7310ebcc2661a3b810a745016981 100644 (file)
@@ -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. 
index bee347be36facacee02f29715e221c50a5398e62..3e2ddd5b022ac309a3f5e0dce80f8d36754485be 100644 (file)
@@ -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
index 7b8fad079cdac618eda4880c54c60857bde50472..7e36a155cbf8a8166b3b4f095d5e24126e95fb99 100644 (file)
@@ -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<std::string, SamReadGroup>, 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<std::string, SamReadGroup>, 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<SamReadGroup>& 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<SamReadGroup>& 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];
 }
index 5aa44aba613054682c4f71737d3d1313a01d7593..c66c6d5b233dee35648bfaf4b65d01ec257a9f0b 100644 (file)
@@ -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<std::string, SamReadGroup>   SamReadGroupContainer;
+typedef std::vector<SamReadGroup>             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<std::string, SamReadGroup> m_lookupData;
 };
 
 } // namespace BamTools
index 80042d651a88b88446bd9256b176d42db9ad24f1..25694f34f723f053c192658817314fa058058a1c 100644 (file)
@@ -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<std::string, SamSequence>, 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<std::string, SamSequence>, 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<SamSequence>& 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<SamSequence>& 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];
 }
index a583f046e10ec78a73394bdcb0906c0fa79e4b6b..cf7c2f3eb4049fef90739a77e6c7ce6ba7556911 100644 (file)
@@ -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<std::string, SamSequence>   SamSequenceContainer;
+typedef std::vector<SamSequence>             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<std::string, SamSequence> m_lookupData;
 };
 
 } // namespace BamTools
index a5b61a017bbdf4bcaa63d26b2e489a8078f31e5a..f9a118e5c9d5f6eb8e8beb96000e715c38b9c153 100644 (file)
@@ -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:<Name> LN:<Length>
         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:<ID>
         out << Constants::SAM_RG_BEGIN_TOKEN
index 9d7f6d42dcb6c63fba649827edb2a71cf581583a..c76fff95ba3a9fd2d8198abd1fd1cb035f7df91f 100644 (file)
@@ -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
index cdf53eeeca9de0eb99e1a923431e82ea1f054a57..cb42f5b4243322fbc026c6c2b25610f4b02bf0ed 100644 (file)
@@ -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<string, ReadGroupResolver>(rg.ID, ReadGroupResolver()) );
     }
 }