rust_htslib::faidx

Struct Reader

Source
pub struct Reader { /* private fields */ }
Expand description

A Fasta reader.

Implementations§

Source§

impl Reader

Source

pub fn from_path<P: AsRef<Path>>(path: P) -> Result<Self, Error>

Create a new Reader from a path.

§Arguments
  • path - the path to open.
Source

pub fn from_url(url: &Url) -> Result<Self, Error>

Create a new Reader from an URL.

§Arguments
  • url - the url to open
Source

pub fn fetch_seq<N: AsRef<str>>( &self, name: N, begin: usize, end: usize, ) -> Result<Vec<u8>>

Fetch the sequence as a byte array.

§Arguments
  • name - the name of the template sequence (e.g., “chr1”)
  • begin - the offset within the template sequence (starting with 0)
  • end - the end position to return (if smaller than begin, the behavior is undefined).
Source

pub fn fetch_seq_string<N: AsRef<str>>( &self, name: N, begin: usize, end: usize, ) -> Result<String>

Fetches the sequence and returns it as string.

§Arguments
  • name - the name of the template sequence (e.g., “chr1”)
  • begin - the offset within the template sequence (starting with 0)
  • end - the end position to return (if smaller than begin, the behavior is undefined).
Source

pub fn n_seqs(&self) -> u64

Fetches the number of sequences in the fai index

Source

pub fn seq_name(&self, i: i32) -> Result<String>

Fetches the i-th sequence name

§Arguments
  • i - index to query
Source

pub fn fetch_seq_len<N: AsRef<str>>(&self, name: N) -> u64

Fetches the length of the given sequence name.

§Arguments
  • name - the name of the template sequence (e.g., “chr1”)
Source

pub fn seq_names(&self) -> Result<Vec<String>>

Returns a Result<Vector> for all seq names.

§Errors
  • errors::Error::FaidxBadSeqName - missing sequence name for sequence id.

If thrown, the index is malformed, and the number of sequences in the index does not match the number of sequence names available.

 use rust_htslib::faidx::build;
 let path = std::path::PathBuf::from(concat!(env!("CARGO_MANIFEST_DIR"),"/test/test_cram.fa"));
 build(&path).expect("Failed to build fasta index");
 let reader = rust_htslib::faidx::Reader::from_path(path).expect("Failed to open faidx");
 assert_eq!(reader.seq_names(), Ok(vec!["chr1".to_string(), "chr2".to_string(), "chr3".to_string()]));

Trait Implementations§

Source§

impl Debug for Reader

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Reader

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Reader

§

impl RefUnwindSafe for Reader

§

impl !Send for Reader

§

impl !Sync for Reader

§

impl Unpin for Reader

§

impl UnwindSafe for Reader

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> MaybeSendSync for T