Skip to content

Commit

Permalink
bam/reader: Remove UnmappedRecords iterator
Browse files Browse the repository at this point in the history
This is replaced by an `impl Trait`. Use `impl Iterator<Item =
io::Result<Record>>` instead.
  • Loading branch information
zaeleus committed Aug 31, 2023
1 parent e2523f0 commit fec9e9d
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
7 changes: 7 additions & 0 deletions noodles-bam/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
It's possible for a chunk to include mapped records, which are subsequently
filtered out, but they do require the associated header to decode.

### Removed

* bam/reader: Remove `UnmappedRecords` iterator.

This is replaced by an `impl Trait`. Use `impl Iterator<Item =
io::Result<Record>>` instead.

## 0.43.0 - 2023-08-24

### Added
Expand Down
4 changes: 1 addition & 3 deletions noodles-bam/src/indexed_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ use noodles_core::Region;
use noodles_csi as csi;
use noodles_sam::{self as sam, alignment::Record};

use crate::reader::UnmappedRecords;

use super::{
lazy,
reader::{LazyRecords, Query, Records},
Expand Down Expand Up @@ -107,7 +105,7 @@ where
pub fn query_unmapped<'r>(
&'r mut self,
header: &'r sam::Header,
) -> io::Result<UnmappedRecords<'r, R>> {
) -> io::Result<impl Iterator<Item = io::Result<Record>> + 'r> {
self.inner.query_unmapped(header, &self.index)
}
}
17 changes: 9 additions & 8 deletions noodles-bam/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,8 @@ mod lazy_records;
pub(crate) mod query;
mod record;
mod records;
mod unmapped_records;

pub use self::{
builder::Builder, lazy_records::LazyRecords, query::Query, records::Records,
unmapped_records::UnmappedRecords,
};
pub use self::{builder::Builder, lazy_records::LazyRecords, query::Query, records::Records};

use std::{
ffi::CStr,
Expand Down Expand Up @@ -376,22 +372,27 @@ where
///
/// for result in query {
/// let record = result?;
/// println!("{:?}", record);
/// // ...
/// }
/// # Ok::<(), io::Error>(())
/// ```
pub fn query_unmapped<'r>(
&'r mut self,
header: &'r sam::Header,
index: &csi::Index,
) -> io::Result<UnmappedRecords<'r, R>> {
) -> io::Result<impl Iterator<Item = io::Result<Record>> + 'r> {
if let Some(pos) = index.first_record_in_last_linear_bin_start_position() {
self.seek(pos)?;
} else {
self.seek_to_first_record()?;
}

Ok(UnmappedRecords::new(self, header))
Ok(self.records(header).filter(|result| {
result
.as_ref()
.map(|record| record.flags().is_unmapped())
.unwrap_or(true)
}))
}
}

Expand Down

0 comments on commit fec9e9d

Please sign in to comment.