Struct seq_io::fastq::Reader

source ·
pub struct Reader<R: Read, P = StdPolicy> { /* private fields */ }
Expand description

FASTQ parser.

Implementations§

source§

impl<R> Reader<R, StdPolicy>where R: Read,

source

pub fn new(reader: R) -> Reader<R, StdPolicy>

Creates a new reader with the default buffer size of 64 KiB

Example:
use seq_io::fastq::{Reader, Record};
let fastq = b"@id\nACGT\n+\nIIII";

let mut reader = Reader::new(&fastq[..]);
let record = reader.next().unwrap().unwrap();
assert_eq!(record.id(), Ok("id"))
source

pub fn with_capacity(reader: R, capacity: usize) -> Reader<R, StdPolicy>

Creates a new reader with a given buffer capacity. The minimum allowed capacity is 3.

source§

impl Reader<File, StdPolicy>

source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Reader<File>>

Creates a reader from a file path.

Example:
use seq_io::fastq::Reader;

let mut reader = Reader::from_path("seqs.fastq").unwrap();

// (... do something with the reader)
source§

impl<R, P> Reader<R, P>where R: Read, P: BufPolicy,

source

pub fn set_policy<T: BufPolicy>(self, policy: T) -> Reader<R, T>

Returns a reader with the given buffer policy applied

source

pub fn policy(&self) -> &P

Returns the BufPolicy of the reader

source

pub fn next(&mut self) -> Option<Result<RefRecord<'_>, Error>>

Searches the next FASTQ record and returns a RefRecord that borrows its data from the underlying buffer of this reader.

Example:
use seq_io::fastq::{Reader, Record};

let mut reader = Reader::from_path("seqs.fastq").unwrap();

while let Some(record) = reader.next() {
    let record = record.unwrap();
    println!("{}", record.id().unwrap());
}
source

pub fn read_record_set( &mut self, rset: &mut RecordSet ) -> Option<Result<(), Error>>

Updates a RecordSet with new data. The contents of the internal buffer are just copied over to the record set and the positions of all records are found. Old data will be erased. Returns None if the input reached its end.

source

pub fn position(&self) -> &Position

Returns the current position (useful with seek())

Example
use seq_io::fastq::{Reader, Position};

let fastq = b"@id1
ACGT
+
IIII
@id2
TGCA
+
IIII";

let mut reader = Reader::new(&fastq[..]);

// skip one record
reader.next().unwrap();
// second position
reader.next().unwrap();

assert_eq!(reader.position(), &Position::new(5, 17));
source

pub fn records(&mut self) -> RecordsIter<'_, R, P>

Returns a borrowed iterator over all FASTQ records. The records are owned (OwnedRecord), this is therefore slower than using Reader::next().

Example
use seq_io::fastq::{Reader, OwnedRecord};

let fastq = b"@id1
ACGT
+
IIII
@id2
TGCA
+
IIII";

let mut reader = Reader::new(&fastq[..]);

let records: Result<Vec<_>, _> = reader
    .records()
    .collect();

assert_eq!(records.unwrap(),
    vec![
        OwnedRecord {head: b"id1".to_vec(), seq: b"ACGT".to_vec(), qual: b"IIII".to_vec()},
        OwnedRecord {head: b"id2".to_vec(), seq: b"TGCA".to_vec(), qual: b"IIII".to_vec()}
    ]
);
source

pub fn into_records(self) -> RecordsIntoIter<R, P>

Returns an iterator over all FASTQ records like Reader::records(), but with the difference that it owns the underlying reader.

source§

impl<R, P> Reader<R, P>where R: Read + Seek, P: BufPolicy,

source

pub fn seek(&mut self, pos: &Position) -> Result<(), Error>

Seeks to a specified position. Keep the underyling buffer if the seek position is found within it, otherwise it has to be discarded. If an error was returned before, seeking to that position will return the same error. The same is not always true with None. If there is no newline character at the end of the file, the last record will be returned instead of None.

Example
use seq_io::fastq::{Reader, Position, OwnedRecord};
use std::io::Cursor;

let fastq = b"@id1
ACGT
+
IIII
@id2
TGCA
+
IIII";

let mut cursor = Cursor::new(&fastq[..]);
let mut reader = Reader::new(cursor);

// read the first record and get its position
let record1 = reader.next().unwrap().unwrap().to_owned_record();
let pos1 = reader.position().to_owned();

// read the second record
reader.next().unwrap().unwrap();

// now seek to position of first record
reader.seek(&pos1);
assert_eq!(reader.next().unwrap().unwrap().to_owned_record(), record1);

Trait Implementations§

source§

impl<R, P> Reader for Reader<R, P>where R: Read, P: BufPolicy + Send,

§

type DataSet = RecordSet

§

type Err = Error

source§

fn fill_data(&mut self, rset: &mut RecordSet) -> Option<Result<(), Error>>

Auto Trait Implementations§

§

impl<R, P> RefUnwindSafe for Reader<R, P>where P: RefUnwindSafe, R: RefUnwindSafe,

§

impl<R, P> Send for Reader<R, P>where P: Send, R: Send,

§

impl<R, P> Sync for Reader<R, P>where P: Sync, R: Sync,

§

impl<R, P> Unpin for Reader<R, P>where P: Unpin, R: Unpin,

§

impl<R, P> UnwindSafe for Reader<R, P>where P: UnwindSafe, R: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.