This class serves for reading in and writing FASTA files If the protein/gene sequence contains unusual symbols (such as translation end (*)), they will be kept! You can use aggregate methods load() and store() to read/write a set of protein sequences at the cost of memory.
More...
#include <OpenMS/FORMAT/FASTAFile.h>
|
| struct | FASTAEntry |
| | FASTA entry type (identifier, description and sequence) The first std::string corresponds to the identifier that is written after the > in the FASTA file. The part after the first whitespace is stored in description and the text from the next line until the next > (exclusive) is stored in sequence. More...
|
| |
|
| bool | readEntry_ (std::string &id, std::string &description, std::string &seq) |
| | Reads a protein entry from the current file position and returns the ID and sequence.
|
| |
| std::streampos | progressPosition_ () |
| | The position for the progress logger: the file size once the end of the file is reached (tellg() is -1 then)
|
| |
| std::string | errorLocation_ () const |
| | Where the entry that readEntry_() read last starts: its line if known, otherwise its byte offset.
|
| |
This class serves for reading in and writing FASTA files If the protein/gene sequence contains unusual symbols (such as translation end (*)), they will be kept! You can use aggregate methods load() and store() to read/write a set of protein sequences at the cost of memory.
Or use single read/write of protein sequences using readStart(), readNext() and writeStart(), writeNext(), writeEnd() for more memory efficiency. Reading from one and writing to another FASTA file can be handled by one single FASTAFile instance.
◆ FASTAFile()
◆ ~FASTAFile()
◆ atEnd()
◆ errorLocation_()
| std::string errorLocation_ |
( |
| ) |
const |
|
protected |
Where the entry that readEntry_() read last starts: its line if known, otherwise its byte offset.
◆ load()
| void load |
( |
const std::string & |
filename, |
|
|
std::vector< FASTAEntry > & |
data |
|
) |
| const |
◆ position()
| std::streampos position |
( |
| ) |
|
current stream position when reading a file
◆ progressPosition_()
| std::streampos progressPosition_ |
( |
| ) |
|
|
protected |
The position for the progress logger: the file size once the end of the file is reached (tellg() is -1 then)
◆ readEntry_()
| bool readEntry_ |
( |
std::string & |
id, |
|
|
std::string & |
description, |
|
|
std::string & |
seq |
|
) |
| |
|
protected |
Reads a protein entry from the current file position and returns the ID and sequence.
A header line that is followed by the next header line or the end of the file gives an entry without sequence.
- Returns
- Return true if the protein entry was read and saved successfully, false otherwise (error_ says why)
◆ readNext()
Reads the next FASTA entry from file.
An entry without sequence (a header followed by the next header or the end of the file) is skipped with a warning. The errors name the file and the line (or, after setPosition(), the byte offset) of the entry that could not be read.
If you want to read all entries in one go, use load().
- Returns
- true if entry was read; false if EOF was reached
- Exceptions
-
◆ readNextWithProgress()
same as readNext(), but does internal progress logging; use readStartWithProgress() to enable this Calls progressEnd() when EOF is reached (i.e. when returning false)
◆ readStart()
| void readStart |
( |
const std::string & |
filename | ) |
|
Prepares a FASTA file given by filename for streamed reading using readNext().
- Exceptions
-
◆ readStartWithProgress()
| void readStartWithProgress |
( |
const std::string & |
filename, |
|
|
const std::string & |
progress_label |
|
) |
| |
◆ setPosition()
| bool setPosition |
( |
const std::streampos & |
pos | ) |
|
◆ store()
| void store |
( |
const std::string & |
filename, |
|
|
const std::vector< FASTAEntry > & |
data |
|
) |
| const |
stores the data given by 'data' at the file 'filename'
This uses more RAM than writeStart() and writeNext().
- Exceptions
-
◆ writeEnd()
Closes the file (flush). Called implicitly when FASTAFile object goes out of scope.
◆ writeNext()
◆ writeStart()
| void writeStart |
( |
const std::string & |
filename | ) |
|
Prepares a FASTA file given by 'filename' for streamed writing using writeNext().
- Exceptions
-
◆ description_
description of currently read protein
◆ entries_read_
some internal book-keeping during reading
◆ entry_line_
line of the entry read last (0: unknown)
◆ entry_offset_
| std::streampos entry_offset_ {} |
|
protected |
byte offset of the entry read last
◆ error_
◆ filename_
◆ fileSize_
| std::streampos fileSize_ {} |
|
protected |
total number of characters of filestream
◆ id_
identifier of currently read protein
◆ infile_
filestream for reading; init using FastaFile::readStart()
◆ line_
line of the next character read (1-based); 0: unknown, after setPosition()
◆ outfile_
filestream for writing; init using FastaFile::writeStart()
◆ seq_
sequence of currently read protein