pub struct Reader<R> { /* private fields */ }
Expand description

A FASTA reader.

Implementations

Creates a FASTA reader.

Examples
use noodles_fasta as fasta;
let data = b">sq0\nACGT\n>sq1\nNNNN\nNNNN\nNN\n";
let mut reader = fasta::Reader::new(&data[..]);

Returns a reference to the underlying reader.

Examples
use noodles_fasta as fasta;
let reader = fasta::Reader::new(&[][..]);
assert!(reader.get_ref().is_empty());

Returns a mutable reference to the underlying reader.

Examples
use noodles_fasta as fasta;
let mut reader = fasta::Reader::new(&[][..]);
assert!(reader.get_mut().is_empty());

Returns the underlying reader.

Examples
use noodles_fasta as fasta;
let reader = fasta::Reader::new(&[][..]);
assert!(reader.into_inner().is_empty());

Reads a raw definition line.

The given buffer will not include the trailing newline. It can subsequently be parsed as a crate::record::Definition.

The position of the stream is expected to be at the start or at the start of another definition.

If successful, this returns the number of bytes read from the stream. If the number of bytes read is 0, the stream reached EOF.

Examples
use noodles_fasta as fasta;

let data = b">sq0\nACGT\n>sq1\nNNNN\nNNNN\nNN\n";
let mut reader = fasta::Reader::new(&data[..]);

let mut buf = String::new();
reader.read_definition(&mut buf)?;

assert_eq!(buf, ">sq0");

Reads a sequence.

The given buffer consumes a sequence without newlines until another definition or EOF is reached.

The position of the stream is expected to be at the start of a sequence, which is directly after a definition.

If successful, this returns the number of bytes read from the stream. If the number of bytes read is 0, the stream reached EOF (though this case is likely an error).

Examples
use noodles_fasta as fasta;

let data = b">sq0\nACGT\n>sq1\nNNNN\nNNNN\nNN\n";
let mut reader = fasta::Reader::new(&data[..]);
reader.read_definition(&mut String::new())?;

let mut buf = Vec::new();
reader.read_sequence(&mut buf)?;

assert_eq!(buf, b"ACGT");

Returns an iterator over records starting from the current stream position.

The position of the stream is expected to be at the start or at the start of another definition.

use noodles_fasta::{self as fasta, record::{Definition, Sequence}};

let data = b">sq0\nACGT\n>sq1\nNNNN\nNNNN\nNN\n";
let mut reader = fasta::Reader::new(&data[..]);

let mut records = reader.records();

assert_eq!(records.next().transpose()?, Some(fasta::Record::new(
    Definition::new("sq0", None),
    Sequence::from(b"ACGT".to_vec()),
)));

assert_eq!(records.next().transpose()?, Some(fasta::Record::new(
    Definition::new("sq1", None),
    Sequence::from(b"NNNNNNNNNN".to_vec()),
)));

assert!(records.next().is_none());

Returns a record of the given region.

Examples
use noodles_core::Region;
use noodles_fasta::{self as fasta, fai, record::{Definition, Sequence}};

let data = b">sq0\nNNNN\n>sq1\nACGT\n>sq2\nNNNN\n";
let index = vec![
    fai::Record::new(String::from("sq0"), 4, 5, 4, 5),
    fai::Record::new(String::from("sq1"), 4, 15, 4, 5),
    fai::Record::new(String::from("sq2"), 4, 25, 4, 5),
];

let mut reader = fasta::Reader::new(Cursor::new(data));

let region = Region::new("sq1", ..);
let record = reader.query(&index, &region)?;
assert_eq!(record, fasta::Record::new(
    Definition::new("sq1", None),
    Sequence::from(b"ACGT".to_vec()),
));

let region = "sq1:2-3".parse()?;
let record = reader.query(&index, &region)?;
assert_eq!(record, fasta::Record::new(
    Definition::new("sq1:2-3", None),
    Sequence::from(b"CG".to_vec()),
));

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.