]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamSequenceDictionary.h
Added SAM header-handling classes for read/write/validate.
[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: 23 December 2010 (DB)
7 // ---------------------------------------------------------------------------
8 // Provides container operations for collection of sequence 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 <vector>
18
19 namespace BamTools {
20
21 typedef std::vector<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(void);
31
32     // query/modify sequence data
33     public:
34         // add a sequence
35         void Add(const SamSequence& sequence);
36         void Add(const std::string& sequenceNames);
37
38         // add multiple sequences
39         void Add(const std::vector<SamSequence>& sequences);
40         void Add(const std::vector<std::string>& sequenceNames);
41
42         // clear all sequence records
43         void Clear(void);
44
45         // returns true if dictionary contains this sequence
46         bool Contains(const SamSequence& sequence) const;
47         bool Contains(const std::string& sequenceName) const;
48
49         // returns true if dictionary is empty
50         bool IsEmpty(void) const;
51
52         // remove a single sequence (does nothing if sequence not found)
53         void Remove(const SamSequence& sequence);
54         void Remove(const std::string& sequenceName);
55
56         // remove multiple sequences
57         void Remove(const std::vector<SamSequence>& sequences);
58         void Remove(const std::vector<std::string>& sequenceNames);
59
60         // returns size of dictionary (number of current elements)
61         int Size(void) const;
62
63         // retrieves the SamSequence object associated with this name
64         // if sequenceName is unknown, a new SamSequence is created with this name (and invalid length 0)
65         // and a reference to this new sequence entry is returned (like std::map)
66         //
67         // * To avoid these partial entries being created, it is recommended to check
68         //   for existence first using Contains()
69         SamSequence& operator[](const std::string& sequenceName);
70
71     // retrieve sequence iterators
72     // these are typedefs for STL iterators and thus are compatible with STL containers/algorithms
73     public:
74         SamSequenceIterator      Begin(void);
75         SamSequenceConstIterator Begin(void) const;
76         SamSequenceConstIterator ConstBegin(void) const;
77         SamSequenceIterator      End(void);
78         SamSequenceConstIterator End(void) const;
79         SamSequenceConstIterator ConstEnd(void) const;
80
81     // internal methods
82     private:
83         int IndexOf(const SamSequence& sequence) const;
84         int IndexOf(const std::string& sequenceName) const;
85
86     // data members
87     private:
88         SamSequenceContainer m_data;
89 };
90
91 } // namespace BamTools
92
93 #endif // SAM_SEQUENCE_DICTIONARY 
94