This class allows a user to get/set the fields in a SAM/BAM Header. More...
#include <SamFileHeader.h>
Public Member Functions | |
void | resetHeader () |
Initialize the header. | |
int | getReferenceID (const String &referenceName, bool addID=false) |
Get the reference ID for the specified reference name (chromosome). | |
int | getReferenceID (const char *referenceName, bool addID=false) |
Get the reference ID for the specified reference name (chromosome). | |
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 () |
int | getNumSQs () |
Get the number of SQ objects. | |
int | getNumRGs () |
Get the number of RG objects. | |
int | getNumPGs () |
Get the number of PG objects. | |
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. | |
const char * | getErrorMessage () |
Get the failure message if a method returned failure. | |
Copying a Header | |
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. | |
Get the Entire Header | |
bool | getHeaderString (std::string &header) const |
Set the passed in string to the entire header string, clearing its current contents. | |
Adding an entire header/comment line. | |
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. | |
bool | addHeaderLine (const char *headerLine) |
Add a header line that is already preformatted in a const char*. | |
bool | addHeader (const char *header) |
Add a header that is already preformatted in a const char*. | |
bool | addComment (const char *comment) |
Add the specified comment to the header (do not include "@CO" or "\n"). | |
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="". | |
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="". | |
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="". | |
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="". | |
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. | |
bool | addSQ (SamHeaderSQ *sq) |
Add the SQ record to the header. | |
bool | addRG (SamHeaderRG *rg) |
Add the RG record to the header. | |
bool | addPG (SamHeaderPG *pg) |
Add the PG record to the header. | |
bool | addRecordCopy (const SamHeaderRecord &hdrRec) |
Add a copy of the specified header record to the header. | |
Remove an Entire Header Record | |
bool | removeHD () |
Remove the HD record. | |
bool | removeSQ (const char *name) |
Remove SQ record with the specified key. | |
bool | removeRG (const char *id) |
Remove RG record with the specified key. | |
bool | removePG (const char *id) |
Remove PG record with the specified key. | |
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. | |
Get a Specific Header Record | |
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. | |
SamHeaderPG * | getPG (const char *id) |
Get the PG object with the specified id, returning NULL if there is no PG object with that key. | |
Get the Header Record/Comment/Line by Record/Comment/Line | |
SamHeaderRecord * | getNextSQRecord () |
Get the next SQ header record. | |
SamHeaderRecord * | getNextRGRecord () |
Get the next RG header record. | |
SamHeaderRecord * | getNextPGRecord () |
Get the next PG header record. | |
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. | |
SamHeaderRecord * | getNextHeaderRecord () |
Get the next header record, but not comment line. | |
bool | getNextHeaderLine (std::string &headerLine) |
Set the passed in string to the next header line, overwritting the passed in string. | |
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. | |
void | resetCommentIter () |
Resets to the beginning of the comments so getNextComment returns the first comment. | |
Static Public Attributes | |
static const std::string | EMPTY_RETURN = "" |
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().
00394 { 00395 // If there is already an HD header or if null 00396 // was passed in, return false. 00397 if(myHD != NULL) 00398 { 00399 myErrorMessage = "Failed add an HD tag - there is already one"; 00400 return(false); 00401 } 00402 if(hd == NULL) 00403 { 00404 myErrorMessage = "Failed add an HD tag - no tag specified"; 00405 return(false); 00406 } 00407 myHD = hd; 00408 00409 myHeaderRecords.push_back(myHD); 00410 return(true); 00411 }
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.
00205 { 00206 // Parse the added header line. 00207 String headerString = header; 00208 return(parseHeader(headerString)); 00209 }
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.
00196 { 00197 // Parse the added header line. 00198 String headerString = headerLine; 00199 return(parseHeader(headerString)); 00200 }
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.
00182 { 00183 String headerLine; 00184 headerLine += "@"; 00185 headerLine += type; 00186 headerLine += "\t"; 00187 headerLine += tag; 00188 headerLine += ":"; 00189 headerLine += value; 00190 return(addHeaderLine(headerLine.c_str())); 00191 }
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().
00493 { 00494 // If a null pointer was passed in, return false. 00495 if(pg == NULL) 00496 { 00497 myErrorMessage = "SAM/BAM Header line failed to allocate PG."; 00498 return(false); 00499 } 00500 const char* id = pg->getTagValue("ID"); 00501 if(strcmp(id, EMPTY_RETURN.c_str()) == 0) 00502 { 00503 // ID is not set, so can't add the header record. 00504 myErrorMessage = "SAM/BAM Header line failure: Skipping PG line that is missing the ID field."; 00505 return(false); 00506 } 00507 00508 // Determine whether or not a record with this 00509 // key is already in the hash. 00510 if(myPGs.Find(id) < 0) 00511 { 00512 // It is not already in the hash so 00513 // add it. 00514 myPGs.Add(id, pg); 00515 myHeaderRecords.push_back(pg); 00516 return(true); 00517 } 00518 00519 // It is already in the hash, so cannot be added. 00520 myErrorMessage = "SAM/BAM Header line failure: Skipping PG line that has a repeated ID field."; 00521 return(false); 00522 }
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.
00527 { 00528 SamHeaderRecord* newRec = hdrRec.createCopy(); 00529 bool returnVal = true; 00530 switch(newRec->getType()) 00531 { 00532 case SamHeaderRecord::HD: 00533 returnVal = addHD((SamHeaderHD*)newRec); 00534 break; 00535 case SamHeaderRecord::PG: 00536 returnVal = addPG((SamHeaderPG*)newRec); 00537 break; 00538 case SamHeaderRecord::RG: 00539 returnVal = addRG((SamHeaderRG*)newRec); 00540 break; 00541 case SamHeaderRecord::SQ: 00542 returnVal = addSQ((SamHeaderSQ*)newRec); 00543 break; 00544 default: 00545 myErrorMessage = "Failed to copy a header record, unknown type."; 00546 returnVal = false; 00547 break; 00548 } 00549 return(returnVal); 00550 }
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().
00459 { 00460 if(rg == NULL) 00461 { 00462 // null pointer passed in, can't add it. 00463 myErrorMessage = "SAM/BAM Header line failed to allocate RG."; 00464 return(false); 00465 } 00466 const char* id = rg->getTagValue("ID"); 00467 if(strcmp(id, EMPTY_RETURN.c_str()) == 0) 00468 { 00469 // ID is not set, so can't add it. 00470 myErrorMessage = "SAM/BAM Header line failure: Skipping RG line that is missing the ID field."; 00471 return(false); 00472 } 00473 00474 // Determine whether or not a record with this 00475 // key is already in the hash. 00476 if(myRGs.Find(id) < 0) 00477 { 00478 // It is not already in the hash so 00479 // add it. 00480 myRGs.Add(id, rg); 00481 myHeaderRecords.push_back(rg); 00482 return(true); 00483 } 00484 00485 // It is already in the hash, so cannot be added. 00486 myErrorMessage = "SAM/BAM Header line failure: Skipping RG line that has a repeated ID field."; 00487 return(false); 00488 }
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().
00416 { 00417 if(sq == NULL) 00418 { 00419 // null pointer passed in, can't add it. 00420 myErrorMessage = "SAM/BAM Header line failed to allocate SQ."; 00421 return(false); 00422 } 00423 const char* name = sq->getTagValue("SN"); 00424 const char* length = sq->getTagValue("LN"); 00425 if(strcmp(name, EMPTY_RETURN.c_str()) == 0) 00426 { 00427 // SN is not set, so can't add it. 00428 myErrorMessage = 00429 "SAM/BAM Header line failure: Skipping SQ line that is missing the SN field."; 00430 return(false); 00431 } 00432 if(strcmp(length, EMPTY_RETURN.c_str()) == 0) 00433 { 00434 // LN is not set, so can't add it. 00435 myErrorMessage = 00436 "SAM/BAM Header line failure: Skipping SQ line that is missing the LN field."; 00437 return(false); 00438 } 00439 00440 // Determine whether or not a record with this 00441 // key is already in the hash. 00442 if(mySQs.Find(name) < 0) 00443 { 00444 // It is not already in the hash so add it. 00445 mySQs.Add(name, sq); 00446 myHeaderRecords.push_back(sq); 00447 myReferenceInfo.add(name, atoi(length)); 00448 return(true); 00449 } 00450 00451 // It is already in the hash, so cannot be added. 00452 myErrorMessage = "SAM/BAM Header line failure: Skipping SQ line that has a repeated SN field."; 00453 return(false); 00454 }
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().
00060 { 00061 // Check to see if the passed in value is the same as this. 00062 if(this == &header) 00063 { 00064 return(true); 00065 } 00066 00067 resetHeader(); 00068 00069 // Copy the records by getting the other header's header string 00070 // and parsing it. 00071 std::string newString; 00072 bool status = header.getHeaderString(newString); 00073 String newHeaderString = newString.c_str(); 00074 00075 status &= parseHeader(newHeaderString); 00076 00077 myCurrentHeaderIndex = header.myCurrentHeaderIndex; 00078 myCurrentCommentIndex = header.myCurrentCommentIndex; 00079 00080 // Clear the reference info and copy it to ensure it is the same. 00081 myReferenceInfo.clear(); 00082 // Copy Reference contigs, hash, lengths. 00083 myReferenceInfo = header.myReferenceInfo; 00084 00085 return(status); 00086 }
const char * SamFileHeader::getHDTagValue | ( | const char * | tag | ) |
Returns the value associated with the specified HD tag, returning "" if the tag does not exist in the header.
Definition at line 683 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00684 { 00685 if(myHD == NULL) 00686 { 00687 // return blank since there is no HD type. 00688 return(EMPTY_RETURN.c_str()); 00689 } 00690 return(myHD->getTagValue(tag)); 00691 }
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.
00942 { 00943 headerLine = EMPTY_RETURN.c_str(); 00944 00945 // Until the header is set, keep reading. 00946 // Header could return EMPTY_RETURN.c_str() if the header line is blank. 00947 while(headerLine == EMPTY_RETURN.c_str()) 00948 { 00949 if(getHeaderLine(myCurrentHeaderIndex, headerLine) == false) 00950 { 00951 // getHeaderLine failed, so stop processing, and return false. 00952 return(false); 00953 } 00954 else 00955 { 00956 // In range, increment the index. 00957 ++myCurrentHeaderIndex; 00958 } 00959 } 00960 return(true); 00961 }
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().
00909 { 00910 // Get the next header record 00911 SamHeaderRecord* foundRecord = NULL; 00912 // Loop until a record is found or until out of range of the 00913 // headerRecord vector. 00914 while((myCurrentHeaderIndex < myHeaderRecords.size()) 00915 && (foundRecord == NULL)) 00916 { 00917 // Get the next record. 00918 foundRecord = myHeaderRecords[myCurrentHeaderIndex]; 00919 // Either way, increment the index. 00920 ++myCurrentHeaderIndex; 00921 // Check to see if the next record is active. 00922 if(!foundRecord->isActiveHeaderRecord()) 00923 { 00924 // Not active, so clear the pointer. 00925 foundRecord = NULL; 00926 } 00927 } 00928 00929 // Return the record if it was found. Will be null if none were found. 00930 return(foundRecord); 00931 }
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().
00873 { 00874 SamHeaderRecord* foundRecord = NULL; 00875 // Loop until a record is found or until out of range of the 00876 // headerRecord vector. 00877 while((index < myHeaderRecords.size()) 00878 && (foundRecord == NULL)) 00879 { 00880 // Get the next record. 00881 foundRecord = myHeaderRecords[index]; 00882 // Either way, increment the index. 00883 ++index; 00884 // Check to see if the next record is active. 00885 if(!foundRecord->isActiveHeaderRecord()) 00886 { 00887 // Not active, so clear the pointer. 00888 foundRecord = NULL; 00889 } 00890 // Check to see if the record is the right type. 00891 else if(foundRecord->getType() != headerType) 00892 { 00893 // Not the right type, so clear the pointer. 00894 foundRecord = NULL; 00895 } 00896 } 00897 00898 // Return the record if it was found. Will be null if none were found. 00899 return(foundRecord); 00900 }
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.
00836 { 00837 return(getNextHeaderRecord(myCurrentPGIndex, 00838 SamHeaderRecord::PG)); 00839 }
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.
00827 { 00828 return(getNextHeaderRecord(myCurrentRGIndex, 00829 SamHeaderRecord::RG)); 00830 }
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.
00818 { 00819 return(getNextHeaderRecord(myCurrentSQIndex, 00820 SamHeaderRecord::SQ)); 00821 }
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().
00790 { 00791 return((SamHeaderPG*)(myPGs.Object(id))); 00792 }
const char * SamFileHeader::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.
Definition at line 730 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00731 { 00732 // Look up the id in the hash to get the associated PG object. 00733 SamHeaderPG* pg = (SamHeaderPG*)(myPGs.Object(id)); 00734 00735 // If it is NULL - the tag was not found, so return 00736 if(pg == NULL) 00737 { 00738 return(EMPTY_RETURN.c_str()); 00739 } 00740 00741 // Found the object, so return the PG Tag. 00742 return(pg->getTagValue(tag)); 00743 }
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().
00153 { 00154 return(myReferenceInfo.getReferenceID(referenceName, addID)); 00155 }
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().
00147 { 00148 return(myReferenceInfo.getReferenceID(referenceName, addID)); 00149 }
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().
00783 { 00784 return((SamHeaderRG*)(myRGs.Object(id))); 00785 }
const char * SamFileHeader::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.
Definition at line 714 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00715 { 00716 // Look up the id in the hash to get the associated RG object. 00717 SamHeaderRG* rg = (SamHeaderRG*)(myRGs.Object(id)); 00718 00719 // If it is NULL - the tag was not found, so return 00720 if(rg == NULL) 00721 { 00722 return(EMPTY_RETURN.c_str()); 00723 } 00724 00725 // Found the object, so return the RG Tag. 00726 return(rg->getTagValue(tag)); 00727 }
const char * SamFileHeader::getSortOrder | ( | ) |
Return the Sort Order value that is set in the Header, returning "" if this field does not exist.
Definition at line 797 of file SamFileHeader.cpp.
Referenced by getTagSO().
SamHeaderSQ * SamFileHeader::getSQ | ( | const char * | name | ) |
Get the SQ object with the specified sequence name, returning NULL if there is no SQ object with that key.
Definition at line 775 of file SamFileHeader.cpp.
Referenced by SamValidator::isValidRname(), and setSQTag().
00776 { 00777 return((SamHeaderSQ*)(mySQs.Object(name))); 00778 }
const char * SamFileHeader::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.
Definition at line 696 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00697 { 00698 // Look up the name in the hash to get the associated SQ object. 00699 SamHeaderSQ* sq = (SamHeaderSQ*)(mySQs.Object(name)); 00700 00701 // If it is NULL - the tag was not found, so return 00702 if(sq == NULL) 00703 { 00704 return(EMPTY_RETURN.c_str()); 00705 } 00706 00707 // Found the object, so return the SQ Tag. 00708 return(sq->getTagValue(tag)); 00709 }
bool SamFileHeader::removeHD | ( | ) |
Remove the HD record.
Definition at line 554 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00555 { 00556 if(myHD != NULL) 00557 { 00558 // Reset the record. Do not delete it since it is in the headerRecords 00559 // vector and it is not worth the time to remove it from the middle of 00560 // that vector since this is the header and the space does not need 00561 // to be conserved. 00562 myHD->reset(); 00563 00564 // Set myHD to null so a new HD could be added. 00565 myHD = NULL; 00566 } 00567 00568 return(true); 00569 }
bool SamFileHeader::removePG | ( | const char * | id | ) |
Remove PG record with the specified key.
Definition at line 647 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00648 { 00649 // Look up the id in the hash. 00650 int hashIndex = myPGs.Find(id); 00651 if(hashIndex < 0) 00652 { 00653 // Not found in the hash, so nothing to 00654 // delete, return true it does not exist 00655 // in the hash. 00656 return(true); 00657 } 00658 00659 // Get the PG. 00660 SamHeaderPG* pg = (SamHeaderPG*)(myPGs.Object(hashIndex)); 00661 00662 if(pg == NULL) 00663 { 00664 // pg is null, this is an error since hashIndex was greater than 0, 00665 // so it should have been found. 00666 myErrorMessage = "SAM/BAM Header line failed to get PG object."; 00667 return(false); 00668 } 00669 00670 // Reset the record. Do not delete it since it is in the headerRecords 00671 // vector and it is not worth the time to remove it from the middle of 00672 // that vector since this is the header and the space does not need 00673 // to be conserved. 00674 pg->reset(); 00675 00676 // Delete the entry from the hash. 00677 myPGs.Delete(hashIndex); 00678 00679 return(true); 00680 }
bool SamFileHeader::removeRG | ( | const char * | id | ) |
Remove RG record with the specified key.
Definition at line 610 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00611 { 00612 // Look up the id in the hash. 00613 int hashIndex = myRGs.Find(id); 00614 if(hashIndex < 0) 00615 { 00616 // Not found in the hash, so nothing to 00617 // delete, return true it does not exist 00618 // in the hash. 00619 return(true); 00620 } 00621 00622 // Get the RG. 00623 SamHeaderRG* rg = (SamHeaderRG*)(myRGs.Object(hashIndex)); 00624 00625 if(rg == NULL) 00626 { 00627 // rg is null, this is an error since hashIndex was greater than 0, 00628 // so it should have been found. 00629 myErrorMessage = "SAM/BAM Header line failed to get RG object."; 00630 return(false); 00631 } 00632 00633 // Reset the record. Do not delete it since it is in the headerRecords 00634 // vector and it is not worth the time to remove it from the middle of 00635 // that vector since this is the header and the space does not need 00636 // to be conserved. 00637 rg->reset(); 00638 00639 // Delete the entry from the hash. 00640 myRGs.Delete(hashIndex); 00641 00642 return(true); 00643 }
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().
00574 { 00575 // Look up the name in the hash. 00576 int hashIndex = mySQs.Find(name); 00577 if(hashIndex < 0) 00578 { 00579 // Not found in the hash, so nothing to 00580 // delete, return true it does not exist 00581 // in the hash. 00582 return(true); 00583 } 00584 00585 // Get the SQ. 00586 SamHeaderSQ* sq = (SamHeaderSQ*)(mySQs.Object(hashIndex)); 00587 00588 if(sq == NULL) 00589 { 00590 // sq is null, this is an error since hashIndex was greater than 0, 00591 // so it should have been found. 00592 myErrorMessage = "SAM/BAM Header line failed to get SQ object."; 00593 return(false); 00594 } 00595 00596 // Reset the record. Do not delete it since it is in the headerRecords 00597 // vector and it is not worth the time to remove it from the middle of 00598 // that vector since this is the header and the space does not need 00599 // to be conserved. 00600 sq->reset(); 00601 00602 // Delete the entry from the hash. 00603 mySQs.Delete(hashIndex); 00604 00605 return(true); 00606 }
void SamFileHeader::resetCommentIter | ( | ) |
Resets to the beginning of the comments so getNextComment returns the first comment.
Definition at line 998 of file SamFileHeader.cpp.
Referenced by resetHeader().
void SamFileHeader::resetHeaderRecordIter | ( | ) |
Reset to the beginning of the header records so the next call to getNextHeaderRecord returns the first header line.
Definition at line 966 of file SamFileHeader.cpp.
Referenced by resetHeader().
void SamFileHeader::resetPGRecordIter | ( | ) |
Reset to the beginning of the header records so the next call to getNextPGRecord returns the first PG header record.
Definition at line 860 of file SamFileHeader.cpp.
Referenced by resetHeader().
void SamFileHeader::resetRGRecordIter | ( | ) |
Reset to the beginning of the header records so the next call to getNextRGRecord returns the first RG header record.
Definition at line 852 of file SamFileHeader.cpp.
Referenced by resetHeader().
void SamFileHeader::resetSQRecordIter | ( | ) |
Reset to the beginning of the header records so the next call to getNextSQRecord returns the first SQ header record.
Definition at line 844 of file SamFileHeader.cpp.
Referenced by resetHeader().
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().
00226 { 00227 if(myHD == NULL) 00228 { 00229 // Need to create the HD line. 00230 myHD = new SamHeaderHD(); 00231 if(myHD == NULL) 00232 { 00233 // New failed, return false. 00234 myErrorMessage = "SamFileHeader: Failed to allocate a new HD tag"; 00235 return(false); 00236 } 00237 // Succeeded to create the line, add it to the 00238 // list. 00239 myHeaderRecords.push_back(myHD); 00240 } 00241 if(!myHD->setTag(tag, value)) 00242 { 00243 myErrorMessage = "SamFileHeader: Failed to set the specified HD tag"; 00244 return(false); 00245 } 00246 return(true); 00247 }
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().
00354 { 00355 // Get the PG record for the specified name. 00356 SamHeaderPG* pg = getPG(id); 00357 if(pg == NULL) 00358 { 00359 // The PG does not yet exist. 00360 // Add it. 00361 pg = new SamHeaderPG(); 00362 00363 if(pg == NULL) 00364 { 00365 // Could not create the header record. 00366 myErrorMessage = "Failed to allocate a new PG tag"; 00367 return(false); 00368 } 00369 00370 // Created the header record, so add it to the list of PG lines. 00371 myPGs.Add(id, pg); 00372 myHeaderRecords.push_back(pg); 00373 00374 // Add the key tag 00375 if(!pg->addKey(id)) 00376 { 00377 // Failed to add the key tag, return false. 00378 myErrorMessage = "Failed to add the specified PG key"; 00379 return(false); 00380 } 00381 } 00382 00383 if(!pg->setTag(tag, value)) 00384 { 00385 myErrorMessage = "Failed to set the specified PG tag"; 00386 return(false); 00387 } 00388 return(true); 00389 }
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().
00312 { 00313 // Get the RG record for the specified name. 00314 SamHeaderRG* rg = getRG(id); 00315 if(rg == NULL) 00316 { 00317 // The RG does not yet exist. 00318 // Add it. 00319 rg = new SamHeaderRG(); 00320 00321 if(rg == NULL) 00322 { 00323 // Could not create the header record. 00324 myErrorMessage = "Failed to allocate a new RG tag"; 00325 return(false); 00326 } 00327 00328 // Created the header record, so add it to the list of RG lines. 00329 myRGs.Add(id, rg); 00330 myHeaderRecords.push_back(rg); 00331 00332 // Add the key tag 00333 if(!rg->addKey(id)) 00334 { 00335 // Failed to add the key tag, return false. 00336 myErrorMessage = "Failed to add the specified RG key"; 00337 return(false); 00338 } 00339 } 00340 00341 if(!rg->setTag(tag, value)) 00342 { 00343 myErrorMessage = "Failed to set the specified RG tag"; 00344 return(false); 00345 } 00346 return(true); 00347 }
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().
00254 { 00255 // Get the SQ record for the specified name. 00256 SamHeaderSQ* sq = getSQ(name); 00257 if(sq == NULL) 00258 { 00259 // The SQ does not yet exist. 00260 // Make sure the tag is LN. 00261 if(strcmp(tag, "LN") != 0) 00262 { 00263 // LN is required so must be the first tag added 00264 myErrorMessage = 00265 "SamFileHeader:Failed to add the specified SQ key, LN not specified."; 00266 return(false); 00267 } 00268 00269 // Add it. 00270 sq = new SamHeaderSQ(); 00271 00272 if(sq == NULL) 00273 { 00274 // Could not create the header record. 00275 myErrorMessage = "SamFileHeader: Failed to allocate a new SQ tag"; 00276 return(false); 00277 } 00278 00279 // Created the header record, so add it to the list of SQ lines. 00280 mySQs.Add(name, sq); 00281 myHeaderRecords.push_back(sq); 00282 // value is the length, so update the reference info. 00283 myReferenceInfo.add(name, atoi(value)); 00284 00285 // Add the key tag 00286 if(!sq->addKey(name)) 00287 { 00288 // Failed to add the key tag, return false. 00289 myErrorMessage = "SamFileHeader:Failed to add the specified SQ key"; 00290 return(false); 00291 } 00292 } 00293 else if(strcmp(tag, "LN") == 0) 00294 { 00295 // Cannot modify/remove the LN tag. 00296 myErrorMessage = "SamFileHeader:Cannot modify/remove the SQ's LN tag"; 00297 return(false); 00298 } 00299 00300 if(!sq->setTag(tag, value)) 00301 { 00302 myErrorMessage = "Failed to set the specified SQ tag"; 00303 return(false); 00304 } 00305 return(true); 00306 }