]> git.donarmstrong.com Git - bamtools.git/blobdiff - src/api/internal/SamHeaderValidator_p.h
Removed STDERR pollution by API
[bamtools.git] / src / api / internal / SamHeaderValidator_p.h
index 41c04ee8cf674609045070e6cc79df964925465a..7d0c60aa32e464f1774c882848413d27cd034f8e 100644 (file)
@@ -1,9 +1,8 @@
 // ***************************************************************************
 // SamHeaderValidator.h (c) 2010 Derek Barnett
 // Marth Lab, Department of Biology, Boston College
-// All rights reserved.
 // ---------------------------------------------------------------------------
-// Last modified: 23 December 2010 (DB)
+// Last modified: 6 October 2011 (DB)
 // ---------------------------------------------------------------------------
 // Provides functionality for validating SamHeader data
 // ***************************************************************************
 //
 // We mean it.
 
+#include <iostream>
 #include <string>
 #include <vector>
 
 namespace BamTools {
 
 class SamHeader;
+class SamReadGroup;
+class SamSequence;
 
 namespace Internal {
 
 class SamHeaderValidator {
 
+    // ctor & dtor
     public:
-        SamHeaderValidator(const BamTools::SamHeader& header);
+        SamHeaderValidator(const SamHeader& header);
         ~SamHeaderValidator(void);
 
+    // SamHeaderValidator interface
     public:
-        // validates SamHeader data
-        // prints error & warning messages to stderr when (verbose == true)
-        bool Validate(bool verbose = false);
 
+        // prints error & warning messages
+        void PrintMessages(std::ostream& stream);
+
+        // validates SamHeader data, returns true/false accordingly
+        bool Validate(void);
+
+    // internal methods
+    private:
+
+        // validate header metadata
+        bool ValidateMetadata(void);
+        bool ValidateVersion(void);
+        bool ContainsOnlyDigits(const std::string& s);
+        bool ValidateSortOrder(void);
+        bool ValidateGroupOrder(void);
+
+        // validate sequence dictionary
+        bool ValidateSequenceDictionary(void);
+        bool ContainsUniqueSequenceNames(void);
+        bool CheckNameFormat(const std::string& name);
+        bool ValidateSequence(const SamSequence& seq);
+        bool CheckLengthInRange(const std::string& length);
+
+        // validate read group dictionary
+        bool ValidateReadGroupDictionary(void);
+        bool ContainsUniqueIDsAndPlatformUnits(void);
+        bool ValidateReadGroup(const SamReadGroup& rg);
+        bool CheckReadGroupID(const std::string& id);
+        bool CheckSequencingTechnology(const std::string& technology);
+
+        // validate program data
+        bool ValidateProgramChain(void);
+        bool ContainsUniqueProgramIds(void);
+        bool ValidatePreviousProgramIds(void);
+
+        // error reporting
+        void AddError(const std::string& message);
+        void AddWarning(const std::string& message);
+        void PrintErrorMessages(std::ostream& stream);
+        void PrintWarningMessages(std::ostream& stream);
+
+    // data members
     private:
-        struct SamHeaderValidatorPrivate;
-        SamHeaderValidatorPrivate* d;
+
+        // SamHeader being validated
+        const SamHeader& m_header;
+
+        // error reporting helpers
+        static const std::string ERROR_PREFIX;
+        static const std::string WARN_PREFIX;
+        static const std::string NEWLINE;
+
+        // error reporting messages
+        std::vector<std::string> m_errorMessages;
+        std::vector<std::string> m_warningMessages;
 };
 
 } // namespace Internal