GlfRecord Class Reference

This class allows a user to easily get/set the fields in a GLF record. More...

#include <GlfRecord.h>

Collaboration diagram for GlfRecord:
Collaboration graph
[legend]

List of all members.

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

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.

Detailed Description

This class allows a user to easily get/set the fields in a GLF record.

Definition at line 28 of file GlfRecord.h.


Member Function Documentation

int16_t GlfRecord::getIndel1 ( std::string &  indelSeq  ) 

Get the sequence and length (+:ins, -:del) of the 1st indel allele.

Parameters:
indelSeq string to set with the sequence of the 1st indel allele
Returns:
length of the 1st indel allele (positive=insertion; negative=deletion; 0=no-indel)

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.

Parameters:
indelSeq string to set with the sequence of the 2nd indel allele
Returns:
length of the 2nd indel allele (positive=insertion; negative=deletion; 0=no-indel)

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.

Parameters:
index index of the genotype for which the likelihood should be returned. See: GenotypeIndexTable
Returns:
likelihood of the specified index.

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.

Returns:
likelihood of a hetereozygote.

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.

Returns:
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.

Returns:
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)

Returns:
minimum likelihood and read depth

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.

Returns:
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.

Returns:
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.

Returns:
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.

Returns:
record type for this record: 0 - endMarker, 1 - simple likelihood, 2 - indel likelihood

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().

00127     {
00128         return(myRecTypeRefBase >> REC_TYPE_SHIFT);
00129     }

int GlfRecord::getRefBase (  )  const [inline]

Return the reference base as an integer.

Returns:
integer representation of the reference base. See: BaseCharacterIntMap

Definition at line 134 of file GlfRecord.h.

Referenced by print().

00135     {
00136         return(myRecTypeRefBase & REF_BASE_MASK);
00137     }

char GlfRecord::getRefBaseChar (  )  const

Return the reference base as a character.

Returns:
character representation of the reference base.

Definition at line 251 of file GlfRecord.cpp.

Referenced by print().

00252 {
00253     int index = myRecTypeRefBase & REF_BASE_MASK;
00254     if((index > REF_BASE_MAX) || (index < 0))
00255     {
00256         // TODO throw exception.
00257         return('N');
00258     }
00259     return(REF_BASE_CHAR[index]);
00260 }

uint8_t GlfRecord::getRmsMapQ (  ) 

Return the RMS of mapping qualities of reads covering the site.

Returns:
RMS of maping qualities.

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).

Parameters:
filePtr file to read from that is in the correct position.
Returns:
true if the record was successfully read from the file (even if it is an endMarker), false if it was not successfully read.

Definition at line 65 of file GlfRecord.cpp.

References GlfStatus::FAIL_IO, getRecordType(), 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.

Parameters:
indelSeq sequence of the first indel allele (deletion).
Returns:
true if successfully set, false if not.

Definition at line 399 of file GlfRecord.cpp.

00400 {
00401     myRec2Base.indelLen1 = -(indelSeq.length());
00402     myIndelSeq1 = indelSeq;
00403     return(true);
00404 }

bool GlfRecord::setDeletionIndel2 ( const std::string &  indelSeq  ) 

Set the sequence of the 2nd indel allele if the 2nd indel is an deletion.

Parameters:
indelSeq sequence of the 2nd indel allele (deletion).
Returns:
true if successfully set, false if not.

Definition at line 413 of file GlfRecord.cpp.

00414 {
00415     myRec2Base.indelLen2 = -(indelSeq.length());
00416     myIndelSeq2 = indelSeq;
00417     return(true);
00418 }

bool GlfRecord::setInsertionIndel1 ( const std::string &  indelSeq  ) 

Set the sequence of the first indel allele if the first indel is an insertion.

Parameters:
indelSeq sequence of the first indel allele (insertion).
Returns:
true if successfully set, false if not.

Definition at line 392 of file GlfRecord.cpp.

00393 {
00394     myRec2Base.indelLen1 = indelSeq.length();
00395     myIndelSeq1 = indelSeq;
00396     return(true);
00397 }

bool GlfRecord::setInsertionIndel2 ( const std::string &  indelSeq  ) 

Set the sequence of the 2nd indel allele if the 2nd indel is an insertion.

Parameters:
indelSeq sequence of the 2nd indel allele (insertion).
Returns:
true if successfully set, false if not.

Definition at line 406 of file GlfRecord.cpp.

00407 {
00408     myRec2Base.indelLen2 = indelSeq.length();
00409     myIndelSeq2 = indelSeq;
00410     return(true);
00411 }

bool GlfRecord::setLk ( int  index,
uint8_t  value 
)

Set the likelihood for the specified genotype.

Throws an exception if index is out of range.

Parameters:
index index for the genotype for which the likelihood is being set.

Index0123456789
GenotypeAAACAGATCCCGCTGGGTTT
value likelihood for the genotype at the specified index.
Returns:
true if successfully set, false if not.

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.

Parameters:
lk likelihood of a heterozygote (capped at 255)
Returns:
true if successfully set, false if not.

Definition at line 386 of file GlfRecord.cpp.

00387 {
00388     myRec2Base.lkHet = lk;
00389     return(true);
00390 }

bool GlfRecord::setLkHom1 ( uint8_t  lk  ) 

Set the likelihood of the first homozygous indel allele.

Parameters:
lk likelihood of the 1st homozygous indel allele (capped at 255)
Returns:
true if successfully set, false if not.

Definition at line 374 of file GlfRecord.cpp.

00375 {
00376     myRec2Base.lkHom1 = lk;
00377     return(true);
00378 }

bool GlfRecord::setLkHom2 ( uint8_t  lk  ) 

Set the likelihood of the 2nd homozygous indel allele.

Parameters:
lk likelihood of the 2nd homozygous indel allele (capped at 255)
Returns:
true if successfully set, false if not.

Definition at line 380 of file GlfRecord.cpp.

00381 {
00382     myRec2Base.lkHom2 = lk;
00383     return(true);
00384 }

bool GlfRecord::setMinDepth ( uint32_t  minDepth  ) 

Set the minimum likelihood and the read depth.

Parameters:
minDepth minimum likelihood and read depth. Formatted as: min_lk<<24|read_dpeth. (min_lk capped at 255)
Returns:
true if successfully set, false if not.

Definition at line 222 of file GlfRecord.cpp.

Referenced by setMinLk(), and setReadDepth().

00223 {
00224     myRec1Base.min_depth = minDepth;
00225     myRec2Base.min_depth = minDepth;
00226     return(true);
00227 }

bool GlfRecord::setMinLk ( uint8_t  minLk  ) 

Set the minimum likelihood.

Parameters:
minLk minimum likelihood (capped at 255).
Returns:
true if successfully set, false if not.

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.

Parameters:
offset offset from the precedent record.
Returns:
true if successfully set, false if not.

Definition at line 215 of file GlfRecord.cpp.

00216 {
00217     myRec1Base.offset = offset;
00218     myRec2Base.offset = offset;
00219     return(true);
00220 }

bool GlfRecord::setReadDepth ( uint32_t  readDepth  ) 

Set the the read depth.

Parameters:
readDepth read depth.
Returns:
true if successfully set, false if not.

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.

Parameters:
recType record type: 1 - simple likelihood record, 2 - indel likelihood record, 0 - end maker
Returns:
true if the record type was successfully set, false if not.

Definition at line 194 of file GlfRecord.cpp.

00195 {
00196     myRecTypeRefBase = 
00197         (myRecTypeRefBase & REF_BASE_MASK) | (recType << REC_TYPE_SHIFT);
00198     return(true);
00199 }

bool GlfRecord::setRefBaseInt ( uint8_t  refBase  ) 

Set the reference base from an integer value.

Parameters:
refBase integer representation of the reference base.

Int Value0123456789101112131415
Character BaseXACMGRSVTWYHKDBN
Returns:
true if the reference base was successfully set, false if not.

Definition at line 201 of file GlfRecord.cpp.

00202 {
00203     myRecTypeRefBase = 
00204         (myRecTypeRefBase & REC_TYPE_MASK) | (refBase & REF_BASE_MASK);
00205     return(true);
00206 }

bool GlfRecord::setRmsMapQ ( uint8_t  rmsMapQ  ) 

Set the RMS of mapping qualities of reads covering the site.

Parameters:
rmsMapQ RMS of mapping qualities
Returns:
true if successfully set, false if not.

Definition at line 243 of file GlfRecord.cpp.

00244 {
00245     myRec1Base.rmsMapQ = rmsMapQ;
00246     myRec2Base.rmsMapQ = rmsMapQ;
00247     return(true);
00248 }

bool GlfRecord::setRtypeRef ( uint8_t  rtypeRef  ) 

Set the record type and reference base.

Parameters:
rtypeRef record type & reference base. Formatted as: record_type<<4|numeric_ref_base.
Returns:
true if the record type and reference base were successfully set, false if not.

Definition at line 188 of file GlfRecord.cpp.

00189 {
00190     myRecTypeRefBase = rtypeRef;
00191     return(true);
00192 }

bool GlfRecord::write ( IFILE  filePtr  )  const

Write the record to the specified file.

Parameters:
filePtr file to write to that is in the correct position.
Returns:
true if the record was successfully written to the file, false if not.

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 }


The documentation for this class was generated from the following files:
Generated on Wed Nov 17 15:38:32 2010 for StatGen Software by  doxygen 1.6.3