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 fe7b532..d58a60c 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. @@ -147,7 +147,6 @@ impl BitArray { pub fn get_data_slice(&self, start_slice: usize, end_slice: usize) -> &[u64] { &self.data[start_slice..end_slice] } - } /// Writes the data to a writer in a binary format using a bit array. This function is helpfull @@ -168,7 +167,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 @@ -312,10 +311,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] @@ -334,23 +336,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] @@ -365,16 +371,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 5b3feb2..c6fc2d6 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/lib.rs b/libsais64-rs/src/lib.rs index e2a87f6..b2a1d3a 100644 --- a/libsais64-rs/src/lib.rs +++ b/libsais64-rs/src/lib.rs @@ -16,7 +16,11 @@ include!(concat!(env!("OUT_DIR"), "/bindings.rs")); pub fn sais64(text: &[u8]) -> Option> { let mut sa = vec![0; text.len()]; let exit_code = unsafe { libsais64(text.as_ptr(), sa.as_mut_ptr(), text.len() as i64, 0, std::ptr::null_mut()) }; - if exit_code == 0 { Some(sa) } else { None } + if exit_code == 0 { + Some(sa) + } else { + None + } } #[cfg(test)] diff --git a/sa-builder/src/lib.rs b/sa-builder/src/lib.rs index c0e13cd..f20ec27 100644 --- a/sa-builder/src/lib.rs +++ b/sa-builder/src/lib.rs @@ -21,14 +21,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 @@ -48,7 +48,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); @@ -56,7 +56,7 @@ pub fn build_ssa( // Build the suffix array using the selected algorithm let mut sa = match construction_algorithm { SAConstructionAlgorithm::LibSais => libsais64_rs::sais64(text), - SAConstructionAlgorithm::LibDivSufSort => libdivsufsort_rs::divsufsort64(text) + SAConstructionAlgorithm::LibDivSufSort => libdivsufsort_rs::divsufsort64(text), } .ok_or("Building suffix array failed")?; @@ -125,7 +125,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 01cc3c4..20f2e8a 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 55d629f..02e4975 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(), } } } @@ -50,7 +50,7 @@ pub fn search_proteins_for_peptide<'a>( searcher: &'a Searcher, peptide: &str, cutoff: usize, - equate_il: bool + equate_il: bool, ) -> Option<(bool, Vec<&'a Protein>)> { let peptide = peptide.trim_end().to_uppercase(); @@ -63,7 +63,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); @@ -77,7 +77,7 @@ pub fn search_peptide(searcher: &Searcher, peptide: &str, cutoff: usize, equate_ Some(SearchResult { sequence: peptide.to_string(), proteins: proteins.iter().map(|&protein| protein.into()).collect(), - cutoff_used + cutoff_used, }) } @@ -99,7 +99,7 @@ pub fn search_all_peptides( searcher: &Searcher, peptides: &Vec, cutoff: usize, - equate_il: bool + equate_il: bool, ) -> Vec { peptides .par_iter() @@ -123,7 +123,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(); @@ -138,7 +138,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 d2250ed..119af6c 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 @@ -265,7 +265,7 @@ impl Searcher { match bound { Minimum => (found, right), - Maximum => (found, left) + Maximum => (found, left), } } @@ -307,7 +307,7 @@ impl Searcher { &self, search_string: &[u8], max_matches: usize, - equate_il: bool + equate_il: bool, ) -> SearchAllSuffixesResult { let mut matching_suffixes: Vec = vec![]; let mut il_locations = vec![]; @@ -394,7 +394,7 @@ impl Searcher { il_locations: &[usize], search_string: &[u8], text_slice: ProteinTextSlice, - equate_il: bool + equate_il: bool, ) -> bool { if equate_il { true @@ -432,7 +432,7 @@ mod tests { use crate::{ sa_searcher::{BoundSearchResult, SearchAllSuffixesResult, Searcher}, suffix_to_protein_index::SparseSuffixToProtein, - SuffixArray + SuffixArray, }; #[test] @@ -465,24 +465,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![], }, - ] + ], } } @@ -568,8 +568,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); @@ -591,8 +591,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); @@ -613,10 +613,10 @@ 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); let suffix_index_to_protein = SparseSuffixToProtein::new(&proteins.text); let searcher = Searcher::new(sparse_sa, proteins, Box::new(suffix_index_to_protein)); @@ -629,14 +629,14 @@ mod tests { fn test_il_suffix_check() { let input_string = "IIIILL$"; let text = ProteinText::from_string(input_string); - + let proteins = Proteins { text, 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); @@ -659,8 +659,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); diff --git a/sa-index/src/suffix_to_protein_index.rs b/sa-index/src/suffix_to_protein_index.rs index 6aed362..1a224d2 100644 --- a/sa-index/src/suffix_to_protein_index.rs +++ b/sa-index/src/suffix_to_protein_index.rs @@ -8,7 +8,7 @@ use text_compression::ProteinText; #[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 626ead3..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, }); } @@ -126,7 +126,6 @@ impl Proteins { let text = ProteinText::from_string(&input_string); Ok(text) - } /// Creates a `vec` which represents all the proteins concatenated from the database file @@ -165,7 +164,6 @@ impl Proteins { input_string.shrink_to_fit(); Ok(input_string.into_bytes()) - } } @@ -197,7 +195,7 @@ mod tests { .unwrap(); file.write( "P13579\t17\tKEGILQYCQEVYPELQITNVVEANQPVTIQNWCKRGRKQCKTHPH\tGO:0009279;IPR:IPR016364;IPR:IPR008816\n" - .as_bytes() + .as_bytes(), ) .unwrap(); @@ -209,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"); @@ -227,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 5284546..c65ba7c 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 @@ -58,7 +58,7 @@ struct InputData { cutoff: usize, #[serde(default = "bool::default")] // default value is false // TODO: maybe default should be true? - equate_il: bool + equate_il: bool, } #[tokio::main] @@ -81,7 +81,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); diff --git a/text-compression/src/lib.rs b/text-compression/src/lib.rs index 6bfaf1a..dc7f71e 100644 --- a/text-compression/src/lib.rs +++ b/text-compression/src/lib.rs @@ -1,8 +1,8 @@ +use std::collections::HashMap; use std::{ error::Error, - io::{BufRead, Write} + io::{BufRead, Write}, }; -use std::collections::HashMap; use bitarray::{data_to_writer, Binary, BitArray}; @@ -17,7 +17,6 @@ pub struct ProteinText { } impl ProteinText { - /// Creates the hashmap storing the mappings between the characters as `u8` and 5 bit numbers. /// /// # Returns @@ -44,9 +43,9 @@ impl ProteinText { } vec } - + /// Creates the compressed text from a string. - /// + /// /// # Arguments /// * `input_string` - The text (proteins) in string format /// @@ -67,7 +66,7 @@ impl ProteinText { } /// Creates the compressed text from a vector. - /// + /// /// # Arguments /// * `input_vec` - The text (proteins) in a vector with elements of type `u8` representing the amino acids. /// @@ -88,7 +87,7 @@ impl ProteinText { } /// Creates the compressed text from a bit array. - /// + /// /// # Arguments /// * `bit_array` - The text (proteins) in a bit array using 5 bits for each amino acid. /// @@ -102,7 +101,7 @@ impl ProteinText { } /// Creates an instance of `ProteinText` with a given capacity. - /// + /// /// # Arguments /// * `capacity` - The amount of characters in the text. /// @@ -114,7 +113,7 @@ impl ProteinText { } /// Search the character at a given position in the compressed text. - /// + /// /// # Arguments /// * `index` - The index of the character to search. /// @@ -127,7 +126,7 @@ impl ProteinText { } /// Set the character at a given index. - /// + /// /// # Arguments /// * `index` - The index of the character to change. /// * `value` - The character to fill in as `u8`. @@ -139,7 +138,7 @@ impl ProteinText { /// Queries the length of the text. /// /// # Returns - /// + /// /// the length of the text pub fn len(&self) -> usize { self.bit_array.len() @@ -148,7 +147,7 @@ impl ProteinText { /// Check if the text is empty (length 0). /// /// # Returns - /// + /// /// true if the the text has length 0, false otherwise. pub fn is_empty(&self) -> bool { self.bit_array.len() == 0 @@ -162,21 +161,20 @@ impl ProteinText { /// Get an iterator over the characters of the text. /// /// # Returns - /// + /// /// A `ProteinTextIterator`, which can iterate over the characters of the text. pub fn iter(&self) -> ProteinTextIterator { - ProteinTextIterator {protein_text: self, index: 0, } + ProteinTextIterator { protein_text: self, index: 0 } } /// Get a slice of the text /// /// # Returns - /// + /// /// An `ProteinTextSlice` representing a slice of the text. - pub fn slice(&self, start: usize, end:usize) -> ProteinTextSlice { + pub fn slice(&self, start: usize, end: usize) -> ProteinTextSlice { ProteinTextSlice::new(self, start, end) } - } /// Structure representing a slice of a `ProteinText`. @@ -186,13 +184,12 @@ 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> { - /// Creates an instance of `ProteintextSlice`, given the text and boundaries. - /// + /// /// # Arguments /// * `text` - The `Proteintext` representing the text of proteins with 5 bits per amino acid. /// * `start` - The start of the slice. @@ -202,11 +199,11 @@ impl<'a> ProteinTextSlice<'a> { /// /// An instance of `ProteinTextSlice` pub fn new(text: &'a ProteinText, start: usize, end: usize) -> ProteinTextSlice { - Self {text, start, end } + Self { text, start, end } } /// Get a character (amino acid) in the slice. - /// + /// /// # Arguments /// * `index` - The index in the slice of the character to get. /// @@ -228,7 +225,7 @@ impl<'a> ProteinTextSlice<'a> { /// Checks if the slice and a given array of `u8` are equal. /// I and L can be equated. - /// + /// /// # Arguments /// * `other` - the array of `u8` to compare the slice with. /// * `equate_il` - true if I and L need to be equated, false otherwise. @@ -245,12 +242,15 @@ impl<'a> ProteinTextSlice<'a> { || (search_character == b'L' && text_character == b'I') }) } else { - other.iter().zip(self.iter()).all(|(&search_character, text_character)| search_character == text_character) + other + .iter() + .zip(self.iter()) + .all(|(&search_character, text_character)| search_character == text_character) } } /// Check if the slice and a given array of `u8` are equal on the I and L positions. - /// + /// /// # Arguments /// * `skip` - The amount of positions this slice skipped, this has an influence on the I and L positions. /// * `il_locations` - The positions where I and L occur. @@ -259,12 +259,7 @@ impl<'a> ProteinTextSlice<'a> { /// # Returns /// /// True if the slice and `search_string` have the same contents on the I and L positions, false otherwise. - pub fn check_il_locations( - &self, - skip: usize, - il_locations: &[usize], - search_string: &[u8], - ) -> bool { + pub fn check_il_locations(&self, skip: usize, il_locations: &[usize], search_string: &[u8]) -> bool { for &il_location in il_locations { let index = il_location - skip; if search_string[index] != self.get(index) { @@ -280,7 +275,7 @@ impl<'a> ProteinTextSlice<'a> { /// /// An iterator over the slice. pub fn iter(&self) -> ProteinTextSliceIterator { - ProteinTextSliceIterator {text_slice: self, index: 0, } + ProteinTextSliceIterator { text_slice: self, index: 0 } } } @@ -297,13 +292,12 @@ pub struct ProteinTextSliceIterator<'a> { } impl<'a> Iterator for ProteinTextSliceIterator<'a> { - type Item = u8; - + /// Get the next character in the `ProteinTextSlice`. - /// + /// /// # Returns - /// + /// /// The next character in the slice. fn next(&mut self) -> Option { if self.index >= self.text_slice.len() { @@ -316,13 +310,12 @@ impl<'a> Iterator for ProteinTextSliceIterator<'a> { } impl<'a> Iterator for ProteinTextIterator<'a> { - type Item = u8; - + /// Get the next character in the `ProteinText`. - /// + /// /// # Returns - /// + /// /// The next character in the text. fn next(&mut self) -> Option { if self.index >= self.protein_text.len() { @@ -344,10 +337,7 @@ impl<'a> Iterator for ProteinTextIterator<'a> { /// # Errors /// /// Returns an error if writing to the writer fails. -pub fn dump_compressed_text( - text: Vec, - writer: &mut impl Write -) -> Result<(), Box> { +pub fn dump_compressed_text(text: Vec, writer: &mut impl Write) -> Result<(), Box> { let bits_per_value = 5; // Write the flags to the writer @@ -378,9 +368,7 @@ pub fn dump_compressed_text( /// # Errors /// /// Returns an error if reading from the reader fails. -pub fn load_compressed_text( - reader: &mut impl BufRead -) -> Result> { +pub fn load_compressed_text(reader: &mut impl BufRead) -> Result> { let bits_per_value: usize = 5; // Read the size of the text from the binary file (8 bytes) let mut size_buffer = [0_u8; 8]; @@ -406,7 +394,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 { @@ -426,7 +414,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 { @@ -514,7 +502,7 @@ mod tests { fn test_text_slice() { let input_string = "ACACA-CAC$"; let start = 1; - let end = 5; + let end = 5; let text = ProteinText::from_string(&input_string); let text_slice = text.slice(start, end); @@ -533,7 +521,7 @@ mod tests { let eq_slice_il_true = [b'C', b'L', b'C', b'A']; assert!(text_slice.equals_slice(&eq_slice_true, false)); - assert!(! text_slice.equals_slice(&eq_slice_false, false)); + assert!(!text_slice.equals_slice(&eq_slice_false, false)); assert!(text_slice.equals_slice(&eq_slice_il_true, true)); } @@ -547,7 +535,7 @@ mod tests { let il_false = [b'C', b'I', b'C', b'A']; assert!(text_slice.check_il_locations(0, &il_locations, &il_true)); - assert!(! text_slice.check_il_locations(0, &il_locations, &il_false)); + assert!(!text_slice.check_il_locations(0, &il_locations, &il_false)); } #[test] @@ -557,12 +545,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] @@ -592,9 +583,9 @@ mod tests { #[test] fn test_load_compressed_text() { let data = vec![ - // size of the text + // size of the text 10, 0, 0, 0, 0, 0, 0, 0, // compressed text - 0, 128, 74, 232, 152, 66, 134, 8 + 0, 128, 74, 232, 152, 66, 134, 8, ]; let mut reader = std::io::BufReader::new(&data[..]);