Skip to content

Commit

Permalink
feat: implement Clone for bcf::Record (#394)
Browse files Browse the repository at this point in the history
wrapper for htslib::bcf_dup function
  • Loading branch information
astaric authored Jun 5, 2023
1 parent 8930a84 commit e89538d
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/bcf/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1090,6 +1090,19 @@ impl Record {
}
}

impl Clone for Record {
fn clone(&self) -> Self {
let inner = unsafe {
let inner = htslib::bcf_dup(self.inner);
inner
};
Record {
inner,
header: self.header.clone(),
}
}
}

impl genome::AbstractLocus for Record {
fn contig(&self) -> &str {
str::from_utf8(
Expand Down Expand Up @@ -1569,6 +1582,26 @@ mod tests {
assert_eq!(record.pos(), 0)
}

#[test]
fn test_record_clone() {
let tmp = NamedTempFile::new().unwrap();
let path = tmp.path();
let header = Header::new();
let vcf = Writer::from_path(path, &header, true, Format::Vcf).unwrap();
let mut record = vcf.empty_record();
let alleles: &[&[u8]] = &[b"AGG", b"TG"];
record.set_alleles(alleles).expect("Failed to set alleles");
record.set_pos(6);

let mut cloned_record = record.clone();
cloned_record.set_pos(5);

assert_eq!(record.pos(), 6);
assert_eq!(record.allele_count(), 2);
assert_eq!(cloned_record.pos(), 5);
assert_eq!(cloned_record.allele_count(), 2);
}

#[test]
fn test_record_has_filter_pass_is_default() {
let tmp = NamedTempFile::new().unwrap();
Expand Down

0 comments on commit e89538d

Please sign in to comment.