Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: move empty_record to header #453

Merged
merged 2 commits into from
Dec 2, 2024
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
30 changes: 30 additions & 0 deletions src/bcf/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use std::ffi;
use std::os::raw::c_char;
use std::rc::Rc;
use std::slice;
use std::str;

Expand Down Expand Up @@ -506,6 +507,13 @@
}
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 {
Expand Down Expand Up @@ -540,3 +548,25 @@
Genotypes,
Variable,
}

#[cfg(test)]
mod tests {
use super::*;

Check warning on line 554 in src/bcf/header.rs

View workflow job for this annotation

GitHub Actions / Testing-Features (no-default-features)

unused import: `super::*`

Check warning on line 554 in src/bcf/header.rs

View workflow job for this annotation

GitHub Actions / Testing-Features (all-features)

unused import: `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
}
}
2 changes: 1 addition & 1 deletion src/bcf/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
Loading