Records

FASTX files are considered a sequence of Records, FASTA.Record for FASTA files and FASTQ.Record for FASTQ. For convenience, FASTARecord and FASTQRecord are aliases of FASTA.Record and FASTQ.Record.

A Record object stores a normalized form of a FASTX record's source text, e.g. the following FASTA record:

>some header here
TAGATGAA
AA

is stored in a FASTA.Record object roughly as its constituent bytes, plus some metadata. Only the header and sequence text (and, for FASTQ, quality text) are retained. Record does not store uninformative data such as line-break locations or the optional second description following + in a FASTQ record. Consequently, records that differ only in that data are identical. There is no notion in the record object of being a DNA or RNA sequence - it's simply an array of bytes.

Records can be constructed from raw parts (i.e. description and sequence and, for FASTQ, quality), where

  • description::AbstractString
  • sequence::Union{AbstractString, BioSequence}
  • quality::Union{AbstractString, Vector{<:Number}}

Alternatively, they can be parsed directly from a string or an AbstractVector{UInt8}.

julia> record = parse(FASTARecord, ">abc\nAGCC\nCCGA");

julia> record2 = FASTARecord("abc", "AGCCCCGA");

julia> record == record2
true

Records can be queried for their information, namely identifier, description and sequence (and quality, for FASTQ). By default, this returns an AbstractString view into the Record's data:

julia> record = parse(FASTARecord, ">ident desc\nUGU\nGA");

julia> (identifier(record), description(record), sequence(record))
("ident", "ident desc", "UGUGA")

However, you can ask for getting the sequences as a String or any subtype of BioSequence:

julia> record = parse(FASTARecord, ">abc\nUGC\nCCA");

julia> using BioSequences # LongRNA defined in BioSequences.jl

julia> sequence(LongRNA{2}, record)
6nt RNA Sequence:
UGCCCA

julia> sequence(String, record)
"UGCCCA"

The number of bytes in the sequence of a Record can be queried using seqsize:

julia> record = parse(FASTARecord, ">abc\nUGC\nCCA");

julia> seqsize(record)
6

Byte-oriented sequence positions

FASTX stores and addresses record sequences as raw bytes. It assumes sequence symbols are ASCII; it does not interpret sequence text as UTF-8. Therefore, the optional part passed to sequence, the source offset passed to copyto! when copying from a record to a BioSequence, and the range passed to indexed FASTA extract are all one-based byte positions. A byte range can split a multi-byte UTF-8 symbol and yield invalid text.

If your data deliberately uses multi-byte text symbols, first materialize the record sequence as a String, then build or index a character-oriented sequence from that string:

text = sequence(String, record)
characters = collect(text)
characters[2:3]

FASTA.Writer(width=...) likewise wraps after width bytes, rather than after width Unicode characters.

Reference:

FASTX.identifierFunction
identifier(record::Record)::AbstractString

Get the sequence identifier of record. The identifier is the description before any whitespace. If the identifier is missing, return an empty string. Returns an AbstractString view into the record. If the record is overwritten, the string data will be corrupted.

See also: description, sequence

Examples

julia> record = parse(FASTA.Record, ">ident_here some descr \nTAGA");

julia> identifier(record)
"ident_here"
source
FASTX.descriptionFunction
description(record::Record)::AbstractString

Get the description of record. The description is the entire header line, minus the leading > or @ symbols for FASTA/FASTQ records, respectively, including trailing whitespace. Returns an AbstractString view into the record. If the record is overwritten, the string data will be corrupted.

See also: identifier, sequence

Examples

julia> record = parse(FASTA.Record, ">ident_here some descr \nTAGA");

julia> description(record)
"ident_here some descr "
source
FASTX.sequenceFunction
sequence([::Type{S}], record::Record, [part::UnitRange{Int}])::S

Get the sequence of record.

S can be either a subtype of BioSequences.BioSequence, AbstractString or String. If elided, S defaults to an AbstractString subtype. If part is given, it returns that part of the sequence. part is a one-based range of byte positions (not Unicode character positions). FASTX record sequences are byte-oriented and are intended for ASCII sequence symbols. Thus, a range can split a multi-byte UTF-8 symbol.

For character-oriented handling of text with multi-byte symbols, first materialize the sequence as a String (for example, text = sequence(String, record)), then derive or index a character-oriented sequence from text.

See also: identifier, description

Examples

julia> record = parse(FASTQ.Record, "@read1\nTAGA\n+\n;;]]");

julia> sequence(record)
"TAGA"

julia> sequence(LongDNA{2}, record)
4nt DNA Sequence:
TAGA
source
FASTX.seqsizeFunction
seqsize(::Record)::Int

Get the number of bytes in the sequence of a Record. Note that in the presence of non-ASCII characters, this may differ from length(sequence(record)). This is also the coordinate system used by sequence ranges and other operations that address positions in a record sequence.

See also: sequence

Examples

julia> seqsize(parse(FASTA.Record, ">hdr\nKRRLPW\nYHS"))
9

julia> seqsize(parse(FASTA.Record, ">hdr\nαβγδϵ"))
10
source