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>

Public Member Functions

 GlfRefSection (const GlfRefSection &refSection)
 Copy Constructor. More...
 
GlfRefSectionoperator= (const GlfRefSection &refSection)
 Overload operator= to copy the passed in refSection into this one. More...
 
bool copy (const GlfRefSection &refSection)
 Copy the passed in refSection into this refSection. More...
 
void resetRefSection ()
 Clear this reference section back to the default setting. More...
 
bool read (IFILE filePtr)
 Read the refSection from the specified file (file MUST be in the correct position for reading a refSection). More...
 
bool write (IFILE filePtr) const
 Write the refSection to the specified file. More...
 
bool getName (std::string &name) const
 Get the reference name. More...
 
uint32_t getRefLen () const
 Get the length of the reference sequence. More...
 
bool setName (const std::string &name)
 Set the reference name. More...
 
bool setRefLen (uint32_t refLen)
 Set the length of the reference sequence. More...
 
void print () const
 Print the reference section in a readable format. More...
 

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() [1/2]

GlfRefSection::GlfRefSection ( )

Definition at line 22 of file GlfRefSection.cpp.

23 : myRefName()
24{
26}
void resetRefSection()
Clear this reference section back to the default setting.

◆ ~GlfRefSection()

GlfRefSection::~GlfRefSection ( )

Definition at line 29 of file GlfRefSection.cpp.

30{
32}

◆ GlfRefSection() [2/2]

GlfRefSection::GlfRefSection ( const GlfRefSection refSection)

Copy Constructor.

Parameters
refSectionreference section to copy into this one.

Definition at line 36 of file GlfRefSection.cpp.

37 : myRefName()
38{
39 copy(refSection);
40}
bool copy(const GlfRefSection &refSection)
Copy the passed in refSection into this refSection.

References copy().

Member Function Documentation

◆ copy()

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.

52{
53 // Check to see if the passed in value is the same as this.
54 if(this == &refSection)
55 {
56 return(true);
57 }
58
60
61 // Copy the refSection.
62 myRefName = refSection.myRefName;
63 myRefLen = refSection.myRefLen;
64
65 return(true);
66}

References resetRefSection().

Referenced by GlfRefSection(), and operator=().

◆ getName()

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.

194{
195 name = myRefName.c_str();
196 return(true);
197}

◆ getRefLen()

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.

201{
202 return(myRefLen);
203}

◆ operator=()

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.

45{
46 copy(refSection);
47 return(*this);
48}

References copy().

◆ print()

void GlfRefSection::print ( ) const

Print the reference section in a readable format.

Definition at line 220 of file GlfRefSection.cpp.

221{
222 std::cout << "l_name: " << myRefName.length()
223 << "; name: " << myRefName.c_str()
224 << "; ref_len: " << myRefLen
225 << "\n";
226}

◆ read()

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.

80{
81 // Read the reference sequence name length
82 int numRead = 0;
83 int32_t refNameLen = 0;
84 int byteLen = sizeof(int32_t);
85 numRead = ifread(filePtr, &refNameLen, byteLen);
86 if(numRead != byteLen)
87 {
88 // If no bytes were read and it is the end of the file, then return
89 // false, but do not throw an exception. This is not an error, just
90 // the end of the file.
91 if((numRead == 0) && ifeof(filePtr))
92 {
93 return(false);
94 }
95
96 String errorMsg =
97 "Failed to read the length of the reference sequence name (";
98 errorMsg += byteLen;
99 errorMsg += " bytes). Only read ";
100 errorMsg += numRead;
101 errorMsg += " bytes.";
102 std::string errorString = errorMsg.c_str();
103 throw(GlfException(GlfStatus::FAIL_IO, errorString));
104 return(false);
105 }
106
107 // Read the refSection from the file.
108 numRead = myRefName.readFromFile(filePtr, refNameLen);
109 if(numRead != refNameLen)
110 {
111 String errorMsg = "Failed to read the reference sequence name (";
112 errorMsg += refNameLen;
113 errorMsg += " bytes). Only read ";
114 errorMsg += numRead;
115 errorMsg += " bytes.";
116 std::string errorString = errorMsg.c_str();
117 throw(GlfException(GlfStatus::FAIL_IO, errorString));
118 return(false);
119 }
120
121 // Read the ref length.
122 byteLen = sizeof(uint32_t);
123 numRead = ifread(filePtr, &myRefLen, byteLen);
124 if(numRead != byteLen)
125 {
126 String errorMsg = "Failed to read the reference sequence length (";
127 errorMsg += byteLen;
128 errorMsg += " bytes). Only read ";
129 errorMsg += numRead;
130 errorMsg += " bytes.";
131 std::string errorString = errorMsg.c_str();
132 throw(GlfException(GlfStatus::FAIL_IO, errorString));
133 return(false);
134 }
135
136 // Successfully read, return success.
137 return(true);
138}
int ifeof(IFILE file)
Check to see if we have reached the EOF (returns 0 if not EOF).
Definition: InputFile.h:654
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
GlfException objects should be thrown by functions that operate on Glf files for exceptions.
Definition: GlfException.h:28
@ FAIL_IO
method failed due to an I/O issue.
Definition: GlfStatus.h:34

References GlfStatus::FAIL_IO, ifeof(), and ifread().

Referenced by GlfFile::getNextRefSection().

◆ resetRefSection()

void GlfRefSection::resetRefSection ( )

Clear this reference section back to the default setting.

Definition at line 70 of file GlfRefSection.cpp.

71{
72 myRefName.reset();
73 myRefLen = 0;
74}

Referenced by copy().

◆ setName()

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.

207{
208 myRefName = name;
209 return(true);
210}

◆ setRefLen()

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.

214{
215 myRefLen = refLen;
216 return(true);
217}

◆ write()

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.

143{
144 int refNameLen = myRefName.length();
145 int byteLen = sizeof(int32_t);
146 int numWrite = ifwrite(filePtr, &refNameLen, byteLen);
147 if(numWrite != byteLen)
148 {
149 String errorMsg =
150 "Failed to write the length of the reference sequence name (";
151 errorMsg += byteLen;
152 errorMsg += " bytes). Only wrote ";
153 errorMsg += numWrite;
154 errorMsg += " bytes.";
155 std::string errorString = errorMsg.c_str();
156 throw(GlfException(GlfStatus::FAIL_IO, errorString));
157 return(false);
158 }
159
160 numWrite = ifwrite(filePtr, myRefName.c_str(), refNameLen);
161 if(numWrite != refNameLen)
162 {
163 String errorMsg = "Failed to write the reference sequence name (";
164 errorMsg += refNameLen;
165 errorMsg += " bytes). Only wrote ";
166 errorMsg += numWrite;
167 errorMsg += " bytes.";
168 std::string errorString = errorMsg.c_str();
169 throw(GlfException(GlfStatus::FAIL_IO, errorString));
170 return(false);
171 }
172
173 // Write the length of the reference sequence
174 byteLen = sizeof(uint32_t);
175 numWrite = ifwrite(filePtr, &myRefLen, byteLen);
176 if(numWrite != byteLen)
177 {
178 String errorMsg = "Failed to write the reference sequence length (";
179 errorMsg += byteLen;
180 errorMsg += " bytes). Only wrote ";
181 errorMsg += numWrite;
182 errorMsg += " bytes.";
183 std::string errorString = errorMsg.c_str();
184 throw(GlfException(GlfStatus::FAIL_IO, errorString));
185 return(false);
186 }
187
188 // Successfully wrote, return success.
189 return(true);
190}
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

References GlfStatus::FAIL_IO, and ifwrite().

Referenced by GlfFile::writeRefSection().


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