Cigar Class Reference

This class represents the CIGAR without any methods to set the cigar (see CigarRoller for that). More...

`#include <Cigar.h>`

Inheritance diagram for Cigar:
[legend]
Collaboration diagram for Cigar:
[legend]

## Classes

struct | CigarOperator

## Public Types

enum | Operation { none =0 , match , mismatch , insert , del , skip , softClip , hardClip , pad }
| Enum for the cigar operations. More...

## Public Member Functions

| Cigar ()
| Default constructor initializes as a CIGAR with no operations. More...
void | getCigarString (String &cigarString) const
| Set the passed in String to the string reprentation of the Cigar operations in this object. More...
void | getCigarString (std::string &cigarString) const
| Set the passed in std::string to the string reprentation of the Cigar operations in this object. More...
void | getExpandedString (std::string &s) const
| Sets the specified string to a valid CIGAR string of characters that represent the cigar with no digits (a CIGAR of "3M" would return "MMM"). More...
const CigarOperator & | operator[] (int i) const
| Return the Cigar Operation at the specified index (starting at 0). More...
const CigarOperator & | getOperator (int i) const
| Return the Cigar Operation at the specified index (starting at 0). More...
bool | operator== (Cigar &rhs) const
| Return true if the 2 Cigars are the same (the same operations of the same sizes). More...
int | size () const
| Return the number of cigar operations. More...
void | Dump () const
| Write this object as a string to cout. More...
int | getExpectedQueryBaseCount () const
| Return the length of the read that corresponds to the current CIGAR string. More...
int | getExpectedReferenceBaseCount () const
| Return the number of bases in the reference that this CIGAR "spans". More...
int | getNumBeginClips () const
| Return the number of clips that are at the beginning of the cigar. More...
int | getNumEndClips () const
| Return the number of clips that are at the end of the cigar. More...
int32_t | getRefOffset (int32_t queryIndex)
| Return the reference offset associated with the specified query index or INDEX_NA based on this cigar. More...
int32_t | getQueryIndex (int32_t refOffset)
| Return the query index associated with the specified reference offset or INDEX_NA based on this cigar. More...
int32_t | getRefPosition (int32_t queryIndex, int32_t queryStartPos)
| Return the reference position associated with the specified query index or INDEX_NA based on this cigar and the specified queryStartPos which is the leftmost mapping position of the first matching base in the query. More...
int32_t | getQueryIndex (int32_t refPosition, int32_t queryStartPos)
| Return the query index or INDEX_NA associated with the specified reference offset when the query starts at the specified reference position. More...
int32_t | getExpandedCigarIndexFromQueryIndex (int32_t queryIndex)
| Returns the index into the expanded cigar for the cigar associated with the specified queryIndex. More...
int32_t | getExpandedCigarIndexFromRefOffset (int32_t refOffset)
| Returns the index into the expanded cigar for the cigar associated with the specified reference offset. More...
int32_t | getExpandedCigarIndexFromRefPos (int32_t refPosition, int32_t queryStartPos)
| Returns the index into the expanded cigar for the cigar associated with the specified reference position and queryStartPos. More...
char | getCigarCharOp (int32_t expandedCigarIndex)
| Return the character code of the cigar operator associated with the specified expanded CIGAR index. More...
char | getCigarCharOpFromQueryIndex (int32_t queryIndex)
| Return the character code of the cigar operator associated with the specified queryIndex. More...
char | getCigarCharOpFromRefOffset (int32_t refOffset)
| Return the character code of the cigar operator associated with the specified reference offset. More...
char | getCigarCharOpFromRefPos (int32_t refPosition, int32_t queryStartPos)
| Return the character code of the cigar operator associated with the specified reference position. More...
uint32_t | getNumOverlaps (int32_t start, int32_t end, int32_t queryStartPos)
| Return the number of bases that overlap the reference and the read associated with this cigar that falls within the specified region. More...
bool | hasIndel ()
| Return whether or not the cigar has indels (insertions or delections) More...

## Static Public Member Functions

static bool | foundInReference (Operation op)
| Return true if the specified operation is found in the reference sequence, false if not. More...
static bool | foundInReference (char op)
| Return true if the specified operation is found in the reference sequence, false if not. More...
static bool | foundInReference (const CigarOperator &op)
| Return true if the specified operation is found in the reference sequence, false if not. More...
static bool | foundInQuery (Operation op)
| Return true if the specified operation is found in the query sequence, false if not. More...
static bool | foundInQuery (char op)
| Return true if the specified operation is found in the query sequence, false if not. More...
static bool | foundInQuery (const CigarOperator &op)
| Return true if the specified operation is found in the query sequence, false if not. More...
static bool | isClip (Operation op)
| Return true if the specified operation is a clipping operation, false if not. More...
static bool | isClip (char op)
| Return true if the specified operation is a clipping operation, false if not. More...
static bool | isClip (const CigarOperator &op)
| Return true if the specified operation is a clipping operation, false if not. More...
static bool | isMatchOrMismatch (Operation op)
| Return true if the specified operation is a match/mismatch operation, false if not. More...
static bool | isMatchOrMismatch (const CigarOperator &op)
| Return true if the specified operation is a match/mismatch operation, false if not. More...

## Static Public Attributes

static const int | MAX_OP_VALUE = pad
static const int32_t | INDEX_NA = -1
| Value associated with an index that is not applicable/does not exist, used for converting between query and reference indexes/offsets when an associated index/offset does not exist. More...

## Protected Member Functions

void | clearQueryAndReferenceIndexes ()
void | setQueryAndReferenceIndexes ()

## Protected Attributes

std::vector< CigarOperator > | cigarOperations

## Friends

std::ostream & | operator<< (std::ostream &stream, const Cigar &cigar)
| Writes all of the cigar operations contained in the cigar to the passed in stream. More...

## Detailed Description

This class represents the CIGAR without any methods to set the cigar (see CigarRoller for that).

This class represents the CIGAR. It contains methods for converting to strings and extracting information from the cigar on how a read maps to the reference.

It only contains read only methods. There are no ways to set values. To set a value, a child class must be used.

Definition at line 83 of file Cigar.h.

## Member Enumeration Documentation

## Operation

enum Cigar::Operation

Enum for the cigar operations.

Enumerator
none | no operation has been set.
match | match/mismatch operation. Associated with CIGAR Operation "M"
mismatch | mismatch operation. Associated with CIGAR Operation "M"
insert | insertion to the reference (the query sequence contains bases that have no corresponding base in the reference). Associated with CIGAR Operation "I"
del | deletion from the reference (the reference contains bases that have no corresponding base in the query sequence). Associated with CIGAR Operation "D"
skip | skipped region from the reference (the reference contains bases that have no corresponding base in the query sequence). Associated with CIGAR Operation "N"
softClip | Soft clip on the read (clipped sequence present in the query sequence, but not in reference). Associated with CIGAR Operation "S".
hardClip | Hard clip on the read (clipped sequence not present in the query sequence or reference). Associated with CIGAR Operation "H".
pad | Padding (not in reference or query). Associated with CIGAR Operation "P".

Definition at line 87 of file Cigar.h.

{
none=0, ///< no operation has been set.
match, ///< match/mismatch operation. Associated with CIGAR Operation "M"
mismatch, ///< mismatch operation. Associated with CIGAR Operation "M"
insert, ///< insertion to the reference (the query sequence contains bases that have no corresponding base in the reference). Associated with CIGAR Operation "I"
del, ///< deletion from the reference (the reference contains bases that have no corresponding base in the query sequence). Associated with CIGAR Operation "D"
skip, ///< skipped region from the reference (the reference contains bases that have no corresponding base in the query sequence). Associated with CIGAR Operation "N"
softClip, ///< Soft clip on the read (clipped sequence present in the query sequence, but not in reference). Associated with CIGAR Operation "S"
hardClip, ///< Hard clip on the read (clipped sequence not present in the query sequence or reference). Associated with CIGAR Operation "H"
pad ///< Padding (not in reference or query). Associated with CIGAR Operation "P"
};
Cigar::del
@ del
deletion from the reference (the reference contains bases that have no corresponding base in the quer...
Definition: Cigar.h:92
Cigar::mismatch
@ mismatch
mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:90
Cigar::hardClip
@ hardClip
Hard clip on the read (clipped sequence not present in the query sequence or reference)....
Definition: Cigar.h:95
Cigar::match
@ match
match/mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:89
Cigar::pad
@ pad
Padding (not in reference or query). Associated with CIGAR Operation "P".
Definition: Cigar.h:96
Cigar::insert
@ insert
insertion to the reference (the query sequence contains bases that have no corresponding base in the ...
Definition: Cigar.h:91
Cigar::skip
@ skip
skipped region from the reference (the reference contains bases that have no corresponding base in th...
Definition: Cigar.h:93
Cigar::softClip
@ softClip
Soft clip on the read (clipped sequence present in the query sequence, but not in reference)....
Definition: Cigar.h:94
Cigar::none
@ none
no operation has been set.
Definition: Cigar.h:88

## Constructor & Destructor Documentation

## Cigar()

Cigar::Cigar | ( |  | ) |

inline

Default constructor initializes as a CIGAR with no operations.

Definition at line 326 of file Cigar.h.

{
clearQueryAndReferenceIndexes();
}

## Member Function Documentation

## clearQueryAndReferenceIndexes()

void Cigar::clearQueryAndReferenceIndexes | ( |  | ) |

protected

Definition at line 415 of file Cigar.cpp.

{
queryToRef.clear();
refToQuery.clear();
refToCigar.clear();
queryToCigar.clear();
myExpandedCigar.clear();
}

## Dump()

void Cigar::Dump | ( |  | ) | const

inline

Write this object as a string to cout.

Definition at line 370 of file Cigar.h.

{
String cigarString;
getCigarString(cigarString);
std::cout << cigarString ;
}
Cigar::getCigarString
void getCigarString(String &cigarString) const
Set the passed in String to the string reprentation of the Cigar operations in this object.
Definition: Cigar.cpp:52
String
Definition: StringBasics.h:39

References getCigarString().

## foundInQuery() [1/3]

static bool Cigar::foundInQuery | ( | char | op | ) |

inline static

Return true if the specified operation is found in the query sequence, false if not.

Definition at line 236 of file Cigar.h.

{
switch(op)
{
case 'M':
case '=':
case 'X':
case 'I':
case 'S':
return true;
default:
return false;
}
return false;
}

## foundInQuery() [2/3]

static bool Cigar::foundInQuery | ( | const CigarOperator & | op | ) |

inline static

Return true if the specified operation is found in the query sequence, false if not.

Definition at line 254 of file Cigar.h.

{
return(foundInQuery(op.operation));
}
Cigar::foundInQuery
static bool foundInQuery(Operation op)
Return true if the specified operation is found in the query sequence, false if not.
Definition: Cigar.h:219

References foundInQuery().

## foundInQuery() [3/3]

static bool Cigar::foundInQuery | ( | Operation | op | ) |

inline static

Return true if the specified operation is found in the query sequence, false if not.

Definition at line 219 of file Cigar.h.

{
switch(op)
{
case match:
case mismatch:
case insert:
case softClip:
return true;
default:
return false;
}
return false;
}

References insert, match, mismatch, and softClip.

Referenced by foundInQuery(), SamRecord::shiftIndelsLeft(), SamFilter::softClip(), CigarHelper::softClipBeginByRefPos(), and CigarHelper::softClipEndByRefPos().

## foundInReference() [1/3]

static bool Cigar::foundInReference | ( | char | op | ) |

inline static

Return true if the specified operation is found in the reference sequence, false if not.

Definition at line 194 of file Cigar.h.

{
switch(op)
{
case 'M':
case '=':
case 'X':
case 'D':
case 'N':
return true;
default:
return false;
}
return false;
}

## foundInReference() [2/3]

static bool Cigar::foundInReference | ( | const CigarOperator & | op | ) |

inline static

Return true if the specified operation is found in the reference sequence, false if not.

Definition at line 212 of file Cigar.h.

{
return(foundInReference(op.operation));
}
Cigar::foundInReference
static bool foundInReference(Operation op)
Return true if the specified operation is found in the reference sequence, false if not.
Definition: Cigar.h:177

References foundInReference().

## foundInReference() [3/3]

static bool Cigar::foundInReference | ( | Operation | op | ) |

inline static

Return true if the specified operation is found in the reference sequence, false if not.

Definition at line 177 of file Cigar.h.

{
switch(op)
{
case match:
case mismatch:
case del:
case skip:
return true;
default:
return false;
}
return false;
}

References del, match, mismatch, and skip.

Referenced by foundInReference(), CigarHelper::softClipBeginByRefPos(), and CigarHelper::softClipEndByRefPos().

## getCigarCharOp()

char Cigar::getCigarCharOp | ( | int32_t | expandedCigarIndex | ) |

Return the character code of the cigar operator associated with the specified expanded CIGAR index.

'?' is returned for an out of range index.

Definition at line 295 of file Cigar.cpp.

{
// Check if the expanded cigar has been set yet
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
// Set the expanded cigar.
setQueryAndReferenceIndexes();
}
// Check to see if the index is in range.
if((expandedCigarIndex < 0) ||
((uint32_t)expandedCigarIndex >= myExpandedCigar.length()))
{
return('?');
}
return(myExpandedCigar[expandedCigarIndex]);
}

Referenced by getCigarCharOpFromQueryIndex(), getCigarCharOpFromRefOffset(), and getCigarCharOpFromRefPos().

## getCigarCharOpFromQueryIndex()

char Cigar::getCigarCharOpFromQueryIndex | ( | int32_t | queryIndex | ) |

Return the character code of the cigar operator associated with the specified queryIndex.

'?' is returned for an out of range index.

Definition at line 314 of file Cigar.cpp.

{
return(getCigarCharOp(getExpandedCigarIndexFromQueryIndex(queryIndex)));
}
Cigar::getCigarCharOp
char getCigarCharOp(int32_t expandedCigarIndex)
Return the character code of the cigar operator associated with the specified expanded CIGAR index.
Definition: Cigar.cpp:295
Cigar::getExpandedCigarIndexFromQueryIndex
int32_t getExpandedCigarIndexFromQueryIndex(int32_t queryIndex)
Returns the index into the expanded cigar for the cigar associated with the specified queryIndex.
Definition: Cigar.cpp:258

References getCigarCharOp(), and getExpandedCigarIndexFromQueryIndex().

## getCigarCharOpFromRefOffset()

char Cigar::getCigarCharOpFromRefOffset | ( | int32_t | refOffset | ) |

Return the character code of the cigar operator associated with the specified reference offset.

'?' is returned for an out of range offset.

Definition at line 320 of file Cigar.cpp.

{
return(getCigarCharOp(getExpandedCigarIndexFromRefOffset(refOffset)));
}
Cigar::getExpandedCigarIndexFromRefOffset
int32_t getExpandedCigarIndexFromRefOffset(int32_t refOffset)
Returns the index into the expanded cigar for the cigar associated with the specified reference offse...
Definition: Cigar.cpp:273

References getCigarCharOp(), and getExpandedCigarIndexFromRefOffset().

## getCigarCharOpFromRefPos()

char Cigar::getCigarCharOpFromRefPos | ( | int32_t | refPosition,
|  | int32_t | queryStartPos
| ) |  |

Return the character code of the cigar operator associated with the specified reference position.

'?' is returned for an out of range reference position.

Definition at line 326 of file Cigar.cpp.

{
return(getCigarCharOp(getExpandedCigarIndexFromRefPos(refPosition, queryStartPos)));
}
Cigar::getExpandedCigarIndexFromRefPos
int32_t getExpandedCigarIndexFromRefPos(int32_t refPosition, int32_t queryStartPos)
Returns the index into the expanded cigar for the cigar associated with the specified reference posit...
Definition: Cigar.cpp:288

References getCigarCharOp(), and getExpandedCigarIndexFromRefPos().

## getCigarString() [1/2]

void Cigar::getCigarString | ( | std::string & | cigarString | ) | const

Set the passed in std::string to the string reprentation of the Cigar operations in this object.

Definition at line 36 of file Cigar.cpp.

{
using namespace STLUtilities;
std::vector<CigarOperator>::const_iterator i;
cigarString.clear(); // clear result string
// Progressively append the character representations of the operations to
// the cigar string.
for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
{
cigarString << (*i).count << (*i).getChar();
}
}
STLUtilities
This file is inspired by the poor quality of string support in STL for what should be trivial capabil...
Definition: STLUtilities.cpp:21

## getCigarString() [2/2]

void Cigar::getCigarString | ( | String & | cigarString | ) | const

Set the passed in String to the string reprentation of the Cigar operations in this object.

Definition at line 52 of file Cigar.cpp.

{
std::string cigar;
getCigarString(cigar);
cigarString = cigar.c_str();
return;
}

References getCigarString().

Referenced by Dump(), getCigarString(), and SamRecord::setCigar().

## getExpandedCigarIndexFromQueryIndex()

int32_t Cigar::getExpandedCigarIndexFromQueryIndex | ( | int32_t | queryIndex | ) |

Returns the index into the expanded cigar for the cigar associated with the specified queryIndex.

INDEX_NA returned if the index is out of range.

Definition at line 258 of file Cigar.cpp.

{
// If the vectors aren't set, set them.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToCigar.size()))
{
return(INDEX_NA);
}
return(queryToCigar[queryIndex]);
}
Cigar::INDEX_NA
static const int32_t INDEX_NA
Value associated with an index that is not applicable/does not exist, used for converting between que...
Definition: Cigar.h:492

References INDEX_NA.

Referenced by getCigarCharOpFromQueryIndex().

## getExpandedCigarIndexFromRefOffset()

int32_t Cigar::getExpandedCigarIndexFromRefOffset | ( | int32_t | refOffset | ) |

Returns the index into the expanded cigar for the cigar associated with the specified reference offset.

INDEX_NA returned if the offset is out of range.

Definition at line 273 of file Cigar.cpp.

{
// If the vectors aren't set, set them.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
if ((refOffset < 0) || ((uint32_t)refOffset >= refToCigar.size()))
{
return(INDEX_NA);
}
return(refToCigar[refOffset]);
}

References INDEX_NA.

Referenced by getCigarCharOpFromRefOffset(), and getExpandedCigarIndexFromRefPos().

## getExpandedCigarIndexFromRefPos()

int32_t Cigar::getExpandedCigarIndexFromRefPos | ( | int32_t | refPosition,
|  | int32_t | queryStartPos
| ) |  |

Returns the index into the expanded cigar for the cigar associated with the specified reference position and queryStartPos.

INDEX_NA returned if the position is out of range.

Definition at line 288 of file Cigar.cpp.

{
return(getExpandedCigarIndexFromRefOffset(refPosition - queryStartPos));
}

References getExpandedCigarIndexFromRefOffset().

Referenced by getCigarCharOpFromRefPos().

## getExpandedString()

void Cigar::getExpandedString | ( | std::string & | s | ) | const

Sets the specified string to a valid CIGAR string of characters that represent the cigar with no digits (a CIGAR of "3M" would return "MMM").

The returned string is actually also a valid CIGAR string. In theory this makes it easier to parse some reads.

Returns
  s the string to populate

Definition at line 63 of file Cigar.cpp.

{
s = "";
std::vector<CigarOperator>::const_iterator i;
// Progressively append the character representations of the operations to
// the string passed in
for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
{
for (uint32_t j = 0; j<(*i).count; j++) s += (*i).getChar();
}
return;
}

## getExpectedQueryBaseCount()

int Cigar::getExpectedQueryBaseCount | ( |  | ) | const

Return the length of the read that corresponds to the current CIGAR string.

For validation, we should expect that a sequence read in a SAM file will be the same length as the value returned by this method.

Example: 3M2D3M describes a read with three bases matching the reference, then skips 2 bases, then has three more bases that match the reference (match/mismatch). In this case, the read length is expected to be 6.

Example: 3M2I3M describes a read with 3 match/mismatch bases, two extra bases, and then 3 more match/mistmatch bases. The total in this example is 8 bases.

Returns
  returns the expected read length

Definition at line 95 of file Cigar.cpp.

{
int matchCount = 0;
std::vector<CigarOperator>::const_iterator i;
for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
{
switch (i->operation)
{
case match:
case mismatch:
case softClip:
case insert:
matchCount += i->count;
break;
default:
// we only care about operations that are in the query sequence.
break;
}
}
return matchCount;
}

References insert, match, mismatch, and softClip.

Referenced by SamValidator::isValidCigar(), and SamFilter::softClip().

## getExpectedReferenceBaseCount()

int Cigar::getExpectedReferenceBaseCount | ( |  | ) | const

Return the number of bases in the reference that this CIGAR "spans".

When doing range checking, we occassionally need to know how many total bases the CIGAR string represents as compared to the reference.

Examples: 3M2D3M describes a read that overlays 8 bases in the reference. 3M2I3M describes a read with 3 bases that match the reference, two additional bases that aren't in the reference, and 3 more bases that match the reference, so it spans 6 bases in the reference.

Returns
  how many bases in the reference are spanned by the given CIGAR string

Definition at line 120 of file Cigar.cpp.

{
int matchCount = 0;
std::vector<CigarOperator>::const_iterator i;
for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
{
switch (i->operation)
{
case match:
case mismatch:
case del:
case skip:
matchCount += i->count;
break;
default:
// we only care about operations that are in the reference sequence.
break;
}
}
return matchCount;
}

References del, match, mismatch, and skip.

Referenced by SamTags::createMDTag().

## getNumBeginClips()

int Cigar::getNumBeginClips | ( |  | ) | const

Return the number of clips that are at the beginning of the cigar.

Definition at line 144 of file Cigar.cpp.

{
int numBeginClips = 0;
for (unsigned int i = 0; i != cigarOperations.size(); i++)
{
if ((cigarOperations[i].operation == softClip) ||
(cigarOperations[i].operation == hardClip))
{
// Clipping operator, increment the counter.
numBeginClips += cigarOperations[i].count;
}
else
{
// Break out of the loop since a non-clipping operator was found.
break;
}
}
return(numBeginClips);
}

References hardClip, and softClip.

## getNumEndClips()

int Cigar::getNumEndClips | ( |  | ) | const

Return the number of clips that are at the end of the cigar.

Definition at line 166 of file Cigar.cpp.

{
int numEndClips = 0;
for (int i = (cigarOperations.size() - 1); i >= 0; i--)
{
if ((cigarOperations[i].operation == softClip) ||
(cigarOperations[i].operation == hardClip))
{
// Clipping operator, increment the counter.
numEndClips += cigarOperations[i].count;
}
else
{
// Break out of the loop since a non-clipping operator was found.
break;
}
}
return(numEndClips);
}

References hardClip, and softClip.

## getNumOverlaps()

uint32_t Cigar::getNumOverlaps | ( | int32_t | start,
|  | int32_t | end,
|  | int32_t | queryStartPos
| ) |  |

Return the number of bases that overlap the reference and the read associated with this cigar that falls within the specified region.

Parameters

  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.)
  queryStartPos | : 0-based leftmost mapping position of the first matcihng base in the query.

Definition at line 334 of file Cigar.cpp.

{
// Get the overlap info.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
// Get the start and end offsets.
int32_t startRefOffset = 0;
// If the specified start is more than the queryStartPos, set
// the startRefOffset to the appropriate non-zero value.
// (if start is <= queryStartPos, than startRefOffset is 0 - it should
// not be set to a negative value.)
if (start > queryStartPos)
{
startRefOffset = start - queryStartPos;
}
int32_t endRefOffset = end - queryStartPos;
if (end == -1)
{
// -1 means that the region goes to the end of the refrerence.
// So set endRefOffset to the max refOffset + 1 which is the
// size of the refToQuery vector.
endRefOffset = refToQuery.size();
}
// if endRefOffset is less than 0, then this read does not fall within
// the specified region, so return 0.
if (endRefOffset < 0)
{
return(0);
}
// Get the overlaps for these offsets.
// Loop through the read counting positions that match the reference
// within this region.
int32_t refOffset = 0;
int32_t numOverlaps = 0;
for (unsigned int queryIndex = 0; queryIndex < queryToRef.size();
queryIndex++)
{
refOffset = getRefOffset(queryIndex);
if (refOffset > endRefOffset)
{
// Past the end of the specified region, so stop checking
// for overlaps since there will be no more.
break;
}
else if ((refOffset >= startRefOffset) && (refOffset < endRefOffset))
{
// within the region, increment the counter.
++numOverlaps;
}
}
return(numOverlaps);
}
Cigar::getRefOffset
int32_t getRefOffset(int32_t queryIndex)
Return the reference offset associated with the specified query index or INDEX_NA based on this cigar...
Definition: Cigar.cpp:187

References getRefOffset().

Referenced by SamRecord::getNumOverlaps().

## getOperator()

const CigarOperator & Cigar::getOperator | ( | int | i | ) | const

inline

Return the Cigar Operation at the specified index (starting at 0).

Definition at line 354 of file Cigar.h.

{
return cigarOperations[i];
}

Referenced by SamFilter::softClip(), CigarHelper::softClipBeginByRefPos(), and CigarHelper::softClipEndByRefPos().

## getQueryIndex() [1/2]

int32_t Cigar::getQueryIndex | ( | int32_t | refOffset | ) |

Return the query index associated with the specified reference offset or INDEX_NA based on this cigar.

Definition at line 202 of file Cigar.cpp.

{
// If the vectors aren't set, set them.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
if ((refOffset < 0) || ((uint32_t)refOffset >= refToQuery.size()))
{
return(INDEX_NA);
}
return(refToQuery[refOffset]);
}

References INDEX_NA.

Referenced by PileupElementBaseQual::addEntry(), SamRecordHelper::checkSequence(), and SamTags::createMDTag().

## getQueryIndex() [2/2]

int32_t Cigar::getQueryIndex | ( | int32_t | refPosition,
|  | int32_t | queryStartPos
| ) |  |

Return the query index or INDEX_NA associated with the specified reference offset when the query starts at the specified reference position.

Definition at line 240 of file Cigar.cpp.

{
// If the vectors aren't set, set them.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
int32_t refOffset = refPosition - queryStartPos;
if ((refOffset < 0) || ((uint32_t)refOffset >= refToQuery.size()))
{
return(INDEX_NA);
}
return(refToQuery[refOffset]);
}

References INDEX_NA.

## getRefOffset()

int32_t Cigar::getRefOffset | ( | int32_t | queryIndex | ) |

Return the reference offset associated with the specified query index or INDEX_NA based on this cigar.

Definition at line 187 of file Cigar.cpp.

{
// If the vectors aren't set, set them.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToRef.size()))
{
return(INDEX_NA);
}
return(queryToRef[queryIndex]);
}

References INDEX_NA.

Referenced by SamQuerySeqWithRefIter::getNextMatchMismatch(), getNumOverlaps(), SamQuerySeqWithRef::seqWithEquals(), and SamQuerySeqWithRef::seqWithoutEquals().

## getRefPosition()

int32_t Cigar::getRefPosition | ( | int32_t | queryIndex,
|  | int32_t | queryStartPos
| ) |  |

Return the reference position associated with the specified query index or INDEX_NA based on this cigar and the specified queryStartPos which is the leftmost mapping position of the first matching base in the query.

Definition at line 217 of file Cigar.cpp.

{
// If the vectors aren't set, set them.
if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
{
setQueryAndReferenceIndexes();
}
if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToRef.size()))
{
return(INDEX_NA);
}
if (queryToRef[queryIndex] != INDEX_NA)
{
return(queryToRef[queryIndex] + queryStartPos);
}
return(INDEX_NA);
}

References INDEX_NA.

Referenced by SamFilter::softClip().

## hasIndel()

bool Cigar::hasIndel | ( |  | ) |

Return whether or not the cigar has indels (insertions or delections)

Returns
  true if it has an insertion or deletion, false if not.

Definition at line 398 of file Cigar.cpp.

{
for(unsigned int i = 0; i < cigarOperations.size(); i++)
{
if((cigarOperations[i].operation == insert) ||
(cigarOperations[i].operation == del))
{
// Found an indel, so return true.
return(true);
}
}
// Went through all the operations, and found no indel, so return false.
return(false);
}

References del, and insert.

## isClip() [1/3]

static bool Cigar::isClip | ( | char | op | ) |

inline static

Return true if the specified operation is a clipping operation, false if not.

Definition at line 276 of file Cigar.h.

{
switch(op)
{
case 'S':
case 'H':
return true;
default:
return false;
}
return false;
}

## isClip() [2/3]

static bool Cigar::isClip | ( | const CigarOperator & | op | ) |

inline static

Return true if the specified operation is a clipping operation, false if not.

Definition at line 291 of file Cigar.h.

{
return(isClip(op.operation));
}
Cigar::isClip
static bool isClip(Operation op)
Return true if the specified operation is a clipping operation, false if not.
Definition: Cigar.h:261

References isClip().

## isClip() [3/3]

static bool Cigar::isClip | ( | Operation | op | ) |

inline static

Return true if the specified operation is a clipping operation, false if not.

Definition at line 261 of file Cigar.h.

{
switch(op)
{
case softClip:
case hardClip:
return true;
default:
return false;
}
return false;
}

References hardClip, and softClip.

Referenced by isClip(), SamFilter::softClip(), and CigarHelper::softClipEndByRefPos().

## isMatchOrMismatch() [1/2]

static bool Cigar::isMatchOrMismatch | ( | const CigarOperator & | op | ) |

inline static

Return true if the specified operation is a match/mismatch operation, false if not.

Definition at line 313 of file Cigar.h.

{
return(isMatchOrMismatch(op.operation));
}
Cigar::isMatchOrMismatch
static bool isMatchOrMismatch(Operation op)
Return true if the specified operation is a match/mismatch operation, false if not.
Definition: Cigar.h:298

References isMatchOrMismatch().

## isMatchOrMismatch() [2/2]

static bool Cigar::isMatchOrMismatch | ( | Operation | op | ) |

inline static

Return true if the specified operation is a match/mismatch operation, false if not.

Definition at line 298 of file Cigar.h.

{
switch(op)
{
case match:
case mismatch:
return true;
default:
return false;
}
return false;
}

References match, and mismatch.

Referenced by isMatchOrMismatch(), and SamRecord::shiftIndelsLeft().

## operator==()

bool Cigar::operator== | ( | Cigar & | rhs | ) | const

Return true if the 2 Cigars are the same (the same operations of the same sizes).

Definition at line 80 of file Cigar.cpp.

{
if (this->size() != rhs.size()) return false;
for (int i = 0; i < this->size(); i++)
{
if (cigarOperations[i]!=rhs.cigarOperations[i]) return false;
}
return true;
}
Cigar::size
int size() const
Return the number of cigar operations.
Definition: Cigar.h:364

References size().

## operator[]()

const CigarOperator & Cigar::operator[] | ( | int | i | ) | const

inline

Return the Cigar Operation at the specified index (starting at 0).

Definition at line 348 of file Cigar.h.

{
return cigarOperations[i];
}

## setQueryAndReferenceIndexes()

void Cigar::setQueryAndReferenceIndexes | ( |  | ) |

protected

Definition at line 441 of file Cigar.cpp.

{
// First ensure that the vectors are clear by clearing them.
clearQueryAndReferenceIndexes();
int extPos = 0;
// Process each cigar index.
for (uint32_t cigarIndex = 0; cigarIndex < cigarOperations.size(); cigarIndex++)
{
// Process the cigar operation.
switch (cigarOperations[cigarIndex].operation)
{
case match:
case mismatch:
// For match/mismatch, update the maps between query
// and reference for the number of matches/mismatches.
for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
{
// The associated indexes are the next location in
// each array, which is equal to the current size.
int32_t queryToRefLen = queryToRef.size();
int32_t refToQueryLen = refToQuery.size();
queryToRef.push_back(refToQueryLen);
refToQuery.push_back(queryToRefLen);
refToCigar.push_back(extPos);
queryToCigar.push_back(extPos++);
myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
}
break;
case insert:
case softClip:
// Add N/A reference offset for each query index that this
// insert covers.
for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
{
queryToRef.push_back(INDEX_NA);
queryToCigar.push_back(extPos++);
myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
}
break;
case del:
case skip:
// Add N/A query index for each reference offset that this
// deletion/skip covers.
for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
{
refToQuery.push_back(INDEX_NA);
refToCigar.push_back(extPos++);
myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
}
break;
case hardClip:
case pad:
case none:
for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
{
myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
++extPos;
}
break;
};
}
}

## size()

int Cigar::size | ( |  | ) | const

inline

Return the number of cigar operations.

Definition at line 364 of file Cigar.h.

{
return cigarOperations.size();
}

Referenced by operator==(), SamRecord::shiftIndelsLeft(), SamFilter::softClip(), CigarHelper::softClipBeginByRefPos(), and CigarHelper::softClipEndByRefPos().

## Friends And Related Function Documentation

## operator<<

std::ostream & operator<< | ( | std::ostream & | stream,
|  | const Cigar & | cigar
| ) |  |

friend

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

Definition at line 540 of file Cigar.h.

{
stream << cigar.cigarOperations;
return stream;
}

## Member Data Documentation

## cigarOperations

std::vector<CigarOperator> Cigar::cigarOperations

protected

Definition at line 502 of file Cigar.h.

## INDEX_NA

const int32_t Cigar::INDEX_NA = -1

static

Value associated with an index that is not applicable/does not exist, used for converting between query and reference indexes/offsets when an associated index/offset does not exist.

Definition at line 492 of file Cigar.h.

Referenced by PileupElementBaseQual::addEntry(), SamRecordHelper::checkSequence(), SamTags::createMDTag(), getExpandedCigarIndexFromQueryIndex(), getExpandedCigarIndexFromRefOffset(), SamQuerySeqWithRefIter::getNextMatchMismatch(), getQueryIndex(), getRefOffset(), getRefPosition(), SamQuerySeqWithRef::seqWithEquals(), SamQuerySeqWithRef::seqWithoutEquals(), and SamFilter::softClip().

## MAX_OP_VALUE

const int Cigar::MAX_OP_VALUE = pad

static

Definition at line 101 of file Cigar.h.

The documentation for this class was generated from the following files:

- general/Cigar.h
- general/Cigar.cpp