-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bam/bai/io/writer/index: Split writers into modules
- Loading branch information
Showing
14 changed files
with
585 additions
and
506 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use tokio::io::{self, AsyncWrite, AsyncWriteExt}; | ||
|
||
use crate::bai::MAGIC_NUMBER; | ||
|
||
pub(super) async fn write_magic_number<W>(writer: &mut W) -> io::Result<()> | ||
where | ||
W: AsyncWrite + Unpin, | ||
{ | ||
writer.write_all(&MAGIC_NUMBER).await | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[tokio::test] | ||
async fn test_write_magic_number() -> io::Result<()> { | ||
let mut buf = Vec::new(); | ||
write_magic_number(&mut buf).await?; | ||
assert_eq!(buf, b"BAI\x01"); | ||
Ok(()) | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
noodles-bam/src/bai/async/io/writer/index/reference_sequences.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
mod bins; | ||
mod intervals; | ||
mod metadata; | ||
|
||
use noodles_csi::binning_index::{ | ||
index::{reference_sequence::index::LinearIndex, ReferenceSequence}, | ||
ReferenceSequence as _, | ||
}; | ||
use tokio::io::{self, AsyncWrite, AsyncWriteExt}; | ||
|
||
use self::{bins::write_bins, intervals::write_intervals, metadata::write_metadata}; | ||
|
||
pub(super) async fn write_reference_sequences<W>( | ||
writer: &mut W, | ||
reference_sequences: &[ReferenceSequence<LinearIndex>], | ||
) -> io::Result<()> | ||
where | ||
W: AsyncWrite + Unpin, | ||
{ | ||
let n_ref = u32::try_from(reference_sequences.len()) | ||
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?; | ||
writer.write_u32_le(n_ref).await?; | ||
|
||
for reference_sequence in reference_sequences { | ||
write_reference_sequence(writer, reference_sequence).await?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn write_reference_sequence<W>( | ||
writer: &mut W, | ||
reference_sequence: &ReferenceSequence<LinearIndex>, | ||
) -> io::Result<()> | ||
where | ||
W: AsyncWrite + Unpin, | ||
{ | ||
write_bins( | ||
writer, | ||
reference_sequence.bins(), | ||
reference_sequence.metadata(), | ||
) | ||
.await?; | ||
|
||
write_intervals(writer, reference_sequence.index()).await?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.