Difference between revisions of "C++ Class: InputFile"

From Genome Analysis Wiki
Jump to navigationJump to search
Line 14: Line 14:
 
Defaults to [[C++ Class: InputFile#ClassEnums|DEFAULT]] which determines the file type from the extension when opening a file for write.
 
Defaults to [[C++ Class: InputFile#ClassEnums|DEFAULT]] which determines the file type from the extension when opening a file for write.
 
|}
 
|}
 +
 +
==== Using the static methods ====
 +
Here is an example of using setWriteFileType (writes a glf as a standard file rather than in bgzf which would be the default):
 +
<source lang="cpp">
 +
    InputFile::setWriteFileType(InputFile::STD);
 +
    std::string filename = "results/stdFile.glf";
 +
    assert(InputFile::openFile(filename.c_str(), "wt") == true);
 +
    assert(ifwrite(TEST_FILE_CONTENTS.c_str(), TEST_FILE_CONTENTS.length())
 +
          == TEST_FILE_CONTENTS.length());
 +
    assert(ifclose() == 0);
 +
</source>
  
  

Revision as of 11:54, 20 May 2010

InputFile / IFILE

This is our class for file operations. It hides the underlying file structure from the user. That way code can generically open and operate on a file using the exact same interface without having to know if the file is standard, gzip, or bgzf format.


static Class Methods

Method Name Description
void InputFile::setWriteFileType(FileTypeEnum fileType) Set the type of file to open when opening a file for write.

Must be called prior to calling ifopen().

Defaults to DEFAULT which determines the file type from the extension when opening a file for write.

Using the static methods

Here is an example of using setWriteFileType (writes a glf as a standard file rather than in bgzf which would be the default):

    InputFile::setWriteFileType(InputFile::STD);
    std::string filename = "results/stdFile.glf";
    assert(InputFile::openFile(filename.c_str(), "wt") == true);
    assert(ifwrite(TEST_FILE_CONTENTS.c_str(), TEST_FILE_CONTENTS.length()) 
           == TEST_FILE_CONTENTS.length());
    assert(ifclose() == 0);


Public Class Methods

Method Name Description
***NEEDS TO BE FILLED IN*** ***NEEDS TO BE FILLED IN***

Class Enums

Enum Value Description
enum FileTypeEnum
DEFAULT Use the default method for determining file type.
STD Standard File Type.
GZ Gzip File Type.
BGZF bgzf File Type.


BGZF Notes

Newer BGZF files have a empty BGZF block at the end to mark the EOF. By default when opening BGZF Files for reading, the software requires the empty block and the fail opens if it is not there. To support files without the empty block, the following call must first be made:

 BgzfFileType::setRequireEofBlock(false);

With that call, the empty block is not checked for when opening the file.