libStatGen Software  1
GlfRefSection Class Reference

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

#include <GlfRefSection.h>

List of all members.

Public Member Functions

 GlfRefSection (const GlfRefSection &refSection)
 Copy Constructor.
GlfRefSectionoperator= (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.

Detailed Description

This class allows a user to easily get/set the fields in a GLF section/chromosome header.

The GlfRefSection contains:

  • Reference Sequence Name
  • Reference Sequence Length

Definition at line 31 of file GlfRefSection.h.


Constructor & Destructor Documentation

GlfRefSection::GlfRefSection ( const GlfRefSection refSection)

Copy Constructor.

Parameters:
refSectionreference section to copy into this one.

Definition at line 36 of file GlfRefSection.cpp.

References copy().

    : myRefName()
{
    copy(refSection);
}

Member Function Documentation

bool GlfRefSection::copy ( const GlfRefSection refSection)

Copy the passed in refSection into this refSection.

Parameters:
refSectionreference 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.

Parameters:
namestring to populate with the reference name.
Returns:
true if the name was successfully returned, false if not.

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.

Returns:
reference sequence length for this reference section.

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.

Parameters:
refSectionreference 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).

Parameters:
filePtrfile to read from that is in the correct position.
Returns:
true if the reference section was successfully read from the file, false if not.

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.

Parameters:
namereference name to set this section to.
Returns:
true if the name was successfully set, false if not.

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.

Parameters:
refLenreference sequence length to set this section to.
Returns:
true if the length was successfully set, false if not.

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.

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

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);
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends