Skip to content
Open
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
4 changes: 3 additions & 1 deletion src/bam/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,7 @@ CCCCCCCCCCCCCCCCCCC"[..],
// fix qual offset
let qual: Vec<u8> = quals[i].iter().map(|&q| q - 33).collect();
assert_eq!(rec.qual(), &qual[..]);
assert_eq!(rec.aux(b"X"), Err(Error::BamAuxStringError));
assert_eq!(rec.aux(b"NotAvailableAux"), Err(Error::BamAuxTagNotFound));
}

Expand Down Expand Up @@ -2009,7 +2010,8 @@ CCCCCCCCCCCCCCCCCCC"[..],
rec.remove_aux(b"YT").unwrap();
}

assert!(rec.remove_aux(b"ab").is_err());
assert_eq!(rec.remove_aux(b"X"), Err(Error::BamAuxStringError));
assert_eq!(rec.remove_aux(b"ab"), Err(Error::BamAuxTagNotFound));

assert_eq!(rec.aux(b"XS"), Err(Error::BamAuxTagNotFound));
assert_eq!(rec.aux(b"YT"), Err(Error::BamAuxTagNotFound));
Expand Down
12 changes: 8 additions & 4 deletions src/bam/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,13 @@ impl Record {
/// Only the first two bytes of a given tag are used for the look-up of a field.
/// See [`Aux`] for more details.
pub fn aux(&self, tag: &[u8]) -> Result<Aux<'_>> {
let c_str = ffi::CString::new(tag).map_err(|_| Error::BamAuxStringError)?;
if tag.len() < 2 {
return Err(Error::BamAuxStringError);
}
let aux = unsafe {
htslib::bam_aux_get(
&self.inner as *const htslib::bam1_t,
c_str.as_ptr() as *mut c_char,
tag.as_ptr() as *const c_char,
)
};
unsafe { Self::read_aux_field(aux).map(|(aux_field, _length)| aux_field) }
Expand Down Expand Up @@ -1224,11 +1226,13 @@ impl Record {

// Delete auxiliary tag.
pub fn remove_aux(&mut self, tag: &[u8]) -> Result<()> {
let c_str = ffi::CString::new(tag).map_err(|_| Error::BamAuxStringError)?;
if tag.len() < 2 {
return Err(Error::BamAuxStringError);
}
let aux = unsafe {
htslib::bam_aux_get(
&self.inner as *const htslib::bam1_t,
c_str.as_ptr() as *mut c_char,
tag.as_ptr() as *const c_char,
)
};
unsafe {
Expand Down
Loading