]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequenceDictionary.h
a583f046e10ec78a73394bdcb0906c0fa79e4b6b
[bamtools.git] / src / api / SamSequenceDictionary.h
1 // ***************************************************************************
2 // SamSequenceDictionary.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 12 October 2011
6 // ---------------------------------------------------------------------------
7 // Provides methods for operating on a collection of SamSequence entries.
8 // ***************************************************************************
9
10 #ifndef SAM_SEQUENCE_DICTIONARY_H
11 #define SAM_SEQUENCE_DICTIONARY_H
12
13 #include "api/api_global.h"
14 #include "api/SamSequence.h"
15 #include <map>
16 #include <string>
17 #include <vector>
18
19 namespace BamTools {
20
21 typedef std::map<std::string, SamSequence>   SamSequenceContainer;
22 typedef SamSequenceContainer::iterator       SamSequenceIterator;
23 typedef SamSequenceContainer::const_iterator SamSequenceConstIterator;
24
25 class API_EXPORT SamSequenceDictionary {
26
27     // ctor & dtor
28     public:
29         SamSequenceDictionary(void);
30         SamSequenceDictionary(const SamSequenceDictionary& other);
31         ~SamSequenceDictionary(void);
32
33     // query/modify sequence data
34     public:
35         // adds a sequence
36         void Add(const SamSequence& sequence);
37         void Add(const std::string& name, const int& length);
38
39         // adds multiple sequences
40         void Add(const SamSequenceDictionary& sequences);
41         void Add(const std::vector<SamSequence>& sequences);
42         void Add(const std::map<std::string, int>& sequenceMap);
43
44         // clears all sequence entries
45         void Clear(void);
46
47         // returns true if dictionary contains this sequence
48         bool Contains(const SamSequence& sequence) const;
49         bool Contains(const std::string& sequenceName) const;
50
51         // returns true if dictionary is empty
52         bool IsEmpty(void) const;
53
54         // removes sequence, if found
55         void Remove(const SamSequence& sequence);
56         void Remove(const std::string& sequenceName);
57
58         // removes multiple sequences
59         void Remove(const std::vector<SamSequence>& sequences);
60         void Remove(const std::vector<std::string>& sequenceNames);
61
62         // returns number of sequences in dictionary
63         int Size(void) const;
64
65         // retrieves a modifiable reference to the SamSequence object associated with this name
66         SamSequence& operator[](const std::string& sequenceName);
67
68     // retrieve STL-compatible iterators
69     public:
70         SamSequenceIterator      Begin(void);               // returns iterator to begin()
71         SamSequenceConstIterator Begin(void) const;         // returns const_iterator to begin()
72         SamSequenceConstIterator ConstBegin(void) const;    // returns const_iterator to begin()
73         SamSequenceIterator      End(void);                 // returns iterator to end()
74         SamSequenceConstIterator End(void) const;           // returns const_iterator to end()
75         SamSequenceConstIterator ConstEnd(void) const;      // returns const_iterator to end()
76
77     // data members
78     private:
79         SamSequenceContainer m_data;
80 };
81
82 } // namespace BamTools
83
84 #endif // SAM_SEQUENCE_DICTIONARY_H
85