]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/SamHeaderValidator_p.h
ee48f891500d72ba57e111273b2d23443e921f93
[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 ValidateReadGroup(const SamReadGroup& rg);
68         bool ContainsUniqueIDsAndPlatformUnits(void);
69         bool CheckReadGroupID(const std::string& id);
70         bool CheckSequencingTechnology(const std::string& technology);
71         bool Is454(const std::string& technology);
72         bool IsHelicos(const std::string& technology);
73         bool IsIllumina(const std::string& technology);
74         bool IsPacBio(const std::string& technology);
75         bool IsSolid(const std::string& technology);
76
77         // validate program data
78         bool ValidateProgramData(void);
79         bool ContainsUniqueProgramIds(void);
80         bool ValidatePreviousProgramIds(void);
81
82         // error reporting
83         void AddError(const std::string& message);
84         void AddWarning(const std::string& message);
85         void PrintErrorMessages(void);
86         void PrintWarningMessages(void);
87
88     // data members
89     private:
90
91         // SamHeader being validated
92         const SamHeader& m_header;
93
94         // error reporting helpers
95         static const std::string ERROR_PREFIX;
96         static const std::string WARN_PREFIX;
97         static const std::string NEWLINE;
98
99         // error reporting messages
100         std::vector<std::string> m_errorMessages;
101         std::vector<std::string> m_warningMessages;
102 };
103
104 } // namespace Internal
105 } // namespace BamTools
106
107 #endif // SAM_HEADER_VALIDATOR_P_H