Iterates through the query and compare with reference.
More...
#include <SamQuerySeqWithRefHelper.h>
Iterates through the query and compare with reference.
NOTE: References to the GenomeSequence and SamRecord are stored, the objects are not copied, so they must remain valid as long as this class is used.
Definition at line 58 of file SamQuerySeqWithRefHelper.h.
◆ SamQuerySeqWithRefIter()
| SamQuerySeqWithRefIter::SamQuerySeqWithRefIter |
( |
SamRecord & | record, |
|
|
GenomeSequence & | refSequence, |
|
|
bool | forward = true ) |
Definition at line 24 of file SamQuerySeqWithRefHelper.cpp.
27 : myRecord(record),
28 myRefSequence(refSequence),
29 myCigar(NULL),
30 myStartOfReadOnRefIndex(INVALID_GENOME_INDEX),
31 myQueryIndex(0),
32 myForward(forward)
33{
34 myCigar = myRecord.getCigarInfo();
35 myStartOfReadOnRefIndex =
37
38 if(myStartOfReadOnRefIndex != INVALID_GENOME_INDEX)
39 {
40
41
42 myStartOfReadOnRefIndex += myRecord.get0BasedPosition();
43 }
44
45 if(!forward)
46 {
47 myQueryIndex = myRecord.getReadLength() - 1;
48 }
49}
genomeIndex_t getGenomePosition(const char *chromosomeName, unsigned int chromosomeIndex) const
given a chromosome name and position, return the genome position
◆ ~SamQuerySeqWithRefIter()
| SamQuerySeqWithRefIter::~SamQuerySeqWithRefIter |
( |
| ) |
|
|
virtual |
◆ getNextMatchMismatch()
Returns information for the next position where the query and the reference match or mismatch.
To be a match or mismatch, both the query and reference must have a base that is not 'N'. This means: insertions and deletions are not mismatches or matches. 'N' bases are not matches or mismatches
- Parameters
-
| matchMismatchInfo | return parameter with the information about the matching/mismatching base. |
- Returns
- true if there was another match/mismatch (matchMismatchInfo was set); false if not.
Definition at line 102 of file SamQuerySeqWithRefHelper.cpp.
103{
104
105
106 if(!SamFlag::isMapped(myRecord.getFlag()))
107 {
108
109 return(false);
110 }
111
112
113 if(myCigar == NULL)
114 {
115
116 throw(std::runtime_error("Cannot determine matches/mismatches since failed to retrieve the cigar"));
117 return(false);
118 }
119
120
121
122 if(myStartOfReadOnRefIndex == INVALID_GENOME_INDEX)
123 {
124
125
126 return(false);
127 }
128
129
130
131
132
133
134 while((myQueryIndex < myRecord.getReadLength()) &&
135 (myQueryIndex >= 0))
136 {
137
138
139
140 int32_t refOffset = myCigar->getRefOffset(myQueryIndex);
142 {
143
144
145
146 nextIndex();
147 continue;
148 }
149
150
152 char refBase = myRefSequence[myStartOfReadOnRefIndex + refOffset];
153
154
155
158 {
159
160
161 nextIndex();
162 continue;
163 }
164
165
166
168
169
171 {
172
173 matchMismatchInfo.
setType(SamSingleBaseMatchInfo::MATCH);
174
175 nextIndex();
176 return(true);
177 }
178 else
179 {
180
181 matchMismatchInfo.
setType(SamSingleBaseMatchInfo::MISMATCH);
182
183 nextIndex();
184 return(true);
185 }
186 }
187
188
189 return(false);
190}
static bool isAmbiguous(char base)
Returns whether or not the specified bases is an indicator for ambiguity.
static bool areEqual(char base1, char base2)
Returns whether or not two bases are equal (case insensitive), if one of the bases is '=',...
static const int32_t INDEX_NA
Value associated with an index that is not applicable/does not exist, used for converting between que...
@ NONE
Leave the sequence as is.
void setQueryIndex(int32_t queryIndex)
Set the query index for this object.
void setType(Type newType)
Set the type (match/mismatch/unkown) for this object.
References BaseUtilities::areEqual(), Cigar::INDEX_NA, BaseUtilities::isAmbiguous(), SamRecord::NONE, SamSingleBaseMatchInfo::setQueryIndex(), and SamSingleBaseMatchInfo::setType().
Referenced by SamFilter::clipOnMismatchThreshold(), and SamFilter::sumMismatchQuality().
◆ reset()
| bool SamQuerySeqWithRefIter::reset |
( |
bool | forward = true | ) |
|
Reset to start at the beginning of the record.
This will re-read values from SamRecord, so can be used if it has changed to contain information for a new record.
- Parameters
-
| forward | true means to start from the beginning and go to the end; false means to start from the end and go to the beginning. |
- Returns
- true if successfully reset; false if failed to read the Cigar.
Definition at line 58 of file SamQuerySeqWithRefHelper.cpp.
59{
60 myCigar = myRecord.getCigarInfo();
61 if(myCigar == NULL)
62 {
63
64 return(false);
65 }
66
67
68
69 myStartOfReadOnRefIndex =
70 myRefSequence.getGenomePosition(myRecord.getReferenceName());
71
72 if(myStartOfReadOnRefIndex != INVALID_GENOME_INDEX)
73 {
74
75
76 myStartOfReadOnRefIndex += myRecord.get0BasedPosition();
77 }
78
79 myForward = forward;
80
81 if(myForward)
82 {
83 myQueryIndex = 0;
84 }
85 else
86 {
87
88 myQueryIndex = myRecord.getReadLength() - 1;
89 }
90 return(true);
91}
The documentation for this class was generated from the following files: