This class allows a user to easily get/set the fields in a GLF record. More...
#include <GlfRecord.h>
Public Member Functions | |
GlfRecord () | |
Constructor. | |
~GlfRecord () | |
Destructor. | |
void | reset () |
Clear this record back to the default setting. | |
bool | read (IFILE filePtr) |
Read the record from the specified file (file MUST be in the correct position for reading a record). | |
bool | write (IFILE filePtr) const |
Write the record to the specified file. | |
void | print () const |
Print the reference section in a readable format. | |
Generic Accessors for Record Types 1 & 2 | |
bool | setRtypeRef (uint8_t rtypeRef) |
Set the record type and reference base. | |
bool | setRecordType (uint8_t recType) |
Set the record type. | |
bool | setRefBaseInt (uint8_t refBase) |
Set the reference base from an integer value. | |
bool | setOffset (uint32_t offset) |
Set the offset from the precedent record. | |
bool | setMinDepth (uint32_t minDepth) |
Set the minimum likelihood and the read depth. | |
bool | setMinLk (uint8_t minLk) |
Set the minimum likelihood. | |
bool | setReadDepth (uint32_t readDepth) |
Set the the read depth. | |
bool | setRmsMapQ (uint8_t rmsMapQ) |
Set the RMS of mapping qualities of reads covering the site. | |
int | getRecordType () const |
Return the record type. | |
int | getRefBase () const |
Return the reference base as an integer. | |
char | getRefBaseChar () const |
Return the reference base as a character. | |
uint32_t | getOffset () |
Return the offset from the precedent record. | |
uint32_t | getMinDepth () |
Return the minimum likelihood and read depth. | |
uint8_t | getMinLk () |
Return the minimum likelihood. | |
uint32_t | getReadDepth () |
Return the read depth. | |
uint8_t | getRmsMapQ () |
Return the RMS of mapping qualities of reads covering the site. | |
Record Type 1 Accessors | |
bool | setLk (int index, uint8_t value) |
Set the likelihood for the specified genotype. | |
uint8_t | getLk (int index) |
Get the likelihood for the specified genotype index. | |
Record Type 2 Accessors | |
bool | setLkHom1 (uint8_t lk) |
Set the likelihood of the first homozygous indel allele. | |
bool | setLkHom2 (uint8_t lk) |
Set the likelihood of the 2nd homozygous indel allele. | |
bool | setLkHet (uint8_t lk) |
Set the likelihood of a heterozygote. | |
bool | setInsertionIndel1 (const std::string &indelSeq) |
Set the sequence of the first indel allele if the first indel is an insertion. | |
bool | setDeletionIndel1 (const std::string &indelSeq) |
Set the sequence of the first indel allele if the first indel is an deletion. | |
bool | setInsertionIndel2 (const std::string &indelSeq) |
Set the sequence of the 2nd indel allele if the 2nd indel is an insertion. | |
bool | setDeletionIndel2 (const std::string &indelSeq) |
Set the sequence of the 2nd indel allele if the 2nd indel is an deletion. | |
uint8_t | getLkHom1 () |
Return the likelihood of the 1st homozygous indel allele. | |
uint8_t | getLkHom2 () |
Return the likelihood of the 2nd homozygous indel allele. | |
uint8_t | getLkHet () |
Return the likelihood of a heterozygote. | |
int16_t | getIndel1 (std::string &indelSeq) |
Get the sequence and length (+:ins, -:del) of the 1st indel allele. | |
int16_t | getIndel2 (std::string &indelSeq) |
Get the sequence and length (+:ins, -:del) of the 2nd indel allele. |
This class allows a user to easily get/set the fields in a GLF record.
Definition at line 28 of file GlfRecord.h.
int16_t GlfRecord::getIndel1 | ( | std::string & | indelSeq | ) |
Get the sequence and length (+:ins, -:del) of the 1st indel allele.
indelSeq | string to set with the sequence of the 1st indel allele |
Definition at line 453 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00454 { 00455 if(getRecordType() != 2) 00456 { 00457 throw(GlfException(GlfStatus::UNKNOWN, 00458 "Tried to call getIndel1 for Record not of type 2.")); 00459 return(0); 00460 } 00461 indelSeq = myIndelSeq1.c_str(); 00462 return(myRec2Base.indelLen1); 00463 }
int16_t GlfRecord::getIndel2 | ( | std::string & | indelSeq | ) |
Get the sequence and length (+:ins, -:del) of the 2nd indel allele.
indelSeq | string to set with the sequence of the 2nd indel allele |
Definition at line 465 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00466 { 00467 if(getRecordType() != 2) 00468 { 00469 throw(GlfException(GlfStatus::UNKNOWN, 00470 "Tried to call getIndel2 for Record not of type 2.")); 00471 return(0); 00472 } 00473 indelSeq = myIndelSeq2.c_str(); 00474 return(myRec2Base.indelLen2); 00475 }
uint8_t GlfRecord::getLk | ( | int | index | ) |
Get the likelihood for the specified genotype index.
Throws an exception if index is out of range.
index | index of the genotype for which the likelihood should be returned. See: GenotypeIndexTable |
Definition at line 355 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00356 { 00357 if(getRecordType() != 1) 00358 { 00359 throw(GlfException(GlfStatus::UNKNOWN, 00360 "Tried to call getLk for Record not of type 1.")); 00361 return(0); 00362 } 00363 if((index < 0) || (index >= NUM_REC1_LIKELIHOOD)) 00364 { 00365 throw(GlfException(GlfStatus::UNKNOWN, 00366 "Tried to call getLk for index < 0 or >= 10.")); 00367 return(0); 00368 } 00369 return(myRec1Base.lk[index]); 00370 }
uint8_t GlfRecord::getLkHet | ( | ) |
Return the likelihood of a heterozygote.
Definition at line 442 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00443 { 00444 if(getRecordType() != 2) 00445 { 00446 throw(GlfException(GlfStatus::UNKNOWN, 00447 "Tried to call getLkHet for Record not of type 2.")); 00448 return(0); 00449 } 00450 return(myRec2Base.lkHet); 00451 }
uint8_t GlfRecord::getLkHom1 | ( | ) |
Return the likelihood of the 1st homozygous indel allele.
Definition at line 420 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00421 { 00422 if(getRecordType() != 2) 00423 { 00424 throw(GlfException(GlfStatus::UNKNOWN, 00425 "Tried to call getLkHom1 for Record not of type 2.")); 00426 return(0); 00427 } 00428 return(myRec2Base.lkHom1); 00429 }
uint8_t GlfRecord::getLkHom2 | ( | ) |
Return the likelihood of the 2nd homozygous indel allele.
Definition at line 431 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00432 { 00433 if(getRecordType() != 2) 00434 { 00435 throw(GlfException(GlfStatus::UNKNOWN, 00436 "Tried to call getLkHom2 for Record not of type 2.")); 00437 return(0); 00438 } 00439 return(myRec2Base.lkHom2); 00440 }
uint32_t GlfRecord::getMinDepth | ( | ) |
Return the minimum likelihood and read depth.
Formatted as: min_lk<<24|read_dpeth. (min_lk capped at 255)
Definition at line 278 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00279 { 00280 if(getRecordType() == 1) 00281 { 00282 return(myRec1Base.min_depth); 00283 } 00284 else if(getRecordType() == 2) 00285 { 00286 return(myRec2Base.min_depth); 00287 } 00288 throw(GlfException(GlfStatus::UNKNOWN, 00289 "Tried to call getMinDepth for Record not of type 1 or 2.")); 00290 return(0); 00291 }
uint8_t GlfRecord::getMinLk | ( | ) |
Return the minimum likelihood.
Definition at line 293 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00294 { 00295 if(getRecordType() == 1) 00296 { 00297 return(myRec1Base.min_depth >> MIN_LK_SHIFT); 00298 } 00299 else if(getRecordType() == 2) 00300 { 00301 return(myRec2Base.min_depth >> MIN_LK_SHIFT); 00302 } 00303 throw(GlfException(GlfStatus::UNKNOWN, 00304 "Tried to call getMinLk for Record not of type 1 or 2.")); 00305 return(0); 00306 }
uint32_t GlfRecord::getOffset | ( | ) |
Return the offset from the precedent record.
Definition at line 263 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00264 { 00265 if(getRecordType() == 1) 00266 { 00267 return(myRec1Base.offset); 00268 } 00269 else if(getRecordType() == 2) 00270 { 00271 return(myRec2Base.offset); 00272 } 00273 throw(GlfException(GlfStatus::UNKNOWN, 00274 "Tried to call getOffset for Record not of type 1 or 2.")); 00275 return(0); 00276 }
uint32_t GlfRecord::getReadDepth | ( | ) |
Return the read depth.
Definition at line 308 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00309 { 00310 if(getRecordType() == 1) 00311 { 00312 return(myRec1Base.min_depth & READ_DEPTH_MASK); 00313 } 00314 else if(getRecordType() == 2) 00315 { 00316 return(myRec2Base.min_depth & READ_DEPTH_MASK); 00317 } 00318 throw(GlfException(GlfStatus::UNKNOWN, 00319 "Tried to call getReadDepth for Record not of type 1 or 2.")); 00320 return(0); 00321 }
int GlfRecord::getRecordType | ( | ) | const [inline] |
Return the record type.
Definition at line 126 of file GlfRecord.h.
Referenced by getIndel1(), getIndel2(), getLk(), getLkHet(), getLkHom1(), getLkHom2(), getMinDepth(), getMinLk(), GlfFile::getNextRecord(), getOffset(), getReadDepth(), getRmsMapQ(), print(), read(), write(), and GlfFile::writeRecord().
int GlfRecord::getRefBase | ( | ) | const [inline] |
Return the reference base as an integer.
Definition at line 134 of file GlfRecord.h.
Referenced by print().
char GlfRecord::getRefBaseChar | ( | ) | const |
Return the reference base as a character.
Definition at line 251 of file GlfRecord.cpp.
Referenced by print().
uint8_t GlfRecord::getRmsMapQ | ( | ) |
Return the RMS of mapping qualities of reads covering the site.
Definition at line 323 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
00324 { 00325 if(getRecordType() == 1) 00326 { 00327 return(myRec1Base.rmsMapQ); 00328 } 00329 else if(getRecordType() == 2) 00330 { 00331 return(myRec2Base.rmsMapQ); 00332 } 00333 throw(GlfException(GlfStatus::UNKNOWN, 00334 "Tried to call getRmsMapQ for Record not of type 1 or 2.")); 00335 return(0); 00336 }
bool GlfRecord::read | ( | IFILE | filePtr | ) |
Read the record from the specified file (file MUST be in the correct position for reading a record).
filePtr | file to read from that is in the correct position. |
Definition at line 65 of file GlfRecord.cpp.
References GlfStatus::FAIL_IO, getRecordType(), ifread(), and GlfStatus::INVALID.
Referenced by GlfFile::getNextRecord().
00066 { 00067 // Read the record type and reference base. 00068 int numRead = 0; 00069 int byteLen = sizeof(uint8_t); 00070 numRead = ifread(filePtr, &myRecTypeRefBase, byteLen); 00071 if(numRead != byteLen) 00072 { 00073 String errorMsg = "Failed to read the record type & reference base ("; 00074 errorMsg += byteLen; 00075 errorMsg += " bytes). Only read "; 00076 errorMsg += numRead; 00077 errorMsg += " bytes."; 00078 std::string errorString = errorMsg.c_str(); 00079 throw(GlfException(GlfStatus::FAIL_IO, errorString)); 00080 return(false); 00081 } 00082 00083 // TODO, split up by types of records... 00084 switch(getRecordType()) 00085 { 00086 case 0: 00087 // Last record. 00088 // Nothing more to read. 00089 break; 00090 case 1: 00091 // Read type 1. 00092 readType1(filePtr); 00093 break; 00094 case 2: 00095 // Read type 2. 00096 readType2(filePtr); 00097 break; 00098 default: 00099 String errorMsg = "Failed to read the record: unknown type: "; 00100 errorMsg += getRecordType(); 00101 std::string errorString = errorMsg.c_str(); 00102 throw(GlfException(GlfStatus::INVALID, errorString)); 00103 return(false); 00104 break; 00105 }; 00106 00107 // Successfully read, return success. 00108 return(true); 00109 }
bool GlfRecord::setDeletionIndel1 | ( | const std::string & | indelSeq | ) |
Set the sequence of the first indel allele if the first indel is an deletion.
indelSeq | sequence of the first indel allele (deletion). |
Definition at line 399 of file GlfRecord.cpp.
bool GlfRecord::setDeletionIndel2 | ( | const std::string & | indelSeq | ) |
Set the sequence of the 2nd indel allele if the 2nd indel is an deletion.
indelSeq | sequence of the 2nd indel allele (deletion). |
Definition at line 413 of file GlfRecord.cpp.
bool GlfRecord::setInsertionIndel1 | ( | const std::string & | indelSeq | ) |
Set the sequence of the first indel allele if the first indel is an insertion.
indelSeq | sequence of the first indel allele (insertion). |
Definition at line 392 of file GlfRecord.cpp.
bool GlfRecord::setInsertionIndel2 | ( | const std::string & | indelSeq | ) |
Set the sequence of the 2nd indel allele if the 2nd indel is an insertion.
indelSeq | sequence of the 2nd indel allele (insertion). |
Definition at line 406 of file GlfRecord.cpp.
bool GlfRecord::setLk | ( | int | index, | |
uint8_t | value | |||
) |
Set the likelihood for the specified genotype.
Throws an exception if index is out of range.
index | index for the genotype for which the likelihood is being set.
| |||||||||||||||||||||||
value | likelihood for the genotype at the specified index. |
Definition at line 340 of file GlfRecord.cpp.
References GlfStatus::UNKNOWN.
00341 { 00342 if((index < 0) || (index >= NUM_REC1_LIKELIHOOD)) 00343 { 00344 // Out of range. 00345 throw(GlfException(GlfStatus::UNKNOWN, 00346 "Trying to set Record Type 1 likelihood position< 0 or >= 10.")); 00347 return(false); 00348 } 00349 00350 // In range. 00351 myRec1Base.lk[index] = value; 00352 return(true); 00353 }
bool GlfRecord::setLkHet | ( | uint8_t | lk | ) |
Set the likelihood of a heterozygote.
lk | likelihood of a heterozygote (capped at 255) |
Definition at line 386 of file GlfRecord.cpp.
bool GlfRecord::setLkHom1 | ( | uint8_t | lk | ) |
Set the likelihood of the first homozygous indel allele.
lk | likelihood of the 1st homozygous indel allele (capped at 255) |
Definition at line 374 of file GlfRecord.cpp.
bool GlfRecord::setLkHom2 | ( | uint8_t | lk | ) |
Set the likelihood of the 2nd homozygous indel allele.
lk | likelihood of the 2nd homozygous indel allele (capped at 255) |
Definition at line 380 of file GlfRecord.cpp.
bool GlfRecord::setMinDepth | ( | uint32_t | minDepth | ) |
Set the minimum likelihood and the read depth.
minDepth | minimum likelihood and read depth. Formatted as: min_lk<<24|read_dpeth. (min_lk capped at 255) |
Definition at line 222 of file GlfRecord.cpp.
Referenced by setMinLk(), and setReadDepth().
bool GlfRecord::setMinLk | ( | uint8_t | minLk | ) |
Set the minimum likelihood.
minLk | minimum likelihood (capped at 255). |
Definition at line 229 of file GlfRecord.cpp.
References setMinDepth().
00230 { 00231 setMinDepth((myRec1Base.min_depth & READ_DEPTH_MASK) | 00232 (minLk << MIN_LK_SHIFT)); 00233 return(true); 00234 }
bool GlfRecord::setOffset | ( | uint32_t | offset | ) |
Set the offset from the precedent record.
0-based coordinate of the record minus the coordinate of the precedent record. For the first record in a reference sequence, the previous coordinate is 0. For insertions between x & x+1, the coordinate is x. For deletions between x & y, the coordinate is x.
offset | offset from the precedent record. |
Definition at line 215 of file GlfRecord.cpp.
bool GlfRecord::setReadDepth | ( | uint32_t | readDepth | ) |
Set the the read depth.
readDepth | read depth. |
Definition at line 236 of file GlfRecord.cpp.
References setMinDepth().
00237 { 00238 setMinDepth((myRec1Base.min_depth & MIN_LK_MASK) | 00239 (readDepth & READ_DEPTH_MASK)); 00240 return(true); 00241 }
bool GlfRecord::setRecordType | ( | uint8_t | recType | ) |
Set the record type.
recType | record type: 1 - simple likelihood record, 2 - indel likelihood record, 0 - end maker |
Definition at line 194 of file GlfRecord.cpp.
bool GlfRecord::setRefBaseInt | ( | uint8_t | refBase | ) |
Set the reference base from an integer value.
refBase | integer representation of the reference base.
|
Definition at line 201 of file GlfRecord.cpp.
bool GlfRecord::setRmsMapQ | ( | uint8_t | rmsMapQ | ) |
Set the RMS of mapping qualities of reads covering the site.
rmsMapQ | RMS of mapping qualities |
Definition at line 243 of file GlfRecord.cpp.
bool GlfRecord::setRtypeRef | ( | uint8_t | rtypeRef | ) |
Set the record type and reference base.
rtypeRef | record type & reference base. Formatted as: record_type<<4|numeric_ref_base. |
Definition at line 188 of file GlfRecord.cpp.
bool GlfRecord::write | ( | IFILE | filePtr | ) | const |
Write the record to the specified file.
filePtr | file to write to that is in the correct position. |
Definition at line 113 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::INVALID.
Referenced by GlfFile::writeRecord().
00114 { 00115 // TODO, split up by types of records... 00116 switch(getRecordType()) 00117 { 00118 case 0: 00119 writeRtypeRef(filePtr); 00120 break; 00121 case 1: 00122 // write type 1. 00123 writeType1(filePtr); 00124 break; 00125 case 2: 00126 // write type 2. 00127 writeType2(filePtr); 00128 break; 00129 default: 00130 // unknown type, return error. 00131 String errorMsg = "Failed to write the record: unknown type: "; 00132 errorMsg += getRecordType(); 00133 std::string errorString = errorMsg.c_str(); 00134 throw(GlfException(GlfStatus::INVALID, errorString)); 00135 return(false); 00136 break; 00137 }; 00138 00139 return(true); 00140 }