]> git.donarmstrong.com Git - bamtools.git/blob - src/api/SamReadGroupDictionary.h
Added SAM header-handling classes for read/write/validate.
[bamtools.git] / src / api / SamReadGroupDictionary.h
1 // ***************************************************************************
2 // SamReadGroupDictionary.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 read group entries
9 // *************************************************************************
10
11 #ifndef SAM_READGROUP_DICTIONARY_H
12 #define SAM_READGROUP_DICTIONARY_H
13
14 #include <api/api_global.h>
15 #include <api/SamReadGroup.h>
16 #include <string>
17 #include <vector>
18
19 namespace BamTools {
20
21 typedef std::vector<SamReadGroup>             SamReadGroupContainer;
22 typedef SamReadGroupContainer::iterator       SamReadGroupIterator;
23 typedef SamReadGroupContainer::const_iterator SamReadGroupConstIterator;
24
25 // stores read groups
26 // can access read groups using SamReadGroup object or (std::string) read group ID tag
27 class API_EXPORT SamReadGroupDictionary {
28
29     // ctor & dtor
30     public:
31         SamReadGroupDictionary(void);
32         ~SamReadGroupDictionary(void);
33
34     // query/modify read group data
35     public:
36         // add a read group
37         void Add(const SamReadGroup& readGroup);
38         void Add(const std::string& readGroupIds);
39
40         // add multiple read groups
41         void Add(const std::vector<SamReadGroup>& readGroups);
42         void Add(const std::vector<std::string>& readGroupIds);
43
44         // clear all read groups records
45         void Clear(void);
46
47         // returns true if dictionary contains this read group
48         bool Contains(const SamReadGroup& readGroup) const;
49         bool Contains(const std::string& readGroupId) const;
50
51         // returns true if dictionary is empty
52         bool IsEmpty(void) const;
53
54         // remove a single read group (does nothing if read group not found)
55         void Remove(const SamReadGroup& readGroup);
56         void Remove(const std::string& readGroupId);
57
58         // remove multiple read groups
59         void Remove(const std::vector<SamReadGroup>& readGroups);
60         void Remove(const std::vector<std::string>& readGroupIds);
61
62         // returns size of dictionary (number of current elements)
63         int Size(void) const;
64
65         // retrieves the SamReadGroup object associated with this ID
66         // if readGroupId is unknown, a new SamReadGroup is created with this ID (and no other data)
67         // and a reference to this new read group entry is returned (like std::map)
68         //
69         // * To avoid these partial entries being created, it is recommended to check
70         //   for existence first using Contains()
71         SamReadGroup& operator[](const std::string& readGroupId);
72
73     // retrieve read group iterators
74     // these are typedefs for STL iterators and thus are compatible with STL containers/algorithms
75     public:
76         SamReadGroupIterator      Begin(void);
77         SamReadGroupConstIterator Begin(void) const;
78         SamReadGroupConstIterator ConstBegin(void) const;
79         SamReadGroupIterator      End(void);
80         SamReadGroupConstIterator End(void) const;
81         SamReadGroupConstIterator ConstEnd(void) const;
82
83     // internal methods
84     private:
85         int IndexOf(const SamReadGroup& readGroup) const;
86         int IndexOf(const std::string& readGroupId) const;
87
88     // data members
89     private:
90         SamReadGroupContainer m_data;
91 };
92
93 } // namespace BamTools
94
95 #endif // SAM_READGROUP_DICTIONARY