1 // ***************************************************************************
2 // SamSequenceDictionary.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 23 December 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides container operations for collection of sequence entries
9 // *************************************************************************
11 #ifndef SAM_SEQUENCE_DICTIONARY_H
12 #define SAM_SEQUENCE_DICTIONARY_H
14 #include <api/api_global.h>
15 #include <api/SamSequence.h>
21 typedef std::vector<SamSequence> SamSequenceContainer;
22 typedef SamSequenceContainer::iterator SamSequenceIterator;
23 typedef SamSequenceContainer::const_iterator SamSequenceConstIterator;
25 class API_EXPORT SamSequenceDictionary {
29 SamSequenceDictionary(void);
30 SamSequenceDictionary(const SamSequenceDictionary& other);
31 ~SamSequenceDictionary(void);
33 // query/modify sequence data
36 void Add(const SamSequence& sequence);
37 void Add(const std::string& sequenceNames);
39 // add multiple sequences
40 void Add(const std::vector<SamSequence>& sequences);
41 void Add(const std::vector<std::string>& sequenceNames);
43 // clear all sequence records
46 // returns true if dictionary contains this sequence
47 bool Contains(const SamSequence& sequence) const;
48 bool Contains(const std::string& sequenceName) const;
50 // returns true if dictionary is empty
51 bool IsEmpty(void) const;
53 // remove a single sequence (does nothing if sequence not found)
54 void Remove(const SamSequence& sequence);
55 void Remove(const std::string& sequenceName);
57 // remove multiple sequences
58 void Remove(const std::vector<SamSequence>& sequences);
59 void Remove(const std::vector<std::string>& sequenceNames);
61 // returns size of dictionary (number of current elements)
64 // retrieves the SamSequence object associated with this name
65 // if sequenceName is unknown, a new SamSequence is created with this name (and invalid length 0)
66 // and a reference to this new sequence entry is returned (like std::map)
68 // * To avoid these partial entries being created, it is recommended to check
69 // for existence first using Contains()
70 SamSequence& operator[](const std::string& sequenceName);
72 // retrieve sequence iterators
73 // these are typedefs for STL iterators and thus are compatible with STL containers/algorithms
75 SamSequenceIterator Begin(void);
76 SamSequenceConstIterator Begin(void) const;
77 SamSequenceConstIterator ConstBegin(void) const;
78 SamSequenceIterator End(void);
79 SamSequenceConstIterator End(void) const;
80 SamSequenceConstIterator ConstEnd(void) const;
84 int IndexOf(const SamSequence& sequence) const;
85 int IndexOf(const std::string& sequenceName) const;
89 SamSequenceContainer m_data;
92 } // namespace BamTools
94 #endif // SAM_SEQUENCE_DICTIONARY