pub struct Reader<R> { /* private fields */ }
Expand description
A GTF reader.
Implementations§
Source§impl<R> Reader<R>
impl<R> Reader<R>
Sourcepub fn get_ref(&self) -> &R
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();
Sourcepub fn get_mut(&mut self) -> &mut R
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();
Sourcepub fn into_inner(self) -> R
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,
impl<R> Reader<R>where
R: BufRead,
Sourcepub fn new(inner: R) -> Self
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[..]);
Sourcepub fn read_line(&mut self, buf: &mut String) -> Result<usize>
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\";"
);
Sourcepub fn lines(&mut self) -> impl Iterator<Item = Result<Line>> + '_
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());
Sourcepub fn records(&mut self) -> impl Iterator<Item = Result<Record>> + '_
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
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(())
}
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more