Class for extracting information from a SAM Flag. More...
#include <SamRecordHelper.h>
Static Public Member Functions | |
static int | checkSequence (SamRecord &record, int32_t pos0Based, const char *sequence) |
Helper method that checks if the record's read sequence starting at the specified 0-based reference position matches the passed in sequence. | |
static bool | genSamTagsString (SamRecord &record, String &returnString, char delim= '\t') |
Helper to append the SAM string representation of all the tags to the specified string. | |
static bool | genSamTagString (const char *tag, char vtype, void *value, String &returnString) |
Helper to append the SAM string representation of the specified tag to the specified string. |
Class for extracting information from a SAM Flag.
Definition at line 24 of file SamRecordHelper.h.
int SamRecordHelper::checkSequence | ( | SamRecord & | record, | |
int32_t | pos0Based, | |||
const char * | sequence | |||
) | [static] |
Helper method that checks if the record's read sequence starting at the specified 0-based reference position matches the passed in sequence.
Definition at line 21 of file SamRecordHelper.cpp.
References SamRecord::get0BasedPosition(), SamRecord::getCigarInfo(), Cigar::getQueryIndex(), SamRecord::getSequence(), and Cigar::INDEX_NA.
00023 { 00024 const char* readSeq = record.getSequence(); 00025 00026 // Get the cigar. 00027 Cigar* cigar = record.getCigarInfo(); 00028 00029 if(cigar == NULL) 00030 { 00031 throw std::runtime_error("Failed to get Cigar."); 00032 } 00033 00034 int32_t readStartIndex = 00035 cigar->getQueryIndex(pos0Based, record.get0BasedPosition()); 00036 00037 // if the read start is negative, this position was deleted, so 00038 // return false, it doesn't match. 00039 if(readStartIndex == Cigar::INDEX_NA) 00040 { 00041 return(false); 00042 } 00043 00044 // Increment the readSeq start to where this position is found. 00045 readSeq += readStartIndex; 00046 if(strncmp(readSeq, sequence, strlen(sequence)) == 0) 00047 { 00048 // Match, so return the readStartIndex (cycle). 00049 return(readStartIndex); 00050 } 00051 // Did not match. 00052 return(-1); 00053 }
bool SamRecordHelper::genSamTagsString | ( | SamRecord & | record, | |
String & | returnString, | |||
char | delim = '\t' | |||
) | [static] |
Helper to append the SAM string representation of all the tags to the specified string.
Does NOT add a preceding delimiter before the first tag.
record | record whose tags to append. | |
returnString | string to append the tags to. | |
delim | delimiter to use to separate different tags. |
Definition at line 56 of file SamRecordHelper.cpp.
References genSamTagString(), SamRecord::getNextSamTag(), and SamRecord::resetTagIter().
00059 { 00060 char tag[3]; 00061 char vtype; 00062 void* value; 00063 00064 // Reset the tag iterator to ensure that all the tags are written. 00065 record.resetTagIter(); 00066 00067 // While there are more tags, write them to the recordString. 00068 bool firstEntry = true; 00069 bool returnStatus = true; 00070 while(record.getNextSamTag(tag, vtype, &value) != false) 00071 { 00072 if(!firstEntry) 00073 { 00074 returnString += delim; 00075 } 00076 else 00077 { 00078 firstEntry = false; 00079 } 00080 returnStatus &= genSamTagString(tag, vtype, value, returnString); 00081 } 00082 return(returnStatus); 00083 }
bool SamRecordHelper::genSamTagString | ( | const char * | tag, | |
char | vtype, | |||
void * | value, | |||
String & | returnString | |||
) | [static] |
Helper to append the SAM string representation of the specified tag to the specified string.
tag | the tag name. | |
vtype | the vtype. | |
value | pointer to the value of the tag (will be cast to int, double, char, or string based on vtype). | |
returnString | string to append the tag to. |
Definition at line 86 of file SamRecordHelper.cpp.
References SamRecord::isCharType(), SamRecord::isDoubleType(), SamRecord::isIntegerType(), and SamRecord::isStringType().
Referenced by genSamTagsString().
00088 { 00089 returnString += tag; 00090 returnString += ":"; 00091 returnString += vtype; 00092 returnString += ":"; 00093 if(SamRecord::isIntegerType(vtype)) 00094 { 00095 returnString += (int)*(int*)value; 00096 } 00097 else if(SamRecord::isDoubleType(vtype)) 00098 { 00099 returnString += (double)*(double*)value; 00100 } 00101 else if(SamRecord::isCharType(vtype)) 00102 { 00103 returnString += (char)*(char*)value; 00104 } 00105 else if(SamRecord::isStringType(vtype)) 00106 { 00107 // String type. 00108 returnString += (String)*(String*)value; 00109 } 00110 else 00111 { 00112 // Could not determine the type. 00113 return(false); 00114 } 00115 return(true); 00116 }