Changes

From Genome Analysis Wiki
Jump to navigationJump to search
1,260 bytes removed ,  10:47, 2 February 2017
Line 1: Line 1:  +
[[Category:C++]]
 +
[[Category:libStatGen]]
 +
[[Category:libStatGen general]]
 +
 
= InputFile / IFILE =
 
= 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 (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).
Line 10: Line 14:     
=== Global IFILE Methods ===
 
=== Global IFILE Methods ===
{| style="margin: 1em 1em 1em 0; background-color: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;" border="1"
  −
|-style="background: #f2f2f2; text-align: center;"
  −
! Method Name !!  Description
  −
|-
  −
| <code>IFILE ifopen(const char * filename, const char * mode, InputFile::ifileCompression compressionMode = InputFile::DEFAULT)</code>
  −
| 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).
  −
|}
     −
=== Class Enums ===
+
See: http://csg.sph.umich.edu//mktrost/doxygen/current/InputFile_8h.html for documentation on the global IFILE methods.
{| style="margin: 1em 1em 1em 0; background-color: #f9f9f9; border: 1px #aaa solid; border-collapse: collapse;" border="1"
  −
|-style="background: #f2f2f2; text-align: center;"
     −
! Enum Value !!  Description
+
=== InputFile Class Documentation ===
|-
  −
! colspan="2"| enum ifileCompression
  −
|-
  −
| DEFAULT
  −
| Use the default method for determining file type.
  −
Opens as UNCOMPRESSED unless the filename ends in ".gz", then opened as GZIP
  −
|-
  −
| UNCOMPRESSED
  −
| Standard, Uncompressed File Type.
  −
|-
  −
| GZIP
  −
| Gzip File Type.
  −
|-
  −
| BGZF
  −
| bgzf File Type.
  −
|}
      +
See: http://csg.sph.umich.edu//mktrost/doxygen/current/classInputFile.html
    
=== BGZF Notes ===
 
=== BGZF Notes ===
Line 85: Line 36:  
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.
 
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.
    +
'''When writing programs that will use stdout and pipes to send input from one program to the next, make sure that all error, debug, or info messages are written to stderr/cerr and not stdout/cout.'''
   −
==== Example ====
+
=== Example ===
 
<source lang="cpp">
 
<source lang="cpp">
 +
// specify to open stdin for read.
 +
// replace the - with a filename in order to read from a file.
 
  const char* filename = "-";
 
  const char* filename = "-";
 
  IFILE myFilePtr = ifopen(filename, "rb", InputFile::BGZF);
 
  IFILE myFilePtr = ifopen(filename, "rb", InputFile::BGZF);
 +
if (myFilePtr == NULL)
 +
{
 +
    std::cerr << "Failed to open the file\n";
 +
}
 +
else
 +
{
 +
    // File was successfully opened.
 +
    // Read the magic string.
 +
    char magic[4];
 +
    if(ifread(myFilePtr, magic, 4) != 4)
 +
    {
 +
      std::cerr << "Could not read 4 bytes from the file\n";
 +
    }
 +
    ifclose(myFilePtr);
 +
    myFilePtr = NULL;
 +
}
 
</source>
 
</source>
96

edits

Navigation menu