|
libStatGen Software
1
|
This class allows a user to easily get/set the fields in a GLF section/chromosome header. More...
#include <GlfRefSection.h>
Public Member Functions | |
| GlfRefSection (const GlfRefSection &refSection) | |
| Copy Constructor. | |
| GlfRefSection & | operator= (const GlfRefSection &refSection) |
| Overload operator= to copy the passed in refSection into this one. | |
| bool | copy (const GlfRefSection &refSection) |
| Copy the passed in refSection into this refSection. | |
| void | resetRefSection () |
| Clear this reference section back to the default setting. | |
| bool | read (IFILE filePtr) |
| Read the refSection from the specified file (file MUST be in the correct position for reading a refSection). | |
| bool | write (IFILE filePtr) const |
| Write the refSection to the specified file. | |
| bool | getName (std::string &name) const |
| Get the reference name. | |
| uint32_t | getRefLen () const |
| Get the length of the reference sequence. | |
| bool | setName (const std::string &name) |
| Set the reference name. | |
| bool | setRefLen (uint32_t refLen) |
| Set the length of the reference sequence. | |
| void | print () const |
| Print the reference section in a readable format. | |
This class allows a user to easily get/set the fields in a GLF section/chromosome header.
The GlfRefSection contains:
Definition at line 31 of file GlfRefSection.h.
| GlfRefSection::GlfRefSection | ( | const GlfRefSection & | refSection | ) |
Copy Constructor.
| refSection | reference section to copy into this one. |
Definition at line 36 of file GlfRefSection.cpp.
References copy().
: myRefName()
{
copy(refSection);
}
| bool GlfRefSection::copy | ( | const GlfRefSection & | refSection | ) |
Copy the passed in refSection into this refSection.
| refSection | reference section to copy into this one. |
Definition at line 51 of file GlfRefSection.cpp.
References resetRefSection().
Referenced by GlfRefSection(), and operator=().
{
// Check to see if the passed in value is the same as this.
if(this == &refSection)
{
return(true);
}
resetRefSection();
// Copy the refSection.
myRefName = refSection.myRefName;
myRefLen = refSection.myRefLen;
return(true);
}
| bool GlfRefSection::getName | ( | std::string & | name | ) | const |
Get the reference name.
| name | string to populate with the reference name. |
Definition at line 193 of file GlfRefSection.cpp.
{
name = myRefName.c_str();
return(true);
}
| uint32_t GlfRefSection::getRefLen | ( | ) | const |
Get the length of the reference sequence.
Definition at line 200 of file GlfRefSection.cpp.
{
return(myRefLen);
}
| GlfRefSection & GlfRefSection::operator= | ( | const GlfRefSection & | refSection | ) |
Overload operator= to copy the passed in refSection into this one.
| refSection | reference section to copy into this one. |
Definition at line 44 of file GlfRefSection.cpp.
References copy().
{
copy(refSection);
return(*this);
}
| bool GlfRefSection::read | ( | IFILE | filePtr | ) |
Read the refSection from the specified file (file MUST be in the correct position for reading a refSection).
| filePtr | file to read from that is in the correct position. |
Definition at line 79 of file GlfRefSection.cpp.
References GlfStatus::FAIL_IO, ifeof(), and ifread().
Referenced by GlfFile::getNextRefSection().
{
// Read the reference sequence name length
int numRead = 0;
int32_t refNameLen = 0;
int byteLen = sizeof(int32_t);
numRead = ifread(filePtr, &refNameLen, byteLen);
if(numRead != byteLen)
{
// If no bytes were read and it is the end of the file, then return
// false, but do not throw an exception. This is not an error, just
// the end of the file.
if((numRead == 0) && ifeof(filePtr))
{
return(false);
}
String errorMsg =
"Failed to read the length of the reference sequence name (";
errorMsg += byteLen;
errorMsg += " bytes). Only read ";
errorMsg += numRead;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Read the refSection from the file.
numRead = myRefName.readFromFile(filePtr, refNameLen);
if(numRead != refNameLen)
{
String errorMsg = "Failed to read the reference sequence name (";
errorMsg += refNameLen;
errorMsg += " bytes). Only read ";
errorMsg += numRead;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Read the ref length.
byteLen = sizeof(uint32_t);
numRead = ifread(filePtr, &myRefLen, byteLen);
if(numRead != byteLen)
{
String errorMsg = "Failed to read the reference sequence length (";
errorMsg += byteLen;
errorMsg += " bytes). Only read ";
errorMsg += numRead;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Successfully read, return success.
return(true);
}
| bool GlfRefSection::setName | ( | const std::string & | name | ) |
Set the reference name.
| name | reference name to set this section to. |
Definition at line 206 of file GlfRefSection.cpp.
{
myRefName = name;
return(true);
}
| bool GlfRefSection::setRefLen | ( | uint32_t | refLen | ) |
Set the length of the reference sequence.
| refLen | reference sequence length to set this section to. |
Definition at line 213 of file GlfRefSection.cpp.
{
myRefLen = refLen;
return(true);
}
| bool GlfRefSection::write | ( | IFILE | filePtr | ) | const |
Write the refSection to the specified file.
| filePtr | file to write to that is in the correct position. |
Definition at line 142 of file GlfRefSection.cpp.
References GlfStatus::FAIL_IO, and ifwrite().
Referenced by GlfFile::writeRefSection().
{
int refNameLen = myRefName.length();
int byteLen = sizeof(int32_t);
int numWrite = ifwrite(filePtr, &refNameLen, byteLen);
if(numWrite != byteLen)
{
String errorMsg =
"Failed to write the length of the reference sequence name (";
errorMsg += byteLen;
errorMsg += " bytes). Only wrote ";
errorMsg += numWrite;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
numWrite = ifwrite(filePtr, myRefName.c_str(), refNameLen);
if(numWrite != refNameLen)
{
String errorMsg = "Failed to write the reference sequence name (";
errorMsg += refNameLen;
errorMsg += " bytes). Only wrote ";
errorMsg += numWrite;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Write the length of the reference sequence
byteLen = sizeof(uint32_t);
numWrite = ifwrite(filePtr, &myRefLen, byteLen);
if(numWrite != byteLen)
{
String errorMsg = "Failed to write the reference sequence length (";
errorMsg += byteLen;
errorMsg += " bytes). Only wrote ";
errorMsg += numWrite;
errorMsg += " bytes.";
std::string errorString = errorMsg.c_str();
throw(GlfException(GlfStatus::FAIL_IO, errorString));
return(false);
}
// Successfully wrote, return success.
return(true);
}