Struct noodles_gtf::Reader

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

A GTF reader.

Implementations§

source§

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

source

pub fn new(inner: R) -> Self

Creates a GTF reader.

§Examples
use noodles_gtf as gtf;
let data = [];
let reader = gtf::Reader::new(&data[..]);
source

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

Reads a raw GTF line.

§Examples
use noodles_gtf as gtf;

let data = b"sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id \"ndls0\"; transcript_id \"ndls0\";";
let mut reader = gtf::Reader::new(&data[..]);

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

assert_eq!(
    buf,
    "sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id \"ndls0\"; transcript_id \"ndls0\";"
);
source

pub fn lines(&mut self) -> impl Iterator<Item = Result<Line>> + '_

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

§Examples
use noodles_gtf as gtf;

let data = b"##format: gtf
sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id \"g0\"; transcript_id \"t0\";
";
let mut reader = gtf::Reader::new(&data[..]);

let mut lines = reader.lines();

let line = lines.next().transpose()?;
assert_eq!(line, Some(gtf::Line::Comment(String::from("#format: gtf"))));

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

assert!(lines.next().is_none());
source

pub fn records(&mut self) -> impl Iterator<Item = Result<Record>> + '_

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

§Examples
use noodles_core::Position;
use noodles_gtf as gtf;

let data = b"##format: gtf
sq0\tNOODLES\tgene\t8\t13\t.\t+\t.\tgene_id \"g0\"; transcript_id \"t0\";
";
let mut reader = gtf::Reader::new(&data[..]);

let mut records = reader.records();

let record = records.next().transpose()?;
assert_eq!(record.map(|r| r.start()), Position::new(8));
// ...

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

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

    for result in reader.records() {
        let record = result?;
        println!("{record}");
    }

    Ok(())
}
More examples
Hide additional examples
examples/gtf_count.rs (line 19)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
fn main() -> io::Result<()> {
    let src = env::args().nth(1).expect("missing src");

    let mut reader = File::open(src).map(BufReader::new).map(gtf::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.