bam_builder/wrappers.rs
1//! Helper wrappers over awkward [`rust_htslib`] types.
2#![warn(missing_docs)]
3use rust_htslib::bam::record::Aux;
4/// Wrapper type for a ReadGroupID.
5#[derive(Debug)]
6pub struct ReadGroupId(pub String);
7
8impl Default for ReadGroupId {
9 /// Default [`ReadGroupId`] is "A".
10 fn default() -> Self {
11 Self(String::from("A"))
12 }
13}
14
15/// Wrapper type for a Sample Name
16#[derive(Debug)]
17pub struct SampleName(pub String);
18
19impl Default for SampleName {
20 /// Default [`SampleName`] is "Sample1".
21 fn default() -> Self {
22 Self(String::from("Sample1"))
23 }
24}
25
26/// Wrapper for Aux that owns its own data. [`Aux::from`] is implemented in order
27/// to facilitate conversion between the wrapper and the underlying [`Aux`] type.
28#[derive(Clone, Debug)]
29pub enum AuxType {
30 /// Corresponds to [Aux::Integer].
31 Integer(i32),
32 /// Corresponds to [Aux::String], but as an owned String.
33 String(String),
34 /// Corresponds to [Aux::Float].
35 Float(f32),
36 /// Corresponds to [Aux::Char].
37 Char(u8),
38}
39
40impl<'a> From<&'a AuxType> for Aux<'a> {
41 /// Convert a ref [`AuxType`] to ref [`Aux`].
42 fn from(aux_type: &'a AuxType) -> Self {
43 match aux_type {
44 AuxType::Integer(x) => Aux::I32(*x),
45 AuxType::String(x) => Aux::String(x.as_str()),
46 AuxType::Float(x) => Aux::Float(*x),
47 AuxType::Char(x) => Aux::Char(*x),
48 }
49 }
50}
51
52/// Wrapper around strandedness of a read.
53#[derive(Clone, Debug)]
54pub enum Strand {
55 /// Forward strand.
56 Plus,
57 /// Reverse strand.
58 Minus,
59}