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,
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::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::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::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::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
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(())
}
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