libStatGen Software 1
|
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record. More...
#include <SamRecord.h>
Public Types | |
enum | SequenceTranslation { NONE , EQUAL , BASES } |
Enum containing the settings on how to translate the sequence if a reference is available. More... | |
Public Member Functions | |
SamRecord () | |
Default Constructor. | |
SamRecord (ErrorHandler::HandlingType errorHandlingType) | |
Constructor that sets the error handling type. | |
~SamRecord () | |
Destructor. | |
void | resetRecord () |
Reset the fields of the record to a default value. | |
bool | isValid (SamFileHeader &header) |
Returns whether or not the record is valid, setting the status to indicate success or failure. | |
void | setReference (GenomeSequence *reference) |
Set the reference to the specified genome sequence object. | |
void | setSequenceTranslation (SequenceTranslation translation) |
Set the type of sequence translation to use when getting the sequence. | |
Set Alignment Data | |
Set methods for record fields. All of the "set" methods set the status to indicate success or the failure reason. | |
bool | setReadName (const char *readName) |
Set QNAME to the passed in name. | |
bool | setFlag (uint16_t flag) |
Set the bitwise FLAG to the specified value. | |
bool | setReferenceName (SamFileHeader &header, const char *referenceName) |
Set the reference sequence name (RNAME) to the specified name, using the header to determine the reference id. | |
bool | set1BasedPosition (int32_t position) |
Set the leftmost position (POS) using the specified 1-based (SAM format) value. | |
bool | set0BasedPosition (int32_t position) |
Set the leftmost position using the specified 0-based (BAM format) value. | |
bool | setMapQuality (uint8_t mapQuality) |
Set the mapping quality (MAPQ). | |
bool | setCigar (const char *cigar) |
Set the CIGAR to the specified SAM formatted cigar string. | |
bool | setCigar (const Cigar &cigar) |
Set the CIGAR to the specified Cigar object. | |
bool | setMateReferenceName (SamFileHeader &header, const char *mateReferenceName) |
Set the mate/next fragment's reference sequence name (RNEXT) to the specified name, using the header to determine the mate reference id. | |
bool | set1BasedMatePosition (int32_t matePosition) |
Set the mate/next fragment's leftmost position (PNEXT) using the specified 1-based (SAM format) value. | |
bool | set0BasedMatePosition (int32_t matePosition) |
Set the mate/next fragment's leftmost position using the specified 0-based (BAM format) value. | |
bool | setInsertSize (int32_t insertSize) |
Sets the inferred insert size (ISIZE)/observed template length (TLEN). | |
bool | setSequence (const char *seq) |
Sets the sequence (SEQ) to the specified SAM formatted sequence string. | |
bool | setQuality (const char *quality) |
Sets the quality (QUAL) to the specified SAM formatted quality string. | |
bool | shiftIndelsLeft () |
Shift the indels (if any) to the left by updating the CIGAR. | |
SamStatus::Status | setBuffer (const char *fromBuffer, uint32_t fromBufferSize, SamFileHeader &header) |
Sets the SamRecord to contain the information in the BAM formatted fromBuffer. | |
SamStatus::Status | setBufferFromFile (IFILE filePtr, SamFileHeader &header) |
Read the BAM record from a file. | |
Set Tag Data | |
Set methods for tags. | |
bool | addIntTag (const char *tag, int32_t value) |
Add the specified integer tag to the record. | |
bool | addTag (const char *tag, char vtype, const char *value) |
Add the specified tag,vtype,value to the record. | |
void | clearTags () |
Clear the tags in this record. | |
bool | rmTag (const char *tag, char type) |
Remove a tag. | |
bool | rmTags (const char *tags) |
Remove tags. | |
Get Alignment Data | |
Get methods for record fields. All of the "get" methods set the status to indicate success or the failure reason. | |
const void * | getRecordBuffer () |
Get a const pointer to the buffer that contains the BAM representation of the record. | |
const void * | getRecordBuffer (SequenceTranslation translation) |
Get a const pointer to the buffer that contains the BAM representation of the record using the specified translation on the sequence. | |
SamStatus::Status | writeRecordBuffer (IFILE filePtr) |
Write the record as a BAM into the specified already opened file. | |
SamStatus::Status | writeRecordBuffer (IFILE filePtr, SequenceTranslation translation) |
Write the record as a BAM into the specified already opened file using the specified translation on the sequence. | |
int32_t | getBlockSize () |
Get the block size of the record (BAM format). | |
const char * | getReferenceName () |
Get the reference sequence name (RNAME) of the record. | |
int32_t | getReferenceID () |
Get the reference sequence id of the record (BAM format rid). | |
int32_t | get1BasedPosition () |
Get the 1-based(SAM) leftmost position (POS) of the record. | |
int32_t | get0BasedPosition () |
Get the 0-based(BAM) leftmost position of the record. | |
uint8_t | getReadNameLength () |
Get the length of the readname (QNAME) including the null. | |
uint8_t | getMapQuality () |
Get the mapping quality (MAPQ) of the record. | |
uint16_t | getBin () |
Get the BAM bin for the record. | |
uint16_t | getCigarLength () |
Get the length of the BAM formatted CIGAR. | |
uint16_t | getFlag () |
Get the flag (FLAG). | |
int32_t | getReadLength () |
Get the length of the read. | |
const char * | getMateReferenceName () |
Get the mate/next fragment's reference sequence name (RNEXT). | |
const char * | getMateReferenceNameOrEqual () |
Get the mate/next fragment's reference sequence name (RNEXT), returning "=" if it is the same as the reference name, unless they are both "*" in which case "*" is returned. | |
int32_t | getMateReferenceID () |
Get the mate reference id of the record (BAM format: mate_rid/next_refID). | |
int32_t | get1BasedMatePosition () |
Get the 1-based(SAM) leftmost mate/next fragment's position (PNEXT). | |
int32_t | get0BasedMatePosition () |
Get the 0-based(BAM) leftmost mate/next fragment's position. | |
int32_t | getInsertSize () |
Get the inferred insert size of the read pair (ISIZE) or observed template length (TLEN). | |
int32_t | get0BasedAlignmentEnd () |
Returns the 0-based inclusive rightmost position of the clipped sequence. | |
int32_t | get1BasedAlignmentEnd () |
Returns the 1-based inclusive rightmost position of the clipped sequence. | |
int32_t | getAlignmentLength () |
Returns the length of the clipped sequence, returning 0 if the cigar is '*'. | |
int32_t | get0BasedUnclippedStart () |
Returns the 0-based inclusive left-most position adjusted for clipped bases. | |
int32_t | get1BasedUnclippedStart () |
Returns the 1-based inclusive left-most position adjusted for clipped bases. | |
int32_t | get0BasedUnclippedEnd () |
Returns the 0-based inclusive right-most position adjusted for clipped bases. | |
int32_t | get1BasedUnclippedEnd () |
Returns the 1-based inclusive right-most position adjusted for clipped bases. | |
const char * | getReadName () |
Returns the SAM formatted Read Name (QNAME). | |
const char * | getCigar () |
Returns the SAM formatted CIGAR string. | |
const char * | getSequence () |
Returns the SAM formatted sequence string (SEQ), translating the base as specified by setSequenceTranslation. | |
const char * | getSequence (SequenceTranslation translation) |
Returns the SAM formatted sequence string (SEQ) performing the specified sequence translation. | |
const char * | getQuality () |
Returns the SAM formatted quality string (QUAL). | |
char | getSequence (int index) |
Get the sequence base at the specified index into this sequence 0 to readLength - 1, translating the base as specified by setSequenceTranslation. | |
char | getSequence (int index, SequenceTranslation translation) |
Get the sequence base at the specified index into this sequence 0 to readLength - 1 performing the specified sequence translation. | |
char | getQuality (int index) |
Get the quality character at the specified index into the quality 0 to readLength - 1. | |
Cigar * | getCigarInfo () |
Returns a pointer to the Cigar object associated with this record. | |
uint32_t | getNumOverlaps (int32_t start, int32_t end) |
Return the number of bases in this read that overlap the passed in region. | |
bool | getFields (bamRecordStruct &recStruct, String &readName, String &cigar, String &sequence, String &quality) |
Returns the values of all fields except the tags. | |
bool | getFields (bamRecordStruct &recStruct, String &readName, String &cigar, String &sequence, String &quality, SequenceTranslation translation) |
Returns the values of all fields except the tags using the specified sequence translation. | |
GenomeSequence * | getReference () |
Returns a pointer to the genome sequence object associated with this record if it was set (NULL if it was not set). | |
Get Tag Methods | |
Get methods for obtaining information on tags. | |
uint32_t | getTagLength () |
Returns the length of the BAM formatted tags. | |
bool | getNextSamTag (char *tag, char &vtype, void **value) |
Get the next tag from the record. | |
void | resetTagIter () |
Reset the tag iterator to the beginning of the tags. | |
bool | getTagsString (const char *tags, String &returnString, char delim='\t') |
Get the string representation of the tags from the record, formatted as TAG:TYPE:VALUE<delim>TAG:TYPE:VALUE... Sets the Status to SUCCESS when the tags are successfully returned or the tags were not found. | |
const String * | getStringTag (const char *tag) |
Get the string value for the specified tag. | |
int * | getIntegerTag (const char *tag) |
Get the integer value for the specified tag, DEPRECATED, use one that returns a bool (success/failure). | |
bool | getIntegerTag (const char *tag, int &tagVal) |
Get the integer value for the specified tag. | |
bool | getFloatTag (const char *tag, float &tagVal) |
Get the float value for the specified tag. | |
const String & | getString (const char *tag) |
Get the string value for the specified tag. | |
int & | getInteger (const char *tag) |
Get the integer value for the specified tag, DEPRECATED, use getIntegerTag that returns a bool. | |
bool | checkString (const char *tag) |
Check if the specified tag contains a string. | |
bool | checkInteger (const char *tag) |
Check if the specified tag contains an integer. | |
bool | checkFloat (const char *tag) |
Check if the specified tag contains a string. | |
bool | checkTag (const char *tag, char type) |
Check if the specified tag contains a value of the specified vtype. | |
const SamStatus & | getStatus () |
Returns the status associated with the last method that sets the status. | |
static bool | isIntegerType (char vtype) |
Returns whether or not the specified vtype is an integer type. | |
static bool | isFloatType (char vtype) |
Returns whether or not the specified vtype is a float type. | |
static bool | isCharType (char vtype) |
Returns whether or not the specified vtype is a char type. | |
static bool | isStringType (char vtype) |
Returns whether or not the specified vtype is a string type. | |
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
Definition at line 51 of file SamRecord.h.
Enum containing the settings on how to translate the sequence if a reference is available.
If no reference is available, no translation is done.
Enumerator | |
---|---|
NONE | Leave the sequence as is. |
EQUAL | Translate bases that match the reference to '='. |
BASES | Translate '=' to the actual base. |
Definition at line 57 of file SamRecord.h.
SamRecord::SamRecord | ( | ) |
Default Constructor.
Definition at line 34 of file SamRecord.cpp.
References resetRecord().
SamRecord::SamRecord | ( | ErrorHandler::HandlingType | errorHandlingType | ) |
Constructor that sets the error handling type.
errorHandlingType | how to handle errors. |
Definition at line 53 of file SamRecord.cpp.
References resetRecord().
SamRecord::~SamRecord | ( | ) |
Destructor.
Definition at line 72 of file SamRecord.cpp.
References resetRecord().
bool SamRecord::addIntTag | ( | const char * | tag, |
int32_t | value | ||
) |
Add the specified integer tag to the record.
Internal processing handles switching between SAM/BAM formats when read/written and determining the type for BAM format. If the tag is already there this code will replace it if the specified value is different.
tag | two character tag to be added to the SAM/BAM record. |
value | value for the specified tag. |
Definition at line 647 of file SamRecord.cpp.
References StatGenStatus::INVALID, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
Referenced by addTag().
bool SamRecord::addTag | ( | const char * | tag, |
char | vtype, | ||
const char * | value | ||
) |
Add the specified tag,vtype,value to the record.
Vtype can be SAM/BAM format. Internal processing handles switching between SAM/BAM formats when read/written. If the tag is already there this code will replace it if the specified value is different.
tag | two character tag to be added to the SAM/BAM record. |
vtype | vtype of the specified value - either SAM/BAM vtypes. |
value | value as a string for the specified tag. |
Definition at line 791 of file SamRecord.cpp.
References addIntTag(), StatGenStatus::FAIL_PARSE, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
|
inline |
Check if the specified tag contains a string.
Does not set SamStatus.
tag | SAM tag to check contents of. |
Definition at line 613 of file SamRecord.h.
References checkTag().
|
inline |
Check if the specified tag contains an integer.
Does not set SamStatus.
tag | SAM tag to check contents of. |
Definition at line 607 of file SamRecord.h.
References checkTag().
|
inline |
Check if the specified tag contains a string.
Does not set SamStatus.
tag | SAM tag to check contents of. |
Definition at line 600 of file SamRecord.h.
References checkTag().
bool SamRecord::checkTag | ( | const char * | tag, |
char | type | ||
) |
Check if the specified tag contains a value of the specified vtype.
Does not set SamStatus.
tag | SAM tag to check contents of. |
type | value type to check if the SAM tag matches. |
Definition at line 2381 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by checkFloat(), checkInteger(), and checkString().
void SamRecord::clearTags | ( | ) |
Clear the tags in this record.
Does not set SamStatus.
Definition at line 977 of file SamRecord.cpp.
References resetTagIter().
Referenced by resetRecord().
int32_t SamRecord::get0BasedAlignmentEnd | ( | ) |
Returns the 0-based inclusive rightmost position of the clipped sequence.
Definition at line 1467 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by get0BasedUnclippedEnd(), get1BasedAlignmentEnd(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignment(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignmentRegion(), and CigarHelper::softClipEndByRefPos().
int32_t SamRecord::get0BasedMatePosition | ( | ) |
Get the 0-based(BAM) leftmost mate/next fragment's position.
Definition at line 1452 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
int32_t SamRecord::get0BasedPosition | ( | ) |
Get the 0-based(BAM) leftmost position of the record.
Definition at line 1319 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamCoordOutput::add(), PileupElementBaseQual::addEntry(), SamRecordHelper::checkSequence(), SamTags::createMDTag(), getNumOverlaps(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignment(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignmentRegion(), SamQuerySeqWithRefIter::reset(), SamFilter::softClip(), CigarHelper::softClipBeginByRefPos(), CigarHelper::softClipEndByRefPos(), and SamFile::validateSortOrder().
int32_t SamRecord::get0BasedUnclippedEnd | ( | ) |
Returns the 0-based inclusive right-most position adjusted for clipped bases.
Definition at line 1526 of file SamRecord.cpp.
References get0BasedAlignmentEnd().
Referenced by get1BasedUnclippedEnd().
int32_t SamRecord::get0BasedUnclippedStart | ( | ) |
Returns the 0-based inclusive left-most position adjusted for clipped bases.
Definition at line 1506 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by get1BasedUnclippedStart().
int32_t SamRecord::get1BasedAlignmentEnd | ( | ) |
Returns the 1-based inclusive rightmost position of the clipped sequence.
Definition at line 1486 of file SamRecord.cpp.
References get0BasedAlignmentEnd().
Referenced by getBin().
int32_t SamRecord::get1BasedMatePosition | ( | ) |
Get the 1-based(SAM) leftmost mate/next fragment's position (PNEXT).
Definition at line 1445 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
int32_t SamRecord::get1BasedPosition | ( | ) |
Get the 1-based(SAM) leftmost position (POS) of the record.
Definition at line 1312 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamValidator::isValid().
int32_t SamRecord::get1BasedUnclippedEnd | ( | ) |
Returns the 1-based inclusive right-most position adjusted for clipped bases.
Definition at line 1535 of file SamRecord.cpp.
References get0BasedUnclippedEnd().
int32_t SamRecord::get1BasedUnclippedStart | ( | ) |
Returns the 1-based inclusive left-most position adjusted for clipped bases.
Definition at line 1519 of file SamRecord.cpp.
References get0BasedUnclippedStart().
int32_t SamRecord::getAlignmentLength | ( | ) |
Returns the length of the clipped sequence, returning 0 if the cigar is '*'.
Definition at line 1493 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
uint16_t SamRecord::getBin | ( | ) |
Get the BAM bin for the record.
Definition at line 1347 of file SamRecord.cpp.
References get1BasedAlignmentEnd(), and StatGenStatus::SUCCESS.
int32_t SamRecord::getBlockSize | ( | ) |
Get the block size of the record (BAM format).
Definition at line 1281 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
const char * SamRecord::getCigar | ( | ) |
Returns the SAM formatted CIGAR string.
Definition at line 1555 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by getFields(), SamValidator::isValidCigar(), CigarHelper::softClipBeginByRefPos(), and CigarHelper::softClipEndByRefPos().
Cigar * SamRecord::getCigarInfo | ( | ) |
Returns a pointer to the Cigar object associated with this record.
The object is essentially read-only, only allowing modifications due to lazy evaluations.
Definition at line 1836 of file SamRecord.cpp.
Referenced by PileupElementBaseQual::addEntry(), SamRecordHelper::checkSequence(), SamTags::createMDTag(), getSequence(), getSequence(), SamQuerySeqWithRefIter::reset(), SamFilter::softClip(), CigarHelper::softClipBeginByRefPos(), and CigarHelper::softClipEndByRefPos().
uint16_t SamRecord::getCigarLength | ( | ) |
Get the length of the BAM formatted CIGAR.
Definition at line 1362 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
bool SamRecord::getFields | ( | bamRecordStruct & | recStruct, |
String & | readName, | ||
String & | cigar, | ||
String & | sequence, | ||
String & | quality | ||
) |
Returns the values of all fields except the tags.
recStruct | structure containing the contents of all non-variable length fields. |
readName | read name from the record (return param) |
cigar | cigar string from the record (return param) |
sequence | sequence string from the record (return param) |
quality | quality string from the record (return param) |
Definition at line 1866 of file SamRecord.cpp.
References getFields().
Referenced by getFields().
bool SamRecord::getFields | ( | bamRecordStruct & | recStruct, |
String & | readName, | ||
String & | cigar, | ||
String & | sequence, | ||
String & | quality, | ||
SequenceTranslation | translation | ||
) |
Returns the values of all fields except the tags using the specified sequence translation.
recStruct | structure containing the contents of all non-variable length fields. |
readName | read name from the record (return param) |
cigar | cigar string from the record (return param) |
sequence | sequence string from the record (return param) |
quality | quality string from the record (return param) |
translation | type of sequence translation to use. |
Definition at line 1875 of file SamRecord.cpp.
References getCigar(), getQuality(), getReadName(), getSequence(), and StatGenStatus::SUCCESS.
uint16_t SamRecord::getFlag | ( | ) |
Get the flag (FLAG).
Definition at line 1384 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamFilter::filterRead(), SamQuerySeqWithRefIter::getNextMatchMismatch(), SamValidator::isValid(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processFile(), and SamFile::ReadRecord().
bool SamRecord::getFloatTag | ( | const char * | tag, |
float & | tagVal | ||
) |
Get the float value for the specified tag.
tag | tag to retrieve |
tagVal | return parameter with integer value for the tag |
Definition at line 2281 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
int32_t SamRecord::getInsertSize | ( | ) |
Get the inferred insert size of the read pair (ISIZE) or observed template length (TLEN).
Definition at line 1459 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
int & SamRecord::getInteger | ( | const char * | tag | ) |
Get the integer value for the specified tag, DEPRECATED, use getIntegerTag that returns a bool.
Definition at line 2350 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
int * SamRecord::getIntegerTag | ( | const char * | tag | ) |
Get the integer value for the specified tag, DEPRECATED, use one that returns a bool (success/failure).
tag | tag to retrieve \retun pointer to the tag's integer value if found, NULL if not found. |
Definition at line 2216 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
bool SamRecord::getIntegerTag | ( | const char * | tag, |
int & | tagVal | ||
) |
Get the integer value for the specified tag.
tag | tag to retrieve |
tagVal | return parameter with integer value for the tag \retun bool true if Integer tag was found and tagVal was set, false if not. |
Definition at line 2248 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
uint8_t SamRecord::getMapQuality | ( | ) |
Get the mapping quality (MAPQ) of the record.
Definition at line 1340 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamValidator::isValid().
int32_t SamRecord::getMateReferenceID | ( | ) |
Get the mate reference id of the record (BAM format: mate_rid/next_refID).
Definition at line 1438 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
const char * SamRecord::getMateReferenceName | ( | ) |
Get the mate/next fragment's reference sequence name (RNEXT).
If it is equal to the reference name, it still returns the reference name.
Definition at line 1410 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
const char * SamRecord::getMateReferenceNameOrEqual | ( | ) |
Get the mate/next fragment's reference sequence name (RNEXT), returning "=" if it is the same as the reference name, unless they are both "*" in which case "*" is returned.
Definition at line 1420 of file SamRecord.cpp.
References getReferenceName(), and StatGenStatus::SUCCESS.
bool SamRecord::getNextSamTag | ( | char * | tag, |
char & | vtype, | ||
void ** | value | ||
) |
Get the next tag from the record.
Sets the Status to SUCCESS when a tag is successfully returned or when there are no more tags. Otherwise the status is set to describe why it failed (parsing, etc).
tag | set to the tag when a tag is read. |
vtype | set to the vtype when a tag is read. |
value | pointer to the value of the tag (will need to cast to int, float, char, or string based on vtype). |
Definition at line 1962 of file SamRecord.cpp.
References StatGenStatus::FAIL_PARSE, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
Referenced by SamRecordHelper::genSamTagsString().
uint32_t SamRecord::getNumOverlaps | ( | int32_t | start, |
int32_t | end | ||
) |
Return the number of bases in this read that overlap the passed in region.
Matches & mismatches between the read and the reference are counted as overlaps, but insertions, deletions, skips, clips, and pads are not counted.
start | inclusive 0-based start position (reference position) of the region to check for overlaps in. (-1 indicates to start at the beginning of the reference.) |
end | exclusive 0-based end position (reference position) of the region to check for overlaps in. (-1 indicates to go to the end of the reference.) |
Definition at line 1853 of file SamRecord.cpp.
References get0BasedPosition(), and Cigar::getNumOverlaps().
Referenced by SamFile::GetNumOverlaps().
const char * SamRecord::getQuality | ( | ) |
Returns the SAM formatted quality string (QUAL).
Definition at line 1638 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by PileupElementBaseQual::addEntry(), getFields(), SamValidator::isValidQuality(), and SamFilter::sumMismatchQuality().
char SamRecord::getQuality | ( | int | index | ) |
Get the quality character at the specified index into the quality 0 to readLength - 1.
Throws an exception if index is out of range.
index | index into the quality string (0 to readLength-1). |
Definition at line 1782 of file SamRecord.cpp.
References getReadLength(), and BaseUtilities::UNKNOWN_QUALITY_CHAR.
int32_t SamRecord::getReadLength | ( | ) |
Get the length of the read.
Definition at line 1391 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamFilter::clipOnMismatchThreshold(), SamQuerySeqWithRefIter::getNextMatchMismatch(), getQuality(), getSequence(), SamValidator::isValidCigar(), SamValidator::isValidQuality(), SamQuerySeqWithRefIter::reset(), and CigarHelper::softClipEndByRefPos().
const char * SamRecord::getReadName | ( | ) |
Returns the SAM formatted Read Name (QNAME).
Definition at line 1542 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by getFields(), SamValidator::isValid(), and SamFile::validateSortOrder().
uint8_t SamRecord::getReadNameLength | ( | ) |
Get the length of the readname (QNAME) including the null.
Definition at line 1326 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamValidator::isValid().
const void * SamRecord::getRecordBuffer | ( | ) |
Get a const pointer to the buffer that contains the BAM representation of the record.
Definition at line 1204 of file SamRecord.cpp.
References getRecordBuffer().
Referenced by getRecordBuffer().
const void * SamRecord::getRecordBuffer | ( | SequenceTranslation | translation | ) |
Get a const pointer to the buffer that contains the BAM representation of the record using the specified translation on the sequence.
translation | type of sequence translation to use. |
Definition at line 1211 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
GenomeSequence * SamRecord::getReference | ( | ) |
Returns a pointer to the genome sequence object associated with this record if it was set (NULL if it was not set).
Definition at line 1923 of file SamRecord.cpp.
Referenced by SamValidator::isValidTags().
int32_t SamRecord::getReferenceID | ( | ) |
Get the reference sequence id of the record (BAM format rid).
Definition at line 1305 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamCoordOutput::add(), SamValidator::isValid(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignment(), Pileup< PILEUP_TYPE, FUNC_CLASS >::processAlignmentRegion(), and SamFile::validateSortOrder().
const char * SamRecord::getReferenceName | ( | ) |
Get the reference sequence name (RNAME) of the record.
Definition at line 1298 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by PileupElement::addEntry(), SamTags::createMDTag(), getMateReferenceNameOrEqual(), getSequence(), getSequence(), SamValidator::isValid(), and SamQuerySeqWithRefIter::reset().
const char * SamRecord::getSequence | ( | ) |
Returns the SAM formatted sequence string (SEQ), translating the base as specified by setSequenceTranslation.
Definition at line 1568 of file SamRecord.cpp.
References getSequence().
Referenced by PileupElementBaseQual::addEntry(), SamRecordHelper::checkSequence(), SamTags::createMDTag(), getFields(), SamQuerySeqWithRefIter::getNextMatchMismatch(), getSequence(), getSequence(), and shiftIndelsLeft().
char SamRecord::getSequence | ( | int | index | ) |
Get the sequence base at the specified index into this sequence 0 to readLength - 1, translating the base as specified by setSequenceTranslation.
Throws an exception if index is out of range.
index | index into the sequence string (0 to readLength-1). |
Definition at line 1651 of file SamRecord.cpp.
References getSequence().
char SamRecord::getSequence | ( | int | index, |
SequenceTranslation | translation | ||
) |
Get the sequence base at the specified index into this sequence 0 to readLength - 1 performing the specified sequence translation.
Throws an exception if index is out of range.
index | index into the sequence string (0 to readLength-1). |
translation | type of sequence translation to use. |
Definition at line 1657 of file SamRecord.cpp.
References EQUAL, getCigarInfo(), getReadLength(), getReferenceName(), NONE, SamQuerySeqWithRef::seqWithEquals(), and SamQuerySeqWithRef::seqWithoutEquals().
const char * SamRecord::getSequence | ( | SequenceTranslation | translation | ) |
Returns the SAM formatted sequence string (SEQ) performing the specified sequence translation.
translation | type of sequence translation to use. |
Definition at line 1574 of file SamRecord.cpp.
References EQUAL, getCigarInfo(), getReferenceName(), NONE, SamQuerySeqWithRef::seqWithEquals(), SamQuerySeqWithRef::seqWithoutEquals(), and StatGenStatus::SUCCESS.
const SamStatus & SamRecord::getStatus | ( | ) |
Returns the status associated with the last method that sets the status.
Definition at line 2403 of file SamRecord.cpp.
const String & SamRecord::getString | ( | const char * | tag | ) |
Get the string value for the specified tag.
Definition at line 2314 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
const String * SamRecord::getStringTag | ( | const char * | tag | ) |
Get the string value for the specified tag.
tag | tag to retrieve |
pointer | to the tag's string value if found, NULL if not found. |
Definition at line 2180 of file SamRecord.cpp.
Referenced by SamTags::isMDTagCorrect(), and SamValidator::isValidTags().
uint32_t SamRecord::getTagLength | ( | ) |
Returns the length of the BAM formatted tags.
Definition at line 1929 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
bool SamRecord::getTagsString | ( | const char * | tags, |
String & | returnString, | ||
char | delim = '\t' |
||
) |
Get the string representation of the tags from the record, formatted as TAG:TYPE:VALUE<delim>TAG:TYPE:VALUE... Sets the Status to SUCCESS when the tags are successfully returned or the tags were not found.
If a different error occured, the status is set appropriately. The delimiter between the tags to retrieve is ',' or ';'. ',' was added since the original delimiter, ';', requires the string to be quoted on the command-line.
tags | the tags to retrieve, formatted as TAG:TYPE,TAG:TYPE... |
returnString | the String to set (this method first clears returnString) to TAG:TYPE:VALUE<delim>TAG:TYPE:VALUE... |
delim | delimiter to use to separate two tags, default is a tab. |
Definition at line 2082 of file SamRecord.cpp.
References StatGenStatus::INVALID, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
|
static |
Returns whether or not the specified vtype is a char type.
Does not set SamStatus.
vtype | value type to check. |
Definition at line 2062 of file SamRecord.cpp.
Referenced by SamRecordHelper::genSamTagString().
|
static |
Returns whether or not the specified vtype is a float type.
Does not set SamStatus.
vtype | value type to check. |
Definition at line 2052 of file SamRecord.cpp.
Referenced by SamRecordHelper::genSamTagString().
|
static |
Returns whether or not the specified vtype is an integer type.
Does not set SamStatus.
vtype | value type to check. |
Definition at line 2040 of file SamRecord.cpp.
Referenced by SamRecordHelper::genSamTagString().
|
static |
Returns whether or not the specified vtype is a string type.
Does not set SamStatus.
vtype | value type to check. |
Definition at line 2072 of file SamRecord.cpp.
Referenced by SamRecordHelper::genSamTagString().
bool SamRecord::isValid | ( | SamFileHeader & | header | ) |
Returns whether or not the record is valid, setting the status to indicate success or failure.
header | SAM Header associated with the record. Used to perform some validation against the header. |
Definition at line 161 of file SamRecord.cpp.
References SamValidationErrors::getErrorString(), StatGenStatus::INVALID, SamValidator::isValid(), StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
void SamRecord::resetRecord | ( | ) |
Reset the fields of the record to a default value.
This is not necessary when you are reading a SAM/BAM file, but if you are setting fields, it is a good idea to clean out a record before reusing it. Clearing it allows you to not have to set any empty fields.
Definition at line 91 of file SamRecord.cpp.
References clearTags(), NONE, and StatGenStatus::SUCCESS.
Referenced by SamRecord(), SamRecord(), ~SamRecord(), setBuffer(), and setBufferFromFile().
void SamRecord::resetTagIter | ( | ) |
Reset the tag iterator to the beginning of the tags.
Definition at line 2034 of file SamRecord.cpp.
Referenced by clearTags(), and SamRecordHelper::genSamTagsString().
bool SamRecord::rmTag | ( | const char * | tag, |
char | type | ||
) |
Remove a tag.
tag | tag to remove. |
type | of the tag to be removed. |
Definition at line 992 of file SamRecord.cpp.
References getString(), StatGenStatus::INVALID, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
bool SamRecord::rmTags | ( | const char * | tags | ) |
Remove tags.
The delimiter between the tags is ',' or ';'. ',' was added since the original delimiter, ';', requires the string to be quoted on the command-line.
tags | tags to remove, formatted as Tag:Type,Tag:Type,Tag:Type... |
Definition at line 1083 of file SamRecord.cpp.
References getString(), StatGenStatus::INVALID, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
bool SamRecord::set0BasedMatePosition | ( | int32_t | matePosition | ) |
Set the mate/next fragment's leftmost position using the specified 0-based (BAM format) value.
Internal processing handles the switching between SAM/BAM formats when read/written.
position | 0-based start position |
Definition at line 328 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by set1BasedMatePosition().
bool SamRecord::set0BasedPosition | ( | int32_t | position | ) |
Set the leftmost position using the specified 0-based (BAM format) value.
Internal processing handles the switching between SAM/BAM formats when read/written.
position | 0-based start position |
Definition at line 242 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by set1BasedPosition(), and SamFilter::softClip().
bool SamRecord::set1BasedMatePosition | ( | int32_t | matePosition | ) |
Set the mate/next fragment's leftmost position (PNEXT) using the specified 1-based (SAM format) value.
Internal processing handles the switching between SAM/BAM formats when read/written.
position | 1-based start position |
Definition at line 322 of file SamRecord.cpp.
References set0BasedMatePosition().
bool SamRecord::set1BasedPosition | ( | int32_t | position | ) |
Set the leftmost position (POS) using the specified 1-based (SAM format) value.
Internal processing handles the switching between SAM/BAM formats when read/written.
position | 1-based start position |
Definition at line 236 of file SamRecord.cpp.
References set0BasedPosition().
SamStatus::Status SamRecord::setBuffer | ( | const char * | fromBuffer, |
uint32_t | fromBufferSize, | ||
SamFileHeader & | header | ||
) |
Sets the SamRecord to contain the information in the BAM formatted fromBuffer.
fromBuffer | buffer to read the BAM record from. |
fromBufferSize | size of the buffer containing the BAM record. |
header | BAM header for the record. |
Definition at line 525 of file SamRecord.cpp.
References StatGenStatus::FAIL_MEM, StatGenStatus::FAIL_PARSE, resetRecord(), StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
SamStatus::Status SamRecord::setBufferFromFile | ( | IFILE | filePtr, |
SamFileHeader & | header | ||
) |
Read the BAM record from a file.
filePtr | file to read the buffer from. |
header | BAM header for the record. |
Definition at line 558 of file SamRecord.cpp.
References StatGenStatus::FAIL_IO, StatGenStatus::FAIL_MEM, StatGenStatus::FAIL_ORDER, StatGenStatus::FAIL_PARSE, InputFile::getFileName(), ifeof(), ifread(), InputFile::isOpen(), StatGenStatus::NO_MORE_RECS, resetRecord(), StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
bool SamRecord::setCigar | ( | const char * | cigar | ) |
Set the CIGAR to the specified SAM formatted cigar string.
Internal processing handles the switching between SAM/BAM formats when read/written.
cigar | string containing the SAM formatted cigar. |
Definition at line 259 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamFilter::filterRead(), shiftIndelsLeft(), and SamFilter::softClip().
bool SamRecord::setCigar | ( | const Cigar & | cigar | ) |
Set the CIGAR to the specified Cigar object.
Internal processing handles the switching between SAM/BAM formats when read/written.
cigar | object to set this record's cigar to have. |
Definition at line 278 of file SamRecord.cpp.
References Cigar::getCigarString(), and StatGenStatus::SUCCESS.
bool SamRecord::setFlag | ( | uint16_t | flag | ) |
Set the bitwise FLAG to the specified value.
flag | integer flag to use. |
Definition at line 215 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamFilter::filterRead().
bool SamRecord::setInsertSize | ( | int32_t | insertSize | ) |
Sets the inferred insert size (ISIZE)/observed template length (TLEN).
insertSize | inferred insert size/observed template length. |
Definition at line 336 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
bool SamRecord::setMapQuality | ( | uint8_t | mapQuality | ) |
Set the mapping quality (MAPQ).
mapQuality | map quality to set in the record. |
Definition at line 251 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
Referenced by SamFilter::filterRead().
bool SamRecord::setMateReferenceName | ( | SamFileHeader & | header, |
const char * | mateReferenceName | ||
) |
Set the mate/next fragment's reference sequence name (RNEXT) to the specified name, using the header to determine the mate reference id.
header | SAM/BAM header to use to determine the mate reference id. |
referenceName | mate reference name to use. |
Definition at line 297 of file SamRecord.cpp.
References SamFileHeader::getReferenceID(), and StatGenStatus::SUCCESS.
bool SamRecord::setQuality | ( | const char * | quality | ) |
Sets the quality (QUAL) to the specified SAM formatted quality string.
Internal processing handles switching between SAM/BAM formats when read/written.
quality | SAM quality string. |
Definition at line 357 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
bool SamRecord::setReadName | ( | const char * | readName | ) |
Set QNAME to the passed in name.
readName | the readname to set the QNAME to. |
Definition at line 193 of file SamRecord.cpp.
References StatGenStatus::INVALID, StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.
void SamRecord::setReference | ( | GenomeSequence * | reference | ) |
Set the reference to the specified genome sequence object.
reference | pointer to the GenomeSequence object. |
Definition at line 178 of file SamRecord.cpp.
Referenced by SamFile::GetNumOverlaps(), SamFile::ReadRecord(), SamFile::validateSortOrder(), and SamFile::WriteRecord().
bool SamRecord::setReferenceName | ( | SamFileHeader & | header, |
const char * | referenceName | ||
) |
Set the reference sequence name (RNAME) to the specified name, using the header to determine the reference id.
header | SAM/BAM header to use to determine the reference id. |
referenceName | reference name to use. |
Definition at line 223 of file SamRecord.cpp.
References SamFileHeader::getReferenceID(), and StatGenStatus::SUCCESS.
bool SamRecord::setSequence | ( | const char * | seq | ) |
Sets the sequence (SEQ) to the specified SAM formatted sequence string.
Internal processing handles switching between SAM/BAM formats when read/written.
seq | SAM sequence string. May contain '='. |
Definition at line 344 of file SamRecord.cpp.
References StatGenStatus::SUCCESS.
void SamRecord::setSequenceTranslation | ( | SequenceTranslation | translation | ) |
Set the type of sequence translation to use when getting the sequence.
The default type (if this method is never called) is NONE (the sequence is left as-is). Can be over-ridden by using the accessors that take a SequenceTranslation parameter.
translation | type of sequence translation to use. |
Definition at line 187 of file SamRecord.cpp.
Referenced by SamFile::GetNumOverlaps(), SamFile::ReadRecord(), and SamFile::validateSortOrder().
bool SamRecord::shiftIndelsLeft | ( | ) |
Shift the indels (if any) to the left by updating the CIGAR.
Definition at line 368 of file SamRecord.cpp.
References BASES, Cigar::foundInQuery(), getSequence(), CigarRoller::IncrementCount(), Cigar::insert, Cigar::isMatchOrMismatch(), CigarRoller::Remove(), setCigar(), Cigar::size(), and CigarRoller::Update().
SamStatus::Status SamRecord::writeRecordBuffer | ( | IFILE | filePtr | ) |
Write the record as a BAM into the specified already opened file.
filePtr | file to write the BAM record into. |
Definition at line 1237 of file SamRecord.cpp.
References writeRecordBuffer().
Referenced by writeRecordBuffer().
SamStatus::Status SamRecord::writeRecordBuffer | ( | IFILE | filePtr, |
SequenceTranslation | translation | ||
) |
Write the record as a BAM into the specified already opened file using the specified translation on the sequence.
filePtr | file to write the BAM record into. |
translation | type of sequence translation to use. |
Definition at line 1244 of file SamRecord.cpp.
References StatGenStatus::FAIL_IO, StatGenStatus::FAIL_ORDER, StatGenStatus::getStatus(), ifwrite(), InputFile::isOpen(), StatGenStatus::setStatus(), and StatGenStatus::SUCCESS.