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. | |
void | addReferenceInfo (const char *referenceSequenceName, int32_t referenceSequenceLength) |
Add reference sequence name and reference sequence length to the header. | |
void | generateReferenceInfo () |
Populate the reference info from the SQ fields. | |
SamStatus::Status | setHeaderFromBamFile (IFILE filePtr) |
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. | |
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* without a trailing "\n". | |
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. | |
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/comment 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. | |
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. |
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 35 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 223 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. \ returns true if the record was successfully added, false otherwise.
Definition at line 359 of file SamFileHeader.cpp.
bool SamFileHeader::addHeaderLine | ( | const char * | headerLine | ) |
Add a header line that is already preformatted in a const char* without a trailing "\n".
Definition at line 208 of file SamFileHeader.cpp.
00209 { 00210 // Parse the added header line. 00211 String headerString = headerLine; 00212 if(parseHeader(headerString)) 00213 { 00214 // Successfully parsed the header line. 00215 return(true); 00216 } 00217 // Failed to parse the header line, return false. 00218 return(false); 00219 }
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 192 of file SamFileHeader.cpp.
00194 { 00195 String headerLine; 00196 headerLine += "@"; 00197 headerLine += type; 00198 headerLine += "\t"; 00199 headerLine += tag; 00200 headerLine += ":"; 00201 headerLine += value; 00202 return(addHeaderLine(headerLine.c_str())); 00203 }
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. \ returns true if the record was successfully added, false otherwise.
Definition at line 437 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00438 { 00439 // If there is already an PG header, return false. 00440 if(pg == NULL) 00441 { 00442 return(false); 00443 } 00444 const char* id = pg->getTagValue("ID"); 00445 if(strcmp(id, EMPTY_RETURN.c_str()) == 0) 00446 { 00447 // ID is not set, so can't add the header record. 00448 return(false); 00449 } 00450 00451 // Determine whether or not a record with this 00452 // key is already in the hash. 00453 if(myPGs.Find(id) < 0) 00454 { 00455 // It is not already in the hash so 00456 // add it. 00457 myPGs.Add(id, pg); 00458 myHeaderRecords.push_back(pg); 00459 return(true); 00460 } 00461 00462 // It is already in the hash, so cannot be added. 00463 return(false); 00464 }
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. \ returns true if the record was successfully added, false otherwise.
Definition at line 406 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00407 { 00408 if(rg == NULL) 00409 { 00410 // null pointer passed in, can't add it. 00411 return(false); 00412 } 00413 const char* id = rg->getTagValue("ID"); 00414 if(strcmp(id, EMPTY_RETURN.c_str()) == 0) 00415 { 00416 // ID is not set, so can't add it. 00417 return(false); 00418 } 00419 00420 // Determine whether or not a record with this 00421 // key is already in the hash. 00422 if(myRGs.Find(id) < 0) 00423 { 00424 // It is not already in the hash so 00425 // add it. 00426 myRGs.Add(id, rg); 00427 myHeaderRecords.push_back(rg); 00428 return(true); 00429 } 00430 00431 // It is already in the hash, so cannot be added. 00432 return(false); 00433 }
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. \ returns true if the record was successfully added, false otherwise.
Definition at line 375 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00376 { 00377 if(sq == NULL) 00378 { 00379 // null pointer passed in, can't add it. 00380 return(false); 00381 } 00382 const char* name = sq->getTagValue("SN"); 00383 if(strcmp(name, EMPTY_RETURN.c_str()) == 0) 00384 { 00385 // SN is not set, so can't add it. 00386 return(false); 00387 } 00388 00389 // Determine whether or not a record with this 00390 // key is already in the hash. 00391 if(mySQs.Find(name) < 0) 00392 { 00393 // It is not already in the hash so 00394 // add it. 00395 mySQs.Add(name, sq); 00396 myHeaderRecords.push_back(sq); 00397 return(true); 00398 } 00399 00400 // It is already in the hash, so cannot be added. 00401 return(false); 00402 }
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 633 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00634 { 00635 if(myHD == NULL) 00636 { 00637 // return blank since there is no HD type. 00638 return(EMPTY_RETURN.c_str()); 00639 } 00640 return(myHD->getTagValue(tag)); 00641 }
bool SamFileHeader::getHeaderString | ( | std::string & | header | ) | const |
Set the passed in string to the entire header string, clearing its current contents.
Definition at line 120 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 924 of file SamFileHeader.cpp.
bool SamFileHeader::getNextHeaderLine | ( | std::string & | headerLine | ) |
Set the passed in string to the next header/comment 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 891 of file SamFileHeader.cpp.
00892 { 00893 headerLine = EMPTY_RETURN.c_str(); 00894 00895 // Until the header is set, keep reading. 00896 // Header could return EMPTY_RETURN.c_str() if the header line is blank. 00897 while(headerLine == EMPTY_RETURN.c_str()) 00898 { 00899 if(getHeaderLine(myCurrentHeaderIndex, headerLine) == false) 00900 { 00901 // getHeaderLine failed, so stop processing, and return false. 00902 return(false); 00903 } 00904 else 00905 { 00906 // In range, increment the index. 00907 ++myCurrentHeaderIndex; 00908 } 00909 } 00910 return(true); 00911 }
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 858 of file SamFileHeader.cpp.
References SamHeaderRecord::isActiveHeaderRecord().
Referenced by generateReferenceInfo(), getNextPGRecord(), getNextRGRecord(), and getNextSQRecord().
00859 { 00860 // Get the next header record 00861 SamHeaderRecord* foundRecord = NULL; 00862 // Loop until a record is found or until out of range of the 00863 // headerRecord vector. 00864 while((myCurrentHeaderIndex < myHeaderRecords.size()) 00865 && (foundRecord == NULL)) 00866 { 00867 // Get the next record. 00868 foundRecord = myHeaderRecords[myCurrentHeaderIndex]; 00869 // Either way, increment the index. 00870 ++myCurrentHeaderIndex; 00871 // Check to see if the next record is active. 00872 if(!foundRecord->isActiveHeaderRecord()) 00873 { 00874 // Not active, so clear the pointer. 00875 foundRecord = NULL; 00876 } 00877 } 00878 00879 // Return the record if it was found. Will be null if none were found. 00880 return(foundRecord); 00881 }
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 821 of file SamFileHeader.cpp.
References SamHeaderRecord::getType(), and SamHeaderRecord::isActiveHeaderRecord().
00823 { 00824 SamHeaderRecord* foundRecord = NULL; 00825 // Loop until a record is found or until out of range of the 00826 // headerRecord vector. 00827 while((index < myHeaderRecords.size()) 00828 && (foundRecord == NULL)) 00829 { 00830 // Get the next record. 00831 foundRecord = myHeaderRecords[index]; 00832 // Either way, increment the index. 00833 ++index; 00834 // Check to see if the next record is active. 00835 if(!foundRecord->isActiveHeaderRecord()) 00836 { 00837 // Not active, so clear the pointer. 00838 foundRecord = NULL; 00839 } 00840 // Check to see if the record is the right type. 00841 else if(foundRecord->getType() != headerType) 00842 { 00843 // Not the right type, so clear the pointer. 00844 foundRecord = NULL; 00845 } 00846 } 00847 00848 // Return the record if it was found. Will be null if none were found. 00849 return(foundRecord); 00850 }
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 785 of file SamFileHeader.cpp.
References getNextHeaderRecord(), and SamHeaderRecord::PG.
00786 { 00787 return(getNextHeaderRecord(myCurrentPGIndex, 00788 SamHeaderRecord::PG)); 00789 }
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 776 of file SamFileHeader.cpp.
References getNextHeaderRecord(), and SamHeaderRecord::RG.
00777 { 00778 return(getNextHeaderRecord(myCurrentRGIndex, 00779 SamHeaderRecord::RG)); 00780 }
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 767 of file SamFileHeader.cpp.
References getNextHeaderRecord(), and SamHeaderRecord::SQ.
00768 { 00769 return(getNextHeaderRecord(myCurrentSQIndex, 00770 SamHeaderRecord::SQ)); 00771 }
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 739 of file SamFileHeader.cpp.
Referenced by setPGTag().
00740 { 00741 return((SamHeaderPG*)(myPGs.Object(id))); 00742 }
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 680 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00681 { 00682 // Look up the id in the hash to get the associated PG object. 00683 SamHeaderPG* pg = (SamHeaderPG*)(myPGs.Object(id)); 00684 00685 // If it is NULL - the tag was not found, so return 00686 if(pg == NULL) 00687 { 00688 return(EMPTY_RETURN.c_str()); 00689 } 00690 00691 // Found the object, so return the PG Tag. 00692 return(pg->getTagValue(tag)); 00693 }
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 141 of file SamFileHeader.cpp.
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 135 of file SamFileHeader.cpp.
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 732 of file SamFileHeader.cpp.
Referenced by setRGTag().
00733 { 00734 return((SamHeaderRG*)(myRGs.Object(id))); 00735 }
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 664 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00665 { 00666 // Look up the id in the hash to get the associated RG object. 00667 SamHeaderRG* rg = (SamHeaderRG*)(myRGs.Object(id)); 00668 00669 // If it is NULL - the tag was not found, so return 00670 if(rg == NULL) 00671 { 00672 return(EMPTY_RETURN.c_str()); 00673 } 00674 00675 // Found the object, so return the RG Tag. 00676 return(rg->getTagValue(tag)); 00677 }
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 747 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 725 of file SamFileHeader.cpp.
Referenced by SamValidator::isValidRname(), and setSQTag().
00726 { 00727 return((SamHeaderSQ*)(mySQs.Object(name))); 00728 }
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 646 of file SamFileHeader.cpp.
References SamHeaderRecord::getTagValue().
00647 { 00648 // Look up the name in the hash to get the associated SQ object. 00649 SamHeaderSQ* sq = (SamHeaderSQ*)(mySQs.Object(name)); 00650 00651 // If it is NULL - the tag was not found, so return 00652 if(sq == NULL) 00653 { 00654 return(EMPTY_RETURN.c_str()); 00655 } 00656 00657 // Found the object, so return the SQ Tag. 00658 return(sq->getTagValue(tag)); 00659 }
bool SamFileHeader::removeHD | ( | ) |
Remove the HD record.
Definition at line 468 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00469 { 00470 if(myHD != NULL) 00471 { 00472 // Reset the record. Do not delete it since it is in the headerRecords 00473 // vector and it is not worth the time to remove it from the middle of 00474 // that vector since this is the header and the space does not need 00475 // to be conserved. 00476 myHD->reset(); 00477 00478 // Set myHD to null so a new HD could be added. 00479 myHD = NULL; 00480 } 00481 00482 return(true); 00483 }
bool SamFileHeader::removePG | ( | const char * | id | ) |
Remove PG record with the specified key.
Definition at line 559 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00560 { 00561 // Look up the id in the hash. 00562 int hashIndex = myPGs.Find(id); 00563 if(hashIndex < 0) 00564 { 00565 // Not found in the hash, so nothing to 00566 // delete, return true it does not exist 00567 // in the hash. 00568 return(true); 00569 } 00570 00571 // Get the PG. 00572 SamHeaderPG* pg = (SamHeaderPG*)(myPGs.Object(hashIndex)); 00573 00574 if(pg == NULL) 00575 { 00576 // pg is null, this is an error since hashIndex was greater than 0, 00577 // so it should have been found. 00578 return(false); 00579 } 00580 00581 // Reset the record. Do not delete it since it is in the headerRecords 00582 // vector and it is not worth the time to remove it from the middle of 00583 // that vector since this is the header and the space does not need 00584 // to be conserved. 00585 pg->reset(); 00586 00587 // Delete the entry from the hash. 00588 myPGs.Delete(hashIndex); 00589 00590 return(true); 00591 }
bool SamFileHeader::removeRG | ( | const char * | id | ) |
Remove RG record with the specified key.
Definition at line 523 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00524 { 00525 // Look up the id in the hash. 00526 int hashIndex = myRGs.Find(id); 00527 if(hashIndex < 0) 00528 { 00529 // Not found in the hash, so nothing to 00530 // delete, return true it does not exist 00531 // in the hash. 00532 return(true); 00533 } 00534 00535 // Get the RG. 00536 SamHeaderRG* rg = (SamHeaderRG*)(myRGs.Object(hashIndex)); 00537 00538 if(rg == NULL) 00539 { 00540 // rg is null, this is an error since hashIndex was greater than 0, 00541 // so it should have been found. 00542 return(false); 00543 } 00544 00545 // Reset the record. Do not delete it since it is in the headerRecords 00546 // vector and it is not worth the time to remove it from the middle of 00547 // that vector since this is the header and the space does not need 00548 // to be conserved. 00549 rg->reset(); 00550 00551 // Delete the entry from the hash. 00552 myRGs.Delete(hashIndex); 00553 00554 return(true); 00555 }
bool SamFileHeader::removeSQ | ( | const char * | name | ) |
Remove SQ record with the specified key.
Definition at line 487 of file SamFileHeader.cpp.
References SamHeaderRecord::reset().
00488 { 00489 // Look up the name in the hash. 00490 int hashIndex = mySQs.Find(name); 00491 if(hashIndex < 0) 00492 { 00493 // Not found in the hash, so nothing to 00494 // delete, return true it does not exist 00495 // in the hash. 00496 return(true); 00497 } 00498 00499 // Get the SQ. 00500 SamHeaderSQ* sq = (SamHeaderSQ*)(mySQs.Object(hashIndex)); 00501 00502 if(sq == NULL) 00503 { 00504 // sq is null, this is an error since hashIndex was greater than 0, 00505 // so it should have been found. 00506 return(false); 00507 } 00508 00509 // Reset the record. Do not delete it since it is in the headerRecords 00510 // vector and it is not worth the time to remove it from the middle of 00511 // that vector since this is the header and the space does not need 00512 // to be conserved. 00513 sq->reset(); 00514 00515 // Delete the entry from the hash. 00516 mySQs.Delete(hashIndex); 00517 00518 return(true); 00519 }
void SamFileHeader::resetCommentIter | ( | ) |
Resets to the beginning of the comments so getNextComment returns the first comment.
Definition at line 937 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 916 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 810 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 802 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 794 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 235 of file SamFileHeader.cpp.
References SamHeaderRecord::setTag().
00236 { 00237 if(myHD == NULL) 00238 { 00239 // Need to create the HD line. 00240 myHD = new SamHeaderHD(); 00241 if(myHD == NULL) 00242 { 00243 // New failed, return false. 00244 return(false); 00245 } 00246 // Succeeded to create the line, add it to the 00247 // list. 00248 myHeaderRecords.push_back(myHD); 00249 } 00250 return(myHD->setTag(tag, value)); 00251 }
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 326 of file SamFileHeader.cpp.
References SamHeaderRecord::addKey(), getPG(), and SamHeaderRecord::setTag().
00327 { 00328 // Get the PG record for the specified name. 00329 SamHeaderPG* pg = getPG(id); 00330 if(pg == NULL) 00331 { 00332 // The PG does not yet exist. 00333 // Add it. 00334 pg = new SamHeaderPG(); 00335 00336 if(pg == NULL) 00337 { 00338 // Could not create the header record. 00339 return(false); 00340 } 00341 00342 // Created the header record, so add it to the list of PG lines. 00343 myPGs.Add(id, pg); 00344 myHeaderRecords.push_back(pg); 00345 00346 // Add the key tag 00347 if(!pg->addKey(id)) 00348 { 00349 // Failed to add the key tag, return false. 00350 return(false); 00351 } 00352 } 00353 00354 return(pg->setTag(tag, value)); 00355 }
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 291 of file SamFileHeader.cpp.
References SamHeaderRecord::addKey(), getRG(), and SamHeaderRecord::setTag().
00292 { 00293 // Get the RG record for the specified name. 00294 SamHeaderRG* rg = getRG(id); 00295 if(rg == NULL) 00296 { 00297 // The RG does not yet exist. 00298 // Add it. 00299 rg = new SamHeaderRG(); 00300 00301 if(rg == NULL) 00302 { 00303 // Could not create the header record. 00304 return(false); 00305 } 00306 00307 // Created the header record, so add it to the list of RG lines. 00308 myRGs.Add(id, rg); 00309 myHeaderRecords.push_back(rg); 00310 00311 // Add the key tag 00312 if(!rg->addKey(id)) 00313 { 00314 // Failed to add the key tag, return false. 00315 return(false); 00316 } 00317 } 00318 00319 return(rg->setTag(tag, value)); 00320 }
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 header is added and so is the SN tag with the value set to the passed in name. The SN tag may not be modified or removed after it is set unless the entire record is deleted.
Definition at line 256 of file SamFileHeader.cpp.
References SamHeaderRecord::addKey(), getSQ(), and SamHeaderRecord::setTag().
00258 { 00259 // Get the SQ record for the specified name. 00260 SamHeaderSQ* sq = getSQ(name); 00261 if(sq == NULL) 00262 { 00263 // The SQ does not yet exist. 00264 // Add it. 00265 sq = new SamHeaderSQ(); 00266 00267 if(sq == NULL) 00268 { 00269 // Could not create the header record. 00270 return(false); 00271 } 00272 00273 // Created the header record, so add it to the list of SQ lines. 00274 mySQs.Add(name, sq); 00275 myHeaderRecords.push_back(sq); 00276 00277 // Add the key tag 00278 if(!sq->addKey(name)) 00279 { 00280 // Failed to add the key tag, return false. 00281 return(false); 00282 } 00283 } 00284 00285 return(sq->setTag(tag, value)); 00286 }