Skip to content

Commit

Permalink
Add seq_names and num_seqs functions to faidx.
Browse files Browse the repository at this point in the history
  • Loading branch information
PB-DB committed Feb 1, 2024
1 parent afba33e commit 427ca61
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ url = "2.1"
bindgen = ["hts-sys/bindgen"]
bzip2 = ["hts-sys/bzip2"]
curl = ["hts-sys/curl"]
default = ["bzip2", "lzma", "curl"]
default = ["bzip2", "lzma", "static"]
gcs = ["hts-sys/gcs"]
libdeflate = ["hts-sys/libdeflate"]
lzma = ["hts-sys/lzma"]
Expand Down
5 changes: 5 additions & 0 deletions src/bam/pileup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ impl<'a> Alignment<'a> {
}
}

/// Position within the read. Returns the value even if is_del or is_refskip
pub fn qpos_raw(&self) -> usize {
self.inner.qpos as usize
}

/// Insertion, deletion (with length) if indel starts at next base or None otherwise.
pub fn indel(&self) -> Indel {
match self.inner.indel {
Expand Down
11 changes: 7 additions & 4 deletions src/bcf/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -981,19 +981,22 @@ impl Record {
};
let tag_c_str = ffi::CString::new(tag).unwrap();
unsafe {
if htslib::bcf_update_info(
let code = htslib::bcf_update_info(
self.header().inner,
self.inner,
tag_c_str.as_ptr() as *mut c_char,
c_str.as_ptr() as *const ::std::os::raw::c_void,
len as i32,
ht as i32,
) == 0
{
);
if code == 0 {
Ok(())
} else {
Err(Error::BcfSetTag {
tag: str::from_utf8(tag).unwrap().to_owned(),
tag: format!(
"Error {} with code {code}",
str::from_utf8(tag).map_or_else(|_| format!("{tag:?}"), |x| x.to_owned())
),
})
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/faidx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ impl Reader {
Ok(cseq.to_bytes())
}

pub fn num_seqs(&self) -> i32 {
unsafe { hts_sys::faidx_nseq(self.inner) }
}

pub fn seq_names(&self) -> Option<Vec<String>> {
let mut ret = Vec::new();
for seq in (0..self.num_seqs()).map(|x| self.seq_name(x)) {
ret.push(seq.ok()?);
}
Some(ret)
}

/// Fetches the sequence and returns it as string.
///
/// # Arguments
Expand Down

0 comments on commit 427ca61

Please sign in to comment.