bio_types/
sequence.rs

1// Copyright 2021 Johannes Köster.
2// Licensed under the MIT license (http://opensource.org/licenses/MIT)
3// This file may not be copied, modified, or distributed
4// except according to those terms.
5
6#[cfg(feature = "serde")]
7use serde::{Deserialize, Serialize};
8use strum_macros::{AsRefStr, Display};
9use SequenceReadPairOrientation::None;
10
11/// A DNA base
12pub type Base = u8;
13/// An amino acid
14pub type AminoAcid = u8;
15/// A biological sequence
16pub type Sequence = Vec<u8>;
17
18pub trait SequenceRead {
19    /// Read name.
20    fn name(&self) -> &[u8];
21    /// Base at position `i` in the read.
22    fn base(&self, i: usize) -> u8;
23    /// Base quality at position `i` in the read.
24    fn base_qual(&self, i: usize) -> u8;
25    /// Read length.
26    fn len(&self) -> usize;
27    /// Return `true` if read is empty.
28    fn is_empty(&self) -> bool {
29        self.len() == 0
30    }
31}
32
33/// Representation of sequence read pair orientation
34/// (e.g. F1R2 means that the forward read comes first on the reference contig,
35/// followed by the reverse read, on the same contig).
36///
37/// This enum can be pretty-printed into a readable string repesentation:
38///
39/// ```rust
40/// use bio_types::sequence::SequenceReadPairOrientation;
41///
42/// // format into string
43/// println!("{}", SequenceReadPairOrientation::F1R2);
44/// // obtain string via `AsRef<&'static str>`
45/// assert_eq!(SequenceReadPairOrientation::R1F2.as_ref(), "R1F2");
46/// ```
47#[derive(Debug, Clone, Copy, PartialEq, Eq, AsRefStr, Display)]
48#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
49pub enum SequenceReadPairOrientation {
50    F1R2,
51    F2R1,
52    R1F2,
53    R2F1,
54    F1F2,
55    R1R2,
56    F2F1,
57    R2R1,
58    None,
59}
60
61impl Default for SequenceReadPairOrientation {
62    fn default() -> Self {
63        None
64    }
65}