X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=src%2Fapi%2FSamSequenceDictionary.cpp;h=61eae2529fb8ea6a02d7f01e1e32f492f3d5d3ee;hb=25a2a1f6598b6452455da96c28a7f58fd9e7ed2d;hp=3249bd4162d846c174a8889546531e62f0a32e47;hpb=8c80d760637f8df39262683cd2570f0589423d36;p=bamtools.git diff --git a/src/api/SamSequenceDictionary.cpp b/src/api/SamSequenceDictionary.cpp index 3249bd4..61eae25 100644 --- a/src/api/SamSequenceDictionary.cpp +++ b/src/api/SamSequenceDictionary.cpp @@ -1,9 +1,8 @@ // *************************************************************************** // SamSequenceDictionary.cpp (c) 2010 Derek Barnett // Marth Lab, Department of Biology, Boston College -// All rights reserved. // --------------------------------------------------------------------------- -// Last modified: 20 March 2011 (DB) +// Last modified: 10 October 2011 (DB) // --------------------------------------------------------------------------- // Provides methods for operating on a collection of SamSequence entries. // ************************************************************************* @@ -38,11 +37,11 @@ SamSequenceDictionary::SamSequenceDictionary(const SamSequenceDictionary& other) SamSequenceDictionary::~SamSequenceDictionary(void) { } /*! \fn void SamSequenceDictionary::Add(const SamSequence& sequence) - \brief Adds a sequence to the dictionary. + \brief Appends a sequence to the dictionary. - Duplicate entries are discarded. + Duplicate entries are silently discarded. - \param sequence entry to be added + \param[in] sequence entry to be added */ void SamSequenceDictionary::Add(const SamSequence& sequence) { if ( IsEmpty() || !Contains(sequence) ) @@ -50,24 +49,39 @@ void SamSequenceDictionary::Add(const SamSequence& sequence) { } /*! \fn void SamSequenceDictionary::Add(const std::string& name, const int& length) - \brief Adds a sequence to the dictionary. + \brief Appends a sequence to the dictionary. This is an overloaded function. - \param name name of sequence entry to be added - \param length length of sequence entry to be added + \param[in] name name of sequence entry to be added + \param[in] length length of sequence entry to be added \sa Add() */ void SamSequenceDictionary::Add(const std::string& name, const int& length) { Add( SamSequence(name, length) ); } +/*! \fn void SamSequenceDictionary::Add(const SamSequenceDictionary& sequences) + \brief Appends another sequence dictionary to this one + + This is an overloaded function. + + \param[in] sequences sequence dictionary to be appended + \sa Add() +*/ +void SamSequenceDictionary::Add(const SamSequenceDictionary& sequences) { + SamSequenceConstIterator seqIter = sequences.ConstBegin(); + SamSequenceConstIterator seqEnd = sequences.ConstEnd(); + for ( ; seqIter != seqEnd; ++seqIter ) + Add(*seqIter); +} + /*! \fn void SamSequenceDictionary::Add(const std::vector& sequences) - \brief Adds multiple sequences to the dictionary. + \brief Appends multiple sequences to the dictionary. This is an overloaded function. - \param sequences entries to be added + \param[in] sequences entries to be added \sa Add() */ void SamSequenceDictionary::Add(const std::vector& sequences) { @@ -78,11 +92,11 @@ void SamSequenceDictionary::Add(const std::vector& sequences) { } /*! \fn void SamSequenceDictionary::Add(const std::map& sequenceMap) - \brief Adds multiple sequences to the dictionary. + \brief Appends multiple sequences to the dictionary. This is an overloaded function. - \param sequenceMap map of sequence entries (name => length) to be added + \param[in] sequenceMap map of sequence entries (name => length) to be added \sa Add() */ void SamSequenceDictionary::Add(const std::map& sequenceMap) { @@ -104,10 +118,10 @@ SamSequenceIterator SamSequenceDictionary::Begin(void) { } /*! \fn SamSequenceConstIterator SamSequenceDictionary::Begin(void) const + \return an STL const_iterator pointing to the first sequence This is an overloaded function. - \return a const STL iterator pointing to the first sequence \sa ConstBegin(), End() */ SamSequenceConstIterator SamSequenceDictionary::Begin(void) const { @@ -122,7 +136,7 @@ void SamSequenceDictionary::Clear(void) { } /*! \fn SamSequenceConstIterator SamSequenceDictionary::ConstBegin(void) const - \return a const STL iterator pointing to the first sequence + \return an STL const_iterator pointing to the first sequence \sa Begin(), ConstEnd() */ SamSequenceConstIterator SamSequenceDictionary::ConstBegin(void) const { @@ -130,7 +144,7 @@ SamSequenceConstIterator SamSequenceDictionary::ConstBegin(void) const { } /*! \fn SamSequenceConstIterator SamSequenceDictionary::ConstEnd(void) const - \return a const STL iterator pointing to the imaginary entry after the last sequence + \return an STL const_iterator pointing to the imaginary entry after the last sequence \sa End(), ConstBegin() */ SamSequenceConstIterator SamSequenceDictionary::ConstEnd(void) const { @@ -139,7 +153,8 @@ SamSequenceConstIterator SamSequenceDictionary::ConstEnd(void) const { /*! \fn bool SamSequenceDictionary::Contains(const std::string& sequenceName) const \brief Returns true if dictionary contains sequence. - \param sequenceName search for sequence matching this name + + \param[in] sequenceName search for sequence matching this name \return \c true if dictionary contains a sequence with this name */ bool SamSequenceDictionary::Contains(const std::string& sequenceName) const { @@ -147,12 +162,15 @@ bool SamSequenceDictionary::Contains(const std::string& sequenceName) const { } /*! \fn bool SamSequenceDictionary::Contains(const SamSequence& sequence) const - \brief Returns true if dictionary contains sequence. - \param sequence search for this sequence - \return \c true if dictionary contains sequence + \brief Returns true if dictionary contains sequence (matches on name). + + This is an overloaded function. + + \param[in] sequence search for this sequence + \return \c true if dictionary contains sequence (matching on name) */ bool SamSequenceDictionary::Contains(const SamSequence& sequence) const { - return ( IndexOf(sequence) != (int)m_data.size() ); + return ( IndexOf(sequence.Name) != (int)m_data.size() ); } /*! \fn SamSequenceIterator SamSequenceDictionary::End(void) @@ -164,41 +182,19 @@ SamSequenceIterator SamSequenceDictionary::End(void) { } /*! \fn SamSequenceConstIterator SamSequenceDictionary::End(void) const + \return an STL const_iterator pointing to the imaginary entry after the last sequence This is an overloaded function. - \return a const STL iterator pointing to the imaginary entry after the last sequence \sa Begin(), ConstEnd() */ SamSequenceConstIterator SamSequenceDictionary::End(void) const { return m_data.end(); } -/*! \fn int SamSequenceDictionary::IndexOf(const SamSequence& sequence) const - \internal - - Uses operator==(SamSequence, SamSequence) - - \return index of sequence if found. Otherwise, returns vector::size() (invalid index). -*/ -int SamSequenceDictionary::IndexOf(const SamSequence& sequence) const { - SamSequenceConstIterator begin = ConstBegin(); - SamSequenceConstIterator iter = begin; - SamSequenceConstIterator end = ConstEnd(); - for ( ; iter != end; ++iter ) { - const SamSequence& currentSeq = (*iter); - if ( currentSeq == sequence ) - break; - } - return distance( begin, iter ); -} - /*! \fn int SamSequenceDictionary::IndexOf(const std::string& name) const \internal - - Use comparison of SamSequence::Name to \a name - - \return index of sequence if found. Otherwise, returns vector::size() (invalid index). + \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(); @@ -221,18 +217,20 @@ bool SamSequenceDictionary::IsEmpty(void) const { } /*! \fn void SamSequenceDictionary::Remove(const SamSequence& sequence) - \brief Removes sequence from dictionary, if found. - \param sequence sequence to remove + \brief Removes sequence from dictionary, if found (matches on name). + + This is an overloaded function. + + \param[in] sequence SamSequence to remove (matching on name) */ void SamSequenceDictionary::Remove(const SamSequence& sequence) { - if ( Contains(sequence) ) - m_data.erase( m_data.begin() + IndexOf(sequence) ); + Remove( sequence.Name ); } /*! \fn void SamSequenceDictionary::Remove(const std::string& sequenceName) \brief Removes sequence from dictionary, if found. - \param sequenceName name of sequence to remove + \param[in] sequenceName name of sequence to remove \sa Remove() */ void SamSequenceDictionary::Remove(const std::string& sequenceName) { @@ -245,7 +243,7 @@ void SamSequenceDictionary::Remove(const std::string& sequenceName) { This is an overloaded function. - \param sequences sequences to remove + \param[in] sequences sequences to remove \sa Remove() */ void SamSequenceDictionary::Remove(const std::vector& sequences) { @@ -260,7 +258,7 @@ void SamSequenceDictionary::Remove(const std::vector& sequences) { This is an overloaded function. - \param sequenceNames names of the sequences to remove + \param[in] sequenceNames names of the sequences to remove \sa Remove() */ void SamSequenceDictionary::Remove(const std::vector& sequenceNames) { @@ -281,13 +279,11 @@ int SamSequenceDictionary::Size(void) const { /*! \fn SamSequence& SamSequenceDictionary::operator[](const std::string& sequenceName) \brief Retrieves the modifiable SamSequence that matches \a sequenceName. - NOTE - If the dictionary contains no sequence matching this name, this function inserts - a new one with this name, and returns a reference to it. - - If you want to avoid this insertion behavior, check the result of Contains() before - using this operator. + \note If the dictionary contains no sequence matching this name, this function inserts + a new one with this name (length:0), and returns a reference to it. If you want to avoid + this insertion behavior, check the result of Contains() before using this operator. - \param sequenceName name of sequence to retrieve + \param[in] sequenceName name of sequence to retrieve \return a modifiable reference to the SamSequence associated with the name */ SamSequence& SamSequenceDictionary::operator[](const std::string& sequenceName) {