Changes

From Genome Analysis Wiki
Jump to navigationJump to search
2,197 bytes added ,  17:21, 29 September 2010
no edit summary
Line 2: Line 2:  
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 (for reading from a file - for reading from stdin and writing, the user has to specify which type to open).
 
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 (for reading from a file - for reading from stdin and writing, the user has to specify which type to open).
    +
The IFILE class is made to mimic FILE.  THe typical way to use IFILE is to call the set of global methods contained in InputFile.h that take IFILE as a parameter
   −
=== Public Class Methods ===
+
To use IFILE, add the following include to your file.
 +
<source lang="cpp">
 +
#include "InputFile.h"
 +
</source>
 +
 
 +
=== Global IFILE Methods ===
 
{| style="margin: 1em 1em 1em 0; background-color: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;" border="1"
 
{| style="margin: 1em 1em 1em 0; background-color: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;" border="1"
 
|-style="background: #f2f2f2; text-align: center;"
 
|-style="background: #f2f2f2; text-align: center;"
 
! Method Name !!  Description
 
! Method Name !!  Description
 
|-
 
|-
| ***NEEDS TO BE FILLED IN***
+
| <code>IFILE ifopen(const char * filename, const char * mode, InputFile::ifileCompression compressionMode = InputFile::DEFAULT)</code>
| ***NEEDS TO BE FILLED IN***
+
| Open the file with the specified name with the specified mode.
 +
A filename = "-" indicates stdin/stdout.
 +
 
 +
When reading a file (not from stdin), the file compression type is determined by reading the file. 
 +
 
 +
When reading from stdin and writing anywhere the file compression type is determined by the passed in parameter.
 +
|-
 +
| <code>int ifclose(IFILE file)</code>
 +
| Close the file.
 +
|-
 +
| <code>unsigned int ifread(IFILE file, void * buffer, unsigned int size)</code>
 +
| Reads up to size bytes from the file into the buffer.  Returns the number of bytes read.
 +
|-
 +
| <code>int ifgetc(IFILE file)</code>
 +
| Reads and returns 1 character from the file.  Returns EOF on error/end of file.
 +
|-
 +
| <code>void ifrewind(IFILE file)</code>
 +
| Go to the beginning of the file (cannot be done for stdin/stdout).
 +
|-
 +
| <code> int ifeof(IFILE file)</code>
 +
| Return 0 if it is not the end of the file, otherwise returns non-zero.
 +
|-
 +
| <code>unsigned int ifwrite(IFILE file, const void * buffer, unsigned int size)</code>
 +
| Write the size bytes from buffer into the file.
 +
|-
 +
| <code>long int iftell(IFILE file)</code>
 +
| Tell the current position in the file.  Can be fed back into ifseek.
 +
|-
 +
| <code>bool ifseek(IFILE file, long int offset, int origin)</code>
 +
| Go to the specified position (result from an iftell) in the file (cannot be done for stdin/stdout).
 
|}
 
|}
   Line 25: Line 60:  
|-
 
|-
 
| UNCOMPRESSED
 
| UNCOMPRESSED
| Standard Uncompressed File Type.
+
| Standard, Uncompressed File Type.
 
|-
 
|-
 
| GZIP
 
| GZIP
Line 41: Line 76:  
   BgzfFileType::setRequireEofBlock(false);
 
   BgzfFileType::setRequireEofBlock(false);
 
With that call, the empty block is not checked for when opening the file.
 
With that call, the empty block is not checked for when opening the file.
 +
 +
 +
=== stdin/stdout ===
 +
This class can be used to read/write to stdin/stdout.
 +
 +
To use stdin/stdout, specify the filename as "-" and use the ifileCompression parameter in ifopen to specify the compression type. 
 +
 +
NOTE: even when reading from stdin, you MUST specify the file type.  It does not read from stdin to determine the compression type like it does for other files.
 +
 +
 +
==== Example ====
 +
<source lang="cpp">
 +
const char* filename = "-";
 +
IFILE myFilePtr = ifopen(filename, "rb", InputFile::BGZF);
 +
</source>

Navigation menu