Skip to content
Open
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
14 changes: 13 additions & 1 deletion src/bam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1439,7 +1439,12 @@ impl HeaderView {
}

pub fn tid2name(&self, tid: u32) -> &[u8] {
unsafe { ffi::CStr::from_ptr(htslib::sam_hdr_tid2name(self.inner, tid as i32)).to_bytes() }
let ptr = unsafe { htslib::sam_hdr_tid2name(self.inner, tid as i32) };
if ptr.is_null() {
b""
} else {
unsafe { ffi::CStr::from_ptr(ptr).to_bytes() }
}
}

pub fn target_count(&self) -> u32 {
Expand Down Expand Up @@ -3183,6 +3188,13 @@ CCCCCCCCCCCCCCCCCCC"[..],
assert_eq!(expected, actual);
}

#[test]
fn test_nonexistent_tidname() {
let header = Header::new();
let header_view = HeaderView::from_header(&header);
assert_eq!(b"", header_view.tid2name(0));
}

// #[test]
// fn test_number_mapped_and_unmapped_cram() {
// let mut reader = IndexedReader::from_path("test/test_cram.cram").unwrap();
Expand Down
Loading