00001 // *************************************************************************** 00002 // SamSequenceDictionary.h (c) 2010 Derek Barnett 00003 // Marth Lab, Department of Biology, Boston College 00004 // --------------------------------------------------------------------------- 00005 // Last modified: 16 October 2011 00006 // --------------------------------------------------------------------------- 00007 // Provides methods for operating on a collection of SamSequence entries. 00008 // *************************************************************************** 00009 00010 #ifndef SAM_SEQUENCE_DICTIONARY_H 00011 #define SAM_SEQUENCE_DICTIONARY_H 00012 00013 #include "api/api_global.h" 00014 #include "api/SamSequence.h" 00015 #include <map> 00016 #include <string> 00017 #include <vector> 00018 00019 namespace BamTools { 00020 00021 typedef std::vector<SamSequence> SamSequenceContainer; 00022 typedef SamSequenceContainer::iterator SamSequenceIterator; 00023 typedef SamSequenceContainer::const_iterator SamSequenceConstIterator; 00024 00025 class API_EXPORT SamSequenceDictionary { 00026 00027 // ctor & dtor 00028 public: 00029 SamSequenceDictionary(void); 00030 SamSequenceDictionary(const SamSequenceDictionary& other); 00031 ~SamSequenceDictionary(void); 00032 00033 // query/modify sequence data 00034 public: 00035 // adds a sequence 00036 void Add(const SamSequence& sequence); 00037 void Add(const std::string& name, const int& length); 00038 00039 // adds multiple sequences 00040 void Add(const SamSequenceDictionary& sequences); 00041 void Add(const std::vector<SamSequence>& sequences); 00042 void Add(const std::map<std::string, int>& sequenceMap); 00043 00044 // clears all sequence entries 00045 void Clear(void); 00046 00047 // returns true if dictionary contains this sequence 00048 bool Contains(const SamSequence& sequence) const; 00049 bool Contains(const std::string& sequenceName) const; 00050 00051 // returns true if dictionary is empty 00052 bool IsEmpty(void) const; 00053 00054 // removes sequence, if found 00055 void Remove(const SamSequence& sequence); 00056 void Remove(const std::string& sequenceName); 00057 00058 // removes multiple sequences 00059 void Remove(const std::vector<SamSequence>& sequences); 00060 void Remove(const std::vector<std::string>& sequenceNames); 00061 00062 // returns number of sequences in dictionary 00063 int Size(void) const; 00064 00065 // retrieves a modifiable reference to the SamSequence object associated with this name 00066 SamSequence& operator[](const std::string& sequenceName); 00067 00068 // retrieve STL-compatible iterators 00069 public: 00070 SamSequenceIterator Begin(void); // returns iterator to begin() 00071 SamSequenceConstIterator Begin(void) const; // returns const_iterator to begin() 00072 SamSequenceConstIterator ConstBegin(void) const; // returns const_iterator to begin() 00073 SamSequenceIterator End(void); // returns iterator to end() 00074 SamSequenceConstIterator End(void) const; // returns const_iterator to end() 00075 SamSequenceConstIterator ConstEnd(void) const; // returns const_iterator to end() 00076 00077 // data members 00078 private: 00079 SamSequenceContainer m_data; 00080 std::map<std::string, size_t> m_lookupData; 00081 }; 00082 00083 } // namespace BamTools 00084 00085 #endif // SAM_SEQUENCE_DICTIONARY_H 00086