21 #include "STLUtilities.h" 40 std::vector<CigarOperator>::const_iterator i;
46 for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
48 cigarString << (*i).count << (*i).getChar();
58 cigarString = cigar.c_str();
67 std::vector<CigarOperator>::const_iterator i;
72 for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
74 for (uint32_t j = 0; j<(*i).count; j++) s += (*i).getChar();
83 if (this->
size() != rhs.
size())
return false;
85 for (
int i = 0; i < this->
size(); i++)
87 if (cigarOperations[i]!=rhs.cigarOperations[i])
return false;
98 std::vector<CigarOperator>::const_iterator i;
99 for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
101 switch (i->operation)
107 matchCount += i->count;
123 std::vector<CigarOperator>::const_iterator i;
124 for (i = cigarOperations.begin(); i != cigarOperations.end(); i++)
126 switch (i->operation)
132 matchCount += i->count;
146 int numBeginClips = 0;
147 for (
unsigned int i = 0; i != cigarOperations.size(); i++)
149 if ((cigarOperations[i].operation ==
softClip) ||
150 (cigarOperations[i].operation ==
hardClip))
153 numBeginClips += cigarOperations[i].count;
161 return(numBeginClips);
169 for (
int i = (cigarOperations.size() - 1); i >= 0; i--)
171 if ((cigarOperations[i].operation ==
softClip) ||
172 (cigarOperations[i].operation ==
hardClip))
175 numEndClips += cigarOperations[i].count;
190 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
192 setQueryAndReferenceIndexes();
194 if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToRef.size()))
198 return(queryToRef[queryIndex]);
205 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
207 setQueryAndReferenceIndexes();
209 if ((refOffset < 0) || ((uint32_t)refOffset >= refToQuery.size()))
213 return(refToQuery[refOffset]);
220 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
222 setQueryAndReferenceIndexes();
224 if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToRef.size()))
229 if (queryToRef[queryIndex] !=
INDEX_NA)
231 return(queryToRef[queryIndex] + queryStartPos);
243 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
245 setQueryAndReferenceIndexes();
248 int32_t refOffset = refPosition - queryStartPos;
249 if ((refOffset < 0) || ((uint32_t)refOffset >= refToQuery.size()))
254 return(refToQuery[refOffset]);
261 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
263 setQueryAndReferenceIndexes();
265 if ((queryIndex < 0) || ((uint32_t)queryIndex >= queryToCigar.size()))
269 return(queryToCigar[queryIndex]);
276 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
278 setQueryAndReferenceIndexes();
280 if ((refOffset < 0) || ((uint32_t)refOffset >= refToCigar.size()))
284 return(refToCigar[refOffset]);
289 int32_t queryStartPos)
298 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
301 setQueryAndReferenceIndexes();
305 if((expandedCigarIndex < 0) ||
306 ((uint32_t)expandedCigarIndex >= myExpandedCigar.length()))
310 return(myExpandedCigar[expandedCigarIndex]);
335 int32_t queryStartPos)
338 if ((queryToRef.size() == 0) || (refToQuery.size() == 0))
340 setQueryAndReferenceIndexes();
344 int32_t startRefOffset = 0;
349 if (start > queryStartPos)
351 startRefOffset = start - queryStartPos;
354 int32_t endRefOffset = end - queryStartPos;
360 endRefOffset = refToQuery.size();
366 if (endRefOffset < 0)
374 int32_t refOffset = 0;
375 int32_t numOverlaps = 0;
376 for (
unsigned int queryIndex = 0; queryIndex < queryToRef.size();
380 if (refOffset > endRefOffset)
386 else if ((refOffset >= startRefOffset) && (refOffset < endRefOffset))
400 for(
unsigned int i = 0; i < cigarOperations.size(); i++)
402 if((cigarOperations[i].operation ==
insert) ||
403 (cigarOperations[i].operation ==
del))
415 void Cigar::clearQueryAndReferenceIndexes()
420 queryToCigar.clear();
421 myExpandedCigar.clear();
441 void Cigar::setQueryAndReferenceIndexes()
444 clearQueryAndReferenceIndexes();
449 for (uint32_t cigarIndex = 0; cigarIndex < cigarOperations.size(); cigarIndex++)
452 switch (cigarOperations[cigarIndex].operation)
458 for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
462 int32_t queryToRefLen = queryToRef.size();
463 int32_t refToQueryLen = refToQuery.size();
464 queryToRef.push_back(refToQueryLen);
465 refToQuery.push_back(queryToRefLen);
466 refToCigar.push_back(extPos);
467 queryToCigar.push_back(extPos++);
468 myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
475 for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
478 queryToCigar.push_back(extPos++);
479 myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
486 for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
489 refToCigar.push_back(extPos++);
490 myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
496 for (uint32_t i = 0; i < cigarOperations[cigarIndex].count; i++)
498 myExpandedCigar.push_back(cigarOperations[cigarIndex].getChar());
int32_t getExpandedCigarIndexFromQueryIndex(int32_t queryIndex)
Returns the index into the expanded cigar for the cigar associated with the specified queryIndex...
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 cig...
insertion to the reference (the query sequence contains bases that have no corresponding base in the ...
Padding (not in reference or query). Associated with CIGAR Operation "P".
int getNumEndClips() const
Return the number of clips that are at the end of the cigar.
skipped region from the reference (the reference contains bases that have no corresponding base in th...
no operation has been set.
int size() const
Return the number of cigar operations.
int getNumBeginClips() const
Return the number of clips that are at the beginning of the cigar.
static const int32_t INDEX_NA
Value associated with an index that is not applicable/does not exist, used for converting between que...
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 fa...
This file is inspired by the poor quality of string support in STL for what should be trivial capabil...
char getCigarCharOp(int32_t expandedCigarIndex)
Return the character code of the cigar operator associated with the specified expanded CIGAR index...
Hard clip on the read (clipped sequence not present in the query sequence or reference). Associated with CIGAR Operation "H".
bool operator==(Cigar &rhs) const
Return true if the 2 Cigars are the same (the same operations of the same sizes). ...
void getCigarString(String &cigarString) const
Set the passed in String to the string reprentation of the Cigar operations in this object...
This class represents the CIGAR without any methods to set the cigar (see CigarRoller for that)...
int32_t getRefOffset(int32_t queryIndex)
Return the reference offset associated with the specified query index or INDEX_NA based on this cigar...
char getCigarCharOpFromRefPos(int32_t refPosition, int32_t queryStartPos)
Return the character code of the cigar operator associated with the specified reference position...
mismatch operation. Associated with CIGAR Operation "M"
bool hasIndel()
Return whether or not the cigar has indels (insertions or delections)
void getExpandedString(std::string &s) const
Sets the specified string to a valid CIGAR string of characters that represent the cigar with no digi...
int getExpectedReferenceBaseCount() const
Return the number of bases in the reference that this CIGAR "spans".
Soft clip on the read (clipped sequence present in the query sequence, but not in reference)...
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...
match/mismatch operation. Associated with CIGAR Operation "M"
int32_t getQueryIndex(int32_t refOffset)
Return the query index associated with the specified reference offset or INDEX_NA based on this cigar...
deletion from the reference (the reference contains bases that have no corresponding base in the quer...
int getExpectedQueryBaseCount() const
Return the length of the read that corresponds to the current CIGAR string.
char getCigarCharOpFromQueryIndex(int32_t queryIndex)
Return the character code of the cigar operator associated with the specified queryIndex.
char getCigarCharOpFromRefOffset(int32_t refOffset)
Return the character code of the cigar operator associated with the specified reference offset...
int32_t getExpandedCigarIndexFromRefOffset(int32_t refOffset)
Returns the index into the expanded cigar for the cigar associated with the specified reference offse...