libStatGen Software
1
|
This class allows a user to get/set the fields in a SAM/BAM Header. More...
#include <SamFileHeader.h>
Public Member Functions | |
Copying a Header | |
These methods are ways of copying the contents of one header into another one. | |
SamFileHeader (const SamFileHeader &header) | |
Copy Constructor copies the specified header into this one. | |
SamFileHeader & | operator= (const SamFileHeader &header) |
Overload operator = to copy the passed in header into this header. | |
bool | copy (const SamFileHeader &header) |
Copy method copies the passed in header into this header. More... | |
void | resetHeader () |
Initialize the header. | |
Get the Entire Header | |
Get the entire header as a single string. | |
bool | getHeaderString (std::string &header) const |
Set the passed in string to the entire header string, clearing its current contents. More... | |
int | getReferenceID (const String &referenceName, bool addID=false) |
Get the reference ID for the specified reference name (chromosome). More... | |
int | getReferenceID (const char *referenceName, bool addID=false) |
Get the reference ID for the specified reference name (chromosome). More... | |
const String & | getReferenceLabel (int id) const |
Return the reference name (chromosome) for the specified reference id. | |
const SamReferenceInfo & | getReferenceInfo () const |
Get the Reference Information. | |
SamReferenceInfo & | getReferenceInfoForBamInterface () |
Adding an entire header/comment line. | |
These methods are ways of adding an entire header line at once. | |
bool | addHeaderLine (const char *type, const char *tag, const char *value) |
Add a header line that is just one tag with a const char* value. More... | |
bool | addHeaderLine (const char *headerLine) |
Add a header line that is already preformatted in a const char*. More... | |
bool | addHeader (const char *header) |
Add a header that is already preformatted in a const char*. More... | |
bool | addComment (const char *comment) |
Add the specified comment to the header (do not include "@CO" or "\n"). More... | |
Set/Add/Remove a Single Tag | |
The passed in tag should be the two character SAM tag as defined in the SAM spec. A tag is removed from the header record by setting it to "". For the SQ and RG header types, the key tags (SN for SQ and ID for RG) may not be modified or removed once set. This is because these values are used as a lookup key for the header record, so the entire record must be removed. | |
bool | setHDTag (const char *tag, const char *value) |
Set the specified tag to the specified value in the HD header, remove the tag by specifying value="". More... | |
bool | setSQTag (const char *tag, const char *value, const char *name) |
Set the specified tag to the specified value in the SQ header with the specified name, remove the tag by specifying value="". More... | |
bool | setRGTag (const char *tag, const char *value, const char *id) |
Set the specified tag to the specified value in the RG header with the specified id, remove the tag by specifying value="". More... | |
bool | setPGTag (const char *tag, const char *value, const char *id) |
Set the specified tag to the specified value in the PG header with the specified id, remove the tag by specifying value="". More... | |
Add an Already Setup SamHeaderRecord | |
NOTE: These methods add a pointer to the passed in record. The header record will be deleted when it's cleaned up from this header. NOTE: Do NOT delete the passed in record, the SamFileHeader class takes care of that itself. | |
bool | addHD (SamHeaderHD *hd) |
Add the HD record to the header. More... | |
bool | addSQ (SamHeaderSQ *sq) |
Add the SQ record to the header. More... | |
bool | addRG (SamHeaderRG *rg) |
Add the RG record to the header. More... | |
bool | addPG (SamHeaderPG *pg) |
Add the PG record to the header. More... | |
bool | addRecordCopy (const SamHeaderRecord &hdrRec) |
Add a copy of the specified header record to the header. More... | |
Remove an Entire Header Record | |
bool | removeHD () |
Remove the HD record. More... | |
bool | removeSQ (const char *name) |
Remove SQ record with the specified key. More... | |
bool | removeRG (const char *id) |
Remove RG record with the specified key. More... | |
bool | removePG (const char *id) |
Remove PG record with the specified key. More... | |
Get a Specific Tag | |
These methods return the value associated with the specified tag. If the tag does not exist in the record "" is returned. For SQ, RG, and PG the value returned is for the tag associated with the specified key (name/id). If a record with that key does not exist or if the tag does not exist for the record with that key, "" is returned. | |
const char * | getHDTagValue (const char *tag) |
Returns the value associated with the specified HD tag, returning "" if the tag does not exist in the header. | |
const char * | getSQTagValue (const char *tag, const char *name) |
Get the value associated with the specified tag on the SQ line with the specified sequence name, returning "" if the tag or key does not exist. | |
const char * | getRGTagValue (const char *tag, const char *id) |
Get the value associated with the specified tag on the RG line with the specified read group identifier, returning "" if the tag or key does not exist. | |
const char * | getPGTagValue (const char *tag, const char *id) |
Get the value associated with the specified tag on the RG line with the specified id, returning "" if the tag or key does not exist. | |
int | getNumSQs () |
Get the number of SQ objects. | |
int | getNumRGs () |
Get the number of RG objects. | |
int | getNumPGs () |
Get the number of PG objects. | |
Get a Specific Header Record | |
These methods return a reference to the specific record that was requested, returning NULL if that record does not exist in the header. The returned record can be modified to add/remove some tags. Since a reference is returned, the SamHeaderFile automatically reflects these changes. | |
SamHeaderHD * | getHD () |
Get the HD object, returning NULL if there is no HD record. | |
SamHeaderSQ * | getSQ (const char *name) |
Get the SQ object with the specified sequence name, returning NULL if there is no SQ object with that key. | |
SamHeaderRG * | getRG (const char *id) |
Get the RG object with the specified read group identifier, returning NULL if there is no RG object with that key. More... | |
SamHeaderPG * | getPG (const char *id) |
Get the PG object with the specified id, returning NULL if there is no PG object with that key. More... | |
const char * | getSortOrder () |
Return the Sort Order value that is set in the Header, returning "" if this field does not exist. | |
const char * | getTagSO () |
DEPRECATED. | |
Get the Header Record/Comment/Line by Record/Comment/Line | |
These methods iterate through the header. NOTE: both getNextHeaderRecord and getNextHeaderLine increment the same iterator. getNextHeaderRecord that takes a header type uses the same iterator as the getNextXXRecord with that type. Otherwise the iterators are independent. | |
static const std::string | EMPTY_RETURN = "" |
SamHeaderRecord * | getNextSQRecord () |
Get the next SQ header record. More... | |
SamHeaderRecord * | getNextRGRecord () |
Get the next RG header record. More... | |
SamHeaderRecord * | getNextPGRecord () |
Get the next PG header record. More... | |
void | resetSQRecordIter () |
Reset to the beginning of the header records so the next call to getNextSQRecord returns the first SQ header record. | |
void | resetRGRecordIter () |
Reset to the beginning of the header records so the next call to getNextRGRecord returns the first RG header record. | |
void | resetPGRecordIter () |
Reset to the beginning of the header records so the next call to getNextPGRecord returns the first PG header record. | |
SamHeaderRecord * | getNextHeaderRecord (uint32_t &index, SamHeaderRecord::SamHeaderRecordType headerType) |
Get the next header record of the specified type starting from the specified index and update the index. More... | |
SamHeaderRecord * | getNextHeaderRecord () |
Get the next header record, but not comment line. More... | |
bool | getNextHeaderLine (std::string &headerLine) |
Set the passed in string to the next header line, overwritting the passed in string. More... | |
void | resetHeaderRecordIter () |
Reset to the beginning of the header records so the next call to getNextHeaderRecord returns the first header line. | |
void | appendCommentLines (std::string &commentLines) |
Append all of the comment lines to the specified string. | |
const char * | getNextComment () |
Returns the comment on the next comment line. More... | |
void | resetCommentIter () |
Resets to the beginning of the comments so getNextComment returns the first comment. | |
const char * | getErrorMessage () |
Get the failure message if a method returned failure. | |
This class allows a user to get/set the fields in a SAM/BAM Header.
Sam/Bam headers contain comments and multiple SamHeaderRecords (HD, SQs, RGs, PGs) comprised of tag/value pairs with each tag only appearing once within a specific record.
Definition at line 34 of file SamFileHeader.h.
bool SamFileHeader::addComment | ( | const char * | comment | ) |
Add the specified comment to the header (do not include "@CO" or "\n").
Definition at line 213 of file SamFileHeader.cpp.
bool SamFileHeader::addHD | ( | SamHeaderHD * | hd | ) |
Add the HD record to the header.
Note: it adds a pointer to the passed in header record. The header record will be deleted when it is cleaned up from this header.
Definition at line 393 of file SamFileHeader.cpp.
Referenced by addRecordCopy().
bool SamFileHeader::addHeader | ( | const char * | header | ) |
Add a header that is already preformatted in a const char*.
Returns true if at least one header line was successfully added.
Definition at line 204 of file SamFileHeader.cpp.
bool SamFileHeader::addHeaderLine | ( | const char * | headerLine | ) |
Add a header line that is already preformatted in a const char*.
Returns true if at least one header line was successfully added.
Definition at line 195 of file SamFileHeader.cpp.
bool SamFileHeader::addHeaderLine | ( | const char * | type, |
const char * | tag, | ||
const char * | value | ||
) |
Add a header line that is just one tag with a const char* value.
Note: This method will only do one tag per type on a line, so if a type has multiple tags, the whole line needs to be added at once, and a different method should be used.
Definition at line 180 of file SamFileHeader.cpp.
bool SamFileHeader::addPG | ( | SamHeaderPG * | pg | ) |
Add the PG record to the header.
Note: it adds a pointer to the passed in header record. The header record will be deleted when it is cleaned up from this header.
Definition at line 492 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
Referenced by addRecordCopy().
bool SamFileHeader::addRecordCopy | ( | const SamHeaderRecord & | hdrRec | ) |
Add a copy of the specified header record to the header.
Note: it creates a new header record that is identical to the specified one and adds it to the header. The passed in pointer will not be deleted due to this.
Definition at line 526 of file SamFileHeader.cpp.
References addHD(), addPG(), addRG(), addSQ(), SamHeaderRecord::createCopy(), SamHeaderRecord::getType(), SamHeaderRecord::HD, SamHeaderRecord::PG, SamHeaderRecord::RG, and SamHeaderRecord::SQ.
bool SamFileHeader::addRG | ( | SamHeaderRG * | rg | ) |
Add the RG record to the header.
Note: it adds a pointer to the passed in header record. The header record will be deleted when it is cleaned up from this header.
Definition at line 458 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
Referenced by addRecordCopy().
bool SamFileHeader::addSQ | ( | SamHeaderSQ * | sq | ) |
Add the SQ record to the header.
Note: it adds a pointer to the passed in header record. The header record will be deleted when it is cleaned up from this header.
Definition at line 415 of file SamFileHeader.cpp.
References SamReferenceInfo::add(), and SamHeaderRecord::getTagValue().
Referenced by addRecordCopy().
bool SamFileHeader::copy | ( | const SamFileHeader & | header | ) |
Copy method copies the passed in header into this header.
Returns true if at least one header line was successfully copied.
Definition at line 59 of file SamFileHeader.cpp.
References SamReferenceInfo::clear(), getHeaderString(), and resetHeader().
Referenced by operator=(), and SamFileHeader().
bool SamFileHeader::getHeaderString | ( | std::string & | header | ) | const |
Set the passed in string to the entire header string, clearing its current contents.
Definition at line 131 of file SamFileHeader.cpp.
Referenced by copy().
const char * SamFileHeader::getNextComment | ( | ) |
Returns the comment on the next comment line.
Returns "" if all comment lines have been returned, until resetCommentIter is called.
Definition at line 985 of file SamFileHeader.cpp.
bool SamFileHeader::getNextHeaderLine | ( | std::string & | headerLine | ) |
Set the passed in string to the next header line, overwritting the passed in string.
If there are no more header lines or there is an error, false is returned and the passed in string is set to "" until a rest is called. NOTE: both getNextHeaderRecord and getNextHeaderLine increment the same iterator.
Definition at line 941 of file SamFileHeader.cpp.
SamHeaderRecord * SamFileHeader::getNextHeaderRecord | ( | ) |
Get the next header record, but not comment line.
After all headers have been retrieved, NULL is returned until a reset is called. NOTE: both getNextHeaderRecord and getNextHeaderLine increment the same iterator.
Definition at line 908 of file SamFileHeader.cpp.
References SamHeaderRecord::isActiveHeaderRecord().
Referenced by getNextPGRecord(), getNextRGRecord(), and getNextSQRecord().
SamHeaderRecord * SamFileHeader::getNextHeaderRecord | ( | uint32_t & | index, |
SamHeaderRecord::SamHeaderRecordType | headerType | ||
) |
Get the next header record of the specified type starting from the specified index and update the index.
After all headers of that type have been retrieved, NULL is returned until a reset is called for that type.
Definition at line 871 of file SamFileHeader.cpp.
References SamHeaderRecord::getType(), and SamHeaderRecord::isActiveHeaderRecord().
SamHeaderRecord * SamFileHeader::getNextPGRecord | ( | ) |
Get the next PG header record.
After all PG headers have been retrieved, NULL is returned until a reset is called. Independent from getNextHeaderRecord, getNextHeaderLine and the other getNextXXRecord methods and the associated reset methods.
Definition at line 835 of file SamFileHeader.cpp.
References getNextHeaderRecord(), and SamHeaderRecord::PG.
SamHeaderRecord * SamFileHeader::getNextRGRecord | ( | ) |
Get the next RG header record.
After all RG headers have been retrieved, NULL is returned until a reset is called. Independent from getNextHeaderRecord, getNextHeaderLine and the other getNextXXRecord methods and the associated reset methods.
Definition at line 826 of file SamFileHeader.cpp.
References getNextHeaderRecord(), and SamHeaderRecord::RG.
SamHeaderRecord * SamFileHeader::getNextSQRecord | ( | ) |
Get the next SQ header record.
After all SQ headers have been retrieved, NULL is returned until a reset is called. Independent from getNextHeaderRecord, getNextHeaderLine and the other getNextXXRecord methods and the associated reset methods.
Definition at line 817 of file SamFileHeader.cpp.
References getNextHeaderRecord(), and SamHeaderRecord::SQ.
SamHeaderPG * SamFileHeader::getPG | ( | const char * | id | ) |
Get the PG object with the specified id, returning NULL if there is no PG object with that key.
Definition at line 789 of file SamFileHeader.cpp.
Referenced by setPGTag().
int SamFileHeader::getReferenceID | ( | const char * | referenceName, |
bool | addID = false |
||
) |
Get the reference ID for the specified reference name (chromosome).
If addID is set to true, a reference id will be created for the referenceName if one does not already exist. If addID is set to false (default), it will return SamReferenceInfo::NO_REF_ID.
Definition at line 152 of file SamFileHeader.cpp.
References SamReferenceInfo::getReferenceID().
int SamFileHeader::getReferenceID | ( | const String & | referenceName, |
bool | addID = false |
||
) |
Get the reference ID for the specified reference name (chromosome).
If addID is set to true, a reference id will be created for the referenceName if one does not already exist. If addID is set to false (default), it will return SamReferenceInfo::NO_REF_ID.
Definition at line 146 of file SamFileHeader.cpp.
References SamReferenceInfo::getReferenceID().
Referenced by SamFile::getNumMappedReadsFromIndex(), SamFile::getNumUnMappedReadsFromIndex(), SamRecord::setMateReferenceName(), and SamRecord::setReferenceName().
SamHeaderRG * SamFileHeader::getRG | ( | const char * | id | ) |
Get the RG object with the specified read group identifier, returning NULL if there is no RG object with that key.
Definition at line 782 of file SamFileHeader.cpp.
Referenced by setRGTag().
bool SamFileHeader::removeHD | ( | ) |
Remove the HD record.
Definition at line 554 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
bool SamFileHeader::removePG | ( | const char * | id | ) |
Remove PG record with the specified key.
Definition at line 647 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
bool SamFileHeader::removeRG | ( | const char * | id | ) |
Remove RG record with the specified key.
Definition at line 610 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
bool SamFileHeader::removeSQ | ( | const char * | name | ) |
Remove SQ record with the specified key.
NOTE: Does not remove it from the BAM index.
Definition at line 573 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
bool SamFileHeader::setHDTag | ( | const char * | tag, |
const char * | value | ||
) |
Set the specified tag to the specified value in the HD header, remove the tag by specifying value="".
Definition at line 225 of file SamFileHeader.cpp.
References SamHeaderRecord::setTag().
bool SamFileHeader::setPGTag | ( | const char * | tag, |
const char * | value, | ||
const char * | id | ||
) |
Set the specified tag to the specified value in the PG header with the specified id, remove the tag by specifying value="".
If the header does not yet exist, the header is added and so is the ID tag with the value set to the passed in id. The ID tag may not be modified or removed after it is set unless the entire record is deleted.
Definition at line 353 of file SamFileHeader.cpp.
References SamHeaderRecord::addKey(), getPG(), and SamHeaderRecord::setTag().
bool SamFileHeader::setRGTag | ( | const char * | tag, |
const char * | value, | ||
const char * | id | ||
) |
Set the specified tag to the specified value in the RG header with the specified id, remove the tag by specifying value="".
If the header does not yet exist, the header is added and so is the ID tag with the value set to the passed in id. The ID tag may not be modified or removed after it is set unless the entire record is deleted.
Definition at line 311 of file SamFileHeader.cpp.
References SamHeaderRecord::addKey(), getRG(), and SamHeaderRecord::setTag().
bool SamFileHeader::setSQTag | ( | const char * | tag, |
const char * | value, | ||
const char * | name | ||
) |
Set the specified tag to the specified value in the SQ header with the specified name, remove the tag by specifying value="".
If the header does not yet exist, the tag must be "LN" and the header is added with the specified LN value and the SN value passed in name.
The SN & LN tags may not be modified or removed after they are set unless the entire record is deleted.
Definition at line 252 of file SamFileHeader.cpp.
References SamReferenceInfo::add(), SamHeaderRecord::addKey(), getSQ(), and SamHeaderRecord::setTag().