Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/bcf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,24 @@ mod tests {
);
}

#[test]
fn test_trailing_omitted_format_fields() {
let mut reader = Reader::from_path("test/test_trailing_omitted_format.vcf").unwrap();
let first_record = reader
.records()
.next()
.unwrap()
.expect("Fail to read record");

let expected: Vec<&[u8]> = Vec::new();
assert_eq!(*first_record.format(b"STR").string().unwrap(), expected,);
assert_eq!(
*first_record.format(b"INT").integer().unwrap(),
vec![&[i32::missing()]],
);
assert!(first_record.format(b"FLT").float().unwrap()[0][0].is_nan(),);
}

// #[test]
// fn test_buffer_lifetime() {
// let mut reader = Reader::from_path("test/obs-cornercase.vcf").unwrap();
Expand Down
3 changes: 3 additions & 0 deletions src/bcf/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,6 +1483,9 @@ impl<'a, 'b, B: BorrowMut<Buffer> + Borrow<Buffer> + 'b> Format<'a, B> {
/// memory.
pub fn string(mut self) -> Result<BufferBacked<'b, Vec<&'b [u8]>, B>> {
self.data(htslib::BCF_HT_STR).map(|ret| {
if ret == 0 {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if this is the behavior we want here. Could consider returning "." but then I guess we'd need to modify the buffer

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

empty seems fine

return BufferBacked::new(Vec::new(), self.buffer);
}
BufferBacked::new(
unsafe {
slice::from_raw_parts(self.buffer.borrow_mut().inner as *const u8, ret as usize)
Expand Down
9 changes: 9 additions & 0 deletions test/test_trailing_omitted_format.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
##fileformat=VCFv4.3
##contig=<ID=chr1,length=10000>
##INFO=<ID=FOO,Number=1,Type=Integer,Description="Some field">
##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">
##FORMAT=<ID=STR,Number=1,Type=String,Description="Some string field">
##FORMAT=<ID=INT,Number=1,Type=Integer,Description="Some integer field">
##FORMAT=<ID=FLT,Number=1,Type=Float,Description="Some float field">
#CHROM POS ID REF ALT QUAL FILTER INFO FORMAT SAMPLE1
chr1 1234 . t a . . FOO=1 GT:STR:FLT:INT .