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