libStatGen Software
1
|
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 () const |
Return the offset from the precedent record. | |
uint32_t | getMinDepth () const |
Return the minimum likelihood and read depth. | |
uint8_t | getMinLk () const |
Return the minimum likelihood. | |
uint32_t | getReadDepth () const |
Return the read depth. | |
uint8_t | getRmsMapQ () const |
Return the RMS of mapping qualities of reads covering the site. | |
Record Type 1 Accessors | |
Record Type 1: Simple Likelihood Record | |
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 | |
Record Type2: Indel Likelihood Record | |
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.
{ if(getRecordType() != 2) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getIndel1 for Record not of type 2.")); return(0); } indelSeq = myIndelSeq1.c_str(); return(myRec2Base.indelLen1); }
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.
{ if(getRecordType() != 2) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getIndel2 for Record not of type 2.")); return(0); } indelSeq = myIndelSeq2.c_str(); return(myRec2Base.indelLen2); }
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.
{ if(getRecordType() != 1) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getLk for Record not of type 1.")); return(0); } if((index < 0) || (index >= NUM_REC1_LIKELIHOOD)) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getLk for index < 0 or >= 10.")); return(0); } return(myRec1Base.lk[index]); }
uint8_t GlfRecord::getLkHet | ( | ) |
Return the likelihood of a heterozygote.
Definition at line 442 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
{ if(getRecordType() != 2) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getLkHet for Record not of type 2.")); return(0); } return(myRec2Base.lkHet); }
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.
{ if(getRecordType() != 2) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getLkHom1 for Record not of type 2.")); return(0); } return(myRec2Base.lkHom1); }
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.
{ if(getRecordType() != 2) { throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getLkHom2 for Record not of type 2.")); return(0); } return(myRec2Base.lkHom2); }
uint32_t GlfRecord::getMinDepth | ( | ) | const |
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.
{ if(getRecordType() == 1) { return(myRec1Base.min_depth); } else if(getRecordType() == 2) { return(myRec2Base.min_depth); } throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getMinDepth for Record not of type 1 or 2.")); return(0); }
uint8_t GlfRecord::getMinLk | ( | ) | const |
Return the minimum likelihood.
Definition at line 293 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
{ if(getRecordType() == 1) { return(myRec1Base.min_depth >> MIN_LK_SHIFT); } else if(getRecordType() == 2) { return(myRec2Base.min_depth >> MIN_LK_SHIFT); } throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getMinLk for Record not of type 1 or 2.")); return(0); }
uint32_t GlfRecord::getOffset | ( | ) | const |
Return the offset from the precedent record.
Definition at line 263 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
{ if(getRecordType() == 1) { return(myRec1Base.offset); } else if(getRecordType() == 2) { return(myRec2Base.offset); } throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getOffset for Record not of type 1 or 2.")); return(0); }
uint32_t GlfRecord::getReadDepth | ( | ) | const |
Return the read depth.
Definition at line 308 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
{ if(getRecordType() == 1) { return(myRec1Base.min_depth & READ_DEPTH_MASK); } else if(getRecordType() == 2) { return(myRec2Base.min_depth & READ_DEPTH_MASK); } throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getReadDepth for Record not of type 1 or 2.")); return(0); }
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().
{
return(myRecTypeRefBase >> REC_TYPE_SHIFT);
}
int GlfRecord::getRefBase | ( | ) | const [inline] |
Return the reference base as an integer.
Definition at line 134 of file GlfRecord.h.
Referenced by print().
{
return(myRecTypeRefBase & REF_BASE_MASK);
}
char GlfRecord::getRefBaseChar | ( | ) | const |
Return the reference base as a character.
Definition at line 251 of file GlfRecord.cpp.
Referenced by print().
{ int index = myRecTypeRefBase & REF_BASE_MASK; if((index > REF_BASE_MAX) || (index < 0)) { // TODO throw exception. return('N'); } return(REF_BASE_CHAR[index]); }
uint8_t GlfRecord::getRmsMapQ | ( | ) | const |
Return the RMS of mapping qualities of reads covering the site.
Definition at line 323 of file GlfRecord.cpp.
References getRecordType(), and GlfStatus::UNKNOWN.
{ if(getRecordType() == 1) { return(myRec1Base.rmsMapQ); } else if(getRecordType() == 2) { return(myRec2Base.rmsMapQ); } throw(GlfException(GlfStatus::UNKNOWN, "Tried to call getRmsMapQ for Record not of type 1 or 2.")); return(0); }
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().
{ // Read the record type and reference base. int numRead = 0; int byteLen = sizeof(uint8_t); numRead = ifread(filePtr, &myRecTypeRefBase, byteLen); if(numRead != byteLen) { String errorMsg = "Failed to read the record type & reference base ("; errorMsg += byteLen; errorMsg += " bytes). Only read "; errorMsg += numRead; errorMsg += " bytes."; std::string errorString = errorMsg.c_str(); throw(GlfException(GlfStatus::FAIL_IO, errorString)); return(false); } // TODO, split up by types of records... switch(getRecordType()) { case 0: // Last record. // Nothing more to read. break; case 1: // Read type 1. readType1(filePtr); break; case 2: // Read type 2. readType2(filePtr); break; default: String errorMsg = "Failed to read the record: unknown type: "; errorMsg += getRecordType(); std::string errorString = errorMsg.c_str(); throw(GlfException(GlfStatus::INVALID, errorString)); return(false); break; }; // Successfully read, return success. return(true); }
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.
{ myRec2Base.indelLen1 = 0 - (indelSeq.length()); myIndelSeq1 = indelSeq; return(true); }
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.
{ myRec2Base.indelLen2 = 0 - (indelSeq.length()); myIndelSeq2 = indelSeq; return(true); }
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.
{ myRec2Base.indelLen1 = indelSeq.length(); myIndelSeq1 = indelSeq; return(true); }
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.
{ myRec2Base.indelLen2 = indelSeq.length(); myIndelSeq2 = indelSeq; return(true); }
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.
{ if((index < 0) || (index >= NUM_REC1_LIKELIHOOD)) { // Out of range. throw(GlfException(GlfStatus::UNKNOWN, "Trying to set Record Type 1 likelihood position< 0 or >= 10.")); return(false); } // In range. myRec1Base.lk[index] = value; return(true); }
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.
{ myRec2Base.lkHet = lk; return(true); }
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.
{ myRec2Base.lkHom1 = lk; return(true); }
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.
{ myRec2Base.lkHom2 = lk; return(true); }
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().
{ myRec1Base.min_depth = minDepth; myRec2Base.min_depth = minDepth; return(true); }
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().
{ setMinDepth((myRec1Base.min_depth & READ_DEPTH_MASK) | (minLk << MIN_LK_SHIFT)); return(true); }
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.
{ myRec1Base.offset = offset; myRec2Base.offset = offset; return(true); }
bool GlfRecord::setReadDepth | ( | uint32_t | readDepth | ) |
Set the the read depth.
readDepth | read depth. |
Definition at line 236 of file GlfRecord.cpp.
References setMinDepth().
{ setMinDepth((myRec1Base.min_depth & MIN_LK_MASK) | (readDepth & READ_DEPTH_MASK)); return(true); }
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.
{ myRecTypeRefBase = (myRecTypeRefBase & REF_BASE_MASK) | (recType << REC_TYPE_SHIFT); return(true); }
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.
{ myRecTypeRefBase = (myRecTypeRefBase & REC_TYPE_MASK) | (refBase & REF_BASE_MASK); return(true); }
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.
{ myRec1Base.rmsMapQ = rmsMapQ; myRec2Base.rmsMapQ = rmsMapQ; return(true); }
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.
{ myRecTypeRefBase = rtypeRef; return(true); }
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().
{ // TODO, split up by types of records... switch(getRecordType()) { case 0: writeRtypeRef(filePtr); break; case 1: // write type 1. writeType1(filePtr); break; case 2: // write type 2. writeType2(filePtr); break; default: // unknown type, return error. String errorMsg = "Failed to write the record: unknown type: "; errorMsg += getRecordType(); std::string errorString = errorMsg.c_str(); throw(GlfException(GlfStatus::INVALID, errorString)); return(false); break; }; return(true); }