# set BamTools version information
set (BamTools_VERSION_MAJOR 2)
set (BamTools_VERSION_MINOR 0)
-set (BamTools_VERSION_BUILD 0)
+set (BamTools_VERSION_BUILD 1)
# set our library and executable destination dirs
set (EXECUTABLE_OUTPUT_PATH "${CMAKE_SOURCE_DIR}/bin")
# This could be handy for archiving the generated documentation or
# if some version control system is used.
-PROJECT_NUMBER = 2.0.0
+PROJECT_NUMBER = 2.0.1
# The OUTPUT_DIRECTORY tag is used to specify the (relative or absolute)
# base path where the generated documentation will be put.
# create main BamTools API shared library
add_library( BamTools SHARED ${BamToolsAPISources} )
-set_target_properties( BamTools PROPERTIES SOVERSION "2.0.0" )
+set_target_properties( BamTools PROPERTIES SOVERSION "2.0.1" )
set_target_properties( BamTools PROPERTIES OUTPUT_NAME "bamtools" )
# create main BamTools API static library
// SamReadGroupDictionary.cpp (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 10 October 2011 (DB)
+// Last modified: 12 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamReadGroup entries.
// ***************************************************************************
#include "api/SamReadGroupDictionary.h"
using namespace BamTools;
-#include <algorithm>
#include <iostream>
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
*/
*/
void SamReadGroupDictionary::Add(const SamReadGroup& readGroup) {
if ( IsEmpty() || !Contains(readGroup) )
- m_data.push_back(readGroup);
+ m_data[readGroup.ID] = readGroup;
}
/*! \fn void SamReadGroupDictionary::Add(const std::string& readGroupId)
SamReadGroupConstIterator rgIter = readGroups.ConstBegin();
SamReadGroupConstIterator rgEnd = readGroups.ConstEnd();
for ( ; rgIter != rgEnd; ++rgIter )
- Add(*rgIter);
+ Add(rgIter->second);
}
/*! \fn void SamReadGroupDictionary::Add(const std::vector<SamReadGroup>& readGroups)
\return \c true if dictionary contains a read group with this ID
*/
bool SamReadGroupDictionary::Contains(const std::string& readGroupId) const {
- return ( IndexOf(readGroupId) != (int)m_data.size() );
+ return ( m_data.find(readGroupId) != m_data.end() );
}
/*! \fn bool SamReadGroupDictionary::Contains(const SamReadGroup& readGroup) const
\return \c true if dictionary contains read group (matching on ID).
*/
bool SamReadGroupDictionary::Contains(const SamReadGroup& readGroup) const {
- return Contains( readGroup.ID );
+ return Contains(readGroup.ID);
}
/*! \fn SamReadGroupIterator SamReadGroupDictionary::End(void)
return m_data.end();
}
-/*! \fn int SamReadGroupDictionary::IndexOf(const std::string& readGroupId) const
- \internal
- \return index of read group if found. Otherwise, returns vector::size() (invalid index).
-*/
-int SamReadGroupDictionary::IndexOf(const std::string& readGroupId) const {
- SamReadGroupConstIterator begin = ConstBegin();
- SamReadGroupConstIterator iter = begin;
- SamReadGroupConstIterator end = ConstEnd();
- for ( ; iter != end; ++iter ) {
- const SamReadGroup& current = (*iter);
- if ( current.ID == readGroupId )
- break;
- }
- return distance( begin, iter );
-}
-
/*! \fn bool SamReadGroupDictionary::IsEmpty(void) const
\brief Returns \c true if dictionary contains no read groups
\sa Size()
\param[in] readGroup read group to remove (matches on ID)
*/
void SamReadGroupDictionary::Remove(const SamReadGroup& readGroup) {
- Remove( readGroup.ID );
+ Remove(readGroup.ID);
}
/*! \fn void SamReadGroupDictionary::Remove(const std::string& readGroupId)
\sa Remove()
*/
void SamReadGroupDictionary::Remove(const std::string& readGroupId) {
- if ( Contains(readGroupId) )
- m_data.erase( m_data.begin() + IndexOf(readGroupId) );
+ m_data.erase(readGroupId);
}
/*! \fn void SamReadGroupDictionary::Remove(const std::vector<SamReadGroup>& readGroups)
\return a modifiable reference to the SamReadGroup associated with the ID
*/
SamReadGroup& SamReadGroupDictionary::operator[](const std::string& readGroupId) {
-
- // look up read group ID
- int index = IndexOf(readGroupId);
-
- // if found, return read group at index
- if ( index != (int)m_data.size() )
- return m_data[index];
-
- // otherwise, append new read group and return reference
- else {
- SamReadGroup rg(readGroupId);
- m_data.push_back(rg);
- return m_data.back();
- }
+ if ( !Contains(readGroupId) )
+ m_data[readGroupId] = SamReadGroup(readGroupId);
+ return m_data[readGroupId];
}
// SamReadGroupDictionary.h (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 10 October 2011 (DB)
+// Last modified: 12 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamReadGroup entries.
// ***************************************************************************
#include "api/api_global.h"
#include "api/SamReadGroup.h"
+#include <map>
#include <string>
#include <vector>
namespace BamTools {
-typedef std::vector<SamReadGroup> SamReadGroupContainer;
+typedef std::map<std::string, SamReadGroup> SamReadGroupContainer;
typedef SamReadGroupContainer::iterator SamReadGroupIterator;
typedef SamReadGroupContainer::const_iterator SamReadGroupConstIterator;
SamReadGroupConstIterator End(void) const; // returns const_iterator to end()
SamReadGroupConstIterator ConstEnd(void) const; // returns const_iterator to end()
- // internal methods
- private:
- int IndexOf(const std::string& readGroupId) const;
-
// data members
private:
SamReadGroupContainer m_data;
// SamSequenceDictionary.cpp (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 10 October 2011 (DB)
+// Last modified: 12 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamSequence entries.
// *************************************************************************
-#include <api/SamSequenceDictionary.h>
+#include "api/SamSequenceDictionary.h"
using namespace BamTools;
#include <iostream>
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
*/
*/
void SamSequenceDictionary::Add(const SamSequence& sequence) {
if ( IsEmpty() || !Contains(sequence) )
- m_data.push_back(sequence);
+ m_data[sequence.Name] = sequence;
}
/*! \fn void SamSequenceDictionary::Add(const std::string& name, const int& length)
SamSequenceConstIterator seqIter = sequences.ConstBegin();
SamSequenceConstIterator seqEnd = sequences.ConstEnd();
for ( ; seqIter != seqEnd; ++seqIter )
- Add(*seqIter);
+ Add(seqIter->second);
}
/*! \fn void SamSequenceDictionary::Add(const std::vector<SamSequence>& sequences)
\return \c true if dictionary contains a sequence with this name
*/
bool SamSequenceDictionary::Contains(const std::string& sequenceName) const {
- return ( IndexOf(sequenceName) != (int)m_data.size() );
+ return ( m_data.find(sequenceName) != m_data.end() );
}
/*! \fn bool SamSequenceDictionary::Contains(const SamSequence& sequence) const
\return \c true if dictionary contains sequence (matching on name)
*/
bool SamSequenceDictionary::Contains(const SamSequence& sequence) const {
- return ( IndexOf(sequence.Name) != (int)m_data.size() );
+ return Contains(sequence.Name);
}
/*! \fn SamSequenceIterator SamSequenceDictionary::End(void)
return m_data.end();
}
-/*! \fn int SamSequenceDictionary::IndexOf(const std::string& name) const
- \internal
- \return index of sequence if found (matching on name). Otherwise, returns vector::size() (invalid index).
-*/
-int SamSequenceDictionary::IndexOf(const std::string& name) const {
- SamSequenceConstIterator begin = ConstBegin();
- SamSequenceConstIterator iter = begin;
- SamSequenceConstIterator end = ConstEnd();
- for ( ; iter != end; ++iter ) {
- const SamSequence& currentSeq = (*iter);
- if ( currentSeq.Name == name )
- break;
- }
- return distance( begin, iter );
-}
-
/*! \fn bool SamSequenceDictionary::IsEmpty(void) const
\brief Returns \c true if dictionary contains no sequences
\sa Size()
\param[in] sequence SamSequence to remove (matching on name)
*/
void SamSequenceDictionary::Remove(const SamSequence& sequence) {
- Remove( sequence.Name );
+ Remove(sequence.Name);
}
/*! \fn void SamSequenceDictionary::Remove(const std::string& sequenceName)
\sa Remove()
*/
void SamSequenceDictionary::Remove(const std::string& sequenceName) {
- if ( Contains(sequenceName) )
- m_data.erase( m_data.begin() + IndexOf(sequenceName) );
+ m_data.erase(sequenceName);
}
/*! \fn void SamSequenceDictionary::Remove(const std::vector<SamSequence>& sequences)
\return a modifiable reference to the SamSequence associated with the name
*/
SamSequence& SamSequenceDictionary::operator[](const std::string& sequenceName) {
-
- // look up sequence ID
- int index = IndexOf(sequenceName);
-
- // if found, return sequence at index
- if ( index != (int)m_data.size() )
- return m_data[index];
-
- // otherwise, append new sequence and return reference
- else {
- m_data.push_back( SamSequence(sequenceName, 0) );
- return m_data.back();
- }
+ if ( !Contains(sequenceName) )
+ m_data[sequenceName] = SamSequence(sequenceName, 0);
+ return m_data[sequenceName];
}
// SamSequenceDictionary.h (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 10 October 2011
+// Last modified: 12 October 2011
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamSequence entries.
// ***************************************************************************
#include "api/api_global.h"
#include "api/SamSequence.h"
-#include <string>
#include <map>
+#include <string>
#include <vector>
namespace BamTools {
-typedef std::vector<SamSequence> SamSequenceContainer;
+typedef std::map<std::string, SamSequence> SamSequenceContainer;
typedef SamSequenceContainer::iterator SamSequenceIterator;
typedef SamSequenceContainer::const_iterator SamSequenceConstIterator;
SamSequenceConstIterator End(void) const; // returns const_iterator to end()
SamSequenceConstIterator ConstEnd(void) const; // returns const_iterator to end()
- // internal methods
- private:
- int IndexOf(const std::string& name) const;
-
// data members
private:
SamSequenceContainer m_data;
// SamFormatPrinter.cpp (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 10 October 2011 (DB)
+// Last modified: 12 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides functionality for printing formatted SAM header to string
// ***************************************************************************
SamSequenceConstIterator seqIter = m_header.Sequences.ConstBegin();
SamSequenceConstIterator seqEnd = m_header.Sequences.ConstEnd();
for ( ; seqIter != seqEnd; ++seqIter ) {
- const SamSequence& seq = (*seqIter);
+ const SamSequence& seq = seqIter->second;
// @SQ SN:<Name> LN:<Length>
out << Constants::SAM_SQ_BEGIN_TOKEN
SamReadGroupConstIterator rgIter = m_header.ReadGroups.ConstBegin();
SamReadGroupConstIterator rgEnd = m_header.ReadGroups.ConstEnd();
for ( ; rgIter != rgEnd; ++rgIter ) {
- const SamReadGroup& rg = (*rgIter);
+ const SamReadGroup& rg = rgIter->second;
// @RG ID:<ID>
out << Constants::SAM_RG_BEGIN_TOKEN
// SamHeaderValidator.cpp (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 10 October 2011 (DB)
+// Last modified: 12 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides functionality for validating SamHeader data
// ***************************************************************************
SamSequenceConstIterator seqIter = sequences.ConstBegin();
SamSequenceConstIterator seqEnd = sequences.ConstEnd();
for ( ; seqIter != seqEnd; ++seqIter ) {
- const SamSequence& seq = (*seqIter);
+ const SamSequence& seq = seqIter->second;
isValid &= ValidateSequence(seq);
}
SamSequenceConstIterator seqIter = sequences.ConstBegin();
SamSequenceConstIterator seqEnd = sequences.ConstEnd();
for ( ; seqIter != seqEnd; ++seqIter ) {
- const SamSequence& seq = (*seqIter);
+ const SamSequence& seq = seqIter->second;
// lookup sequence name
const string& name = seq.Name;
SamReadGroupConstIterator rgIter = readGroups.ConstBegin();
SamReadGroupConstIterator rgEnd = readGroups.ConstEnd();
for ( ; rgIter != rgEnd; ++rgIter ) {
- const SamReadGroup& rg = (*rgIter);
+ const SamReadGroup& rg = rgIter->second;
isValid &= ValidateReadGroup(rg);
}
SamReadGroupConstIterator rgIter = readGroups.ConstBegin();
SamReadGroupConstIterator rgEnd = readGroups.ConstEnd();
for ( ; rgIter != rgEnd; ++rgIter ) {
- const SamReadGroup& rg = (*rgIter);
+ const SamReadGroup& rg = rgIter->second;
// --------------------------------
// check for unique ID
// bamtools_resolve.cpp (c) 2011
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 6 July 2011
+// Last modified: 12 October 2011
// ---------------------------------------------------------------------------
// Resolves paired-end reads (marking the IsProperPair flag as needed).
// ***************************************************************************
SamReadGroupConstIterator rgIter = header.ReadGroups.ConstBegin();
SamReadGroupConstIterator rgEnd = header.ReadGroups.ConstEnd();
for ( ; rgIter != rgEnd; ++rgIter ) {
- const SamReadGroup& rg = (*rgIter);
+ const SamReadGroup& rg = rgIter->second;
m_readGroups.insert( make_pair<string, ReadGroupResolver>(rg.ID, ReadGroupResolver()) );
}
}