Skip to content

Commit

Permalink
cram/async/io/writer: Add alignment record writer
Browse files Browse the repository at this point in the history
Closes #293.
  • Loading branch information
zaeleus committed Aug 26, 2024
1 parent 87e3864 commit f8b5d4a
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
9 changes: 9 additions & 0 deletions noodles-cram/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

## Unreleased

### Added

* cram/async/io/writer: Add alignment record writer
(`Writer::write_alignment_record`) ([#293]).

[#293]: https://github.com/zaeleus/noodles/issues/293

## 0.67.0 - 2024-08-04

### Added
Expand Down
36 changes: 36 additions & 0 deletions noodles-cram/src/async/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,42 @@ where
}
}

/// Writes an alignment record.
///
/// # Examples
///
/// ```
/// # #[tokio::main]
/// # async fn main() -> tokio::io::Result<()> {
/// use noodles_cram as cram;
/// use noodles_sam as sam;
/// use tokio::io;
///
/// let mut writer = cram::r#async::io::Writer::new(io::sink());
/// writer.write_file_definition().await?;
///
/// let header = sam::Header::default();
/// writer.write_file_header(&header).await?;
///
/// let record = sam::Record::default();
/// writer.write_alignment_record(&header, &record).await?;
///
/// writer.shutdown(&header).await?;
/// # Ok(())
/// # }
/// ```
pub async fn write_alignment_record<R>(
&mut self,
header: &sam::Header,
record: &R,
) -> io::Result<()>
where
R: sam::alignment::Record + ?Sized,
{
let record = Record::try_from_alignment_record(header, record)?;
self.write_record(header, record).await
}

async fn flush(&mut self, header: &sam::Header) -> io::Result<()> {
use self::data_container::write_data_container;

Expand Down
5 changes: 1 addition & 4 deletions noodles-util/src/alignment/async/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,7 @@ where
match self {
Self::Sam(writer) => writer.write_alignment_record(header, record).await,
Self::Bam(writer) => writer.write_alignment_record(header, record).await,
Self::Cram(writer) => {
let record = cram::Record::try_from_alignment_record(header, record)?;
writer.write_record(header, record).await
}
Self::Cram(writer) => writer.write_alignment_record(header, record).await,
}
}

Expand Down

0 comments on commit f8b5d4a

Please sign in to comment.