Struct noodles_gff::reader::Reader

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

A GFF reader.

Implementations§

source§

impl<R> Reader<R>
where R: BufRead,

source

pub fn new(inner: R) -> Self

Creates a GFF reader.

§Examples
use noodles_gff as gff;
let data = b"##gff-version 3\n";
let mut reader = gff::Reader::new(&data[..]);
source

pub fn get_ref(&self) -> &R

Returns a reference to the underlying reader.

§Examples
use noodles_gff as gff;

let data = b"##gff-version 3\n";
let reader = gff::Reader::new(&data[..]);

let _ = reader.get_ref();
source

pub fn into_inner(self) -> R

Unwraps and returns the underlying reader.

§Examples
use noodles_gff as gff;

let data = b"##gff-version 3
#format: gff3
";
let mut reader = gff::Reader::new(&data[..]);
reader.read_line(&mut String::new())?;

assert_eq!(reader.into_inner(), b"#format: gff3\n");
source

pub fn read_line(&mut self, buf: &mut String) -> Result<usize>

Reads a raw GFF line.

This reads from the underlying stream until a newline is reached and appends it to the given buffer, sans the final newline character. The buffer can subsequently be parsed as a crate::Line.

It is more ergonomic to read records using an iterator (see Self::lines), but using this method allows control of the line buffer and whether the raw line should be parsed.

If successful, the number of bytes read is returned. If the number of bytes read is 0, the stream reached EOF.

§Examples
use noodles_gff as gff;

let data = b"##gff-version 3
sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id=ndls0;gene_name=gene0
";
let mut reader = gff::Reader::new(&data[..]);

let mut buf = String::new();
reader.read_line(&mut buf)?;
assert_eq!(buf, "##gff-version 3");
source

pub fn lines(&mut self) -> Lines<'_, R>

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

When using this, the caller is responsible to stop reading at either EOF or when the FASTA directive is read, whichever comes first.

Unlike Self::read_line, each line is parsed as a crate::Line.

§Examples
use noodles_gff as gff;

let data = b"##gff-version 3
sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id=ndls0;gene_name=gene0
";
let mut reader = gff::Reader::new(&data[..]);
let mut lines = reader.lines();

let line = lines.next().transpose()?;
assert!(matches!(line, Some(gff::Line::Directive(_))));

let line = lines.next().transpose()?;
assert!(matches!(line, Some(gff::Line::Record(_))));

assert!(lines.next().is_none());
Examples found in repository?
examples/gff_view.rs (line 21)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
fn main() -> io::Result<()> {
    let src = env::args().nth(1).expect("missing src");

    let mut reader = File::open(src).map(BufReader::new).map(gff::Reader::new)?;

    let stdout = io::stdout().lock();
    let mut writer = gff::Writer::new(stdout);

    for result in reader.lines() {
        let line = result?;

        if line == Line::Directive(Directive::StartOfFasta) {
            break;
        }

        writer.write_line(&line)?;
    }

    Ok(())
}
source

pub fn read_lazy_line(&mut self, line: &mut Line) -> Result<usize>

Reads a single line without eagerly decoding it.

source

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

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

This filters lines for only records. It stops at either EOF or when the FASTA directive is read, whichever comes first.

§Examples
use noodles_gff as gff;

let data = b"##gff-version 3
sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id=ndls0;gene_name=gene0
";
let mut reader = gff::Reader::new(&data[..]);
let mut records = reader.records();

assert!(records.next().transpose()?.is_some());
assert!(records.next().is_none());
Examples found in repository?
examples/gff_count.rs (line 20)
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
fn main() -> io::Result<()> {
    let src = env::args().nth(1).expect("missing src");

    let mut reader = File::open(src).map(BufReader::new).map(gff::Reader::new)?;
    let mut n = 0;

    for result in reader.records() {
        let _ = result?;
        n += 1;
    }

    println!("{n}");

    Ok(())
}
source§

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

source

pub fn query<'r, I>( &'r mut self, index: &I, region: &'r Region ) -> Result<impl Iterator<Item = Result<Record>> + 'r>
where I: BinningIndex,

Returns an iterator over records that intersects the given region.

Auto Trait Implementations§

§

impl<R> Freeze for Reader<R>
where R: Freeze,

§

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

§

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

§

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

§

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

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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 T
where 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 T
where 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 T
where 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.