glfHandler Class Reference
Collaboration diagram for glfHandler:
[legend]

## Public Member Functions

bool | Open (const String &filename)
void | OpenStub ()
bool | Create (const String &filename)
bool | isOpen ()
void | Close ()
void | Rewind ()
bool | NextSection ()
bool | NextEntry ()
bool | NextBaseEntry ()
void | BeginSection (const String &sectionLabel, int sectionLength)
void | EndSection ()
void | WriteEntry (int outputPosition)
char | GetReference (int position, char defaultBase)
int | GetDepth (int position)
const double * | GetLikelihoods (int position)
const unsigned char * | GetLogLikelihoods (int position)
int | GetMapQuality (int position)

## Static Public Member Functions

static const double * | GetDefaultLikelihoods ()
static const unsigned char * | GetDefaultLogLikelihoods ()
static int | GenotypeIndex (int base1, int base2)

## Public Attributes

bool | isStub
IFILE | handle
String | header
String | label
int | sections
int | currentSection
int | maxPosition
bool | endOfSection
glfEntry | data
int | position
double | likelihoods [10]
String | indelSequence [2]
const char * | errorMsg

## Detailed Description

Definition at line 72 of file glfHandler.h.

## Constructor & Destructor Documentation

## glfHandler()

glfHandler::glfHandler | ( |  | ) |

Definition at line 26 of file glfHandler.cpp.

{
isStub = true;
sections = 0;
currentSection = 0;
maxPosition = position = endOfSection = 0;
}

## ~glfHandler()

glfHandler::~glfHandler | ( |  | ) |

Definition at line 34 of file glfHandler.cpp.

{
// Not safe to close the file here in case a copy of the file was generated
// if (isOpen())
// Close();
}

## Member Function Documentation

## BeginSection()

void glfHandler::BeginSection | ( | const String & | sectionLabel,
|  | int | sectionLength
| ) |  |

Definition at line 355 of file glfHandler.cpp.

{
int labelLength = sectionLabel.Length() + 1;
ifwrite(handle, &labelLength, sizeof(int));
ifwrite(handle, (void *)(const char *) sectionLabel, labelLength);
ifwrite(handle, &sectionLength, sizeof(int));
label = sectionLabel;
maxPosition = sectionLength;
}
ifwrite
unsigned int ifwrite(IFILE file, const void *buffer, unsigned int size)
Write the specified number of bytes from the specified buffer into the file.
Definition: InputFile.h:669

## Close()

void glfHandler::Close | ( |  | ) |

Definition at line 147 of file glfHandler.cpp.

{
if (isOpen())
ifclose(handle);
}
ifclose
int ifclose(IFILE &file)
Close the file.
Definition: InputFile.h:580

## Create()

bool glfHandler::Create | ( | const String & | filename | ) |

Definition at line 71 of file glfHandler.cpp.

{
isStub = false;
// glf is in BGZF format.
handle = ifopen(filename, "wb", InputFile::BGZF);
if (handle == NULL)
{
isStub = true;
return false;
}
WriteHeader();
return handle != NULL;
}
ifopen
IFILE ifopen(const char *filename, const char *mode, InputFile::ifileCompression compressionMode=InputFile::DEFAULT)
Open a file with the specified name and mode, using a filename of "-" to indicate stdin/stdout.
Definition: InputFile.h:562
InputFile::BGZF
@ BGZF
bgzf file.
Definition: InputFile.h:48

## EndSection()

void glfHandler::EndSection | ( |  | ) |

Definition at line 367 of file glfHandler.cpp.

{
char marker = 0;
ifwrite(handle, &marker, sizeof(char));
}

## GenotypeIndex()

static int glfHandler::GenotypeIndex | ( | int | base1,
|  | int | base2
| ) |  |

inline static

Definition at line 132 of file glfHandler.h.

{
return base1 < base2 ? (base1 - 1) *(10 - base1) / 2 + (base2 - base1) :
(base2 - 1) *(10 - base2) / 2 + (base1 - base2);
}

## GetDefaultLikelihoods()

static const double * glfHandler::GetDefaultLikelihoods | ( |  | ) |

inline static

Definition at line 123 of file glfHandler.h.

{
return nullLikelihoods;
}

## GetDefaultLogLikelihoods()

static const unsigned char * glfHandler::GetDefaultLogLikelihoods | ( |  | ) |

inline static

Definition at line 127 of file glfHandler.h.

{
return nullLogLikelihoods;
}

## GetDepth()

int glfHandler::GetDepth | ( | int | position | ) |

Definition at line 327 of file glfHandler.cpp.

{
if (pos == position)
return data.depth;
return 0;
}
glfEntry::depth
unsigned depth
log10 minimum likelihood * 10 and the number of mapped reads
Definition: glfHandler.h:51

## GetLikelihoods()

const double * glfHandler::GetLikelihoods | ( | int | position | ) |

Definition at line 303 of file glfHandler.cpp.

{
if (pos == position)
return likelihoods;
return nullLikelihoods;
}

## GetLogLikelihoods()

const unsigned char * glfHandler::GetLogLikelihoods | ( | int | position | ) |

Definition at line 311 of file glfHandler.cpp.

{
if (pos == position)
return data.lk;
return nullLogLikelihoods;
}
glfEntry::lk
unsigned char lk[10]
log10 likelihood ratio * 10 for genotypes AA, AC, AG, AT, CC, CG, CT, GG, GT, TT
Definition: glfHandler.h:59

## GetMapQuality()

int glfHandler::GetMapQuality | ( | int | position | ) |

Definition at line 335 of file glfHandler.cpp.

{
if (pos == position)
return data.mapQuality;
return 0;
}
glfEntry::mapQuality
unsigned char mapQuality
root mean squared maximum mapping quality for overlapping reads
Definition: glfHandler.h:54

## GetReference()

char glfHandler::GetReference | ( | int | position,
|  | char | defaultBase
| ) |  |

Definition at line 319 of file glfHandler.cpp.

{
if (pos == position)
return data.refBase;
return defaultBase;
}
glfEntry::refBase
unsigned char refBase
"XACMGRSVTWYHKDBN"[ref_base] gives the reference base
Definition: glfHandler.h:45

## isOpen()

bool glfHandler::isOpen | ( |  | ) |

Definition at line 88 of file glfHandler.cpp.

{
return handle != NULL;
}

## NextBaseEntry()

bool glfHandler::NextBaseEntry | ( |  | ) |

Definition at line 200 of file glfHandler.cpp.

{
bool result = true;
do
{
result = NextEntry();
}
while (result && data.recordType == 2);
return result;
}

## NextEntry()

bool glfHandler::NextEntry | ( |  | ) |

Definition at line 214 of file glfHandler.cpp.

{
if (isStub)
return false;
// Read record type
if (endOfSection || (ifread(handle, &data, 1) != 1))
{
endOfSection = true;
data.recordType = 0;
position = maxPosition + 1;
return false;
}
// printf("%d/%d\n", data.recordType, data.refBase);
if (position > maxPosition)
return true;
switch (data.recordType)
{
case 0 :
endOfSection = true;
position = maxPosition + 1;
return true;
case 1 :
if (ifread(handle,((char *) &data) + 1, sizeof(data) - 1) == sizeof(data) - 1)
{
data.refBase = translateBase[data.refBase];
for (int i = 0; i < 10; i++)
likelihoods[i] = bQualityConvertor.toDouble(data.lk[i]);
position = position + data.offset;
return true;
}
// Premature end of file
data.recordType = 0;
position = maxPosition + 1;
return false;
case 2 :
while (ifread(handle, ((char *) &data) + 1, sizeof(data) - 4) == sizeof(data) - 4)
{
data.refBase = translateBase[data.refBase];
for (int i = 0; i < 3; i++)
likelihoods[i] = bQualityConvertor.toDouble(data.indel.lk[i]);
position = position + data.offset;
indelSequence[0].SetLength(abs(data.indel.length[0]) + 1);
indelSequence[0][abs(data.indel.length[0])] = 0;
if (ifread(handle, indelSequence[0].LockBuffer(), abs(data.indel.length[0])) != (unsigned int) abs(data.indel.length[0]))
break;
indelSequence[1].SetLength(abs(data.indel.length[1]) + 1);
indelSequence[1][abs(data.indel.length[1])] = 0;
if (ifread(handle, indelSequence[1].LockBuffer(), abs(data.indel.length[1])) != (unsigned int) abs(data.indel.length[1]))
break;
return true;
}
// Premature end of file
data.recordType = 0;
position = maxPosition + 1;
return false;
}
return false;
}
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

## NextSection()

bool glfHandler::NextSection | ( |  | ) |

Definition at line 166 of file glfHandler.cpp.

{
if (isStub)
{
endOfSection = true;
data.recordType = 0;
maxPosition = 1999999999;
position = maxPosition + 1;
return true;
}
while (!endOfSection && !ifeof(handle))
NextEntry();
endOfSection = false;
int labelLength = 0;
currentSection++;
position = 0;
if (ifread(handle, &labelLength, sizeof(int)) == sizeof(int))
{
ifread(handle, label.LockBuffer(labelLength+1), labelLength * sizeof(char));
label.UnlockBuffer();
maxPosition = 0;
ifread(handle, &maxPosition, sizeof(int));
return ((maxPosition > 0) && !ifeof(handle));
}
return false;
}
ifeof
int ifeof(IFILE file)
Check to see if we have reached the EOF (returns 0 if not EOF).
Definition: InputFile.h:654

## Open()

bool glfHandler::Open | ( | const String & | filename | ) |

Definition at line 41 of file glfHandler.cpp.

{
isStub = false;
handle = ifopen(filename, "rb");
if (handle == NULL)
{
isStub = true;
return false;
}
if (!ReadHeader())
ifclose(handle);
endOfSection = true;
return handle != NULL;
}

## OpenStub()

void glfHandler::OpenStub | ( |  | ) |

Definition at line 60 of file glfHandler.cpp.

{
isStub = true;
handle = NULL;
endOfSection = true;
data.recordType = 0;
maxPosition = 1999999999;
position = maxPosition + 1;
}

## Rewind()

void glfHandler::Rewind | ( |  | ) |

Definition at line 153 of file glfHandler.cpp.

{
if (isOpen())
{
ifrewind(handle);
if (!ReadHeader())
ifclose(handle);
endOfSection = true;
}
}
ifrewind
void ifrewind(IFILE file)
Reset to the beginning of the file (cannot be done for stdin/stdout).
Definition: InputFile.h:642

## WriteEntry()

void glfHandler::WriteEntry | ( | int | outputPosition | ) |

Definition at line 374 of file glfHandler.cpp.

{
data.offset = outputPosition - position;
position = outputPosition;
switch (data.recordType)
{
case 0 :
EndSection();
return;
case 1 :
data.refBase = backTranslateBase[data.refBase];
ifwrite(handle, &data, sizeof(data));
data.refBase = translateBase[data.refBase];
return;
case 2 :
data.refBase = backTranslateBase[data.refBase];
ifwrite(handle, &data, sizeof(data) - 3);
data.refBase = translateBase[data.refBase];
ifwrite(handle, (void *)(const char *) indelSequence[0], abs(data.indel.length[0]));
ifwrite(handle, (void *)(const char *) indelSequence[1], abs(data.indel.length[1]));
return;
}
}
glfEntry::offset
unsigned int offset
offset of this record from the previous one, in bases
Definition: glfHandler.h:48

## Member Data Documentation

## currentSection

int glfHandler::currentSection

Definition at line 83 of file glfHandler.h.

## data

glfEntry glfHandler::data

Definition at line 90 of file glfHandler.h.

## endOfSection

bool glfHandler::endOfSection

Definition at line 87 of file glfHandler.h.

## errorMsg

const char* glfHandler::errorMsg

Definition at line 96 of file glfHandler.h.

## handle

IFILE glfHandler::handle

Definition at line 77 of file glfHandler.h.

## header

String glfHandler::header

Definition at line 78 of file glfHandler.h.

## indelSequence

String glfHandler::indelSequence[2]

Definition at line 93 of file glfHandler.h.

## isStub

bool glfHandler::isStub

Definition at line 76 of file glfHandler.h.

## label

String glfHandler::label

Definition at line 81 of file glfHandler.h.

## likelihoods

double glfHandler::likelihoods[10]

Definition at line 92 of file glfHandler.h.

## maxPosition

int glfHandler::maxPosition

Definition at line 84 of file glfHandler.h.

## position

int glfHandler::position

Definition at line 91 of file glfHandler.h.

## sections

int glfHandler::sections

Definition at line 82 of file glfHandler.h.

The documentation for this class was generated from the following files:

- general/glfHandler.h
- general/glfHandler.cpp