18 #include "WriteFiles.h" 26 writeTest.testWrite();
29 const std::string TestWrite::HEADER_TEXT1 =
"This is my 1st test header.";
30 const std::string TestWrite::SEC1_REFNAME =
"This is my 1st RefName";
31 const std::string TestWrite::SEC1REC2_INDELSEQ1 =
"AC";
32 const std::string TestWrite::SEC1REC2_INDELSEQ2 =
"TCA";
33 const std::string TestWrite::SEC2_REFNAME =
"This is my 2nd RefName";
34 const std::string TestWrite::HEADER_TEXT2 =
"This is my 2nd test header.";
35 const std::string TestWrite::HEADER_TEXT3 =
"This is my 3rd test header.";
37 void TestWrite::testWrite()
41 std::string testFile =
"results/MyTestOut1.glf";
51 bool caughtException =
false;
56 catch (std::exception& e)
58 caughtException =
true;
60 assert(caughtException);
63 caughtException =
false;
68 catch (std::exception& e)
70 caughtException =
true;
72 assert(caughtException);
75 writeHeader(glfOut, 1);
78 caughtException =
false;
83 catch (std::exception& e)
85 caughtException =
true;
87 assert(caughtException);
91 writeRefSection1(glfOut);
94 caughtException =
false;
99 catch (std::exception& e)
101 caughtException =
true;
103 assert(caughtException);
105 writeSec1Record1(glfOut);
107 caughtException =
false;
112 catch (std::exception& e)
114 caughtException =
true;
116 assert(caughtException);
118 writeSec1Record2(glfOut);
119 writeEndMarker(glfOut);
121 writeRefSection2(glfOut);
122 writeSec2Record1(glfOut);
123 writeEndMarker(glfOut);
134 readHeader(glfIn, 1);
135 readRefSection1(glfIn);
136 readSec1Record1(glfIn);
137 readSec1Record2(glfIn);
138 readEndMarker(glfIn);
139 readRefSection2(glfIn);
140 readSec2Record1(glfIn);
141 readEndMarker(glfIn);
146 testFile =
"results/MyTestOut2.glf";
149 writeHeader(glfOut, 2);
150 writeRefSection1(glfOut);
151 writeSec1Record1(glfOut);
152 writeSec1Record2(glfOut);
154 writeRefSection2(glfOut);
155 writeSec2Record1(glfOut);
163 readHeader(glfIn, 2);
164 readRefSection1(glfIn);
165 readSec1Record1(glfIn);
166 readSec1Record2(glfIn);
167 readEndMarker(glfIn);
168 readRefSection2(glfIn);
169 readSec2Record1(glfIn);
170 readEndMarker(glfIn);
176 testFile =
"results/MyTestOut3.glf";
181 writeHeader(glfOutScoped, 3);
182 writeRefSection1(glfOutScoped);
183 writeSec1Record1(glfOutScoped);
184 writeSec1Record2(glfOutScoped);
186 writeRefSection2(glfOutScoped);
187 writeSec2Record1(glfOutScoped);
196 caughtException =
false;
201 catch (std::exception& e)
203 caughtException =
true;
205 assert(caughtException);
208 caughtException =
false;
213 catch (std::exception& e)
215 caughtException =
true;
217 assert(caughtException);
219 readHeader(glfIn, 3);
222 caughtException =
false;
227 catch (std::exception& e)
229 caughtException =
true;
231 assert(caughtException);
234 caughtException =
false;
239 catch (std::exception& e)
241 caughtException =
true;
243 assert(caughtException);
245 readRefSection1(glfIn);
246 readSec1Record1(glfIn);
247 readSec1Record2(glfIn);
248 readEndMarker(glfIn);
249 readRefSection2(glfIn);
250 readSec2Record1(glfIn);
251 readEndMarker(glfIn);
259 readHeader(glfIn, 3);
260 readRefSection1(glfIn);
261 readRefSection2(glfIn);
262 readSec2Record1(glfIn);
263 readEndMarker(glfIn);
270 void TestWrite::writeHeader(
GlfFile& glfOut,
int headerNum)
273 std::string headerString =
"t";
274 std::string expectedHeader =
"";
277 expectedHeader = HEADER_TEXT1;
279 else if(headerNum == 2)
281 expectedHeader = HEADER_TEXT2;
283 else if(headerNum == 3)
285 expectedHeader = HEADER_TEXT3;
289 assert(headerString ==
"");
292 assert(headerString == expectedHeader);
297 void TestWrite::writeRefSection1(
GlfFile& glfOut)
303 std::string refNameString =
"";
305 assert(glfSection.
getName(refNameString));
306 assert(refNameString ==
"");
310 assert(glfSection.
setName(SEC1_REFNAME));
312 assert(glfSection.
getName(refNameString));
313 assert(refNameString == SEC1_REFNAME);
317 assert(glfSection.
setRefLen(SEC1_REFLEN));
319 assert(glfSection.
getRefLen() == SEC1_REFLEN);
320 assert(glfSection.
getName(refNameString));
321 assert(refNameString == SEC1_REFNAME);
328 void TestWrite::writeSec1Record1(
GlfFile& glfOut)
333 assert(record.
setOffset(SEC1REC1_OFFSET));
334 assert(record.
setMinLk(SEC1REC1_MINLK));
341 assert(record.
getRefBase() == SEC1REC1_REFBASE);
342 assert(record.
getOffset() == SEC1REC1_OFFSET);
343 assert(record.
getMinLk() == SEC1REC1_MINLK);
345 assert(record.
getRmsMapQ() == SEC1REC1_RMSMAPQ);
349 void TestWrite::writeSec1Record2(
GlfFile& glfOut)
357 assert(record.
setOffset(SEC1REC2_OFFSET));
358 assert(record.
setMinLk(SEC1REC2_MINLK));
361 assert(record.
setLkHom1(SEC1REC2_LKHOM1));
362 assert(record.
setLkHom2(SEC1REC2_LKHOM2));
363 assert(record.
setLkHet(SEC1REC2_LKHET));
369 std::string indelSeq =
"";
371 assert(record.
getRefBase() == SEC1REC2_REFBASE);
372 assert(record.
getOffset() == SEC1REC2_OFFSET);
373 assert(record.
getMinLk() == SEC1REC2_MINLK);
375 assert(record.
getRmsMapQ() == SEC1REC2_RMSMAPQ);
376 assert(record.
getLkHom1() == SEC1REC2_LKHOM1);
377 assert(record.
getLkHom2() == SEC1REC2_LKHOM2);
378 assert(record.
getLkHet() == SEC1REC2_LKHET);
379 assert(record.
getIndel1(indelSeq) == SEC1REC2_INDELLEN1);
380 assert(indelSeq == SEC1REC2_INDELSEQ1);
381 assert(record.
getIndel2(indelSeq) == SEC1REC2_INDELLEN2);
382 assert(indelSeq == SEC1REC2_INDELSEQ2);
386 void TestWrite::writeEndMarker(
GlfFile& glfOut)
399 void TestWrite::writeRefSection2(
GlfFile& glfOut)
405 std::string refNameString =
"";
407 assert(glfSection.
getName(refNameString));
408 assert(refNameString ==
"");
412 assert(glfSection.
setName(SEC2_REFNAME));
414 assert(glfSection.
getName(refNameString));
415 assert(refNameString == SEC2_REFNAME);
419 assert(glfSection.
setRefLen(SEC2_REFLEN));
421 assert(glfSection.
getRefLen() == SEC2_REFLEN);
422 assert(glfSection.
getName(refNameString));
423 assert(refNameString == SEC2_REFNAME);
430 void TestWrite::writeSec2Record1(
GlfFile& glfOut)
435 assert(record.
setOffset(SEC2REC1_OFFSET));
436 assert(record.
setMinLk(SEC2REC1_MINLK));
443 assert(record.
getRefBase() == SEC2REC1_REFBASE);
444 assert(record.
getOffset() == SEC2REC1_OFFSET);
445 assert(record.
getMinLk() == SEC2REC1_MINLK);
447 assert(record.
getRmsMapQ() == SEC2REC1_RMSMAPQ);
451 void TestWrite::readHeader(
GlfFile& glfIn,
int headerNum)
454 std::string expectedHeader =
"";
455 std::string headerString;
458 expectedHeader = HEADER_TEXT1;
460 else if(headerNum == 2)
462 expectedHeader = HEADER_TEXT2;
464 else if(headerNum == 3)
466 expectedHeader = HEADER_TEXT3;
471 assert(headerString == expectedHeader);
474 void TestWrite::readRefSection1(
GlfFile& glfIn)
477 std::string refNameString;
480 assert(glfSection.
getName(refNameString));
481 assert(refNameString == SEC1_REFNAME);
482 assert(glfSection.
getRefLen() == SEC1_REFLEN);
485 void TestWrite::readSec1Record1(
GlfFile& glfIn)
491 assert(record.
getRefBase() == SEC1REC1_REFBASE);
492 assert(record.
getOffset() == SEC1REC1_OFFSET);
493 assert(record.
getMinLk() == SEC1REC1_MINLK);
495 assert(record.
getRmsMapQ() == SEC1REC1_RMSMAPQ);
498 void TestWrite::readSec1Record2(
GlfFile& glfIn)
501 std::string indelSeq;
505 assert(record.
getRefBase() == SEC1REC2_REFBASE);
506 assert(record.
getOffset() == SEC1REC2_OFFSET);
507 assert(record.
getMinLk() == SEC1REC2_MINLK);
509 assert(record.
getRmsMapQ() == SEC1REC2_RMSMAPQ);
510 assert(record.
getLkHom1() == SEC1REC2_LKHOM1);
511 assert(record.
getLkHom2() == SEC1REC2_LKHOM2);
512 assert(record.
getLkHet() == SEC1REC2_LKHET);
513 assert(record.
getIndel1(indelSeq) == SEC1REC2_INDELLEN1);
514 assert(indelSeq == SEC1REC2_INDELSEQ1);
515 assert(record.
getIndel2(indelSeq) == SEC1REC2_INDELLEN2);
516 assert(indelSeq == SEC1REC2_INDELSEQ2);
519 void TestWrite::readEndMarker(
GlfFile& glfIn)
529 void TestWrite::readRefSection2(
GlfFile& glfIn)
532 std::string refNameString;
535 assert(glfSection.
getName(refNameString));
536 assert(refNameString == SEC2_REFNAME);
537 assert(glfSection.
getRefLen() == SEC2_REFLEN);
541 void TestWrite::readSec2Record1(
GlfFile& glfIn)
547 assert(record.
getRefBase() == SEC2REC1_REFBASE);
548 assert(record.
getOffset() == SEC2REC1_OFFSET);
549 assert(record.
getMinLk() == SEC2REC1_MINLK);
551 assert(record.
getRmsMapQ() == SEC2REC1_RMSMAPQ);
554 void TestWrite::checkEOF(
GlfFile& glfIn)
561 assert(glfIn.
isEOF());
bool isEOF()
Returns whether or not the end of the file has been reached.
uint32_t getReadDepth() const
Return the read depth.
bool setOffset(uint32_t offset)
Set the offset from the precedent record.
uint8_t getLkHet()
Return the likelihood of a heterozygote.
bool setRefBaseInt(uint8_t refBase)
Set the reference base from an integer value.
bool openForWrite(const char *filename, bool compressed=true)
Open a glf file for writing with the specified filename.
uint32_t getRefLen() const
Get the length of the reference sequence.
This class allows a user to easily get/set the fields in a GLF section/chromosome header...
int16_t getIndel1(std::string &indelSeq)
Get the sequence and length (+:ins, -:del) of the 1st indel allele.
bool setRecordType(uint8_t recType)
Set the record type.
bool setLkHom2(uint8_t lk)
Set the likelihood of the 2nd homozygous indel allele.
int getRefBase() const
Return the reference base as an integer.
void close()
Close the file if there is one open, adding an end marker record if there is a previous section and o...
bool getNextRecord(GlfRecord &record)
Gets the nextrecord from the file & stores it in the passed in record.
uint32_t getOffset() const
Return the offset from the precedent record.
bool openForRead(const char *filename)
Open a glf file for reading with the specified filename.
bool setName(const std::string &name)
Set the reference name.
This class allows a user to easily get/set the fields in a GLF record.
bool writeRefSection(const GlfRefSection &refSection)
Write the reference section to the file, adding an end marker record if there is a previous section a...
bool setLkHom1(uint8_t lk)
Set the likelihood of the first homozygous indel allele.
bool getNextRefSection(GlfRefSection &refSection)
Gets the next reference section from the file & stores it in the passed in section, consuming records until a new section is found.
uint8_t getLkHom2()
Return the likelihood of the 2nd homozygous indel allele.
bool setReadDepth(uint32_t readDepth)
Set the the read depth.
bool setDeletionIndel2(const std::string &indelSeq)
Set the sequence of the 2nd indel allele if the 2nd indel is an deletion.
uint8_t getMinLk() const
Return the minimum likelihood.
int getRecordType() const
Return the record type.
This class allows a user to easily read/write a GLF file.
bool setMinLk(uint8_t minLk)
Set the minimum likelihood.
bool setRefLen(uint32_t refLen)
Set the length of the reference sequence.
uint8_t getRmsMapQ() const
Return the RMS of mapping qualities of reads covering the site.
bool setRmsMapQ(uint8_t rmsMapQ)
Set the RMS of mapping qualities of reads covering the site.
bool readHeader(GlfHeader &header)
Reads the header section from the file and stores it in the passed in header.
bool setLkHet(uint8_t lk)
Set the likelihood of a heterozygote.
bool getName(std::string &name) const
Get the reference name.
bool writeHeader(GlfHeader &header)
Writes the specified header into the file.
uint8_t getLkHom1()
Return the likelihood of the 1st homozygous indel allele.
int16_t getIndel2(std::string &indelSeq)
Get the sequence and length (+:ins, -:del) of the 2nd indel allele.
bool setInsertionIndel1(const std::string &indelSeq)
Set the sequence of the first indel allele if the first indel is an insertion.
bool writeRecord(const GlfRecord &record)
Writes the specified record into the file.