rust_htslib::bam::record

Enum Aux

Source
pub enum Aux<'a> {
Show 18 variants Char(u8), I8(i8), U8(u8), I16(i16), U16(u16), I32(i32), U32(u32), Float(f32), Double(f64), String(&'a str), HexByteArray(&'a str), ArrayI8(AuxArray<'a, i8>), ArrayU8(AuxArray<'a, u8>), ArrayI16(AuxArray<'a, i16>), ArrayU16(AuxArray<'a, u16>), ArrayI32(AuxArray<'a, i32>), ArrayU32(AuxArray<'a, u32>), ArrayFloat(AuxArray<'a, f32>),
}
Expand description

Auxiliary record data

The specification allows a wide range of types to be stored as an auxiliary data field of a BAM record.

Please note that the Aux::Double variant is not part of the specification, but it is supported by htslib.

§Examples

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

//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();

// Add an integer field
let aux_integer_field = Aux::I32(1234);
record.push_aux(b"XI", aux_integer_field).unwrap();

match record.aux(b"XI") {
    Ok(value) => {
        // Typically, callers expect an aux field to be of a certain type.
        // If that's not the case, the value can be `match`ed exhaustively.
        if let Aux::I32(v) = value {
            assert_eq!(v, 1234);
        }
    }
    Err(e) => {
        panic!("Error reading aux field: {}", e);
    }
}

// Add an array field
let array_like_data = vec![0.4, 0.3, 0.2, 0.1];
let slice_of_data = &array_like_data;
let aux_array: AuxArray<f32> = slice_of_data.into();
let aux_array_field = Aux::ArrayFloat(aux_array);
record.push_aux(b"XA", aux_array_field).unwrap();

if let Ok(Aux::ArrayFloat(array)) = record.aux(b"XA") {
    let read_array = array.iter().collect::<Vec<_>>();
    assert_eq!(read_array, array_like_data);
} else {
    panic!("Could not read array data");
}

Variants§

§

Char(u8)

§

I8(i8)

§

U8(u8)

§

I16(i16)

§

U16(u16)

§

I32(i32)

§

U32(u32)

§

Float(f32)

§

Double(f64)

§

String(&'a str)

§

HexByteArray(&'a str)

§

ArrayI8(AuxArray<'a, i8>)

§

ArrayU8(AuxArray<'a, u8>)

§

ArrayI16(AuxArray<'a, i16>)

§

ArrayU16(AuxArray<'a, u16>)

§

ArrayI32(AuxArray<'a, i32>)

§

ArrayU32(AuxArray<'a, u32>)

§

ArrayFloat(AuxArray<'a, f32>)

Trait Implementations§

Source§

impl<'a> Debug for Aux<'a>

Source§

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

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

impl<'a> PartialEq for Aux<'a>

Source§

fn eq(&self, other: &Aux<'a>) -> 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.
Source§

impl<'a> Send for Aux<'a>

Source§

impl<'a> StructuralPartialEq for Aux<'a>

Source§

impl<'a> Sync for Aux<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Aux<'a>

§

impl<'a> RefUnwindSafe for Aux<'a>

§

impl<'a> Unpin for Aux<'a>

§

impl<'a> UnwindSafe for Aux<'a>

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