-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bcf/record: Read static fields from buffer
- Loading branch information
Showing
9 changed files
with
165 additions
and
55 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
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
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
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,80 @@ | ||
mod bounds; | ||
|
||
use std::io; | ||
|
||
use self::bounds::Bounds; | ||
|
||
#[derive(Clone, Debug, Eq, PartialEq)] | ||
pub(crate) struct Fields { | ||
site_buf: Vec<u8>, | ||
samples_buf: Vec<u8>, | ||
bounds: Bounds, | ||
} | ||
|
||
impl Fields { | ||
pub(crate) fn site_buf_mut(&mut self) -> &mut Vec<u8> { | ||
&mut self.site_buf | ||
} | ||
|
||
pub(crate) fn samples_buf_mut(&mut self) -> &mut Vec<u8> { | ||
&mut self.samples_buf | ||
} | ||
|
||
pub(super) fn reference_sequence_id(&self) -> i32 { | ||
let src = &self.site_buf[bounds::REFERENCE_SEQUENCE_ID_RANGE]; | ||
// SAFETY: `src` is 4 bytes. | ||
i32::from_le_bytes(src.try_into().unwrap()) | ||
} | ||
|
||
// N.B. this is 0-based. | ||
pub(super) fn position(&self) -> i32 { | ||
let src = &self.site_buf[bounds::POSITION_RANGE]; | ||
// SAFETY: `src` is 4 bytes. | ||
i32::from_le_bytes(src.try_into().unwrap()) | ||
} | ||
|
||
pub(super) fn span(&self) -> i32 { | ||
let src = &self.site_buf[bounds::SPAN_RANGE]; | ||
// SAFETY: `src` is 4 bytes. | ||
i32::from_le_bytes(src.try_into().unwrap()) | ||
} | ||
|
||
pub(super) fn quality_score(&self) -> io::Result<Option<f32>> { | ||
use crate::record::codec::value::Float; | ||
|
||
let src = &self.site_buf[bounds::QUALITY_SCORE_RANGE]; | ||
// SAFETY: `src` is 4 bytes. | ||
let n = f32::from_le_bytes(src.try_into().unwrap()); | ||
|
||
match Float::from(n) { | ||
Float::Value(n) => Ok(Some(n)), | ||
Float::Missing => Ok(None), | ||
_ => Err(io::Error::new( | ||
io::ErrorKind::InvalidData, | ||
"invalid quality score", | ||
)), | ||
} | ||
} | ||
} | ||
|
||
impl Default for Fields { | ||
fn default() -> Self { | ||
Self { | ||
site_buf: vec![ | ||
0x00, 0x00, 0x00, 0x00, // chrom = 0 | ||
0x00, 0x00, 0x00, 0x00, // pos = 0 (0-based) | ||
0x01, 0x00, 0x00, 0x00, // rlen = 1 | ||
0x01, 0x00, 0x80, 0x7f, // qual = None | ||
0x00, 0x00, // n_info = 0 | ||
0x01, 0x00, // n_allele = 1 | ||
0x00, 0x00, 0x00, // n_sample = 0 | ||
0x00, // n_fmt = 0 | ||
0x07, // ids = [] | ||
0x17, 0x4e, // ref = N | ||
0x00, // filters = [] | ||
], | ||
samples_buf: Vec::new(), | ||
bounds: Bounds, | ||
} | ||
} | ||
} |
Oops, something went wrong.