noodles_gtf::io

Struct Reader

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

A GTF reader.

Implementations§

Source§

impl<R> Reader<R>

Source

pub fn get_ref(&self) -> &R

Returns a reference to the underlying reader.

§Examples
use noodles_gtf as gtf;
let reader = gtf::io::Reader::new(io::empty());
let _ = reader.get_ref();
Source

pub fn get_mut(&mut self) -> &mut R

Returns a mutable reference to the underlying reader.

§Examples
use noodles_gtf as gtf;
let mut reader = gtf::io::Reader::new(io::empty());
let _ = reader.get_mut();
Source

pub fn into_inner(self) -> R

Unwraps and returns the underlying reader.

§Examples
use noodles_gtf as gtf;
let reader = gtf::io::Reader::new(io::empty());
let _ = reader.into_inner();
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::io::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::io::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::io::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::io::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 20)
13
14
15
16
17
18
19
20
21
22
23
24
25
26
fn main() -> io::Result<()> {
    let src = env::args().nth(1).expect("missing src");

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

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

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

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

Source§

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>,

Source§

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.