diff --git a/bitarray/src/lib.rs b/bitarray/src/lib.rs index d2e000c..695aa67 100644 --- a/bitarray/src/lib.rs +++ b/bitarray/src/lib.rs @@ -2,10 +2,13 @@ mod binary; -use std::{cmp::max, io::{ - Result, - Write -}}; +use std::{ + cmp::max, + io::{ + Result, + Write + } +}; /// Re-export the `Binary` trait. pub use binary::Binary; @@ -34,7 +37,11 @@ impl BitArray { /// /// A new `BitArray` with the specified capacity. pub fn with_capacity(capacity: usize, bits_per_value: usize) -> Self { - let extra = if capacity * bits_per_value % 64 == 0 { 0 } else { 1 }; + let extra = if capacity * bits_per_value % 64 == 0 { + 0 + } else { + 1 + }; Self { data: vec![0; capacity * bits_per_value / 64 + extra], mask: (1 << bits_per_value) - 1, @@ -160,9 +167,11 @@ pub fn data_to_writer( // Update the max capacity to be a multiple of the greatest common divisor of the bits per value // and 64. This is done to ensure that the bit array can store the data entirely let greates_common_divisor = gcd(bits_per_value, 64); - let capacity = max(greates_common_divisor, max_capacity / greates_common_divisor * greates_common_divisor); + let capacity = + max(greates_common_divisor, max_capacity / greates_common_divisor * greates_common_divisor); - // If amount of data is less than the max capacity, write the data to the writer in a single chunk + // If amount of data is less than the max capacity, write the data to the writer in a single + // chunk if data.len() <= capacity { let mut bitarray = BitArray::with_capacity(data.len(), bits_per_value); @@ -203,21 +212,21 @@ pub fn data_to_writer( } /// Calculates the greatest common divisor of two numbers. -/// +/// /// # Arguments -/// +/// /// * `a` - The first number. /// * `b` - The second number. -/// +/// /// # Returns -/// +/// /// The greatest common divisor of the two numbers. fn gcd(mut a: usize, mut b: usize) -> usize { while b != 0 { - if b < a { - std::mem::swap(&mut b, &mut a); - } - b %= a; + if b < a { + std::mem::swap(&mut b, &mut a); + } + b %= a; } a } @@ -305,7 +314,7 @@ mod tests { fn test_data_to_writer_chunks_needed_no_remainder() { let data = vec![ 0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, - 0x88888888 + 0x88888888, ]; let mut writer = Vec::new(); @@ -314,9 +323,9 @@ mod tests { assert_eq!( writer, vec![ - 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, - 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, - 0x88, 0x88, 0x77, 0x77, 0x77, 0x77 + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, + 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, + 0x77, 0x77, 0x77, 0x77 ] ); } @@ -325,7 +334,7 @@ mod tests { fn test_data_to_writer_chunks_needed_plus_remainder() { let data = vec![ 0x11111111, 0x22222222, 0x33333333, 0x44444444, 0x55555555, 0x66666666, 0x77777777, - 0x88888888, 0x99999999 + 0x88888888, 0x99999999, ]; let mut writer = Vec::new(); @@ -334,10 +343,9 @@ mod tests { assert_eq!( writer, vec![ - 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, - 0x33, 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, - 0x88, 0x88, 0x77, 0x77, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x99, 0x99, 0x99, - 0x99 + 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x44, 0x44, 0x44, 0x44, 0x33, 0x33, + 0x33, 0x33, 0x66, 0x66, 0x66, 0x66, 0x55, 0x55, 0x55, 0x55, 0x88, 0x88, 0x88, 0x88, + 0x77, 0x77, 0x77, 0x77, 0x00, 0x00, 0x00, 0x00, 0x99, 0x99, 0x99, 0x99 ] ); } diff --git a/sa-builder/src/lib.rs b/sa-builder/src/lib.rs index 1e6d834..57a4cfa 100644 --- a/sa-builder/src/lib.rs +++ b/sa-builder/src/lib.rs @@ -122,12 +122,17 @@ mod tests { #[test] fn test_arguments() { let args = Arguments::parse_from(&[ - "sa-builder", - "--database-file", "database.fa", - "--taxonomy", "taxonomy.tsv", - "--output", "output.fa", - "--sparseness-factor", "2", - "--construction-algorithm", "lib-div-suf-sort", + "sa-builder", + "--database-file", + "database.fa", + "--taxonomy", + "taxonomy.tsv", + "--output", + "output.fa", + "--sparseness-factor", + "2", + "--construction-algorithm", + "lib-div-suf-sort", "--compress-sa" ]); @@ -141,8 +146,14 @@ mod tests { #[test] fn test_sa_construction_algorithm() { - assert_eq!(SAConstructionAlgorithm::from_str("lib-div-suf-sort", false), Ok(SAConstructionAlgorithm::LibDivSufSort)); - assert_eq!(SAConstructionAlgorithm::from_str("lib-sais", false), Ok(SAConstructionAlgorithm::LibSais)); + assert_eq!( + SAConstructionAlgorithm::from_str("lib-div-suf-sort", false), + Ok(SAConstructionAlgorithm::LibDivSufSort) + ); + assert_eq!( + SAConstructionAlgorithm::from_str("lib-sais", false), + Ok(SAConstructionAlgorithm::LibSais) + ); } #[test] diff --git a/sa-compression/src/lib.rs b/sa-compression/src/lib.rs index 1148aca..d4da1eb 100644 --- a/sa-compression/src/lib.rs +++ b/sa-compression/src/lib.rs @@ -196,7 +196,7 @@ mod tests { valid_write_count: 3 }; - dump_compressed_suffix_array(vec![ 1 ], 1, 8, &mut writer).unwrap(); + dump_compressed_suffix_array(vec![1], 1, 8, &mut writer).unwrap(); } #[test] diff --git a/sa-index/src/binary.rs b/sa-index/src/binary.rs index 87e0d0d..ae16a8f 100644 --- a/sa-index/src/binary.rs +++ b/sa-index/src/binary.rs @@ -266,7 +266,9 @@ mod tests { #[test] fn test_fill_buffer_read_error() { - let mut input = FailingReader { valid_read_count: 0 }; + let mut input = FailingReader { + valid_read_count: 0 + }; let mut buffer = vec![0; 800]; assert!(fill_buffer(&mut input, &mut buffer).is_err()); @@ -358,7 +360,7 @@ mod tests { valid_write_count: 3 }; - dump_suffix_array(&vec![ 1 ], 1, &mut writer).unwrap(); + dump_suffix_array(&vec![1], 1, &mut writer).unwrap(); } #[test] diff --git a/sa-index/src/suffix_to_protein_index.rs b/sa-index/src/suffix_to_protein_index.rs index 85a245b..0091fed 100644 --- a/sa-index/src/suffix_to_protein_index.rs +++ b/sa-index/src/suffix_to_protein_index.rs @@ -124,10 +124,10 @@ mod tests { use crate::{ suffix_to_protein_index::{ - SuffixToProteinMappingStyle, DenseSuffixToProtein, SparseSuffixToProtein, - SuffixToProteinIndex + SuffixToProteinIndex, + SuffixToProteinMappingStyle }, Nullable }; @@ -140,8 +140,14 @@ mod tests { #[test] fn test_suffix_to_protein_mapping_style() { - assert_eq!(SuffixToProteinMappingStyle::Dense, SuffixToProteinMappingStyle::from_str("dense", false).unwrap()); - assert_eq!(SuffixToProteinMappingStyle::Sparse, SuffixToProteinMappingStyle::from_str("sparse", false).unwrap()); + assert_eq!( + SuffixToProteinMappingStyle::Dense, + SuffixToProteinMappingStyle::from_str("dense", false).unwrap() + ); + assert_eq!( + SuffixToProteinMappingStyle::Sparse, + SuffixToProteinMappingStyle::from_str("sparse", false).unwrap() + ); } #[test] diff --git a/sa-mappings/src/functionality.rs b/sa-mappings/src/functionality.rs index ec91eff..7a64150 100644 --- a/sa-mappings/src/functionality.rs +++ b/sa-mappings/src/functionality.rs @@ -49,15 +49,15 @@ impl FunctionAggregator { Some('E') => { proteins_with_ec.insert(protein.uniprot_id.clone()); proteins_with_annotations.insert(protein.uniprot_id.clone()); - }, + } Some('G') => { proteins_with_go.insert(protein.uniprot_id.clone()); proteins_with_annotations.insert(protein.uniprot_id.clone()); - }, + } Some('I') => { proteins_with_ipr.insert(protein.uniprot_id.clone()); proteins_with_annotations.insert(protein.uniprot_id.clone()); - }, + } _ => {} };