19 #include "TestValidate.h"
20 #include "BamIndexTest.h"
26 #ifdef __ZLIB_AVAILABLE__
44 assert(!chunkList.empty());
45 testChunk = chunkList.pop();
46 assert(chunkList.empty());
47 assert(testChunk.chunk_beg == 0x4e7);
48 assert(testChunk.chunk_end == 0x599);
52 assert(!chunkList.empty());
53 testChunk = chunkList.pop();
54 assert(chunkList.empty());
55 assert(testChunk.chunk_beg == 0x360);
56 assert(testChunk.chunk_end == 0x4e7);
61 assert(!chunkList.empty());
62 testChunk = chunkList.pop();
63 assert(chunkList.empty());
64 assert(testChunk.chunk_beg == 0x599);
65 assert(testChunk.chunk_end == 0x5ea);
71 assert(chunkList.empty());
75 assert(inFile.
OpenForRead(
"testFiles/sortedBam.bam"));
77 assert(inFile.
ReadBamIndex(
"testFiles/sortedBam.bam.bai"));
111 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
114 assert(inFile.
ReadRecord(samHeader, samRecord));
115 validateRead2(samRecord);
116 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
121 assert(inFile.
ReadRecord(samHeader, samRecord));
122 validateRead8(samRecord);
123 assert(inFile.
ReadRecord(samHeader, samRecord));
124 validateRead10(samRecord);
125 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
130 assert(inFile.
ReadRecord(samHeader, samRecord));
131 validateRead9(samRecord);
132 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
137 assert(inFile.
ReadRecord(samHeader, samRecord));
138 validateRead3(samRecord);
139 assert(inFile.
ReadRecord(samHeader, samRecord));
140 validateRead4(samRecord);
141 assert(inFile.
ReadRecord(samHeader, samRecord));
142 validateRead1(samRecord);
143 assert(inFile.
ReadRecord(samHeader, samRecord));
144 validateRead2(samRecord);
145 assert(inFile.
ReadRecord(samHeader, samRecord));
146 validateRead6(samRecord);
147 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
152 assert(inFile.
ReadRecord(samHeader, samRecord));
153 validateRead5(samRecord);
154 assert(inFile.
ReadRecord(samHeader, samRecord));
155 validateRead7(samRecord);
156 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
159 for(
int i = 3; i < 23; i++)
162 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
168 assert(inFile.
ReadRecord(samHeader, samRecord));
169 validateRead1(samRecord);
175 assert(inFile.
ReadRecord(samHeader, samRecord));
176 validateRead2(samRecord);
182 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
185 assert(inFile.
ReadRecord(samHeader, samRecord));
186 validateRead1(samRecord);
192 assert(inFile.
ReadRecord(samHeader, samRecord));
193 validateRead2(samRecord);
199 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
202 assert(inFile.
ReadRecord(samHeader, samRecord));
203 validateRead1(samRecord);
209 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
212 assert(inFile.
ReadRecord(samHeader, samRecord));
213 validateRead1(samRecord);
219 assert(inFile.
ReadRecord(samHeader, samRecord));
220 validateRead2(samRecord);
226 assert(inFile.
ReadRecord(samHeader, samRecord) ==
false);
234 #ifdef __ZLIB_AVAILABLE__
237 bamIndex.
readIndex(
"testFiles/sortedBam.bam.bai");
241 bool caughtException =
false;
248 catch (std::exception& e)
250 caughtException =
true;
251 assert(strcmp(e.what(),
"FAIL_ORDER: Failed to read the bam Index file - the BAM file needs to be read first in order to determine the index filename.") == 0);
254 assert(caughtException);
257 assert(test1.
ReadBamIndex(
"testFiles/sortedBam.bam.bai"));
258 BamIndex* index = test1.getBamIndex();
259 assert(index != NULL);
263 assert(test1.
OpenForRead(
"testFiles/sortedBam.bam"));
267 index = test1.getBamIndex();
268 assert(index != NULL);
273 assert(test1.
OpenForRead(
"testFiles/sortedBam2.bam"));
277 index = test1.getBamIndex();
278 assert(index != NULL);
bool getChunksForRegion(int32_t refID, int32_t start, int32_t end, SortedChunkList &chunkList)
Get the list of chunks associated with this region.
int32_t getNumMappedReads(int32_t refID)
Get the number of mapped reads for this reference id.
SamStatus::Status readIndex(const char *filename)
int32_t getNumUnMappedReads(int32_t refID)
Get the number of unmapped reads for this reference id.
Allows the user to easily read/write a SAM/BAM file.
bool ReadHeader(SamFileHeader &header)
Reads the header section from the file and stores it in the passed in header.
int32_t getNumUnMappedReadsFromIndex(int32_t refID)
Get the number of unmapped reads in the specified reference id.
bool SetReadSection(int32_t refID)
Sets which reference id (index into the BAM list of reference information) of the BAM file should be ...
@ COORDINATE
file is sorted by coordinate.
bool ReadRecord(SamFileHeader &header, SamRecord &record)
Reads the next record from the file & stores it in the passed in record.
uint32_t GetNumOverlaps(SamRecord &samRecord)
Returns the number of bases in the passed in read that overlap the region that is currently set.
bool OpenForRead(const char *filename, SamFileHeader *header=NULL)
Open a sam/bam file for reading with the specified filename, determing the type of file and SAM/BAM b...
int32_t getNumMappedReadsFromIndex(int32_t refID)
Get the number of mapped reads in the specified reference id.
bool ReadBamIndex(const char *filename)
Read the specified bam index file.
void setSortedValidation(SortedType sortType)
Set the flag to validate that the file is sorted as it is read/written.
Class providing an easy to use interface to get/set/operate on the fields in a SAM/BAM record.
uint32_t getNumOverlaps(int32_t start, int32_t end)
Return the number of bases in this read that overlap the passed in region.