libStatGen Software 1
IndexBase Class Referenceabstract
Inheritance diagram for IndexBase:
Collaboration diagram for IndexBase:

Classes

class  Bin
 
class  Reference
 

Public Member Functions

virtual void resetIndex ()
 Reset the member data for a new index file. More...
 
virtual StatGenStatus::Status readIndex (const char *filename)=0
 
int32_t getNumRefs () const
 Get the number of references in this index. More...
 
bool getMinOffsetFromLinearIndex (int32_t refID, uint32_t position, uint64_t &minOffset) const
 

Static Protected Member Functions

static void getBinsForRegion (uint32_t start, uint32_t end, bool binMap[MAX_NUM_BINS+1])
 

Protected Attributes

int32_t n_ref
 
std::vector< ReferencemyRefs
 

Static Protected Attributes

static const uint32_t MAX_NUM_BINS = 37450
 
static const uint32_t MAX_POSITION = 536870911
 
static const uint32_t LINEAR_INDEX_SHIFT = 14
 

Detailed Description

Definition at line 62 of file IndexBase.h.

Constructor & Destructor Documentation

◆ IndexBase()

IndexBase::IndexBase ( )

Definition at line 116 of file IndexBase.cpp.

117 : n_ref(0)
118{
119 myRefs.clear();
120}

◆ ~IndexBase()

IndexBase::~IndexBase ( )
virtual

Definition at line 124 of file IndexBase.cpp.

125{
126}

Member Function Documentation

◆ getBinsForRegion()

void IndexBase::getBinsForRegion ( uint32_t  start,
uint32_t  end,
bool  binMap[MAX_NUM_BINS+1] 
)
staticprotected

Definition at line 148 of file IndexBase.cpp.

149{
150 for(uint32_t index = 0; index < MAX_NUM_BINS+1; index++)
151 {
152 binMap[index] = false;
153 }
154
155 uint32_t binNum = 0;
156 --end;
157
158 // Check if beg/end go too high, set to max position.
159 if(start > MAX_POSITION)
160 {
161 start = MAX_POSITION;
162 }
163 if(end > MAX_POSITION)
164 {
165 end = MAX_POSITION;
166 }
167
168 // Turn on bins.
169 binMap[binNum] = true;
170 for (binNum = 1 + (start>>26); binNum <= 1 + (end>>26); ++binNum)
171 binMap[binNum] = true;
172 for (binNum = 9 + (start>>23); binNum <= 9 + (end>>23); ++binNum)
173 binMap[binNum] = true;
174 for (binNum = 73 + (start>>20); binNum <= 73 + (end>>20); ++binNum)
175 binMap[binNum] = true;
176 for (binNum = 585 + (start>>17); binNum <= 585 + (end>>17); ++binNum)
177 binMap[binNum] = true;
178 for (binNum = 4681 + (start>>14); binNum <= 4681 + (end>>14); ++binNum)
179 binMap[binNum] = true;
180}

◆ getMinOffsetFromLinearIndex()

bool IndexBase::getMinOffsetFromLinearIndex ( int32_t  refID,
uint32_t  position,
uint64_t &  minOffset 
) const

Definition at line 185 of file IndexBase.cpp.

187{
188 int32_t linearIndex = position >> LINEAR_INDEX_SHIFT;
189
190 minOffset = 0;
191
192 if(refID > n_ref)
193 {
194 // out of range of the references, return false.
195 return(false);
196 }
197 // Check to see if the position is out of range of the linear index.
198 int32_t linearOffsetSize = myRefs[refID].n_intv;
199
200 // If there are no entries in the linear index, return false.
201 // Or if the linear index is not large enough to include
202 // the start block, then there can be no records that cross
203 // our region, so return false.
204 if((linearOffsetSize == 0) || (linearIndex >= linearOffsetSize))
205
206 {
207 return(false);
208 }
209
210 // The linear index is specified for this block, so return that value.
211 minOffset = myRefs[refID].ioffsets[linearIndex];
212
213 // If the offset is 0, go to the previous block that has an offset.
214 // This is due to a couple of bugs in older sam tools indexes.
215 // 1) they add one to the index location (so when reading those, you
216 // may be starting earlier than necessary)
217 // 2) (the bigger issue) They did not include bins 4681-37449 in
218 // the linear index.
219 while((minOffset == 0) && (--linearIndex >= 0))
220 {
221 minOffset = myRefs[refID].ioffsets[linearIndex];
222 }
223
224
225 // If the minOffset is still 0 when moving forward,
226 // check later indices to find a non-zero since we don't want to return
227 // an offset of 0 since the record can't start at 0 we want to at least
228 // return the first record position for this reference.
229 linearIndex = 0;
230 while((minOffset == 0) && (linearIndex < linearOffsetSize))
231 {
232 minOffset = myRefs[refID].ioffsets[linearIndex];
233 linearIndex++;
234 }
235 if(minOffset == 0)
236 {
237 // Could not find a valid start position for this reference.
238 return(false);
239 }
240 return(true);
241}

◆ getNumRefs()

int32_t IndexBase::getNumRefs ( ) const

Get the number of references in this index.

Returns
number of references

Definition at line 139 of file IndexBase.cpp.

140{
141 // Return the number of references.
142 return(myRefs.size());
143}

◆ readIndex()

virtual StatGenStatus::Status IndexBase::readIndex ( const char *  filename)
pure virtual
Parameters
filenamethe bam index file to be read.
Returns
the status of the read.

Implemented in BamIndex, and Tabix.

◆ resetIndex()

void IndexBase::resetIndex ( )
virtual

Reset the member data for a new index file.

Reimplemented in BamIndex, and Tabix.

Definition at line 130 of file IndexBase.cpp.

131{
132 n_ref = 0;
133 // Clear the references.
134 myRefs.clear();
135}

Referenced by BamIndex::resetIndex(), and Tabix::resetIndex().

Member Data Documentation

◆ LINEAR_INDEX_SHIFT

const uint32_t IndexBase::LINEAR_INDEX_SHIFT = 14
staticprotected

Definition at line 95 of file IndexBase.h.

◆ MAX_NUM_BINS

const uint32_t IndexBase::MAX_NUM_BINS = 37450
staticprotected

Definition at line 87 of file IndexBase.h.

◆ MAX_POSITION

const uint32_t IndexBase::MAX_POSITION = 536870911
staticprotected

Definition at line 91 of file IndexBase.h.

◆ myRefs

std::vector<Reference> IndexBase::myRefs
protected

Definition at line 161 of file IndexBase.h.

◆ n_ref

int32_t IndexBase::n_ref
protected

Definition at line 158 of file IndexBase.h.


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