Enum rust_htslib::bam::record::AuxArray[][src]

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

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

Returns the number of elements in the array.

Returns true if the array contains no elements.

Returns an iterator over the array.

Trait Implementations

Formats the value using the given formatter. Read more

Create AuxArrays from slices of allowed target types.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.