View Source Bio.IO.Fasta (bio_elixir v0.2.0)
Allow the input/output of FASTA formatted files. Reads and writes fasta data to and from a number of formats.
The FASTA file format is composed of pairs of lines where the pair is demarcated by the ">" character. All data proceeding the ">" character represents the 'header' of the pair, while the next line after a newline represents sequence data.
The FASTA file format does not specify the type of the data in the sequence. That means that you can reasonably store RNA, DNA, amino acid, or realistically any other polymer sequence using the format. In general, the expectation is that the data is ASCII encoded.
Link to this section Summary
Functions
Read a FASTA formatted file
Read a FASTA formatted file
Write a FASTA file using sequence data.
Link to this section Types
Link to this section Functions
@spec read(filename :: Path.t(), opts :: [read_opts()]) :: {:ok, any()} | {:error, File.posix()}
Read a FASTA formatted file
The read/2 function returns an error tuple of the content or error code from
File.read. You can use :file.format_error/1 to get a descriptive string of
the error.
You can specify the return type of the contents by using a module
which matches the Bio.Behaviours.Sequence. Specifically the type must have a
new/2 method that matches the spec of the behaviour.
options
Options
:type- The module for the type of struct you wish to have returned. This should minimally implement anew/2function equivalent to theBio.Behaviours.Sequencebehaviour.:parse_header- A callable for parsing the header values of the FASTA file.
Read a FASTA formatted file
The same as read/2, but will raise a File.Error on failure.
@spec write(filename :: Path.t(), data :: fasta_data(), [File.mode()]) :: :ok | {:error, File.posix()}
Write a FASTA file using sequence data.
The data type that this function accepts is varied. Help with whatever your
workflow requires, the List types are:
List:
[{header(), sequence()}, ...]
[header(), sequence(), header(), sequence(), ...]
[%Bio.Sequence._{}, ...]Where %Bio.Sequence._{} indicates any struct of the Bio.Sequence module or
child modules implementing the Bio.Behaviours.Sequence behaviour.
It also supports data in a Map format:
%{
headers: [header(), ...],
sequences: [sequence(), ...]
}
examples
Examples
iex> Fasta.write("/tmp/test_file.fasta", ["header", "sequence", "header2", "sequence2"])
:okWill return error types in common with File.write/3