]> git.donarmstrong.com Git - bamtools.git/blob - src/api/internal/SamHeaderValidator_p.h
Removed some debugging 'error string' messages that snuck into last
[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: 6 October 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 <iostream>
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
45         // prints error & warning messages
46         void PrintMessages(std::ostream& stream);
47
48         // validates SamHeader data, returns true/false accordingly
49         bool Validate(void);
50
51     // internal methods
52     private:
53
54         // validate header metadata
55         bool ValidateMetadata(void);
56         bool ValidateVersion(void);
57         bool ContainsOnlyDigits(const std::string& s);
58         bool ValidateSortOrder(void);
59         bool ValidateGroupOrder(void);
60
61         // validate sequence dictionary
62         bool ValidateSequenceDictionary(void);
63         bool ContainsUniqueSequenceNames(void);
64         bool CheckNameFormat(const std::string& name);
65         bool ValidateSequence(const SamSequence& seq);
66         bool CheckLengthInRange(const std::string& length);
67
68         // validate read group dictionary
69         bool ValidateReadGroupDictionary(void);
70         bool ContainsUniqueIDsAndPlatformUnits(void);
71         bool ValidateReadGroup(const SamReadGroup& rg);
72         bool CheckReadGroupID(const std::string& id);
73         bool CheckSequencingTechnology(const std::string& technology);
74
75         // validate program data
76         bool ValidateProgramChain(void);
77         bool ContainsUniqueProgramIds(void);
78         bool ValidatePreviousProgramIds(void);
79
80         // error reporting
81         void AddError(const std::string& message);
82         void AddWarning(const std::string& message);
83         void PrintErrorMessages(std::ostream& stream);
84         void PrintWarningMessages(std::ostream& stream);
85
86     // data members
87     private:
88
89         // SamHeader being validated
90         const SamHeader& m_header;
91
92         // error reporting helpers
93         static const std::string ERROR_PREFIX;
94         static const std::string WARN_PREFIX;
95         static const std::string NEWLINE;
96
97         // error reporting messages
98         std::vector<std::string> m_errorMessages;
99         std::vector<std::string> m_warningMessages;
100 };
101
102 } // namespace Internal
103 } // namespace BamTools
104
105 #endif // SAM_HEADER_VALIDATOR_P_H