]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/SamHeaderValidator_p.h
1fc1644dd5e1033019724bff5826e2218e246c24
[bamtools.git] / src / api / internal / SamHeaderValidator_p.h
1 // ***************************************************************************
2 // SamHeaderValidator.h (c) 2010 Derek Barnett
3 // Marth Lab, Department of Biology, Boston College
4 // ---------------------------------------------------------------------------
5 // Last modified: 13 January 2011 (DB)
6 // ---------------------------------------------------------------------------
7 // Provides functionality for validating SamHeader data
8 // ***************************************************************************
9
10 #ifndef SAM_HEADER_VALIDATOR_P_H
11 #define SAM_HEADER_VALIDATOR_P_H
12
13 //  -------------
14 //  W A R N I N G
15 //  -------------
16 //
17 // This file is not part of the BamTools API.  It exists purely as an
18 // implementation detail. This header file may change from version to version
19 // without notice, or even be removed.
20 //
21 // We mean it.
22
23 #include <string>
24 #include <vector>
25
26 namespace BamTools {
27
28 class SamHeader;
29 class SamReadGroup;
30 class SamSequence;
31
32 namespace Internal {
33
34 class SamHeaderValidator {
35
36     // ctor & dtor
37     public:
38         SamHeaderValidator(const SamHeader& header);
39         ~SamHeaderValidator(void);
40
41     // SamHeaderValidator interface
42     public:
43         // validates SamHeader data, returns true/false accordingly
44         // prints error & warning messages to stderr when @verbose is true
45         bool Validate(bool verbose = false);
46
47     // internal methods
48     private:
49
50         // validate header metadata
51         bool ValidateMetadata(void);
52         bool ValidateVersion(void);
53         bool ContainsOnlyDigits(const std::string& s);
54         bool ValidateSortOrder(void);
55         bool ValidateGroupOrder(void);
56
57         // validate sequence dictionary
58         bool ValidateSequenceDictionary(void);
59         bool ContainsUniqueSequenceNames(void);
60         bool CheckNameFormat(const std::string& name);
61         bool ValidateSequence(const SamSequence& seq);
62         bool CheckLengthInRange(const std::string& length);
63
64         // validate read group dictionary
65         bool ValidateReadGroupDictionary(void);
66         bool ContainsUniqueIDsAndPlatformUnits(void);
67         bool ValidateReadGroup(const SamReadGroup& rg);
68         bool CheckReadGroupID(const std::string& id);
69         bool CheckSequencingTechnology(const std::string& technology);
70
71         // validate program data
72         bool ValidateProgramChain(void);
73         bool ContainsUniqueProgramIds(void);
74         bool ValidatePreviousProgramIds(void);
75
76         // error reporting
77         void AddError(const std::string& message);
78         void AddWarning(const std::string& message);
79         void PrintErrorMessages(void);
80         void PrintWarningMessages(void);
81
82     // data members
83     private:
84
85         // SamHeader being validated
86         const SamHeader& m_header;
87
88         // error reporting helpers
89         static const std::string ERROR_PREFIX;
90         static const std::string WARN_PREFIX;
91         static const std::string NEWLINE;
92
93         // error reporting messages
94         std::vector<std::string> m_errorMessages;
95         std::vector<std::string> m_warningMessages;
96 };
97
98 } // namespace Internal
99 } // namespace BamTools
100
101 #endif // SAM_HEADER_VALIDATOR_P_H