libStatGen Software 1
|
#include <stdio.h>
#include <iostream>
#include <cstring>
#include <stdint.h>
#include "FileType.h"
Go to the source code of this file.
Classes | |
class | InputFile |
Class for easily reading/writing files without having to worry about file type (uncompressed, gzip, bgzf) when reading. More... | |
Typedefs | |
typedef InputFile * | IFILE |
Define IFILE as a pointer to an InputFile object. | |
Functions | |
IFILE | ifopen (const char *filename, const char *mode, InputFile::ifileCompression compressionMode=InputFile::DEFAULT) |
Open a file with the specified name and mode, using a filename of "-" to indicate stdin/stdout. | |
int | ifclose (IFILE &file) |
Close the file. | |
unsigned int | ifread (IFILE file, void *buffer, unsigned int size) |
Read up to size bytes from the file into the buffer. | |
int | ifgetc (IFILE file) |
Get a character from the file. | |
bool | ifgetline (IFILE file, void *buffer, size_t max) |
Get a line from the file. | |
void | ifrewind (IFILE file) |
Reset to the beginning of the file (cannot be done for stdin/stdout). | |
int | ifeof (IFILE file) |
Check to see if we have reached the EOF (returns 0 if not EOF). | |
unsigned int | ifwrite (IFILE file, const void *buffer, unsigned int size) |
Write the specified number of bytes from the specified buffer into the file. | |
int64_t | iftell (IFILE file) |
Get current position in the file. | |
bool | ifseek (IFILE file, int64_t offset, int origin) |
Seek to the specified position (result from an iftell), but cannot be done for stdin/stdout. | |
int | ifprintf (IFILE output, const char *format,...) |
Write to a file using fprintf format. | |
IFILE | operator>> (IFILE stream, std::string &str) |
Read a line from a file using streaming. | |
InputFile & | operator<< (InputFile &stream, const std::string &str) |
Write to a file using streaming. | |
InputFile & | operator<< (InputFile &stream, const char *str) |
Write to a file using streaming. | |
InputFile & | operator<< (InputFile &stream, double num) |
Write to a file using streaming. | |
InputFile & | operator<< (InputFile &stream, int num) |
Write to a file using streaming. | |
InputFile & | operator<< (InputFile &stream, unsigned int num) |
Write to a file using streaming. | |
InputFile & | operator<< (InputFile &stream, char ch) |
Write to a file using streaming. | |
Define IFILE as a pointer to an InputFile object.
Definition at line 551 of file InputFile.h.
|
inline |
Close the file.
file | file to be closed - IFILE is a pointer to an InputFile object |
Definition at line 580 of file InputFile.h.
References InputFile::ifclose().
Referenced by FastQFile::closeFile(), GenomeSequence::loadDBSNP(), BamIndex::readIndex(), and SamFile::resetFile().
|
inline |
Check to see if we have reached the EOF (returns 0 if not EOF).
file | file to be checked - IFILE is a pointer to an InputFile object |
Definition at line 654 of file InputFile.h.
References InputFile::ifeof().
Referenced by FastQFile::isEof(), GlfFile::isEOF(), GlfRefSection::read(), FastQFile::readFastQSequence(), and SamRecord::setBufferFromFile().
|
inline |
Get a character from the file.
Read a character from the internal buffer, or if the end of the buffer has been reached, read from the file into the buffer and return index 0.
file | file to be read - IFILE is a pointer to an InputFile object |
Definition at line 615 of file InputFile.h.
References InputFile::ifgetc().
|
inline |
Get a line from the file.
file | file to be read - IFILE is a pointer to an InputFile object |
buffer | the buffer into which data is to be placed |
max | the maximum size of the buffer, in bytes |
Definition at line 630 of file InputFile.h.
References InputFile::ifgetline().
|
inline |
Open a file with the specified name and mode, using a filename of "-" to indicate stdin/stdout.
filename | file to open ("-" meands stdin/stdout) |
mode | same format as fopen: "r" for read & "w" for write. |
compressionMode | set the type of file to open for writing or for reading from stdin (when reading files not from stdin, the compression type is determined by reading the file). |
Definition at line 562 of file InputFile.h.
References InputFile::isOpen().
Referenced by GenomeSequence::loadDBSNP(), FastQFile::openFile(), GlfFile::openForRead(), SamFile::OpenForRead(), GlfFile::openForWrite(), SamFile::OpenForWrite(), BamIndex::readIndex(), and Tabix::readIndex().
int ifprintf | ( | IFILE | output, |
const char * | format, | ||
... | |||
) |
Write to a file using fprintf format.
file | file to write to - IFILE is a pointer to an InputFile object |
format | printf format for writing, followed by parameters. |
Definition at line 398 of file InputFile.cpp.
|
inline |
Read up to size bytes from the file into the buffer.
file | file to be read - IFILE is a pointer to an InputFile object |
buffer | pointer to memory at least size bytes big to write the data into. |
size | number of bytes to be read |
Definition at line 600 of file InputFile.h.
References InputFile::ifread().
Referenced by SamFile::OpenForRead(), GlfHeader::read(), GlfRecord::read(), GlfRefSection::read(), BamIndex::readIndex(), Tabix::readIndex(), and SamRecord::setBufferFromFile().
|
inline |
Reset to the beginning of the file (cannot be done for stdin/stdout).
file | file to be rewound - IFILE is a pointer to an InputFile object |
Definition at line 642 of file InputFile.h.
References InputFile::ifrewind().
Referenced by SamFile::OpenForRead().
|
inline |
Seek to the specified position (result from an iftell), but cannot be done for stdin/stdout.
file | file to perform seek on - IFILE is a pointer to an InputFile object |
offset | offset into the file to move to (must be from a tell call) |
origin | can be any of the following: Note: not all are valid for all filetypes. SEEK_SET - Beginning of file SEEK_CUR - Current position of the file pointer SEEK_END - End of file |
Definition at line 701 of file InputFile.h.
References InputFile::ifseek().
|
inline |
Get current position in the file.
Can be fed back into ifseek.
file | file to perform tell on - IFILE is a pointer to an InputFile object |
Definition at line 682 of file InputFile.h.
References InputFile::iftell().
Referenced by SamFile::GetCurrentPosition().
|
inline |
Write the specified number of bytes from the specified buffer into the file.
file | file to write to - IFILE is a pointer to an InputFile object |
buffer | buffer containing size bytes to write to the file. |
size | number of bytes to write |
Definition at line 669 of file InputFile.h.
References InputFile::ifwrite().
Referenced by GlfHeader::write(), GlfRefSection::write(), and SamRecord::writeRecordBuffer().
Write to a file using streaming.
stream | file to write to - IFILE is a pointer to an InputFile object |
ch | character that should be written to the file. |
Definition at line 786 of file InputFile.h.
References InputFile::ifwrite().
Write to a file using streaming.
stream | file to write to - IFILE is a pointer to an InputFile object |
str | string containing what should be written to the file. |
Definition at line 753 of file InputFile.h.
References InputFile::ifwrite().
Write to a file using streaming.
stream | file to write to - IFILE is a pointer to an InputFile object |
str | string containing what should be written to the file. |
Definition at line 736 of file InputFile.h.
References InputFile::ifwrite().
Write to a file using streaming.
stream | file to write to - IFILE is a pointer to an InputFile object |
num | number that should be written to the file. |
Definition at line 413 of file InputFile.cpp.
Write to a file using streaming.
stream | file to write to - IFILE is a pointer to an InputFile object |
num | number that should be written to the file. |
Definition at line 422 of file InputFile.cpp.
Write to a file using streaming.
stream | file to write to - IFILE is a pointer to an InputFile object |
num | number that should be written to the file. |
Definition at line 431 of file InputFile.cpp.
Read a line from a file using streaming.
Will not fail when the file hits EOF, so do not do: while(iFile >> iStr) unless within your loop you check for ifeof and break. Instead, do something like: while(!iFile->ifeof() && iFile >> iStr)
stream | file to read from - IFILE is a pointer to an InputFile object |
str | output string containing the line read from the file. |
Definition at line 724 of file InputFile.h.
References InputFile::ifgetc().