Enum rust_htslib::bam::record::Aux [−][src]
pub enum Aux<'a> {
Show 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)