diff --git a/noodles-cram/CHANGELOG.md b/noodles-cram/CHANGELOG.md index 243ef12dc..28d05b357 100644 --- a/noodles-cram/CHANGELOG.md +++ b/noodles-cram/CHANGELOG.md @@ -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 diff --git a/noodles-cram/src/async/io/writer.rs b/noodles-cram/src/async/io/writer.rs index 7ae8e644f..fdc34de04 100644 --- a/noodles-cram/src/async/io/writer.rs +++ b/noodles-cram/src/async/io/writer.rs @@ -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( + &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; diff --git a/noodles-util/src/alignment/async/io/writer.rs b/noodles-util/src/alignment/async/io/writer.rs index c0c156ab0..4d72a82f4 100644 --- a/noodles-util/src/alignment/async/io/writer.rs +++ b/noodles-util/src/alignment/async/io/writer.rs @@ -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, } }