rust_htslib::bam::record

Enum AuxArray

Source
pub enum AuxArray<'a, T> {
    TargetType(AuxArrayTargetType<'a, T>),
    RawLeBytes(AuxArrayRawLeBytes<'a, T>),
}
Expand description

Provides access to aux arrays.

Provides methods to either retrieve single elements or an iterator over the array.

This type is used for wrapping both, array data that was read from a BAM record and slices of data that are going to be stored in one.

In order to be able to add an AuxArray field to a BAM record, AuxArrays can be constructed via the From trait which is implemented for all supported types (see AuxArrayElement for a list).

§Examples

use rust_htslib::{
    bam,
    bam::record::{Aux, AuxArray},
};

//Set up BAM record
let bam_header = bam::Header::new();
let mut record = bam::Record::from_sam(
    &mut bam::HeaderView::from_header(&bam_header),
    "ali1\t4\t*\t0\t0\t*\t*\t0\t0\tACGT\tFFFF".as_bytes(),
).unwrap();

let data = vec![0.4, 0.3, 0.2, 0.1];
let slice_of_data = &data;
let aux_array: AuxArray<f32> = slice_of_data.into();
let aux_field = Aux::ArrayFloat(aux_array);
record.push_aux(b"XA", aux_field);

if let Ok(Aux::ArrayFloat(array)) = record.aux(b"XA") {
    // Retrieve the second element from the array
    assert_eq!(array.get(1).unwrap(), 0.3);
    // Iterate over the array and collect it into a `Vec`
    let read_array = array.iter().collect::<Vec<_>>();
    assert_eq!(read_array, data);
} else {
    panic!("Could not read array data");
}

Variants§

§

TargetType(AuxArrayTargetType<'a, T>)

§

RawLeBytes(AuxArrayRawLeBytes<'a, T>)

Implementations§

Source§

impl<'a, T> AuxArray<'a, T>
where T: AuxArrayElement,

Source

pub fn get(&self, index: usize) -> Option<T>

Returns the element at a position or None if out of bounds.

Source

pub fn len(&self) -> usize

Returns the number of elements in the array.

Source

pub fn is_empty(&self) -> bool

Returns true if the array contains no elements.

Source

pub fn iter(&self) -> AuxArrayIter<'_, T>

Returns an iterator over the array.

Trait Implementations§

Source§

impl<'a, T: Debug> Debug for AuxArray<'a, T>

Source§

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

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

impl<'a, I, T> From<&'a T> for AuxArray<'a, I>
where I: AuxArrayElement, T: AsRef<[I]> + ?Sized,

Create AuxArrays from slices of allowed target types.

Source§

fn from(src: &'a T) -> Self

Converts to this type from the input type.
Source§

impl<T> PartialEq<AuxArray<'_, T>> for AuxArray<'_, T>

Source§

fn eq(&self, other: &AuxArray<'_, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

§

impl<'a, T> Freeze for AuxArray<'a, T>

§

impl<'a, T> RefUnwindSafe for AuxArray<'a, T>
where T: RefUnwindSafe,

§

impl<'a, T> Send for AuxArray<'a, T>
where T: Send + Sync,

§

impl<'a, T> Sync for AuxArray<'a, T>
where T: Sync,

§

impl<'a, T> Unpin for AuxArray<'a, T>
where T: Unpin,

§

impl<'a, T> UnwindSafe for AuxArray<'a, T>

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