libStatGen Software  1
GlfRecord Class Reference

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). More...
 
bool write (IFILE filePtr) const
 Write the record to the specified file. More...
 
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. More...
 
bool setRecordType (uint8_t recType)
 Set the record type. More...
 
bool setRefBaseInt (uint8_t refBase)
 Set the reference base from an integer value. More...
 
bool setOffset (uint32_t offset)
 Set the offset from the precedent record. More...
 
bool setMinDepth (uint32_t minDepth)
 Set the minimum likelihood and the read depth. More...
 
bool setMinLk (uint8_t minLk)
 Set the minimum likelihood. More...
 
bool setReadDepth (uint32_t readDepth)
 Set the the read depth. More...
 
bool setRmsMapQ (uint8_t rmsMapQ)
 Set the RMS of mapping qualities of reads covering the site. More...
 
int getRecordType () const
 Return the record type. More...
 
int getRefBase () const
 Return the reference base as an integer. More...
 
char getRefBaseChar () const
 Return the reference base as a character. More...
 
uint32_t getOffset () const
 Return the offset from the precedent record. More...
 
uint32_t getMinDepth () const
 Return the minimum likelihood and read depth. More...
 
uint8_t getMinLk () const
 Return the minimum likelihood. More...
 
uint32_t getReadDepth () const
 Return the read depth. More...
 
uint8_t getRmsMapQ () const
 Return the RMS of mapping qualities of reads covering the site. More...
 
Record Type 1 Accessors

Record Type 1: Simple Likelihood Record

bool setLk (int index, uint8_t value)
 Set the likelihood for the specified genotype. More...
 
uint8_t getLk (int index)
 Get the likelihood for the specified genotype index. More...
 

Record Type 2 Accessors

Record Type2: Indel Likelihood Record

bool setLkHom1 (uint8_t lk)
 Set the likelihood of the first homozygous indel allele. More...
 
bool setLkHom2 (uint8_t lk)
 Set the likelihood of the 2nd homozygous indel allele. More...
 
bool setLkHet (uint8_t lk)
 Set the likelihood of a heterozygote. More...
 
bool setInsertionIndel1 (const std::string &indelSeq)
 Set the sequence of the first indel allele if the first indel is an insertion. More...
 
bool setDeletionIndel1 (const std::string &indelSeq)
 Set the sequence of the first indel allele if the first indel is an deletion. More...
 
bool setInsertionIndel2 (const std::string &indelSeq)
 Set the sequence of the 2nd indel allele if the 2nd indel is an insertion. More...
 
bool setDeletionIndel2 (const std::string &indelSeq)
 Set the sequence of the 2nd indel allele if the 2nd indel is an deletion. More...
 
uint8_t getLkHom1 ()
 Return the likelihood of the 1st homozygous indel allele. More...
 
uint8_t getLkHom2 ()
 Return the likelihood of the 2nd homozygous indel allele. More...
 
uint8_t getLkHet ()
 Return the likelihood of a heterozygote. More...
 
int16_t getIndel1 (std::string &indelSeq)
 Get the sequence and length (+:ins, -:del) of the 1st indel allele. More...
 
int16_t getIndel2 (std::string &indelSeq)
 Get the sequence and length (+:ins, -:del) of the 2nd indel allele. More...
 

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

◆ getIndel1()

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

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

Parameters
indelSeqstring 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.

454 {
455  if(getRecordType() != 2)
456  {
458  "Tried to call getIndel1 for Record not of type 2."));
459  return(0);
460  }
461  indelSeq = myIndelSeq1.c_str();
462  return(myRec2Base.indelLen1);
463 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getIndel2()

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

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

Parameters
indelSeqstring 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.

466 {
467  if(getRecordType() != 2)
468  {
470  "Tried to call getIndel2 for Record not of type 2."));
471  return(0);
472  }
473  indelSeq = myIndelSeq2.c_str();
474  return(myRec2Base.indelLen2);
475 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getLk()

uint8_t GlfRecord::getLk ( int  index)

Get the likelihood for the specified genotype index.

Throws an exception if index is out of range.

Parameters
indexindex 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.

356 {
357  if(getRecordType() != 1)
358  {
360  "Tried to call getLk for Record not of type 1."));
361  return(0);
362  }
363  if((index < 0) || (index >= NUM_REC1_LIKELIHOOD))
364  {
366  "Tried to call getLk for index < 0 or >= 10."));
367  return(0);
368  }
369  return(myRec1Base.lk[index]);
370 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getLkHet()

uint8_t GlfRecord::getLkHet ( )

Return the likelihood of a heterozygote.

Returns
likelihood of a hetereozygote.

Definition at line 442 of file GlfRecord.cpp.

443 {
444  if(getRecordType() != 2)
445  {
447  "Tried to call getLkHet for Record not of type 2."));
448  return(0);
449  }
450  return(myRec2Base.lkHet);
451 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getLkHom1()

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.

421 {
422  if(getRecordType() != 2)
423  {
425  "Tried to call getLkHom1 for Record not of type 2."));
426  return(0);
427  }
428  return(myRec2Base.lkHom1);
429 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getLkHom2()

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.

432 {
433  if(getRecordType() != 2)
434  {
436  "Tried to call getLkHom2 for Record not of type 2."));
437  return(0);
438  }
439  return(myRec2Base.lkHom2);
440 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getMinDepth()

uint32_t GlfRecord::getMinDepth ( ) const

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.

279 {
280  if(getRecordType() == 1)
281  {
282  return(myRec1Base.min_depth);
283  }
284  else if(getRecordType() == 2)
285  {
286  return(myRec2Base.min_depth);
287  }
289  "Tried to call getMinDepth for Record not of type 1 or 2."));
290  return(0);
291 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getMinLk()

uint8_t GlfRecord::getMinLk ( ) const

Return the minimum likelihood.

Returns
minimum likelihood

Definition at line 293 of file GlfRecord.cpp.

294 {
295  if(getRecordType() == 1)
296  {
297  return(myRec1Base.min_depth >> MIN_LK_SHIFT);
298  }
299  else if(getRecordType() == 2)
300  {
301  return(myRec2Base.min_depth >> MIN_LK_SHIFT);
302  }
304  "Tried to call getMinLk for Record not of type 1 or 2."));
305  return(0);
306 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getOffset()

uint32_t GlfRecord::getOffset ( ) const

Return the offset from the precedent record.

Returns
offset from the precedent record.

Definition at line 263 of file GlfRecord.cpp.

264 {
265  if(getRecordType() == 1)
266  {
267  return(myRec1Base.offset);
268  }
269  else if(getRecordType() == 2)
270  {
271  return(myRec2Base.offset);
272  }
274  "Tried to call getOffset for Record not of type 1 or 2."));
275  return(0);
276 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getReadDepth()

uint32_t GlfRecord::getReadDepth ( ) const

Return the read depth.

Returns
read depth

Definition at line 308 of file GlfRecord.cpp.

309 {
310  if(getRecordType() == 1)
311  {
312  return(myRec1Base.min_depth & READ_DEPTH_MASK);
313  }
314  else if(getRecordType() == 2)
315  {
316  return(myRec2Base.min_depth & READ_DEPTH_MASK);
317  }
319  "Tried to call getReadDepth for Record not of type 1 or 2."));
320  return(0);
321 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ getRecordType()

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.

127  {
128  return(myRecTypeRefBase >> REC_TYPE_SHIFT);
129  }

Referenced by getIndel1(), getIndel2(), getLk(), getLkHet(), getLkHom1(), getLkHom2(), getMinDepth(), getMinLk(), GlfFile::getNextRecord(), getOffset(), getReadDepth(), getRmsMapQ(), print(), read(), write(), and GlfFile::writeRecord().

◆ getRefBase()

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.

135  {
136  return(myRecTypeRefBase & REF_BASE_MASK);
137  }

Referenced by print().

◆ getRefBaseChar()

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.

252 {
253  int index = myRecTypeRefBase & REF_BASE_MASK;
254  if((index > REF_BASE_MAX) || (index < 0))
255  {
256  // TODO throw exception.
257  return('N');
258  }
259  return(REF_BASE_CHAR[index]);
260 }

Referenced by print().

◆ getRmsMapQ()

uint8_t GlfRecord::getRmsMapQ ( ) const

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

Returns
RMS of maping qualities.

Definition at line 323 of file GlfRecord.cpp.

324 {
325  if(getRecordType() == 1)
326  {
327  return(myRec1Base.rmsMapQ);
328  }
329  else if(getRecordType() == 2)
330  {
331  return(myRec2Base.rmsMapQ);
332  }
334  "Tried to call getRmsMapQ for Record not of type 1 or 2."));
335  return(0);
336 }

References getRecordType(), and GlfStatus::UNKNOWN.

◆ read()

bool GlfRecord::read ( IFILE  filePtr)

Read the record from the specified file (file MUST be in the correct position for reading a record).

Parameters
filePtrfile 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.

66 {
67  // Read the record type and reference base.
68  int numRead = 0;
69  int byteLen = sizeof(uint8_t);
70  numRead = ifread(filePtr, &myRecTypeRefBase, byteLen);
71  if(numRead != byteLen)
72  {
73  String errorMsg = "Failed to read the record type & reference base (";
74  errorMsg += byteLen;
75  errorMsg += " bytes). Only read ";
76  errorMsg += numRead;
77  errorMsg += " bytes.";
78  std::string errorString = errorMsg.c_str();
79  throw(GlfException(GlfStatus::FAIL_IO, errorString));
80  return(false);
81  }
82 
83  // TODO, split up by types of records...
84  switch(getRecordType())
85  {
86  case 0:
87  // Last record.
88  // Nothing more to read.
89  break;
90  case 1:
91  // Read type 1.
92  readType1(filePtr);
93  break;
94  case 2:
95  // Read type 2.
96  readType2(filePtr);
97  break;
98  default:
99  String errorMsg = "Failed to read the record: unknown type: ";
100  errorMsg += getRecordType();
101  std::string errorString = errorMsg.c_str();
102  throw(GlfException(GlfStatus::INVALID, errorString));
103  return(false);
104  break;
105  };
106 
107  // Successfully read, return success.
108  return(true);
109 }

References GlfStatus::FAIL_IO, getRecordType(), ifread(), and GlfStatus::INVALID.

Referenced by GlfFile::getNextRecord().

◆ setDeletionIndel1()

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

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

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

Definition at line 399 of file GlfRecord.cpp.

400 {
401  myRec2Base.indelLen1 = 0 - (indelSeq.length());
402  myIndelSeq1 = indelSeq;
403  return(true);
404 }

◆ setDeletionIndel2()

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

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

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

Definition at line 413 of file GlfRecord.cpp.

414 {
415  myRec2Base.indelLen2 = 0 - (indelSeq.length());
416  myIndelSeq2 = indelSeq;
417  return(true);
418 }

◆ setInsertionIndel1()

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

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

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

Definition at line 392 of file GlfRecord.cpp.

393 {
394  myRec2Base.indelLen1 = indelSeq.length();
395  myIndelSeq1 = indelSeq;
396  return(true);
397 }

◆ setInsertionIndel2()

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

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

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

Definition at line 406 of file GlfRecord.cpp.

407 {
408  myRec2Base.indelLen2 = indelSeq.length();
409  myIndelSeq2 = indelSeq;
410  return(true);
411 }

◆ setLk()

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
indexindex for the genotype for which the likelihood is being set.
Index0123456789
GenotypeAAACAGATCCCGCTGGGTTT
valuelikelihood for the genotype at the specified index.
Returns
true if successfully set, false if not.

Definition at line 340 of file GlfRecord.cpp.

341 {
342  if((index < 0) || (index >= NUM_REC1_LIKELIHOOD))
343  {
344  // Out of range.
346  "Trying to set Record Type 1 likelihood position< 0 or >= 10."));
347  return(false);
348  }
349 
350  // In range.
351  myRec1Base.lk[index] = value;
352  return(true);
353 }

References GlfStatus::UNKNOWN.

◆ setLkHet()

bool GlfRecord::setLkHet ( uint8_t  lk)

Set the likelihood of a heterozygote.

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

Definition at line 386 of file GlfRecord.cpp.

387 {
388  myRec2Base.lkHet = lk;
389  return(true);
390 }

◆ setLkHom1()

bool GlfRecord::setLkHom1 ( uint8_t  lk)

Set the likelihood of the first homozygous indel allele.

Parameters
lklikelihood 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.

375 {
376  myRec2Base.lkHom1 = lk;
377  return(true);
378 }

◆ setLkHom2()

bool GlfRecord::setLkHom2 ( uint8_t  lk)

Set the likelihood of the 2nd homozygous indel allele.

Parameters
lklikelihood 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.

381 {
382  myRec2Base.lkHom2 = lk;
383  return(true);
384 }

◆ setMinDepth()

bool GlfRecord::setMinDepth ( uint32_t  minDepth)

Set the minimum likelihood and the read depth.

Parameters
minDepthminimum 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.

223 {
224  myRec1Base.min_depth = minDepth;
225  myRec2Base.min_depth = minDepth;
226  return(true);
227 }

Referenced by setMinLk(), and setReadDepth().

◆ setMinLk()

bool GlfRecord::setMinLk ( uint8_t  minLk)

Set the minimum likelihood.

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

Definition at line 229 of file GlfRecord.cpp.

230 {
231  setMinDepth((myRec1Base.min_depth & READ_DEPTH_MASK) |
232  (minLk << MIN_LK_SHIFT));
233  return(true);
234 }

References setMinDepth().

◆ setOffset()

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
offsetoffset from the precedent record.
Returns
true if successfully set, false if not.

Definition at line 215 of file GlfRecord.cpp.

216 {
217  myRec1Base.offset = offset;
218  myRec2Base.offset = offset;
219  return(true);
220 }

◆ setReadDepth()

bool GlfRecord::setReadDepth ( uint32_t  readDepth)

Set the the read depth.

Parameters
readDepthread depth.
Returns
true if successfully set, false if not.

Definition at line 236 of file GlfRecord.cpp.

237 {
238  setMinDepth((myRec1Base.min_depth & MIN_LK_MASK) |
239  (readDepth & READ_DEPTH_MASK));
240  return(true);
241 }

References setMinDepth().

◆ setRecordType()

bool GlfRecord::setRecordType ( uint8_t  recType)

Set the record type.

Parameters
recTyperecord 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.

195 {
196  myRecTypeRefBase =
197  (myRecTypeRefBase & REF_BASE_MASK) | (recType << REC_TYPE_SHIFT);
198  return(true);
199 }

◆ setRefBaseInt()

bool GlfRecord::setRefBaseInt ( uint8_t  refBase)

Set the reference base from an integer value.

Parameters
refBaseinteger 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.

202 {
203  myRecTypeRefBase =
204  (myRecTypeRefBase & REC_TYPE_MASK) | (refBase & REF_BASE_MASK);
205  return(true);
206 }

◆ setRmsMapQ()

bool GlfRecord::setRmsMapQ ( uint8_t  rmsMapQ)

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

Parameters
rmsMapQRMS of mapping qualities
Returns
true if successfully set, false if not.

Definition at line 243 of file GlfRecord.cpp.

244 {
245  myRec1Base.rmsMapQ = rmsMapQ;
246  myRec2Base.rmsMapQ = rmsMapQ;
247  return(true);
248 }

◆ setRtypeRef()

bool GlfRecord::setRtypeRef ( uint8_t  rtypeRef)

Set the record type and reference base.

Parameters
rtypeRefrecord 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.

189 {
190  myRecTypeRefBase = rtypeRef;
191  return(true);
192 }

◆ write()

bool GlfRecord::write ( IFILE  filePtr) const

Write the record to the specified file.

Parameters
filePtrfile 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.

114 {
115  // TODO, split up by types of records...
116  switch(getRecordType())
117  {
118  case 0:
119  writeRtypeRef(filePtr);
120  break;
121  case 1:
122  // write type 1.
123  writeType1(filePtr);
124  break;
125  case 2:
126  // write type 2.
127  writeType2(filePtr);
128  break;
129  default:
130  // unknown type, return error.
131  String errorMsg = "Failed to write the record: unknown type: ";
132  errorMsg += getRecordType();
133  std::string errorString = errorMsg.c_str();
134  throw(GlfException(GlfStatus::INVALID, errorString));
135  return(false);
136  break;
137  };
138 
139  return(true);
140 }

References getRecordType(), and GlfStatus::INVALID.

Referenced by GlfFile::writeRecord().


The documentation for this class was generated from the following files:
GlfStatus::UNKNOWN
@ UNKNOWN
unknown result (default value should never be used)
Definition: GlfStatus.h:33
String
Definition: StringBasics.h:38
GlfRecord::setMinDepth
bool setMinDepth(uint32_t minDepth)
Set the minimum likelihood and the read depth.
Definition: GlfRecord.cpp:222
GlfRecord::getRecordType
int getRecordType() const
Return the record type.
Definition: GlfRecord.h:126
ifread
unsigned int ifread(IFILE file, void *buffer, unsigned int size)
Read up to size bytes from the file into the buffer.
Definition: InputFile.h:600
GlfStatus::INVALID
@ INVALID
invalid.
Definition: GlfStatus.h:39
GlfException
GlfException objects should be thrown by functions that operate on Glf files for exceptions.
Definition: GlfException.h:27
GlfStatus::FAIL_IO
@ FAIL_IO
method failed due to an I/O issue.
Definition: GlfStatus.h:34