SamHeaderRecord.h

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     ~SamHeaderRecord();
00043 
00044     /// Set the fields from the passed in line.
00045     /// Return true if successfully set.
00046     bool setFields(const StringArray& tokens);
00047 
00048     /// Check to see if the record is valid.
00049     bool isValid();
00050 
00051     /// Return the value associated with the specified tag.
00052     const char* getTagValue(const char* tag) const;
00053 
00054     /// Set the value of the specified tag to the specified value, deletes
00055     /// the tag when value is NULL.
00056     /// Returns whether or not it was successful, fails if tag is the key tag
00057     /// and the key tag already exists.
00058     bool setTag(const char* tag, const char* value);
00059 
00060     /// Reset this header record to an empty state with no tags.
00061     void reset();
00062 
00063     /// Appends the string representation of this header record
00064     /// to the passed in string.
00065     bool appendString(std::string& header);
00066 
00067     /// Add the key tag with the specified value (not for HD headers).
00068     bool addKey(const char* value);
00069 
00070     /// This record is active (true) if there is at least one tag set.
00071     bool isActiveHeaderRecord();
00072 
00073     /// Return the type of this header record (HD, SQ, RG, or PG) as a string.
00074     const char* getTypeString();
00075 
00076     /// Return the type of this header record (HD, SQ, RG, or PG) as an enum.
00077     SamHeaderRecordType getType();
00078 
00079 protected:
00080     void addRequiredTag(const char* requiredTag);
00081 
00082     // The type for this header record.
00083     std::string myTypeString;
00084 
00085     // The type for this header record.
00086     SamHeaderRecordType myType;
00087 
00088     // The TAG name that is the key for this record
00089     // Only applicable if more than one of this type
00090     // of record is allowed.
00091     std::string myKeyTag;
00092 
00093 private:
00094     // hash from tag name to index into the tag values vector.
00095     StringIntHash myTagHash;
00096     std::vector<SamHeaderTag*> myTags;
00097 
00098     // The tags that are required for this record.
00099     std::vector<String> myRequiredTags;
00100 
00101     int myNumActiveTags;
00102 };
00103 
00104 #endif
Generated on Tue Sep 6 17:51:59 2011 for libStatGen Software by  doxygen 1.6.3