diff --git a/Cargo.toml b/Cargo.toml index d1428a77d..91e804e35 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,7 +30,7 @@ newtype_derive = "0.1" regex = "1.3" serde = {version = "^1", optional = true, features = ["derive"]} serde_bytes = {version = "0.11", optional = true} -thiserror = "2" +thiserror = {version = "^2" } url = "2.1" [features] diff --git a/src/bcf/header.rs b/src/bcf/header.rs index 808dbf087..be2d3c389 100644 --- a/src/bcf/header.rs +++ b/src/bcf/header.rs @@ -34,6 +34,7 @@ use std::ffi; use std::os::raw::c_char; +use std::rc::Rc; use std::slice; use std::str; @@ -506,6 +507,13 @@ impl HeaderView { } result } + + /// Create an empty record using this header view. + /// + /// The record can be reused multiple times. + pub fn empty_record(&self) -> crate::bcf::Record { + crate::bcf::Record::new(Rc::new(self.clone())) + } } impl Clone for HeaderView { @@ -540,3 +548,25 @@ pub enum TagLength { Genotypes, Variable, } + +#[cfg(test)] +mod tests { + use super::*; + use crate::bcf::Reader; + + #[test] + fn test_header_view_empty_record() { + // Open a VCF file to get a HeaderView + let vcf = Reader::from_path("test/test_string.vcf").expect("Error opening file"); + let header_view = vcf.header.clone(); + + // Create an empty record from the HeaderView + let record = header_view.empty_record(); + eprintln!("{:?}", record.rid()); + + // Verify the record is properly initialized with default/empty values + assert_eq!(record.rid(), Some(0)); // No chromosome/contig set + assert_eq!(record.pos(), 0); // No position set + assert_eq!(record.qual(), 0.0); // No quality score set + } +} diff --git a/src/bcf/mod.rs b/src/bcf/mod.rs index 149ddd9a2..1b4b83687 100644 --- a/src/bcf/mod.rs +++ b/src/bcf/mod.rs @@ -237,7 +237,7 @@ impl Read for Reader { /// Return empty record. Can be reused multiple times. fn empty_record(&self) -> Record { - Record::new(Rc::clone(&self.header)) + self.header.empty_record() } }