[−][src]Struct seq_io::fasta::Reader
Parser for FASTA files.
Implementations
impl<R> Reader<R, StdPolicy> where
R: Read,
[src]
R: Read,
pub fn new(reader: R) -> Reader<R, StdPolicy>
[src]
Creates a new reader with the default buffer size of 64 KiB
Example:
use seq_io::fasta::{Reader,Record}; let fasta = b">id\nSEQUENCE"; let mut reader = Reader::new(&fasta[..]); let record = reader.next().unwrap().unwrap(); assert_eq!(record.id(), Ok("id"))
pub fn with_capacity(reader: R, capacity: usize) -> Reader<R, StdPolicy>
[src]
Creates a new reader with a given buffer capacity. The minimum allowed capacity is 3.
impl Reader<File, StdPolicy>
[src]
pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Reader<File>>
[src]
Creates a reader from a file path.
Example:
use seq_io::fasta::Reader; let mut reader = Reader::from_path("seqs.fasta").unwrap(); // (... do something with the reader)
impl<R, P> Reader<R, P> where
R: Read,
P: BufPolicy,
[src]
R: Read,
P: BufPolicy,
pub fn set_policy<T: BufPolicy>(self, policy: T) -> Reader<R, T>
[src]
Returns a reader with the given buffer policy applied
pub fn policy(&self) -> &P
[src]
Returns the BufPolicy
of the reader
pub fn next(&mut self) -> Option<Result<RefRecord<'_>, Error>>
[src]
Searches the next FASTA record and returns a RefRecord that borrows its data from the underlying buffer of this reader.
Example:
use seq_io::fasta::{Reader,Record}; let mut reader = Reader::from_path("seqs.fasta").unwrap(); while let Some(record) = reader.next() { let record = record.unwrap(); println!("{}", record.id().unwrap()); }
pub fn read_record_set(
&mut self,
rset: &mut RecordSet
) -> Option<Result<(), Error>>
[src]
&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.
pub fn position(&self) -> Option<&Position>
[src]
Returns the current position (useful with seek()
).
If next()
has not yet been called, None
will be returned.
Example
use seq_io::fasta::{Reader,Position}; let fasta = b">id1 ACGT >id2 TGCA"; let mut reader = Reader::new(&fasta[..]); // skip one record reader.next().unwrap(); // second position reader.next().unwrap(); assert_eq!(reader.position(), Some(&Position::new(3, 10)));
pub fn records(&mut self) -> RecordsIter<'_, R, P>ⓘNotable traits for RecordsIter<'a, R, P>
impl<'a, R, P> Iterator for RecordsIter<'a, R, P> where
P: BufPolicy + 'a,
R: Read + 'a, type Item = Result<OwnedRecord, Error>;
[src]
Notable traits for RecordsIter<'a, R, P>
impl<'a, R, P> Iterator for RecordsIter<'a, R, P> where
P: BufPolicy + 'a,
R: Read + 'a, type Item = Result<OwnedRecord, Error>;
Returns a borrowed iterator over all FASTA records. The records
are owned (OwnedRecord
), this is therefore slower than using
Reader::next()
.
Example
use seq_io::fasta::{Reader,OwnedRecord}; let fasta = b">id1 ACGT >id2 TGCA"; let mut reader = Reader::new(&fasta[..]); let records: Result<Vec<_>, _> = reader .records() .collect(); assert_eq!(records.unwrap(), vec![ OwnedRecord {head: b"id1".to_vec(), seq: b"ACGT".to_vec()}, OwnedRecord {head: b"id2".to_vec(), seq: b"TGCA".to_vec()} ] );
pub fn into_records(self) -> RecordsIntoIter<R, P>ⓘNotable traits for RecordsIntoIter<R, P>
impl<R, P> Iterator for RecordsIntoIter<R, P> where
P: BufPolicy,
R: Read, type Item = Result<OwnedRecord, Error>;
[src]
Notable traits for RecordsIntoIter<R, P>
impl<R, P> Iterator for RecordsIntoIter<R, P> where
P: BufPolicy,
R: Read, type Item = Result<OwnedRecord, Error>;
Returns an iterator over all FASTA records like Reader::records()
,
but with the difference that it owns the underlying reader.
impl<R, P> Reader<R, P> where
R: Read + Seek,
P: BufPolicy,
[src]
R: Read + Seek,
P: BufPolicy,
pub fn seek(&mut self, pos: &Position) -> Result<(), Error>
[src]
Seeks to a specified position. Keeps 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::fasta::{Reader,Position,OwnedRecord}; use std::io::Cursor; let fasta = b">id1 ACGT >id2 TGCA"; let mut cursor = Cursor::new(&fasta[..]); 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().unwrap().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
Auto Trait Implementations
impl<R, P> RefUnwindSafe for Reader<R, P> where
P: RefUnwindSafe,
R: RefUnwindSafe,
P: RefUnwindSafe,
R: RefUnwindSafe,
impl<R, P> Send for Reader<R, P> where
P: Send,
R: Send,
P: Send,
R: Send,
impl<R, P> Sync for Reader<R, P> where
P: Sync,
R: Sync,
P: Sync,
R: Sync,
impl<R, P> Unpin for Reader<R, P> where
P: Unpin,
R: Unpin,
P: Unpin,
R: Unpin,
impl<R, P> UnwindSafe for Reader<R, P> where
P: UnwindSafe,
R: UnwindSafe,
P: UnwindSafe,
R: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
const ALIGN: usize
type Init = T
The type for initializers.
unsafe fn init(init: <T as Pointable>::Init) -> usize
unsafe fn deref<'a>(ptr: usize) -> &'a T
unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,