00001 /* 00002 * Copyright (C) 2010 Regents of the University of Michigan 00003 * 00004 * This program is free software: you can redistribute it and/or modify 00005 * it under the terms of the GNU General Public License as published by 00006 * the Free Software Foundation, either version 3 of the License, or 00007 * (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00016 */ 00017 00018 #ifndef __SAMHEADER_RECORD_H__ 00019 #define __SAMHEADER_RECORD_H__ 00020 00021 #include "StringArray.h" 00022 #include "StringHash.h" 00023 #include "SamHeaderTag.h" 00024 00025 /// This class encapsulates the tag value pairs contained with a SAM Header 00026 /// line with accessors for getting and setting the tags within this header. 00027 class SamHeaderRecord 00028 { 00029 public: 00030 /// Specifies the Type for the sam header record (line). 00031 enum SamHeaderRecordType { 00032 HD, ///< Header 00033 SQ, ///< Sequence Dictionary 00034 RG, ///< Read Group 00035 PG ///< Program 00036 }; 00037 00038 /// Constructor 00039 SamHeaderRecord(); 00040 00041 /// Destructor 00042 virtual ~SamHeaderRecord(); 00043 00044 /// Return a pointer to a newly created header record of the appropriate type 00045 /// that is a copy of this record. The newly created record will not be 00046 /// deleted by this class and it is the responsibility of the calling method 00047 /// to handle the deletion. 00048 /// Returns NULL on failure to copy. 00049 virtual SamHeaderRecord* createCopy() const = 0; 00050 00051 /// Set the fields from the passed in line. 00052 /// Return true if successfully set. 00053 bool setFields(const StringArray& tokens); 00054 00055 /// Check to see if the record is valid. 00056 bool isValid(); 00057 00058 /// Return the value associated with the specified tag. 00059 const char* getTagValue(const char* tag) const; 00060 00061 /// Set the value of the specified tag to the specified value, deletes 00062 /// the tag when value is NULL. 00063 /// Returns whether or not it was successful, fails if tag is the key tag 00064 /// and the key tag already exists. 00065 bool setTag(const char* tag, const char* value); 00066 00067 /// Reset this header record to an empty state with no tags. 00068 void reset(); 00069 00070 /// Appends the string representation of this header record 00071 /// to the passed in string. 00072 bool appendString(std::string& header); 00073 00074 /// Add the key tag with the specified value (not for HD headers). 00075 bool addKey(const char* value); 00076 00077 /// This record is active (true) if there is at least one tag set. 00078 bool isActiveHeaderRecord(); 00079 00080 /// Return the type of this header record (HD, SQ, RG, or PG) as a string. 00081 const char* getTypeString(); 00082 00083 /// Return the type of this header record (HD, SQ, RG, or PG) as an enum. 00084 SamHeaderRecordType getType(); 00085 00086 protected: 00087 void addRequiredTag(const char* requiredTag); 00088 00089 // Copy this record into the specified new one. 00090 virtual void internalCopy(SamHeaderRecord& newRec) const; 00091 00092 // The type for this header record. 00093 std::string myTypeString; 00094 00095 // The type for this header record. 00096 SamHeaderRecordType myType; 00097 00098 // The TAG name that is the key for this record 00099 // Only applicable if more than one of this type 00100 // of record is allowed. 00101 std::string myKeyTag; 00102 00103 private: 00104 SamHeaderRecord(const SamHeaderRecord& samHeaderRecord); 00105 SamHeaderRecord& operator=(const SamHeaderRecord& samHeaderRecord); 00106 00107 // hash from tag name to index into the tag values vector. 00108 StringIntHash myTagHash; 00109 std::vector<SamHeaderTag*> myTags; 00110 00111 // The tags that are required for this record. 00112 std::vector<String> myRequiredTags; 00113 00114 int myNumActiveTags; 00115 }; 00116 00117 #endif