diff --git a/bitarray/src/binary.rs b/bitarray/src/binary.rs index a8084d1..4ab535f 100644 --- a/bitarray/src/binary.rs +++ b/bitarray/src/binary.rs @@ -167,10 +167,13 @@ mod tests { let mut buffer = Vec::new(); bitarray.write_binary(&mut buffer).unwrap(); - assert_eq!(buffer, vec![ - 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0 - ]); + assert_eq!( + buffer, + vec![ + 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0 + ] + ); } #[test] diff --git a/bitarray/src/lib.rs b/bitarray/src/lib.rs index 901b395..de2c508 100644 --- a/bitarray/src/lib.rs +++ b/bitarray/src/lib.rs @@ -4,7 +4,7 @@ mod binary; use std::{ cmp::max, - io::{Result, Write} + io::{Result, Write}, }; /// Re-export the `Binary` trait. @@ -19,7 +19,7 @@ pub struct BitArray { /// The length of the bit array. len: usize, /// The number of bits in a single element of the data vector. - bits_per_value: usize + bits_per_value: usize, } impl BitArray { @@ -39,7 +39,7 @@ impl BitArray { data: vec![0; capacity * bits_per_value / 64 + extra], mask: (1 << bits_per_value) - 1, len: capacity, - bits_per_value + bits_per_value, } } @@ -166,7 +166,7 @@ pub fn data_to_writer( data: Vec, bits_per_value: usize, max_capacity: usize, - writer: &mut impl Write + writer: &mut impl Write, ) -> Result<()> { // 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 @@ -310,10 +310,13 @@ mod tests { data_to_writer(data, 40, 2, &mut writer).unwrap(); - assert_eq!(writer, vec![ - 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, 0x00, - 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0 - ]); + assert_eq!( + writer, + vec![ + 0xef, 0xcd, 0xab, 0x90, 0x78, 0x56, 0x34, 0x12, 0xde, 0xbc, 0x0a, 0x89, 0x67, 0x45, 0x23, 0x01, 0x00, + 0x00, 0x00, 0x00, 0x56, 0x34, 0x12, 0xf0 + ] + ); } #[test] @@ -332,23 +335,27 @@ mod tests { data_to_writer(data, 32, 8, &mut writer).unwrap(); - 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, 0xaa, 0xaa, 0xaa, 0xaa, - 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, - 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, - 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xff, 0xff, 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, 0xaa, 0xaa, - 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, - 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, - 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, - 0xff, 0xff, 0xff, 0xff - ]); + 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, 0xaa, 0xaa, + 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, + 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, + 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, + 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, + 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, + 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0xff + ] + ); } #[test] @@ -363,16 +370,20 @@ mod tests { data_to_writer(data, 32, 8, &mut writer).unwrap(); - 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, 0xaa, 0xaa, 0xaa, 0xaa, - 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, - 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, - 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, - 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33 - ]); + 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, 0xaa, 0xaa, + 0xaa, 0xaa, 0x99, 0x99, 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, + 0xee, 0xdd, 0xdd, 0xdd, 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 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, 0xaa, 0xaa, 0xaa, 0xaa, 0x99, 0x99, + 0x99, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xbb, 0xbb, 0xbb, 0xbb, 0xee, 0xee, 0xee, 0xee, 0xdd, 0xdd, 0xdd, + 0xdd, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0x22, 0x22, 0x22, 0x22, 0x11, 0x11, 0x11, 0x11, + 0x00, 0x00, 0x00, 0x00, 0x33, 0x33, 0x33, 0x33 + ] + ); } #[test] diff --git a/fa-compression/benches/algorithm1/decode.rs b/fa-compression/benches/algorithm1/decode.rs index 24991dc..bd1c94d 100644 --- a/fa-compression/benches/algorithm1/decode.rs +++ b/fa-compression/benches/algorithm1/decode.rs @@ -22,7 +22,7 @@ pub fn decode_benchmark(c: &mut criterion::Criterion) { b.iter_batched( || generate_encoded_annotations(100), |annotations| black_box(decode(annotations.as_slice())), - criterion::BatchSize::SmallInput + criterion::BatchSize::SmallInput, ) }); } diff --git a/fa-compression/benches/algorithm1/encode.rs b/fa-compression/benches/algorithm1/encode.rs index d3a9c86..1d23a6e 100644 --- a/fa-compression/benches/algorithm1/encode.rs +++ b/fa-compression/benches/algorithm1/encode.rs @@ -22,7 +22,7 @@ pub fn encode_benchmark(c: &mut criterion::Criterion) { b.iter_batched( || generate_decoded_annotations(100), |annotations| black_box(encode(annotations.as_str())), - criterion::BatchSize::SmallInput + criterion::BatchSize::SmallInput, ) }); } diff --git a/fa-compression/benches/algorithm2/decode.rs b/fa-compression/benches/algorithm2/decode.rs index 4d562fc..62f8b9e 100644 --- a/fa-compression/benches/algorithm2/decode.rs +++ b/fa-compression/benches/algorithm2/decode.rs @@ -28,7 +28,7 @@ pub fn decode_benchmark(c: &mut criterion::Criterion) { b.iter_batched( || generate_encoded_annotations_and_table(100), |(annotations, ct)| black_box(decode(annotations.as_slice(), ct)), - criterion::BatchSize::SmallInput + criterion::BatchSize::SmallInput, ) }); } diff --git a/fa-compression/benches/algorithm2/encode.rs b/fa-compression/benches/algorithm2/encode.rs index 827dd50..a69ed0e 100644 --- a/fa-compression/benches/algorithm2/encode.rs +++ b/fa-compression/benches/algorithm2/encode.rs @@ -26,7 +26,7 @@ pub fn encode_benchmark(c: &mut criterion::Criterion) { b.iter_batched( || generate_decoded_annotations_and_table(100), |(annotations, ct)| black_box(encode(annotations.as_str(), ct)), - criterion::BatchSize::SmallInput + criterion::BatchSize::SmallInput, ) }); } diff --git a/fa-compression/benches/util.rs b/fa-compression/benches/util.rs index b6ddd9a..0e80765 100644 --- a/fa-compression/benches/util.rs +++ b/fa-compression/benches/util.rs @@ -27,6 +27,6 @@ pub fn generate_annotation(random: &mut ThreadRng) -> String { 0 => generate_ipr(random), 1 => generate_go(random), 2 => generate_ec(random), - _ => unreachable!() + _ => unreachable!(), } } diff --git a/fa-compression/src/algorithm1/encode.rs b/fa-compression/src/algorithm1/encode.rs index ef79372..9138be1 100644 --- a/fa-compression/src/algorithm1/encode.rs +++ b/fa-compression/src/algorithm1/encode.rs @@ -106,16 +106,18 @@ mod tests { #[test] fn test_encode_no_ec() { - assert_eq!(encode("IPR:IPR016364;GO:0009279;IPR:IPR008816"), vec![ - 225, 17, 163, 138, 225, 39, 71, 95, 17, 153, 39 - ]) + assert_eq!( + encode("IPR:IPR016364;GO:0009279;IPR:IPR008816"), + vec![225, 17, 163, 138, 225, 39, 71, 95, 17, 153, 39] + ) } #[test] fn test_encode_no_go() { - assert_eq!(encode("IPR:IPR016364;EC:1.1.1.-;EC:1.2.1.7"), vec![ - 44, 44, 44, 191, 44, 60, 44, 142, 225, 39, 71, 80 - ]) + assert_eq!( + encode("IPR:IPR016364;EC:1.1.1.-;EC:1.2.1.7"), + vec![44, 44, 44, 191, 44, 60, 44, 142, 225, 39, 71, 80] + ) } #[test] @@ -125,8 +127,9 @@ mod tests { #[test] fn test_encode_all() { - assert_eq!(encode("IPR:IPR016364;EC:1.1.1.-;IPR:IPR032635;GO:0009279;IPR:IPR008816"), vec![ - 44, 44, 44, 190, 17, 26, 56, 174, 18, 116, 117, 241, 67, 116, 111, 17, 153, 39 - ]) + assert_eq!( + encode("IPR:IPR016364;EC:1.1.1.-;IPR:IPR032635;GO:0009279;IPR:IPR008816"), + vec![44, 44, 44, 190, 17, 26, 56, 174, 18, 116, 117, 241, 67, 116, 111, 17, 153, 39] + ) } } diff --git a/fa-compression/src/algorithm1/mod.rs b/fa-compression/src/algorithm1/mod.rs index cdf7283..8ea45c5 100644 --- a/fa-compression/src/algorithm1/mod.rs +++ b/fa-compression/src/algorithm1/mod.rs @@ -79,7 +79,7 @@ enum CharacterSet { Comma, /// Annotation separator - Semicolon + Semicolon, } impl Encode for CharacterSet { @@ -110,7 +110,7 @@ impl Encode for CharacterSet { b'n' => CharacterSet::Preliminary, b',' => CharacterSet::Comma, b';' => CharacterSet::Semicolon, - _ => panic!("Invalid character") + _ => panic!("Invalid character"), } } } @@ -143,7 +143,7 @@ impl Decode for CharacterSet { 13 => 'n', 14 => ',', 15 => ';', - _ => panic!("Invalid character") + _ => panic!("Invalid character"), } } } @@ -189,7 +189,7 @@ mod tests { CharacterSet::Point, CharacterSet::Preliminary, CharacterSet::Comma, - CharacterSet::Semicolon + CharacterSet::Semicolon, ]; #[test] diff --git a/fa-compression/src/algorithm2/encode.rs b/fa-compression/src/algorithm2/encode.rs index f55eb11..d60fe61 100644 --- a/fa-compression/src/algorithm2/encode.rs +++ b/fa-compression/src/algorithm2/encode.rs @@ -89,8 +89,9 @@ mod tests { #[test] fn test_encode_all() { let table = create_compresion_table(); - assert_eq!(encode("IPR:IPR000001;EC:1.1.1.-;IPR:IPR000003;GO:0000002", table), vec![ - 0, 0, 0, 7, 0, 0, 2, 0, 0, 5, 0, 0 - ]) + assert_eq!( + encode("IPR:IPR000001;EC:1.1.1.-;IPR:IPR000003;GO:0000002", table), + vec![0, 0, 0, 7, 0, 0, 2, 0, 0, 5, 0, 0] + ) } } diff --git a/fa-compression/src/algorithm2/mod.rs b/fa-compression/src/algorithm2/mod.rs index 8fc505a..117b87c 100644 --- a/fa-compression/src/algorithm2/mod.rs +++ b/fa-compression/src/algorithm2/mod.rs @@ -12,13 +12,13 @@ pub use encode::encode; /// Represents an entry in the compression table. #[doc(hidden)] pub struct CompressionTableEntry { - annotation: String + annotation: String, } /// Represents a compression table. pub struct CompressionTable { /// List of annotations in the compression table. - entries: Vec + entries: Vec, } impl CompressionTable { diff --git a/libsais64-rs/builder.rs b/libsais64-rs/builder.rs index fe8430e..b979d26 100644 --- a/libsais64-rs/builder.rs +++ b/libsais64-rs/builder.rs @@ -3,14 +3,14 @@ use std::{ error::Error, fmt::{Display, Formatter}, path::{Path, PathBuf}, - process::{Command, ExitStatus} + process::{Command, ExitStatus}, }; /// Custom error for compilation of the C library #[derive(Debug)] struct CompileError<'a> { command: &'a str, - exit_code: Option + exit_code: Option, } impl<'a> Display for CompileError<'a> { @@ -43,7 +43,7 @@ impl<'a> Error for CompileError<'a> {} fn exit_status_to_result(name: &str, exit_status: ExitStatus) -> Result<(), CompileError> { match exit_status.success() { true => Ok(()), - false => Err(CompileError { command: name, exit_code: exit_status.code() }) + false => Err(CompileError { command: name, exit_code: exit_status.code() }), } } @@ -61,7 +61,7 @@ fn main() -> Result<(), Box> { Command::new("rm").args(["libsais/CMakeCache.txt"]).status().unwrap_or_default(); // if removing fails, it is since the cmake cache did not exist, we just can ignore it exit_status_to_result( "cmake", - Command::new("cmake").args(["-DCMAKE_BUILD_TYPE=\"Release\"", "libsais", "-Blibsais"]).status()? + Command::new("cmake").args(["-DCMAKE_BUILD_TYPE=\"Release\"", "libsais", "-Blibsais"]).status()?, )?; exit_status_to_result("make", Command::new("make").args(["-C", "libsais"]).status()?)?; diff --git a/libsais64-rs/src/bitpacking.rs b/libsais64-rs/src/bitpacking.rs index d3fb910..cc7faa9 100644 --- a/libsais64-rs/src/bitpacking.rs +++ b/libsais64-rs/src/bitpacking.rs @@ -1,5 +1,3 @@ - - // Function to get the rank of a character fn get_rank(c: u8) -> u8 { match c { @@ -16,14 +14,14 @@ pub const BITS_PER_CHAR: usize = 5; pub fn bitpack_text_8(text: &[u8], sparseness_factor: usize) -> Vec { assert!(BITS_PER_CHAR * sparseness_factor <= 8); - let num_ints = (text.len() + (sparseness_factor-1)) / sparseness_factor; + let num_ints = (text.len() + (sparseness_factor - 1)) / sparseness_factor; let mut text_packed = vec![0; num_ints]; if text.is_empty() { return text_packed; } - for (i, element) in text_packed.iter_mut().enumerate().take(num_ints-1) { + for (i, element) in text_packed.iter_mut().enumerate().take(num_ints - 1) { let ti = i * sparseness_factor; *element = 0u8; for j in 0..sparseness_factor { @@ -42,21 +40,20 @@ pub fn bitpack_text_8(text: &[u8], sparseness_factor: usize) -> Vec { text_packed[num_ints - 1] = last_element; text_packed - } // Bitpack text in a vector of u16 elements. BITS_PER_CHAR * sparseness_factor <= 16. pub fn bitpack_text_16(text: &[u8], sparseness_factor: usize) -> Vec { assert!(BITS_PER_CHAR * sparseness_factor <= 16); - let num_ints = (text.len() + (sparseness_factor-1)) / sparseness_factor; + let num_ints = (text.len() + (sparseness_factor - 1)) / sparseness_factor; let mut text_packed = vec![0; num_ints]; if text.is_empty() { return text_packed; } - for (i, element) in text_packed.iter_mut().enumerate().take(num_ints-1) { + for (i, element) in text_packed.iter_mut().enumerate().take(num_ints - 1) { let ti = i * sparseness_factor; *element = 0u16; for j in 0..sparseness_factor { @@ -75,21 +72,20 @@ pub fn bitpack_text_16(text: &[u8], sparseness_factor: usize) -> Vec { text_packed[num_ints - 1] = last_element; text_packed - } // Bitpack text in a vector of u32 elements. BITS_PER_CHAR * sparseness_factor <= 32. pub fn bitpack_text_32(text: &[u8], sparseness_factor: usize) -> Vec { assert!(BITS_PER_CHAR * sparseness_factor <= 32); - let num_ints = (text.len() + (sparseness_factor-1)) / sparseness_factor; + let num_ints = (text.len() + (sparseness_factor - 1)) / sparseness_factor; let mut text_packed = vec![0; num_ints]; if text.is_empty() { return text_packed; } - for (i, element) in text_packed.iter_mut().enumerate().take(num_ints-1) { + for (i, element) in text_packed.iter_mut().enumerate().take(num_ints - 1) { let ti = i * sparseness_factor; *element = 0u32; for j in 0..sparseness_factor { @@ -108,5 +104,4 @@ pub fn bitpack_text_32(text: &[u8], sparseness_factor: usize) -> Vec { text_packed[num_ints - 1] = last_element; text_packed - -} \ No newline at end of file +} diff --git a/libsais64-rs/src/lib.rs b/libsais64-rs/src/lib.rs index d9eca5a..4b0ba1a 100644 --- a/libsais64-rs/src/lib.rs +++ b/libsais64-rs/src/lib.rs @@ -2,8 +2,8 @@ #![allow(non_upper_case_globals)] #![allow(non_camel_case_types)] #![allow(non_snake_case)] -use std::ptr::null_mut; use crate::bitpacking::{bitpack_text_16, bitpack_text_32, bitpack_text_8, BITS_PER_CHAR}; +use std::ptr::null_mut; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); pub mod bitpacking; @@ -26,26 +26,31 @@ pub fn sais64(text: &Vec, libsais_sparseness: usize) -> Result, &st // bitpacked values fit in uint8_t let packed_text = if libsais_sparseness == 1 { text } else { &bitpack_text_8(text, libsais_sparseness) }; sa = vec![0; packed_text.len()]; - exit_code = unsafe { libsais64(packed_text.as_ptr(), sa.as_mut_ptr(), packed_text.len() as i64, 0, null_mut()) }; + exit_code = + unsafe { libsais64(packed_text.as_ptr(), sa.as_mut_ptr(), packed_text.len() as i64, 0, null_mut()) }; } else if required_bits <= 16 { // bitpacked values fit in uint16_t let packed_text = bitpack_text_16(text, libsais_sparseness); sa = vec![0; packed_text.len()]; - exit_code = unsafe { libsais16x64(packed_text.as_ptr(), sa.as_mut_ptr(), packed_text.len() as i64, 0, null_mut()) }; + exit_code = + unsafe { libsais16x64(packed_text.as_ptr(), sa.as_mut_ptr(), packed_text.len() as i64, 0, null_mut()) }; } else { let packed_text = bitpack_text_32(text, libsais_sparseness); sa = vec![0; packed_text.len()]; let k = 1 << (libsais_sparseness * BITS_PER_CHAR); - exit_code = unsafe { libsais32x64(packed_text.as_ptr(), sa.as_mut_ptr(), packed_text.len() as i64, k, 0, null_mut()) }; + exit_code = + unsafe { libsais32x64(packed_text.as_ptr(), sa.as_mut_ptr(), packed_text.len() as i64, k, 0, null_mut()) }; } - + if exit_code == 0 { for elem in sa.iter_mut() { let libsais_sparseness = libsais_sparseness as i64; *elem *= libsais_sparseness; } - Ok(sa) - } else { Err("Failed building suffix array") } + Ok(sa) + } else { + Err("Failed building suffix array") + } } #[cfg(test)] diff --git a/sa-builder/src/lib.rs b/sa-builder/src/lib.rs index 1ee7199..e78beea 100644 --- a/sa-builder/src/lib.rs +++ b/sa-builder/src/lib.rs @@ -1,5 +1,5 @@ -use std::error::Error; use clap::{Parser, ValueEnum}; +use std::error::Error; /// Build a (sparse, compressed) suffix array from the given text #[derive(Parser, Debug)] @@ -20,14 +20,14 @@ pub struct Arguments { pub construction_algorithm: SAConstructionAlgorithm, /// If the suffix array should be compressed (default value true) #[arg(short, long, default_value_t = false)] - pub compress_sa: bool + pub compress_sa: bool, } /// Enum representing the two possible algorithms to construct the suffix array #[derive(ValueEnum, Clone, Debug, PartialEq)] pub enum SAConstructionAlgorithm { LibDivSufSort, - LibSais + LibSais, } /// Build a sparse suffix array from the given text @@ -47,7 +47,7 @@ pub enum SAConstructionAlgorithm { pub fn build_ssa( text: &mut Vec, construction_algorithm: &SAConstructionAlgorithm, - sparseness_factor: u8 + sparseness_factor: u8, ) -> Result, Box> { // translate all L's to a I translate_l_to_i(text); @@ -55,7 +55,9 @@ pub fn build_ssa( // Build the suffix array using the selected algorithm let mut sa = match construction_algorithm { SAConstructionAlgorithm::LibSais => libsais64(text, sparseness_factor)?, - SAConstructionAlgorithm::LibDivSufSort => libdivsufsort_rs::divsufsort64(text).ok_or("Building suffix array failed")? + SAConstructionAlgorithm::LibDivSufSort => { + libdivsufsort_rs::divsufsort64(text).ok_or("Building suffix array failed")? + } }; // make the SA sparse and decrease the vector size if we have sampling (sampling_rate > 1) @@ -150,7 +152,7 @@ mod tests { "2", "--construction-algorithm", "lib-div-suf-sort", - "--compress-sa" + "--compress-sa", ]); assert_eq!(args.database_file, "database.fa"); diff --git a/sa-builder/src/main.rs b/sa-builder/src/main.rs index 0c77c19..8f7ff20 100644 --- a/sa-builder/src/main.rs +++ b/sa-builder/src/main.rs @@ -1,7 +1,7 @@ use std::{ fs::{File, OpenOptions}, io::BufWriter, - time::{SystemTime, SystemTimeError, UNIX_EPOCH} + time::{SystemTime, SystemTimeError, UNIX_EPOCH}, }; use clap::Parser; @@ -16,7 +16,7 @@ fn main() { output, sparseness_factor, construction_algorithm, - compress_sa + compress_sa, } = Arguments::parse(); eprintln!(); eprintln!("📋 Started loading the proteins..."); diff --git a/sa-compression/src/lib.rs b/sa-compression/src/lib.rs index e9952a2..9814e20 100644 --- a/sa-compression/src/lib.rs +++ b/sa-compression/src/lib.rs @@ -1,6 +1,6 @@ use std::{ error::Error, - io::{BufRead, Write} + io::{BufRead, Write}, }; use bitarray::{data_to_writer, Binary, BitArray}; @@ -22,7 +22,7 @@ pub fn dump_compressed_suffix_array( sa: Vec, sparseness_factor: u8, bits_per_value: usize, - writer: &mut impl Write + writer: &mut impl Write, ) -> Result<(), Box> { // Write the flags to the writer // 00000001 indicates that the suffix array is compressed @@ -59,7 +59,7 @@ pub fn dump_compressed_suffix_array( /// Returns an error if reading from the reader fails. pub fn load_compressed_suffix_array( reader: &mut impl BufRead, - bits_per_value: usize + bits_per_value: usize, ) -> Result> { // Read the sample rate from the binary file (1 byte) let mut sample_rate_buffer = [0_u8; 1]; @@ -92,7 +92,7 @@ mod tests { pub struct FailingWriter { /// The number of times the write function can be called before it fails. - pub valid_write_count: usize + pub valid_write_count: usize, } impl Write for FailingWriter { @@ -112,7 +112,7 @@ mod tests { pub struct FailingReader { /// The number of times the read function can be called before it fails. - pub valid_read_count: usize + pub valid_read_count: usize, } impl Read for FailingReader { @@ -141,13 +141,16 @@ mod tests { let mut writer = vec![]; dump_compressed_suffix_array(sa, 1, 8, &mut writer).unwrap(); - assert_eq!(writer, vec![ - // bits per value - 8, // sparseness factor - 1, // size of the suffix array - 10, 0, 0, 0, 0, 0, 0, 0, // compressed suffix array - 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 10, 9 - ]); + assert_eq!( + writer, + vec![ + // bits per value + 8, // sparseness factor + 1, // size of the suffix array + 10, 0, 0, 0, 0, 0, 0, 0, // compressed suffix array + 8, 7, 6, 5, 4, 3, 2, 1, 0, 0, 0, 0, 0, 0, 10, 9 + ] + ); } #[test] diff --git a/sa-index/src/binary.rs b/sa-index/src/binary.rs index 55c082a..fc41f24 100644 --- a/sa-index/src/binary.rs +++ b/sa-index/src/binary.rs @@ -1,6 +1,6 @@ use std::{ error::Error, - io::{BufRead, Read, Write} + io::{BufRead, Read, Write}, }; use crate::SuffixArray; @@ -190,7 +190,7 @@ mod tests { pub struct FailingWriter { /// The number of times the write function can be called before it fails. - pub valid_write_count: usize + pub valid_write_count: usize, } impl Write for FailingWriter { @@ -210,7 +210,7 @@ mod tests { pub struct FailingReader { /// The number of times the read function can be called before it fails. - pub valid_read_count: usize + pub valid_read_count: usize, } impl Read for FailingReader { @@ -266,10 +266,13 @@ mod tests { values.write_binary(&mut buffer).unwrap(); - assert_eq!(buffer, vec![ - 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, - 0, 0, 0, 0 - ]); + assert_eq!( + buffer, + vec![ + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0 + ] + ); } #[test] @@ -292,14 +295,17 @@ mod tests { dump_suffix_array(&sa, 1, &mut buffer).unwrap(); - assert_eq!(buffer, vec![ - // required bits - 64, // Sparseness factor - 1, // Size of the suffix array - 5, 0, 0, 0, 0, 0, 0, 0, // Suffix array - 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, - 0, 0, 0, 0 - ]); + assert_eq!( + buffer, + vec![ + // required bits + 64, // Sparseness factor + 1, // Size of the suffix array + 5, 0, 0, 0, 0, 0, 0, 0, // Suffix array + 1, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, 0, 0, 5, 0, + 0, 0, 0, 0, 0, 0 + ] + ); } #[test] diff --git a/sa-index/src/lib.rs b/sa-index/src/lib.rs index 53f5348..a43168d 100644 --- a/sa-index/src/lib.rs +++ b/sa-index/src/lib.rs @@ -10,7 +10,7 @@ pub enum SuffixArray { /// The original suffix array. Original(Vec, u8), /// The compressed suffix array. - Compressed(BitArray, u8) + Compressed(BitArray, u8), } impl SuffixArray { @@ -22,7 +22,7 @@ impl SuffixArray { pub fn len(&self) -> usize { match self { SuffixArray::Original(sa, _) => sa.len(), - SuffixArray::Compressed(sa, _) => sa.len() + SuffixArray::Compressed(sa, _) => sa.len(), } } @@ -34,7 +34,7 @@ impl SuffixArray { pub fn bits_per_value(&self) -> usize { match self { SuffixArray::Original(_, _) => 64, - SuffixArray::Compressed(sa, _) => sa.bits_per_value() + SuffixArray::Compressed(sa, _) => sa.bits_per_value(), } } @@ -46,7 +46,7 @@ impl SuffixArray { pub fn sample_rate(&self) -> u8 { match self { SuffixArray::Original(_, sample_rate) => *sample_rate, - SuffixArray::Compressed(_, sample_rate) => *sample_rate + SuffixArray::Compressed(_, sample_rate) => *sample_rate, } } @@ -62,7 +62,7 @@ impl SuffixArray { pub fn get(&self, index: usize) -> i64 { match self { SuffixArray::Original(sa, _) => sa[index], - SuffixArray::Compressed(sa, _) => sa.get(index) as i64 + SuffixArray::Compressed(sa, _) => sa.get(index) as i64, } } diff --git a/sa-index/src/peptide_search.rs b/sa-index/src/peptide_search.rs index b3958c7..8fa852e 100644 --- a/sa-index/src/peptide_search.rs +++ b/sa-index/src/peptide_search.rs @@ -8,7 +8,7 @@ use crate::sa_searcher::{SearchAllSuffixesResult, Searcher}; pub struct SearchResult { pub sequence: String, pub proteins: Vec, - pub cutoff_used: bool + pub cutoff_used: bool, } /// Struct that represents all information known about a certain protein in our database @@ -16,7 +16,7 @@ pub struct SearchResult { pub struct ProteinInfo { pub taxon: u32, pub uniprot_accession: String, - pub functional_annotations: String + pub functional_annotations: String, } impl From<&Protein> for ProteinInfo { @@ -24,7 +24,7 @@ impl From<&Protein> for ProteinInfo { ProteinInfo { taxon: protein.taxon_id, uniprot_accession: protein.uniprot_id.clone(), - functional_annotations: protein.get_functional_annotations() + functional_annotations: protein.get_functional_annotations(), } } } @@ -52,7 +52,7 @@ pub fn search_proteins_for_peptide<'a>( peptide: &str, cutoff: usize, equate_il: bool, - tryptic: bool + tryptic: bool, ) -> Option<(bool, Vec<&'a Protein>)> { let peptide = peptide.trim_end().to_uppercase(); @@ -65,7 +65,7 @@ pub fn search_proteins_for_peptide<'a>( let (suffixes, cutoff_used) = match suffix_search { SearchAllSuffixesResult::MaxMatches(matched_suffixes) => Some((matched_suffixes, true)), SearchAllSuffixesResult::SearchResult(matched_suffixes) => Some((matched_suffixes, false)), - SearchAllSuffixesResult::NoMatches => None + SearchAllSuffixesResult::NoMatches => None, }?; let proteins = searcher.retrieve_proteins(&suffixes); @@ -78,14 +78,14 @@ pub fn search_peptide( peptide: &str, cutoff: usize, equate_il: bool, - tryptic: bool + tryptic: bool, ) -> Option { let (cutoff_used, proteins) = search_proteins_for_peptide(searcher, peptide, cutoff, equate_il, tryptic)?; Some(SearchResult { sequence: peptide.to_string(), proteins: proteins.iter().map(|&protein| protein.into()).collect(), - cutoff_used + cutoff_used, }) } @@ -109,7 +109,7 @@ pub fn search_all_peptides( peptides: &Vec, cutoff: usize, equate_il: bool, - tryptic: bool + tryptic: bool, ) -> Vec { peptides .par_iter() @@ -133,7 +133,7 @@ mod tests { let protein_info = ProteinInfo { taxon: 1, uniprot_accession: "P12345".to_string(), - functional_annotations: "GO:0001234;GO:0005678".to_string() + functional_annotations: "GO:0001234;GO:0005678".to_string(), }; let generated_json = serde_json::to_string(&protein_info).unwrap(); @@ -148,7 +148,7 @@ mod tests { let search_result = SearchResult { sequence: "MSKIAALLPSV".to_string(), proteins: vec![], - cutoff_used: true + cutoff_used: true, }; let generated_json = serde_json::to_string(&search_result).unwrap(); diff --git a/sa-index/src/sa_searcher.rs b/sa-index/src/sa_searcher.rs index dab8577..fee98d7 100644 --- a/sa-index/src/sa_searcher.rs +++ b/sa-index/src/sa_searcher.rs @@ -6,21 +6,21 @@ use text_compression::ProteinTextSlice; use crate::{ sa_searcher::BoundSearch::{Maximum, Minimum}, suffix_to_protein_index::{DenseSuffixToProtein, SparseSuffixToProtein, SuffixToProteinIndex}, - Nullable, SuffixArray + Nullable, SuffixArray, }; /// Enum indicating if we are searching for the minimum, or maximum bound in the suffix array #[derive(Clone, Copy, PartialEq)] enum BoundSearch { Minimum, - Maximum + Maximum, } /// Enum representing the minimum and maximum bound of the found matches in the suffix array #[derive(PartialEq, Debug)] pub enum BoundSearchResult { NoMatches, - SearchResult((usize, usize)) + SearchResult((usize, usize)), } /// Enum representing the matching suffixes after searching a peptide in the suffix array @@ -30,7 +30,7 @@ pub enum BoundSearchResult { pub enum SearchAllSuffixesResult { NoMatches, MaxMatches(Vec), - SearchResult(Vec) + SearchResult(Vec), } /// Custom implementation of partialEq for SearchAllSuffixesResult @@ -67,7 +67,7 @@ impl PartialEq for SearchAllSuffixesResult { array_eq_unordered(arr1, arr2) } (SearchAllSuffixesResult::NoMatches, SearchAllSuffixesResult::NoMatches) => true, - _ => false + _ => false, } } } @@ -123,7 +123,7 @@ impl Deref for DenseSearcher { pub struct Searcher { pub sa: SuffixArray, pub proteins: Proteins, - pub suffix_index_to_protein: Box + pub suffix_index_to_protein: Box, } impl Searcher { @@ -172,7 +172,7 @@ impl Searcher { // Depending on if we are searching for the min of max bound our condition is different let condition_check = match bound { Minimum => |a: u8, b: u8| a < b, - Maximum => |a: u8, b: u8| a > b + Maximum => |a: u8, b: u8| a > b, }; // match as long as possible @@ -263,7 +263,7 @@ impl Searcher { match bound { Minimum => (found, right), - Maximum => (found, left) + Maximum => (found, left), } } @@ -307,7 +307,7 @@ impl Searcher { search_string: &[u8], max_matches: usize, equate_il: bool, - tryptic: bool + tryptic: bool, ) -> SearchAllSuffixesResult { let mut matching_suffixes: Vec = vec![]; let mut il_locations = vec![]; @@ -348,14 +348,14 @@ impl Searcher { || Self::check_prefix( current_search_string_prefix, ProteinTextSlice::new(&self.proteins.text, match_start, suffix), - equate_il + equate_il, )) && Self::check_suffix( skip, il_locations_current_suffix, current_search_string_suffix, ProteinTextSlice::new(&self.proteins.text, suffix, match_end), - equate_il + equate_il, ) && (!tryptic || ((self.check_start_of_protein(match_start) || self.check_tryptic_cut(match_start)) @@ -463,9 +463,13 @@ impl Searcher { il_locations: &[usize], search_string: &[u8], text_slice: ProteinTextSlice, - equate_il: bool + equate_il: bool, ) -> bool { - if equate_il { true } else { text_slice.check_il_locations(skip, il_locations, search_string) } + if equate_il { + true + } else { + text_slice.check_il_locations(skip, il_locations, search_string) + } } /// Returns all the proteins that correspond with the provided suffixes @@ -497,7 +501,7 @@ mod tests { use crate::{ sa_searcher::{BoundSearchResult, SearchAllSuffixesResult, Searcher}, suffix_to_protein_index::SparseSuffixToProtein, - SuffixArray + SuffixArray, }; #[test] @@ -530,24 +534,24 @@ mod tests { Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] + functional_annotations: vec![], }, Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] + functional_annotations: vec![], }, Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] + functional_annotations: vec![], }, Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] + functional_annotations: vec![], }, - ] + ], } } @@ -633,8 +637,8 @@ mod tests { proteins: vec![Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] - }] + functional_annotations: vec![], + }], }; let sparse_sa = SuffixArray::Original(vec![0, 2, 4], 2); @@ -656,8 +660,8 @@ mod tests { proteins: vec![Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] - }] + functional_annotations: vec![], + }], }; let sparse_sa = SuffixArray::Original(vec![6, 0, 1, 5, 4, 3, 2], 1); @@ -678,8 +682,8 @@ mod tests { proteins: vec![Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] - }] + functional_annotations: vec![], + }], }; let sparse_sa = SuffixArray::Original(vec![6, 5, 4, 3, 2, 1, 0], 1); @@ -700,8 +704,8 @@ mod tests { proteins: vec![Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] - }] + functional_annotations: vec![], + }], }; let sparse_sa = SuffixArray::Original(vec![6, 4, 2, 0], 2); @@ -724,8 +728,8 @@ mod tests { proteins: vec![Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] - }] + functional_annotations: vec![], + }], }; let sparse_sa = SuffixArray::Original(vec![6, 5, 4, 3, 2, 1, 0], 1); @@ -747,8 +751,8 @@ mod tests { proteins: vec![Protein { uniprot_id: String::new(), taxon_id: 0, - functional_annotations: vec![] - }] + functional_annotations: vec![], + }], }; let sparse_sa = SuffixArray::Original(vec![13, 3, 12, 11, 1, 4, 2, 5, 9, 8, 6, 10, 0, 7], 1); diff --git a/sa-index/src/suffix_to_protein_index.rs b/sa-index/src/suffix_to_protein_index.rs index a6a4e93..7dc960a 100644 --- a/sa-index/src/suffix_to_protein_index.rs +++ b/sa-index/src/suffix_to_protein_index.rs @@ -8,7 +8,7 @@ use crate::Nullable; #[derive(ValueEnum, Clone, Debug, PartialEq)] pub enum SuffixToProteinMappingStyle { Dense, - Sparse + Sparse, } /// Trait implemented by the SuffixToProtein mappings @@ -29,14 +29,14 @@ pub trait SuffixToProteinIndex: Send + Sync { #[derive(Debug, PartialEq)] pub struct DenseSuffixToProtein { // UniProtKB does not have more that u32::MAX proteins, so a larger type is not needed - mapping: Vec + mapping: Vec, } /// Mapping that uses O(m) memory with m the number of proteins, but retrieval of the protein is /// O(log m) #[derive(Debug, PartialEq)] pub struct SparseSuffixToProtein { - mapping: Vec + mapping: Vec, } impl SuffixToProteinIndex for DenseSuffixToProtein { @@ -113,9 +113,9 @@ mod tests { use crate::{ suffix_to_protein_index::{ - DenseSuffixToProtein, SparseSuffixToProtein, SuffixToProteinIndex, SuffixToProteinMappingStyle + DenseSuffixToProtein, SparseSuffixToProtein, SuffixToProteinIndex, SuffixToProteinMappingStyle, }, - Nullable + Nullable, }; fn build_text() -> ProteinText { @@ -138,7 +138,7 @@ mod tests { let u8_text = &build_text(); let index = DenseSuffixToProtein::new(u8_text); let expected = DenseSuffixToProtein { - mapping: vec![0, 0, 0, u32::NULL, 1, 1, u32::NULL, 2, 2, 2, u32::NULL] + mapping: vec![0, 0, 0, u32::NULL, 1, 1, u32::NULL, 2, 2, 2, u32::NULL], }; assert_eq!(index, expected); } diff --git a/sa-mappings/src/proteins.rs b/sa-mappings/src/proteins.rs index 53e52b8..9285980 100644 --- a/sa-mappings/src/proteins.rs +++ b/sa-mappings/src/proteins.rs @@ -23,7 +23,7 @@ pub struct Protein { pub taxon_id: u32, /// The encoded functional annotations of the protein - pub functional_annotations: Vec + pub functional_annotations: Vec, } /// A struct that represents a collection of proteins @@ -32,7 +32,7 @@ pub struct Proteins { pub text: ProteinText, /// The proteins in the input string - pub proteins: Vec + pub proteins: Vec, } impl Protein { @@ -80,7 +80,7 @@ impl Proteins { proteins.push(Protein { uniprot_id: uniprot_id.to_string(), taxon_id, - functional_annotations + functional_annotations, }); } @@ -195,7 +195,7 @@ mod tests { .unwrap(); file.write( "P13579\t17\tKEGILQYCQEVYPELQITNVVEANQPVTIQNWCKRGRKQCKTHPH\tGO:0009279;IPR:IPR016364;IPR:IPR008816\n" - .as_bytes() + .as_bytes(), ) .unwrap(); @@ -207,7 +207,7 @@ mod tests { let protein = Protein { uniprot_id: "P12345".to_string(), taxon_id: 1, - functional_annotations: vec![0xD1, 0x11] + functional_annotations: vec![0xD1, 0x11], }; assert_eq!(protein.uniprot_id, "P12345"); @@ -225,14 +225,14 @@ mod tests { Protein { uniprot_id: "P12345".to_string(), taxon_id: 1, - functional_annotations: vec![0xD1, 0x11] + functional_annotations: vec![0xD1, 0x11], }, Protein { uniprot_id: "P54321".to_string(), taxon_id: 2, - functional_annotations: vec![0xD1, 0x11] + functional_annotations: vec![0xD1, 0x11], }, - ] + ], }; assert_eq!(proteins.proteins.len(), 2); diff --git a/sa-server/src/main.rs b/sa-server/src/main.rs index 1a1cedf..ddf7b63 100644 --- a/sa-server/src/main.rs +++ b/sa-server/src/main.rs @@ -2,14 +2,14 @@ use std::{ error::Error, fs::File, io::{BufReader, Read}, - sync::Arc + sync::Arc, }; use axum::{ extract::{DefaultBodyLimit, State}, http::StatusCode, routing::post, - Json, Router + Json, Router, }; use clap::Parser; use sa_compression::load_compressed_suffix_array; @@ -17,7 +17,7 @@ use sa_index::{ binary::load_suffix_array, peptide_search::{search_all_peptides, SearchResult}, sa_searcher::SparseSearcher, - SuffixArray + SuffixArray, }; use sa_mappings::proteins::Proteins; use serde::Deserialize; @@ -30,7 +30,7 @@ pub struct Arguments { #[arg(short, long)] database_file: String, #[arg(short, long)] - index_file: String + index_file: String, } /// Function used by serde to place a default value in the cutoff field of the input @@ -60,7 +60,7 @@ struct InputData { // default value is false // TODO: maybe default should be true? equate_il: bool, #[serde(default = "bool::default")] // default false - tryptic: bool + tryptic: bool, } #[tokio::main] @@ -83,7 +83,7 @@ async fn main() { /// Returns the search results from the index as a JSON async fn search( State(searcher): State>, - data: Json + data: Json, ) -> Result>, StatusCode> { let search_result = search_all_peptides(&searcher, &data.peptides, data.cutoff, data.equate_il, data.tryptic); diff --git a/text-compression/src/lib.rs b/text-compression/src/lib.rs index 338e234..3a526ed 100644 --- a/text-compression/src/lib.rs +++ b/text-compression/src/lib.rs @@ -1,7 +1,7 @@ use std::{ collections::HashMap, error::Error, - io::{BufRead, Write} + io::{BufRead, Write}, }; use bitarray::{data_to_writer, Binary, BitArray}; @@ -13,7 +13,7 @@ pub struct ProteinText { /// Hashmap storing the mapping between the character as `u8` and a 5 bit number. char_to_5bit: HashMap, /// Vector storing the mapping between the 5 bit number and the character as `u8`. - bit5_to_char: Vec + bit5_to_char: Vec, } impl ProteinText { @@ -189,7 +189,7 @@ pub struct ProteinTextSlice<'a> { /// The start of the slice. start: usize, // included /// The end of the slice. - end: usize // excluded + end: usize, // excluded } impl<'a> ProteinTextSlice<'a> { @@ -291,13 +291,13 @@ impl<'a> ProteinTextSlice<'a> { /// Structure representing an iterator over a `ProteinText` instance, iterating the characters of the text. pub struct ProteinTextIterator<'a> { protein_text: &'a ProteinText, - index: usize + index: usize, } /// Structure representing an iterator over a `ProteintextSlice` instance, iterating the characters of the slice. pub struct ProteinTextSliceIterator<'a> { text_slice: &'a ProteinTextSlice<'a>, - index: usize + index: usize, } impl<'a> Iterator for ProteinTextSliceIterator<'a> { @@ -403,7 +403,7 @@ mod tests { pub struct FailingWriter { /// The number of times the write function can be called before it fails. - pub valid_write_count: usize + pub valid_write_count: usize, } impl Write for FailingWriter { @@ -423,7 +423,7 @@ mod tests { pub struct FailingReader { /// The number of times the read function can be called before it fails. - pub valid_read_count: usize + pub valid_read_count: usize, } impl Read for FailingReader { @@ -555,12 +555,15 @@ mod tests { let mut writer = vec![]; dump_compressed_text(text, &mut writer).unwrap(); - assert_eq!(writer, vec![ - // bits per value - 5, // size of the text - 10, 0, 0, 0, 0, 0, 0, 0, // compressed text - 0, 128, 74, 232, 152, 66, 134, 8 - ]); + assert_eq!( + writer, + vec![ + // bits per value + 5, // size of the text + 10, 0, 0, 0, 0, 0, 0, 0, // compressed text + 0, 128, 74, 232, 152, 66, 134, 8 + ] + ); } #[test]