libStatGen Software  1
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:
Collaboration diagram for Cigar:

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.
 
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 CigarOperatoroperator[] (int i) const
 Return the Cigar Operation at the specified index (starting at 0).
 
const CigarOperatorgetOperator (int i) const
 Return the Cigar Operation at the specified index (starting at 0).
 
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.
 
void Dump () const
 Write this object as a string to cout.
 
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.
 
int getNumEndClips () const
 Return the number of clips that are at the end of the cigar.
 
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< CigarOperatorcigarOperations
 

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.
 

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 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.

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

Member Function Documentation

◆ foundInQuery() [1/3]

static bool Cigar::foundInQuery ( Operation  op)
inlinestatic

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

Definition at line 219 of file Cigar.h.

References insert, match, mismatch, and softClip.

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

220  {
221  switch(op)
222  {
223  case match:
224  case mismatch:
225  case insert:
226  case softClip:
227  return true;
228  default:
229  return false;
230  }
231  return false;
232  }
insertion to the reference (the query sequence contains bases that have no corresponding base in the ...
Definition: Cigar.h:91
mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:90
Soft clip on the read (clipped sequence present in the query sequence, but not in reference)...
Definition: Cigar.h:94
match/mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:89

◆ foundInQuery() [2/3]

static bool Cigar::foundInQuery ( char  op)
inlinestatic

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

Definition at line 236 of file Cigar.h.

237  {
238  switch(op)
239  {
240  case 'M':
241  case '=':
242  case 'X':
243  case 'I':
244  case 'S':
245  return true;
246  default:
247  return false;
248  }
249  return false;
250  }

◆ foundInQuery() [3/3]

static bool Cigar::foundInQuery ( const CigarOperator op)
inlinestatic

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

Definition at line 254 of file Cigar.h.

References foundInQuery().

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

◆ foundInReference() [1/3]

static bool Cigar::foundInReference ( Operation  op)
inlinestatic

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

Definition at line 177 of file Cigar.h.

References del, match, mismatch, and skip.

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

178  {
179  switch(op)
180  {
181  case match:
182  case mismatch:
183  case del:
184  case skip:
185  return true;
186  default:
187  return false;
188  }
189  return false;
190  }
skipped region from the reference (the reference contains bases that have no corresponding base in th...
Definition: Cigar.h:93
mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:90
match/mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:89
deletion from the reference (the reference contains bases that have no corresponding base in the quer...
Definition: Cigar.h:92

◆ foundInReference() [2/3]

static bool Cigar::foundInReference ( char  op)
inlinestatic

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

Definition at line 194 of file Cigar.h.

195  {
196  switch(op)
197  {
198  case 'M':
199  case '=':
200  case 'X':
201  case 'D':
202  case 'N':
203  return true;
204  default:
205  return false;
206  }
207  return false;
208  }

◆ foundInReference() [3/3]

static bool Cigar::foundInReference ( const CigarOperator op)
inlinestatic

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

Definition at line 212 of file Cigar.h.

References foundInReference().

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

◆ 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.

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

296 {
297  // Check if the expanded cigar has been set yet
298  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
299  {
300  // Set the expanded cigar.
301  setQueryAndReferenceIndexes();
302  }
303 
304  // Check to see if the index is in range.
305  if((expandedCigarIndex < 0) ||
306  ((uint32_t)expandedCigarIndex >= myExpandedCigar.length()))
307  {
308  return('?');
309  }
310  return(myExpandedCigar[expandedCigarIndex]);
311 }

◆ 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.

References getCigarCharOp(), and getExpandedCigarIndexFromQueryIndex().

Referenced by Dump().

315 {
317 }
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
char getCigarCharOp(int32_t expandedCigarIndex)
Return the character code of the cigar operator associated with the specified expanded CIGAR index...
Definition: Cigar.cpp:295

◆ 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.

References getCigarCharOp(), and getExpandedCigarIndexFromRefOffset().

Referenced by Dump().

321 {
323 }
char getCigarCharOp(int32_t expandedCigarIndex)
Return the character code of the cigar operator associated with the specified expanded CIGAR index...
Definition: Cigar.cpp:295
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

◆ 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.

References getCigarCharOp(), and getExpandedCigarIndexFromRefPos().

Referenced by Dump().

327 {
328  return(getCigarCharOp(getExpandedCigarIndexFromRefPos(refPosition, queryStartPos)));
329 }
char getCigarCharOp(int32_t expandedCigarIndex)
Return the character code of the cigar operator associated with the specified expanded CIGAR index...
Definition: Cigar.cpp:295
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

◆ getCigarString() [1/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.

Referenced by Cigar(), Dump(), SamRecord::getStatus(), and SamRecord::setCigar().

53 {
54  std::string cigar;
55 
56  getCigarString(cigar);
57 
58  cigarString = cigar.c_str();
59 
60  return;
61 }
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

◆ getCigarString() [2/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.

37 {
38  using namespace STLUtilities;
39 
40  std::vector<CigarOperator>::const_iterator i;
41 
42  cigarString.clear(); // clear result string
43 
44  // Progressively append the character representations of the operations to
45  // the cigar string.
46  for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
47  {
48  cigarString << (*i).count << (*i).getChar();
49  }
50 }
This file is inspired by the poor quality of string support in STL for what should be trivial capabil...

◆ 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.

References INDEX_NA.

Referenced by Dump(), and getCigarCharOpFromQueryIndex().

259 {
260  // If the vectors aren't set, set them.
261  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
262  {
263  setQueryAndReferenceIndexes();
264  }
265  if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToCigar.size()))
266  {
267  return(INDEX_NA);
268  }
269  return(queryToCigar[queryIndex]);
270 }
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

◆ 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.

References INDEX_NA.

Referenced by Dump(), getCigarCharOpFromRefOffset(), and getExpandedCigarIndexFromRefPos().

274 {
275  // If the vectors aren't set, set them.
276  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
277  {
278  setQueryAndReferenceIndexes();
279  }
280  if ((refOffset < 0) || ((uint32_t)refOffset >= refToCigar.size()))
281  {
282  return(INDEX_NA);
283  }
284  return(refToCigar[refOffset]);
285 }
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

◆ 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.

References getExpandedCigarIndexFromRefOffset().

Referenced by Dump(), and getCigarCharOpFromRefPos().

290 {
291  return(getExpandedCigarIndexFromRefOffset(refPosition - queryStartPos));
292 }
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

◆ 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.

Referenced by Cigar().

64 {
65  s = "";
66 
67  std::vector<CigarOperator>::const_iterator i;
68 
69  // Progressively append the character representations of the operations to
70  // the string passed in
71 
72  for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
73  {
74  for (uint32_t j = 0; j<(*i).count; j++) s += (*i).getChar();
75  }
76  return;
77 }

◆ 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.

References insert, match, mismatch, and softClip.

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

96 {
97  int matchCount = 0;
98  std::vector<CigarOperator>::const_iterator i;
99  for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
100  {
101  switch (i->operation)
102  {
103  case match:
104  case mismatch:
105  case softClip:
106  case insert:
107  matchCount += i->count;
108  break;
109  default:
110  // we only care about operations that are in the query sequence.
111  break;
112  }
113  }
114  return matchCount;
115 }
insertion to the reference (the query sequence contains bases that have no corresponding base in the ...
Definition: Cigar.h:91
mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:90
Soft clip on the read (clipped sequence present in the query sequence, but not in reference)...
Definition: Cigar.h:94
match/mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:89

◆ 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.

References del, match, mismatch, and skip.

Referenced by SamTags::createMDTag(), Dump(), and SamRecord::getStatus().

121 {
122  int matchCount = 0;
123  std::vector<CigarOperator>::const_iterator i;
124  for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
125  {
126  switch (i->operation)
127  {
128  case match:
129  case mismatch:
130  case del:
131  case skip:
132  matchCount += i->count;
133  break;
134  default:
135  // we only care about operations that are in the reference sequence.
136  break;
137  }
138  }
139  return matchCount;
140 }
skipped region from the reference (the reference contains bases that have no corresponding base in th...
Definition: Cigar.h:93
mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:90
match/mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:89
deletion from the reference (the reference contains bases that have no corresponding base in the quer...
Definition: Cigar.h:92

◆ 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.

References getRefOffset().

Referenced by Dump(), and SamRecord::getNumOverlaps().

336 {
337  // Get the overlap info.
338  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
339  {
340  setQueryAndReferenceIndexes();
341  }
342 
343  // Get the start and end offsets.
344  int32_t startRefOffset = 0;
345  // If the specified start is more than the queryStartPos, set
346  // the startRefOffset to the appropriate non-zero value.
347  // (if start is <= queryStartPos, than startRefOffset is 0 - it should
348  // not be set to a negative value.)
349  if (start > queryStartPos)
350  {
351  startRefOffset = start - queryStartPos;
352  }
353 
354  int32_t endRefOffset = end - queryStartPos;
355  if (end == -1)
356  {
357  // -1 means that the region goes to the end of the refrerence.
358  // So set endRefOffset to the max refOffset + 1 which is the
359  // size of the refToQuery vector.
360  endRefOffset = refToQuery.size();
361  }
362 
363 
364  // if endRefOffset is less than 0, then this read does not fall within
365  // the specified region, so return 0.
366  if (endRefOffset < 0)
367  {
368  return(0);
369  }
370 
371  // Get the overlaps for these offsets.
372  // Loop through the read counting positions that match the reference
373  // within this region.
374  int32_t refOffset = 0;
375  int32_t numOverlaps = 0;
376  for (unsigned int queryIndex = 0; queryIndex < queryToRef.size();
377  queryIndex++)
378  {
379  refOffset = getRefOffset(queryIndex);
380  if (refOffset > endRefOffset)
381  {
382  // Past the end of the specified region, so stop checking
383  // for overlaps since there will be no more.
384  break;
385  }
386  else if ((refOffset >= startRefOffset) && (refOffset < endRefOffset))
387  {
388  // within the region, increment the counter.
389  ++numOverlaps;
390  }
391  }
392 
393  return(numOverlaps);
394 }
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

◆ 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.

References INDEX_NA.

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

203 {
204  // If the vectors aren't set, set them.
205  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
206  {
207  setQueryAndReferenceIndexes();
208  }
209  if ((refOffset < 0) || ((uint32_t)refOffset >= refToQuery.size()))
210  {
211  return(INDEX_NA);
212  }
213  return(refToQuery[refOffset]);
214 }
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

◆ 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.

References INDEX_NA.

241 {
242  // If the vectors aren't set, set them.
243  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
244  {
245  setQueryAndReferenceIndexes();
246  }
247 
248  int32_t refOffset = refPosition - queryStartPos;
249  if ((refOffset < 0) || ((uint32_t)refOffset >= refToQuery.size()))
250  {
251  return(INDEX_NA);
252  }
253 
254  return(refToQuery[refOffset]);
255 }
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

◆ 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.

References INDEX_NA.

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

188 {
189  // If the vectors aren't set, set them.
190  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
191  {
192  setQueryAndReferenceIndexes();
193  }
194  if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToRef.size()))
195  {
196  return(INDEX_NA);
197  }
198  return(queryToRef[queryIndex]);
199 }
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

◆ 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.

References INDEX_NA.

Referenced by Dump(), and SamFilter::softClip().

218 {
219  // If the vectors aren't set, set them.
220  if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
221  {
222  setQueryAndReferenceIndexes();
223  }
224  if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToRef.size()))
225  {
226  return(INDEX_NA);
227  }
228 
229  if (queryToRef[queryIndex] != INDEX_NA)
230  {
231  return(queryToRef[queryIndex] + queryStartPos);
232  }
233  return(INDEX_NA);
234 }
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

◆ 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.

References del, hardClip, INDEX_NA, insert, match, mismatch, none, pad, skip, and softClip.

Referenced by Dump().

399 {
400  for(unsigned int i = 0; i < cigarOperations.size(); i++)
401  {
402  if((cigarOperations[i].operation == insert) ||
403  (cigarOperations[i].operation == del))
404  {
405  // Found an indel, so return true.
406  return(true);
407  }
408  }
409  // Went through all the operations, and found no indel, so return false.
410  return(false);
411 }
insertion to the reference (the query sequence contains bases that have no corresponding base in the ...
Definition: Cigar.h:91
deletion from the reference (the reference contains bases that have no corresponding base in the quer...
Definition: Cigar.h:92

◆ isClip() [1/3]

static bool Cigar::isClip ( Operation  op)
inlinestatic

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

Definition at line 261 of file Cigar.h.

References hardClip, and softClip.

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

262  {
263  switch(op)
264  {
265  case softClip:
266  case hardClip:
267  return true;
268  default:
269  return false;
270  }
271  return false;
272  }
Hard clip on the read (clipped sequence not present in the query sequence or reference). Associated with CIGAR Operation "H".
Definition: Cigar.h:95
Soft clip on the read (clipped sequence present in the query sequence, but not in reference)...
Definition: Cigar.h:94

◆ isClip() [2/3]

static bool Cigar::isClip ( char  op)
inlinestatic

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

Definition at line 276 of file Cigar.h.

277  {
278  switch(op)
279  {
280  case 'S':
281  case 'H':
282  return true;
283  default:
284  return false;
285  }
286  return false;
287  }

◆ isClip() [3/3]

static bool Cigar::isClip ( const CigarOperator op)
inlinestatic

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

Definition at line 291 of file Cigar.h.

References isClip().

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

◆ isMatchOrMismatch() [1/2]

static bool Cigar::isMatchOrMismatch ( Operation  op)
inlinestatic

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

Definition at line 298 of file Cigar.h.

References match, and mismatch.

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

299  {
300  switch(op)
301  {
302  case match:
303  case mismatch:
304  return true;
305  default:
306  return false;
307  }
308  return false;
309  }
mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:90
match/mismatch operation. Associated with CIGAR Operation "M"
Definition: Cigar.h:89

◆ isMatchOrMismatch() [2/2]

static bool Cigar::isMatchOrMismatch ( const CigarOperator op)
inlinestatic

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

Definition at line 313 of file Cigar.h.

References isMatchOrMismatch(), and operator<<.

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

◆ 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.

References size().

81 {
82 
83  if (this->size() != rhs.size()) return false;
84 
85  for (int i = 0; i < this->size(); i++)
86  {
87  if (cigarOperations[i]!=rhs.cigarOperations[i]) return false;
88  }
89  return true;
90 }
int size() const
Return the number of cigar operations.
Definition: Cigar.h:364

Member Data Documentation

◆ 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(), hasIndel(), SamQuerySeqWithRef::seqWithEquals(), SamQuerySeqWithRef::seqWithoutEquals(), and SamFilter::softClip().


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