CigarRoller Class Reference

The purpose of this class is to provide accessors for setting, updating, modifying the CIGAR object. It is a child class of Cigar. More...

#include <CigarRoller.h>

Inheritance diagram for CigarRoller:
Inheritance graph
[legend]
Collaboration diagram for CigarRoller:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 CigarRoller ()
 Default constructor initializes as a CIGAR with no operations.
 CigarRoller (const char *cigarString)
 Constructor that initializes the object with the specified cigarString.
CigarRolleroperator+= (CigarRoller &rhs)
 Add the contents of the specified CigarRoller to this object.
CigarRolleroperator+= (const CigarOperator &rhs)
 Append the specified operator to this object.
CigarRolleroperator= (CigarRoller &rhs)
 Set this object to be equal to the specified CigarRoller.
void Add (Operation operation, int count)
 Append the specified operation with the specified count to this object.
void Add (char operation, int count)
 Append the specified operation with the specified count to this object.
void Add (const char *cigarString)
 Append the specified cigarString to this object.
void Add (CigarRoller &rhs)
 Append the specified Cigar object to this object.
bool Remove (int index)
 Remove the operation at the specified index.
bool IncrementCount (int index, int increment)
 Increments the count for the operation at the specified index by the specified value, specify a negative value to decrement.
bool Update (int index, Operation op, int count)
 Updates the operation at the specified index to be the specified operation and have the specified count.
void Set (const char *cigarString)
 Sets this object to the specified cigarString.
void Set (const uint32_t *cigarBuffer, uint16_t bufferLen)
 Sets this object to the BAM formatted cigar found at the beginning of the specified buffer which is bufferLen long.
int getMatchPositionOffset ()
 DEPRECATED - do not use, there are better ways to accomplish that by using read lengths, reference lengths, span of the read, etc.
const char * getString ()
 Get the string reprentation of the Cigar operations in this object, caller must delete the returned value.
void clear ()
 Clear this object so that it has no Cigar Operations.

Friends

std::ostream & operator<< (std::ostream &stream, const CigarRoller &roller)
 Writes all of the cigar operations contained in this roller to the passed in stream.

Detailed Description

The purpose of this class is to provide accessors for setting, updating, modifying the CIGAR object. It is a child class of Cigar.

Docs from Sam1.pdf: Clipped alignment. In Smith-Waterman alignment, a sequence may not be aligned from the first residue to the last one. Subsequences at the ends may be clipped off. We introduce operation ʻSʼ to describe (softly) clipped alignment. Here is an example. Suppose the clipped alignment is: REF: AGCTAGCATCGTGTCGCCCGTCTAGCATACGCATGATCGACTGTCAGCTAGTCAGACTAGTCGATCGATGTG READ: gggGTGTAACC-GACTAGgggg where on the read sequence, bases in uppercase are matches and bases in lowercase are clipped off. The CIGAR for this alignment is: 3S8M1D6M4S.

If the mapping position of the query is not available, RNAME and CIGAR are set as “*”

A CIGAR string is comprised of a series of operation lengths plus the operations. The conventional CIGAR format allows for three types of operations: M for match or mismatch, I for insertion and D for deletion. The extended CIGAR format further allows four more operations, as is shown in the following table, to describe clipping, padding and splicing:

op Description -- ----------- M Match or mismatch I Insertion to the reference D Deletion from the reference N Skipped region from the reference S Soft clip on the read (clipped sequence present in <seq>) H Hard clip on the read (clipped sequence NOT present in <seq>) P Padding (silent deletion from the padded reference sequence) CigarRoller is an aid to correctly generating the CIGAR strings necessary to represent how a read maps to the reference.

It is called once a particular match candidate is being written out, so it is far less performance sensitive than the Smith Waterman code below.

Definition at line 66 of file CigarRoller.h.


Member Function Documentation

int CigarRoller::getMatchPositionOffset (  ) 

DEPRECATED - do not use, there are better ways to accomplish that by using read lengths, reference lengths, span of the read, etc.

Definition at line 235 of file CigarRoller.cpp.

References Cigar::del, and Cigar::insert.

00236 {
00237     int offset = 0;
00238     std::vector<CigarOperator>::iterator i;
00239 
00240     for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
00241     {
00242         switch (i->operation)
00243         {
00244             case insert:
00245                 offset += i->count;
00246                 break;
00247             case del:
00248                 offset -= i->count;
00249                 break;
00250                 // TODO anything for case skip:????
00251             default:
00252                 break;
00253         }
00254     }
00255     return offset;
00256 }

const char * CigarRoller::getString (  ) 

Get the string reprentation of the Cigar operations in this object, caller must delete the returned value.

Definition at line 263 of file CigarRoller.cpp.

00264 {
00265     // NB: the exact size of the string is not important, it just needs to be guaranteed
00266     // larger than the largest number of characters we could put into it.
00267 
00268     // we do not explicitly manage memory usage, and we expect when program exits, the memory used here will be freed
00269     static char *ret = NULL;
00270     static unsigned int retSize = 0;
00271 
00272     if (ret == NULL)
00273     {
00274         retSize = cigarOperations.size() * 12 + 1;  // 12 == a magic number -> > 1 + log base 10 of MAXINT
00275         ret = (char*) malloc(sizeof(char) * retSize);
00276         assert(ret != NULL);
00277 
00278     }
00279     else
00280     {
00281         // currently, ret pointer has enough memory to use
00282         if (retSize > cigarOperations.size() * 12 + 1)
00283         {
00284         }
00285         else
00286         {
00287             retSize = cigarOperations.size() * 12 + 1;
00288             free(ret);
00289             ret = (char*) malloc(sizeof(char) * retSize);
00290         }
00291         assert(ret != NULL);
00292     }
00293 
00294     char *ptr = ret;
00295     char buf[12];   // > 1 + log base 10 of MAXINT
00296 
00297     std::vector<CigarOperator>::iterator i;
00298 
00299     // Progressively append the character representations of the operations to
00300     // the cigar string we allocated above.
00301 
00302     *ptr = '\0';    // clear result string
00303     for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
00304     {
00305         sprintf(buf, "%d%c", (*i).count, (*i).getChar());
00306         strcat(ptr, buf);
00307         while (*ptr)
00308         {
00309             ptr++;    // limit the cost of strcat above
00310         }
00311     }
00312     return ret;
00313 }

bool CigarRoller::IncrementCount ( int  index,
int  increment 
)

Increments the count for the operation at the specified index by the specified value, specify a negative value to decrement.

Returns:
true if it is successfully incremented, false if not.

Definition at line 162 of file CigarRoller.cpp.

Referenced by SamRecord::shiftIndelsLeft().

00163 {
00164     if((index < 0) || ((unsigned int)index >= cigarOperations.size()))
00165     {
00166         // can't update, out of range, return false.
00167         return(false);
00168     }
00169     cigarOperations[index].count += increment;
00170 
00171     // Modifying the cigar, so the query & reference indexes are out of date,
00172     // so clear them.
00173     clearQueryAndReferenceIndexes();
00174     return(true);
00175 }

bool CigarRoller::Remove ( int  index  ) 

Remove the operation at the specified index.

Returns:
true if successfully removed, false if not.

Definition at line 147 of file CigarRoller.cpp.

Referenced by SamRecord::shiftIndelsLeft().

00148 {
00149     if((index < 0) || ((unsigned int)index >= cigarOperations.size()))
00150     {
00151         // can't remove, out of range, return false.
00152         return(false);
00153     }
00154     cigarOperations.erase(cigarOperations.begin() + index);
00155     // Modifying the cigar, so the query & reference indexes are out of date,
00156     // so clear them.
00157     clearQueryAndReferenceIndexes();
00158     return(true);
00159 }

void CigarRoller::Set ( const uint32_t *  cigarBuffer,
uint16_t  bufferLen 
)

Sets this object to the BAM formatted cigar found at the beginning of the specified buffer which is bufferLen long.

Definition at line 202 of file CigarRoller.cpp.

References Add(), and clear().

00203 {
00204     clear();
00205 
00206     // Parse the buffer.
00207     for (int i = 0; i < bufferLen; i++)
00208     {
00209         int opLen = cigarBuffer[i] >> 4;
00210 
00211         Add(cigarBuffer[i] & 0xF, opLen);
00212     }
00213 }

bool CigarRoller::Update ( int  index,
Operation  op,
int  count 
)

Updates the operation at the specified index to be the specified operation and have the specified count.

Returns:
true if it is successfully updated, false if not.

Definition at line 178 of file CigarRoller.cpp.

Referenced by SamRecord::shiftIndelsLeft().

00179 {
00180     if((index < 0) || ((unsigned int)index >= cigarOperations.size()))
00181     {
00182         // can't update, out of range, return false.
00183         return(false);
00184     }
00185     cigarOperations[index].operation = op;
00186     cigarOperations[index].count = count;
00187 
00188     // Modifying the cigar, so the query & reference indexes are out of date,
00189     // so clear them.
00190     clearQueryAndReferenceIndexes();
00191     return(true);
00192 }


Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  stream,
const CigarRoller roller 
) [friend]

Writes all of the cigar operations contained in this roller to the passed in stream.

Definition at line 167 of file CigarRoller.h.

00168 {
00169     stream << roller.cigarOperations;
00170     return stream;
00171 }


The documentation for this class was generated from the following files:
Generated on Tue Sep 6 17:52:01 2011 for libStatGen Software by  doxygen 1.6.3