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, AuxArray
s
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§
Implementations§
Trait Implementations§
Source§impl<'a, I, T> From<&'a T> for AuxArray<'a, I>
impl<'a, I, T> From<&'a T> for AuxArray<'a, I>
Create AuxArrays from slices of allowed target types.
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>
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>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more