# set BamTools version information
set (BamTools_VERSION_MAJOR 2)
set (BamTools_VERSION_MINOR 0)
-set (BamTools_VERSION_BUILD 3)
+set (BamTools_VERSION_BUILD 4)
# 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.3
+PROJECT_NUMBER = 2.0.4
# 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.3" )
+set_target_properties( BamTools PROPERTIES SOVERSION "2.0.4" )
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: 14 October 2011 (DB)
+// Last modified: 16 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamReadGroup entries.
// ***************************************************************************
void SamReadGroupDictionary::Add(const SamReadGroup& readGroup) {
if ( IsEmpty() || !Contains(readGroup) ) {
m_data.push_back(readGroup);
- m_lookupData[readGroup.ID] = readGroup;
+ m_lookupData[readGroup.ID] = m_data.size() - 1;
}
}
*/
void SamReadGroupDictionary::Remove(const std::string& 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 );
- }
+ // skip if empty dictionary or if ID unknown
+ if ( IsEmpty() || !Contains(readGroupId) )
+ return;
+
+ // update 'lookup index' for every entry after @readGroupId
+ const size_t indexToRemove = m_lookupData[readGroupId];
+ const size_t numEntries = m_data.size();
+ for ( size_t i = indexToRemove+1; i < numEntries; ++i ) {
+ const SamReadGroup& rg = m_data.at(i);
+ --m_lookupData[rg.ID];
}
+ // erase entry from containers
+ m_data.erase( Begin() + indexToRemove );
m_lookupData.erase(readGroupId);
}
\return a modifiable reference to the SamReadGroup associated with the ID
*/
SamReadGroup& SamReadGroupDictionary::operator[](const std::string& readGroupId) {
+
if ( !Contains(readGroupId) ) {
SamReadGroup rg(readGroupId);
m_data.push_back(rg);
- m_lookupData[readGroupId] = rg;
+ m_lookupData[readGroupId] = m_data.size() - 1;
}
- return m_lookupData[readGroupId];
+
+ const size_t index = m_lookupData[readGroupId];
+ return m_data.at(index);
}
// SamReadGroupDictionary.h (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 14 October 2011 (DB)
+// Last modified: 16 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamReadGroup entries.
// ***************************************************************************
// data members
private:
SamReadGroupContainer m_data;
- std::map<std::string, SamReadGroup> m_lookupData;
+ std::map<std::string, size_t> m_lookupData;
};
} // namespace BamTools
// SamSequenceDictionary.cpp (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 14 October 2011 (DB)
+// Last modified: 16 October 2011 (DB)
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamSequence entries.
// *************************************************************************
void SamSequenceDictionary::Add(const SamSequence& sequence) {
if ( IsEmpty() || !Contains(sequence) ) {
m_data.push_back(sequence);
- m_lookupData[sequence.Name] = sequence;
+ m_lookupData[sequence.Name] = m_data.size() - 1;
}
}
*/
void SamSequenceDictionary::Remove(const std::string& 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 );
- }
+ // skip if empty dictionary or if name unknown
+ if ( IsEmpty() || !Contains(sequenceName) )
+ return;
+
+ // update 'lookup index' for every entry after @sequenceName
+ const size_t indexToRemove = m_lookupData[sequenceName];
+ const size_t numEntries = m_data.size();
+ for ( size_t i = indexToRemove+1; i < numEntries; ++i ) {
+ const SamSequence& sq = m_data.at(i);
+ --m_lookupData[sq.Name];
}
+ // erase entry from containers
+ m_data.erase( Begin() + indexToRemove );
m_lookupData.erase(sequenceName);
}
\return a modifiable reference to the SamSequence associated with the name
*/
SamSequence& SamSequenceDictionary::operator[](const std::string& sequenceName) {
+
if ( !Contains(sequenceName) ) {
SamSequence seq(sequenceName, 0);
m_data.push_back(seq);
- m_lookupData[sequenceName] = seq;
+ m_lookupData[sequenceName] = m_data.size() - 1;
}
- return m_lookupData[sequenceName];
+
+ const size_t index = m_lookupData[sequenceName];
+ return m_data.at(index);
}
// SamSequenceDictionary.h (c) 2010 Derek Barnett
// Marth Lab, Department of Biology, Boston College
// ---------------------------------------------------------------------------
-// Last modified: 14 October 2011
+// Last modified: 16 October 2011
// ---------------------------------------------------------------------------
// Provides methods for operating on a collection of SamSequence entries.
// ***************************************************************************
// data members
private:
SamSequenceContainer m_data;
- std::map<std::string, SamSequence> m_lookupData;
+ std::map<std::string, size_t> m_lookupData;
};
} // namespace BamTools