Struct noodles_gff::io::Reader
source · pub struct Reader<R> { /* private fields */ }
Expand description
A GFF 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_gff as gff;
let reader = gff::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_gff as gff;
let mut reader = gff::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_gff as gff;
let reader = gff::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 GFF reader.
§Examples
use noodles_gff as gff;
let reader = gff::io::Reader::new(io::empty());
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 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::io::Reader::new(&data[..]);
let mut buf = String::new();
reader.read_line(&mut buf)?;
assert_eq!(buf, "##gff-version 3");
sourcepub fn lines(&mut self) -> Lines<'_, R>
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::io::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());
sourcepub fn read_lazy_line(&mut self, line: &mut Line) -> Result<usize>
pub fn read_lazy_line(&mut self, line: &mut Line) -> Result<usize>
Reads a single line without eagerly decoding it.
§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::io::Reader::new(&data[..]);
let mut line = gff::lazy::Line::default();
reader.read_lazy_line(&mut line)?;
assert!(matches!(line, gff::lazy::Line::Directive(_)));
reader.read_lazy_line(&mut line)?;
assert!(matches!(line, gff::lazy::Line::Record(_)));
assert_eq!(reader.read_lazy_line(&mut line)?, 0);
sourcepub fn records(&mut self) -> Records<'_, R>
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::io::Reader::new(&data[..]);
let mut records = reader.records();
assert!(records.next().transpose()?.is_some());
assert!(records.next().is_none());
source§impl<R> Reader<Reader<R>>
impl<R> Reader<Reader<R>>
sourcepub fn query<'r, I>(
&'r mut self,
index: &I,
region: &'r Region
) -> Result<impl Iterator<Item = Result<Record>> + 'r>where
I: BinningIndex,
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.
§Examples
use noodles_bgzf as bgzf;
use noodles_csi as csi;
use noodles_gff as gff;
let mut reader = File::open("annotations.gff3.gz")
.map(bgzf::Reader::new)
.map(gff::io::Reader::new)?;
let index = csi::read("annotations.gff3.gz.csi")?;
let region = "sq0:8-13".parse()?;
let query = reader.query(&index, ®ion)?;
for result in query {
let record = result?;
// ...
}