]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequenceDictionary.h
Brought API up to compliance with recent SAM Format Spec (v1.4-r962)
[bamtools.git] / src / api / SamSequenceDictionary.h
1 // ***************************************************************************
2 // SamSequenceDictionary.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // All rights reserved.
5 // ---------------------------------------------------------------------------
6 // Last modified: 18 April 2011
7 // ---------------------------------------------------------------------------
8 // Provides methods for operating on a collection of SamSequence entries.
9 // ***************************************************************************
10
11 #ifndef SAM_SEQUENCE_DICTIONARY_H
12 #define SAM_SEQUENCE_DICTIONARY_H
13
14 #include <api/api_global.h>
15 #include <api/SamSequence.h>
16 #include <string>
17 #include <map>
18 #include <vector>
19
20 namespace BamTools {
21
22 typedef std::vector<SamSequence>             SamSequenceContainer;
23 typedef SamSequenceContainer::iterator       SamSequenceIterator;
24 typedef SamSequenceContainer::const_iterator SamSequenceConstIterator;
25
26 class API_EXPORT SamSequenceDictionary {
27
28     // ctor & dtor
29     public:
30         SamSequenceDictionary(void);
31         SamSequenceDictionary(const SamSequenceDictionary& other);
32         ~SamSequenceDictionary(void);
33
34     // query/modify sequence data
35     public:
36         // adds a sequence
37         void Add(const SamSequence& sequence);
38         void Add(const std::string& name, const int& length);
39
40         // adds multiple 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     // internal methods
78     private:
79         int IndexOf(const std::string& name) const;
80
81     // data members
82     private:
83         SamSequenceContainer m_data;
84 };
85
86 } // namespace BamTools
87
88 #endif // SAM_SEQUENCE_DICTIONARY_H
89