Skip to content

Commit

Permalink
feat: add standard derives to all public types (#505)
Browse files Browse the repository at this point in the history
* feat: add standard derives to all public types

* fix(clippy): remove unnecessary clones

* fix(build): fix changes breaking tarpaulin

* fix(bench): removed unneeded derives from benches
  • Loading branch information
TheLostLambda committed Dec 13, 2022
1 parent cd3491d commit c08623b
Show file tree
Hide file tree
Showing 51 changed files with 226 additions and 115 deletions.
5 changes: 3 additions & 2 deletions src/alignment/pairwise/banded.rs
Expand Up @@ -108,6 +108,7 @@ const DEFAULT_MATCH_SCORE: i32 = 2;
/// in the band is less than MAX_CELLS (currently set to 10 million), otherwise it returns an
/// empty alignment
#[allow(non_snake_case)]
#[derive(Default, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
pub struct Aligner<F: MatchFunc> {
S: [Vec<i32>; 2],
I: [Vec<i32>; 2],
Expand Down Expand Up @@ -1029,13 +1030,13 @@ trait MatchPair {
impl MatchPair for (u32, u32) {
fn continues(&self, p: Option<(u32, u32)>) -> bool {
match p {
Some(_p) => (self.0 == _p.0 + 1 && self.1 == _p.1 + 1),
Some(_p) => self.0 == _p.0 + 1 && self.1 == _p.1 + 1,
None => false,
}
}
}

#[derive(Clone, Debug)]
#[derive(Default, Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
struct Band {
rows: usize,
cols: usize,
Expand Down
14 changes: 11 additions & 3 deletions src/alignment/pairwise/mod.rs
Expand Up @@ -171,7 +171,9 @@ pub trait MatchFunc {

/// A concrete data structure which implements trait MatchFunc with constant
/// match and mismatch scores
#[derive(Debug, Clone)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct MatchParams {
pub match_score: i32,
pub mismatch_score: i32,
Expand Down Expand Up @@ -221,7 +223,9 @@ where
/// An [affine gap score model](https://en.wikipedia.org/wiki/Gap_penalty#Affine)
/// is used so that the gap score for a length `k` is:
/// `GapScore(k) = gap_open + gap_extend * k`
#[derive(Debug, Clone)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct Scoring<F: MatchFunc> {
pub gap_open: i32,
pub gap_extend: i32,
Expand Down Expand Up @@ -455,6 +459,7 @@ impl<F: MatchFunc> Scoring<F> {
///
/// `scoring` - see [`bio::alignment::pairwise::Scoring`](struct.Scoring.html)
#[allow(non_snake_case)]
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct Aligner<F: MatchFunc> {
I: [Vec<i32>; 2],
D: [Vec<i32>; 2],
Expand Down Expand Up @@ -1008,7 +1013,9 @@ impl<F: MatchFunc> Aligner<F> {
/// Possible traceback moves include : start, insert, delete, match, substitute,
/// prefix clip and suffix clip for x & y. So we need 4 bits each for matrices I, D, S
/// to keep track of these 9 moves.
#[derive(Copy, Clone, Default)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct TracebackCell {
v: u16,
}
Expand Down Expand Up @@ -1100,6 +1107,7 @@ impl TracebackCell {
}

/// Internal traceback.
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
struct Traceback {
rows: usize,
cols: usize,
Expand Down
10 changes: 7 additions & 3 deletions src/alignment/poa.rs
Expand Up @@ -53,20 +53,21 @@ pub type POAGraph = Graph<u8, i32, Directed, usize>;
// traceback matrix. I have not yet figured out what the best level of
// detail to store is, so Match and Del operations remember In and Out
// nodes on the reference graph.
#[derive(Debug, Clone)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub enum AlignmentOperation {
Match(Option<(usize, usize)>),
Del(Option<(usize, usize)>),
Ins(Option<usize>),
}

#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct Alignment {
pub score: i32,
// xstart: Edge,
operations: Vec<AlignmentOperation>,
}

#[derive(Debug, Clone)]
#[derive(Copy, Clone, Debug, Serialize, Deserialize)]
pub struct TracebackCell {
score: i32,
op: AlignmentOperation,
Expand Down Expand Up @@ -94,6 +95,7 @@ impl PartialEq for TracebackCell {

impl Eq for TracebackCell {}

#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Debug)]
pub struct Traceback {
rows: usize,
cols: usize,
Expand Down Expand Up @@ -196,7 +198,7 @@ impl Traceback {
while i > 0 && j > 0 {
// push operation and edge corresponding to (one of the) optimal
// routes
ops.push(self.matrix[i][j].op.clone());
ops.push(self.matrix[i][j].op);
match self.matrix[i][j].op {
AlignmentOperation::Match(Some((p, _))) => {
i = p + 1;
Expand Down Expand Up @@ -233,6 +235,7 @@ impl Traceback {
/// A partially ordered aligner builder
///
/// Uses consuming builder pattern for constructing partial order alignments with method chaining
#[derive(Default, Clone, Debug)]
pub struct Aligner<F: MatchFunc> {
traceback: Traceback,
query: Vec<u8>,
Expand Down Expand Up @@ -278,6 +281,7 @@ impl<F: MatchFunc> Aligner<F> {
///
/// A directed acyclic graph datastructure that represents the topology of a
/// traceback matrix.
#[derive(Default, Clone, Debug)]
pub struct Poa<F: MatchFunc> {
scoring: Scoring<F>,
pub graph: POAGraph,
Expand Down
2 changes: 1 addition & 1 deletion src/alignment/sparse.rs
Expand Up @@ -36,7 +36,7 @@ use std::hash::BuildHasherDefault;
pub type HashMapFx<K, V> = HashMap<K, V, BuildHasherDefault<FxHasher>>;

/// Result of a sparse alignment
#[derive(Debug, PartialEq, Eq)]
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct SparseAlignmentResult {
/// LCSk++ path, represented as vector of indices into the input matches vector.
pub path: Vec<usize>,
Expand Down
5 changes: 3 additions & 2 deletions src/alphabets/mod.rs
Expand Up @@ -27,7 +27,7 @@ pub mod rna;
pub type SymbolRanks = VecMap<u8>;

/// Representation of an alphabet.
#[derive(Debug, PartialEq, Eq)]
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug)]
pub struct Alphabet {
pub symbols: BitSet,
}
Expand Down Expand Up @@ -217,7 +217,7 @@ impl Alphabet {
///
/// `RankTransform` can be used in to perform bit encoding for texts over a
/// given alphabet via `bio::data_structures::bitenc`.
#[derive(Serialize, Deserialize)]
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct RankTransform {
pub ranks: SymbolRanks,
}
Expand Down Expand Up @@ -384,6 +384,7 @@ impl RankTransform {
}

/// Iterator over q-grams.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)]
pub struct QGrams<'a, C, T>
where
C: Borrow<u8>,
Expand Down
5 changes: 3 additions & 2 deletions src/data_structures/annot_map.rs
Expand Up @@ -47,7 +47,7 @@ use bio_types::annot::loc::Loc;
///
/// Thus, the overlapping annotations identified by querying a
/// `AnnotMap` may need further filtering.
#[derive(Debug, Clone)]
#[derive(Clone, Eq, PartialEq, Debug, Serialize, Deserialize)]
pub struct AnnotMap<R, T>
where
R: Hash + Eq,
Expand Down Expand Up @@ -180,7 +180,7 @@ where
}

/// A view of one annotation in a `AnnotMap` container.
#[derive(Debug, Clone)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize)]
pub struct Entry<'a, R, T>
where
R: Eq + Hash,
Expand Down Expand Up @@ -213,6 +213,7 @@ where
/// `AnnotMap`.
///
/// This struct is created by the `find` function on `AnnotMap`.
#[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize)]
pub struct AnnotMapIterator<'a, R, T>
where
R: Eq + Hash,
Expand Down
7 changes: 7 additions & 0 deletions src/data_structures/bit_tree.rs
Expand Up @@ -41,6 +41,7 @@ pub trait PrefixOp<T> {
/// a smaller element at the same index.
/// Time Complexity: O(n) to build a new tree or O(log n) for get() and set() operations,
/// where `n = tree.len()`.
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct FenwickTree<T: Default + Ord, Op: PrefixOp<T>> {
tree: Vec<T>,
phantom: PhantomData<Op>,
Expand Down Expand Up @@ -84,6 +85,9 @@ impl<T: Ord + Default + Copy, Op: PrefixOp<T>> FenwickTree<T, Op> {
}
}

#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct MaxOp;
impl<T: Copy + Ord> PrefixOp<T> for MaxOp {
fn operation(t1: T, t2: T) -> T {
Expand All @@ -94,6 +98,9 @@ impl<T: Copy + Ord> PrefixOp<T> for MaxOp {
/// Fenwick tree specialized for prefix-max
pub type MaxBitTree<T> = FenwickTree<T, MaxOp>;

#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct SumOp;
impl<T: Copy + Add> PrefixOp<T> for SumOp
where
Expand Down
7 changes: 4 additions & 3 deletions src/data_structures/bitenc.rs
Expand Up @@ -46,7 +46,7 @@
/// For values that are not a divider of 32, some bits will remain unused.
/// For example for `width = 7` only `4 * 7 = 28` bits are used.
/// Five 7-bit values are stored in 2 blocks.
#[derive(Serialize, Deserialize, PartialEq, Eq, Hash)]
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct BitEnc {
storage: Vec<u32>,
width: usize,
Expand Down Expand Up @@ -385,7 +385,7 @@ impl BitEnc {
/// // Add another 2 to create a second block
/// bitenc.push(2);
/// assert_eq!(bitenc.nr_blocks(), 2);
/// ```
/// ```
pub fn nr_blocks(&self) -> usize {
self.storage.len()
}
Expand All @@ -408,7 +408,7 @@ impl BitEnc {
/// assert_eq!(bitenc.nr_symbols(), 4);
/// bitenc.push(2);
/// assert_eq!(bitenc.nr_symbols(), 5);
/// ```
/// ```
pub fn nr_symbols(&self) -> usize {
self.len
}
Expand Down Expand Up @@ -436,6 +436,7 @@ impl BitEnc {

/// Iterator over values of a bitencoded sequence (values will be unpacked into bytes).
/// Used to implement the `iter` method of `BitEnc`.
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize)]
pub struct BitEncIter<'a> {
bitenc: &'a BitEnc,
i: usize,
Expand Down
2 changes: 1 addition & 1 deletion src/data_structures/bwt.rs
Expand Up @@ -73,7 +73,7 @@ pub fn invert_bwt(bwt: &BWTSlice) -> Vec<u8> {
}

/// An occurrence array implementation.
#[derive(Clone, Serialize, Deserialize)]
#[derive(Default, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub struct Occ {
occ: Vec<Vec<usize>>,
k: u32,
Expand Down
18 changes: 13 additions & 5 deletions src/data_structures/fmindex.rs
Expand Up @@ -63,7 +63,9 @@ use crate::data_structures::suffix_array::SuffixArray;
use std::mem::swap;

/// A suffix array interval.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct Interval {
pub lower: usize,
pub upper: usize,
Expand All @@ -86,7 +88,7 @@ impl Interval {
/// The interval returned is the range of suffix array indices for the maximal
/// matching suffix, and the `usize` is the length of the maximal matching suffix.
/// Absent - None suffix of the pattern matched in the text.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize)]
pub enum BackwardSearchResult {
Complete(Interval),
Partial(Interval, usize),
Expand Down Expand Up @@ -201,7 +203,9 @@ pub trait FMIndexable {

/// The Fast Index in Minute space (FM-Index, Ferragina and Manzini, 2000) for finding suffix array
/// intervals matching a given pattern.
#[derive(Serialize, Deserialize)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct FMIndex<DBWT: Borrow<BWT>, DLess: Borrow<Less>, DOcc: Borrow<Occ>> {
bwt: DBWT,
less: DLess,
Expand Down Expand Up @@ -237,7 +241,9 @@ impl<DBWT: Borrow<BWT>, DLess: Borrow<Less>, DOcc: Borrow<Occ>> FMIndex<DBWT, DL
}

/// A bi-interval on suffix array of the forward and reverse strand of a DNA text.
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct BiInterval {
lower: usize,
lower_rev: usize,
Expand Down Expand Up @@ -271,7 +277,9 @@ impl BiInterval {

/// The FMD-Index for linear time search of supermaximal exact matches on forward and reverse
/// strand of DNA texts (Li, 2012).
#[derive(Serialize, Deserialize)]
#[derive(
Default, Copy, Clone, Eq, PartialEq, Ord, PartialOrd, Hash, Debug, Serialize, Deserialize,
)]
pub struct FMDIndex<DBWT: Borrow<BWT>, DLess: Borrow<Less>, DOcc: Borrow<Occ>> {
fmindex: FMIndex<DBWT, DLess, DOcc>,
}
Expand Down
1 change: 1 addition & 0 deletions src/data_structures/interpolation_table.rs
Expand Up @@ -36,6 +36,7 @@ pub fn interpolate(a: f64, b: f64, fraction: f64) -> f64 {
/// Input values are sampled with a given precision and results are stored in a vector.
/// During lookup, infimum and supremum of a given value are calculated and the result is
/// interpolated.
#[derive(Default, Clone, PartialEq, PartialOrd, Debug, Serialize, Deserialize)]
pub struct InterpolationTable<F: Fn(f64) -> f64> {
inner: Vec<f64>,
func: F,
Expand Down
Expand Up @@ -39,7 +39,7 @@ use std::iter::FromIterator;

/// A `find` query on the interval tree does not directly return references to the intervals in the
/// tree but wraps the fields `interval` and `data` in an `Entry`.
#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
struct InternalEntry<N: Ord + Clone + Copy, D> {
data: D,
interval: Interval<N>,
Expand All @@ -48,7 +48,7 @@ struct InternalEntry<N: Ord + Clone + Copy, D> {

/// A `find` query on the interval tree does not directly return references to the nodes in the tree, but
/// wraps the fields `interval` and `data` in an `Entry`.
#[derive(PartialEq, Eq, Debug, Clone)]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug, Serialize)]
pub struct Entry<'a, N: Ord + Clone, D> {
data: &'a D,
interval: &'a Interval<N>,
Expand Down Expand Up @@ -76,6 +76,7 @@ impl<N: Ord + Clone + Copy, D> Default for ArrayBackedIntervalTree<N, D> {
}
}

#[derive(Clone, Eq, PartialEq, Hash, Debug, Serialize, Deserialize)]
pub struct ArrayBackedIntervalTree<N: Ord + Clone + Copy, D> {
entries: Vec<InternalEntry<N, D>>,
max_level: usize,
Expand Down

0 comments on commit c08623b

Please sign in to comment.