pub struct Reader<R, V> { /* private fields */ }Expand description
Implementations§
Source§impl<R, V> Reader<R, V>
impl<R, V> Reader<R, V>
Sourcepub fn create_record_buf(&self) -> Record<Id, V::Item>
pub fn create_record_buf(&self) -> Record<Id, V::Item>
Returns a new record suitable for use in reading.
Examples found in repository?
10fn main() -> io::Result<()> {
11 let path = env::args().nth(1).expect("missing path to SAF member file");
12 let mut reader = saf::reader::Builder::v3().build_from_member_path(path)?;
13
14 let stdout = io::stdout();
15 let mut writer = stdout.lock();
16
17 write!(writer, "{}", reader.index())?;
18
19 let mut record = reader.create_record_buf();
20 while reader.read_record(&mut record)?.is_not_done() {
21 writeln!(writer, "{record:.2}")?;
22 }
23
24 Ok(())
25}More examples
10fn main() -> io::Result<()> {
11 let path = env::args().nth(1).expect("missing path to SAF member file");
12 let mut reader = saf::reader::Builder::v4().build_from_member_path(path)?;
13
14 let stdout = io::stdout();
15 let mut writer = stdout.lock();
16
17 write!(writer, "{}", reader.index())?;
18
19 let mut record = reader.create_record_buf();
20 while reader.read_record(&mut record)?.is_not_done() {
21 writeln!(writer, "{record:.2}")?;
22 }
23
24 Ok(())
25}Sourcepub fn from_bgzf(
index: Index<V>,
position_reader: Reader<R>,
item_reader: Reader<R>,
) -> Option<Self>
pub fn from_bgzf( index: Index<V>, position_reader: Reader<R>, item_reader: Reader<R>, ) -> Option<Self>
Sourcepub fn index(&self) -> &Index<V>
pub fn index(&self) -> &Index<V>
Returns the index.
Examples found in repository?
10fn main() -> io::Result<()> {
11 let path = env::args().nth(1).expect("missing path to SAF member file");
12 let mut reader = saf::reader::Builder::v3().build_from_member_path(path)?;
13
14 let stdout = io::stdout();
15 let mut writer = stdout.lock();
16
17 write!(writer, "{}", reader.index())?;
18
19 let mut record = reader.create_record_buf();
20 while reader.read_record(&mut record)?.is_not_done() {
21 writeln!(writer, "{record:.2}")?;
22 }
23
24 Ok(())
25}More examples
10fn main() -> io::Result<()> {
11 let path = env::args().nth(1).expect("missing path to SAF member file");
12 let mut reader = saf::reader::Builder::v4().build_from_member_path(path)?;
13
14 let stdout = io::stdout();
15 let mut writer = stdout.lock();
16
17 write!(writer, "{}", reader.index())?;
18
19 let mut record = reader.create_record_buf();
20 while reader.read_record(&mut record)?.is_not_done() {
21 writeln!(writer, "{record:.2}")?;
22 }
23
24 Ok(())
25}10fn main() -> io::Result<()> {
11 let readers = env::args()
12 .skip(1)
13 .map(|p| saf::reader::Builder::v3().build_from_member_path(p))
14 .collect::<io::Result<Vec<_>>>()?;
15
16 // Note also the [`Reader::intersect`] and [`Intersect::intersect`] methods to construct
17 // intersecting reader when the number of readers are statically known.
18 let mut intersect = saf::Intersect::new(readers);
19
20 let stdout = io::stdout();
21 let mut writer = stdout.lock();
22
23 let mut bufs = intersect.create_record_bufs();
24 while intersect.read_records(&mut bufs)?.is_not_done() {
25 for (reader, buf) in intersect.get_readers().iter().zip(bufs.iter()) {
26 let contig = reader.index().records()[*buf.contig_id()].name();
27 let position = buf.position();
28 write!(writer, "{contig}\t{position}")?;
29
30 for v in buf.item().iter() {
31 write!(writer, "\t{v:.2}")?;
32 }
33
34 writeln!(writer)?;
35 }
36 }
37
38 Ok(())
39}Sourcepub fn into_parts(self) -> (Index<V>, Reader<R>, Reader<R>)
pub fn into_parts(self) -> (Index<V>, Reader<R>, Reader<R>)
Returns the inner index, position reader, and item reader, consuming self.
Sourcepub fn item_reader(&self) -> &Reader<R>
pub fn item_reader(&self) -> &Reader<R>
Returns the inner item reader.
Sourcepub fn item_reader_mut(&mut self) -> &mut Reader<R>
pub fn item_reader_mut(&mut self) -> &mut Reader<R>
Returns a mutable reference to the inner item reader.
Sourcepub fn position_reader(&self) -> &Reader<R>
pub fn position_reader(&self) -> &Reader<R>
Returns the inner position reader.
Sourcepub fn position_reader_mut(&mut self) -> &mut Reader<R>
pub fn position_reader_mut(&mut self) -> &mut Reader<R>
Returns a mutable reference to the inner position reader.
Sourcepub fn read_item(&mut self, buf: &mut V::Item) -> Result<ReadStatus>
pub fn read_item(&mut self, buf: &mut V::Item) -> Result<ReadStatus>
Reads a single item from the item reader into the provided buffer.
Note that this will bring the item and position readers out of sync. Use
Self::read_record instead unless you wish to manually re-sync the underlying readers.
Sourcepub fn read_magic(&mut self) -> Result<()>
pub fn read_magic(&mut self) -> Result<()>
Reads and checks the magic numbers.
Assumes the streams are positioned at the beginning of the files.
Sourcepub fn read_position(&mut self) -> Result<Option<u32>>
pub fn read_position(&mut self) -> Result<Option<u32>>
Reads a single position from the position reader.
Note that this will bring the item and position readers out of sync. Use
Self::read_record instead unless you wish to manually re-sync the underlying readers.
Sourcepub fn read_record(
&mut self,
record: &mut Record<Id, V::Item>,
) -> Result<ReadStatus>
pub fn read_record( &mut self, record: &mut Record<Id, V::Item>, ) -> Result<ReadStatus>
Reads a single record.
Note that the record buffer needs to be correctly set up. Use Self::create_record_buf
for a correctly initialised record buffer to use for reading.
Examples found in repository?
10fn main() -> io::Result<()> {
11 let path = env::args().nth(1).expect("missing path to SAF member file");
12 let mut reader = saf::reader::Builder::v3().build_from_member_path(path)?;
13
14 let stdout = io::stdout();
15 let mut writer = stdout.lock();
16
17 write!(writer, "{}", reader.index())?;
18
19 let mut record = reader.create_record_buf();
20 while reader.read_record(&mut record)?.is_not_done() {
21 writeln!(writer, "{record:.2}")?;
22 }
23
24 Ok(())
25}More examples
10fn main() -> io::Result<()> {
11 let path = env::args().nth(1).expect("missing path to SAF member file");
12 let mut reader = saf::reader::Builder::v4().build_from_member_path(path)?;
13
14 let stdout = io::stdout();
15 let mut writer = stdout.lock();
16
17 write!(writer, "{}", reader.index())?;
18
19 let mut record = reader.create_record_buf();
20 while reader.read_record(&mut record)?.is_not_done() {
21 writeln!(writer, "{record:.2}")?;
22 }
23
24 Ok(())
25}Source§impl<R, V> Reader<R, V>
impl<R, V> Reader<R, V>
Sourcepub fn intersect(self, other: Self) -> Intersect<R, V>
pub fn intersect(self, other: Self) -> Intersect<R, V>
Creates an intersection of two readers.
The resulting intersecting readers will read only records that lie on the same contigs
and the same positions. Further readers can be added to the resulting intersecting reader
by chaining the Intersect::intersect method.
Sourcepub fn seek(&mut self, contig_id: usize) -> Result<()>
pub fn seek(&mut self, contig_id: usize) -> Result<()>
Seeks to start of contig.
The contig_id refers to the position of records in the index.
§Panics
Panics if contig_id is larger than the number of records defined in the index.
Sourcepub fn seek_by_name(&mut self, name: &str) -> Result<()>
pub fn seek_by_name(&mut self, name: &str) -> Result<()>
Seeks to start of contig by name.
Note that this requires a linear search of names in the index with worst time complexity
linear in the index size.. If the index is large, and the contig ID is known, prefer
Self::seek is more efficient.
§Panics
Panics if sequence name is not defined in index.