From d2feb52bf0d80fe303155bc5b95d4cfa1c769238 Mon Sep 17 00:00:00 2001 From: Simon Van de Vyver Date: Thu, 24 Oct 2024 12:15:22 +0200 Subject: [PATCH] cargo fmt --- fa-compression/benches/algorithm2/decode.rs | 2 +- fa-compression/benches/algorithm2/encode.rs | 2 +- fa-compression/benches/util.rs | 2 +- libsais64-rs/src/bitpacking.rs | 21 ++++++++------------- libsais64-rs/src/lib.rs | 20 +++++++++++++------- sa-builder/src/lib.rs | 5 ++++- sa-builder/src/main.rs | 2 +- sa-compression/src/lib.rs | 2 +- sa-index/src/sa_searcher.rs | 8 ++++---- sa-index/src/suffix_to_protein_index.rs | 4 ++-- sa-server/src/main.rs | 10 +++++----- text-compression/src/lib.rs | 2 +- 12 files changed, 42 insertions(+), 38 deletions(-) diff --git a/fa-compression/benches/algorithm2/decode.rs b/fa-compression/benches/algorithm2/decode.rs index 4d562fc..bc14527 100644 --- a/fa-compression/benches/algorithm2/decode.rs +++ b/fa-compression/benches/algorithm2/decode.rs @@ -1,5 +1,5 @@ use criterion::black_box; -use fa_compression::algorithm2::{decode, encode, CompressionTable}; +use fa_compression::algorithm2::{CompressionTable, decode, encode}; use super::util::generate_annotation; diff --git a/fa-compression/benches/algorithm2/encode.rs b/fa-compression/benches/algorithm2/encode.rs index 827dd50..406487f 100644 --- a/fa-compression/benches/algorithm2/encode.rs +++ b/fa-compression/benches/algorithm2/encode.rs @@ -1,5 +1,5 @@ use criterion::black_box; -use fa_compression::algorithm2::{encode, CompressionTable}; +use fa_compression::algorithm2::{CompressionTable, encode}; use super::util::generate_annotation; diff --git a/fa-compression/benches/util.rs b/fa-compression/benches/util.rs index b6ddd9a..fee2359 100644 --- a/fa-compression/benches/util.rs +++ b/fa-compression/benches/util.rs @@ -1,4 +1,4 @@ -use rand::{rngs::ThreadRng, Rng}; +use rand::{Rng, rngs::ThreadRng}; /// Generate a random InterPro annotation. pub fn generate_ipr(random: &mut ThreadRng) -> String { diff --git a/libsais64-rs/src/bitpacking.rs b/libsais64-rs/src/bitpacking.rs index d3fb910..661589c 100644 --- a/libsais64-rs/src/bitpacking.rs +++ b/libsais64-rs/src/bitpacking.rs @@ -1,11 +1,9 @@ - - // Function to get the rank of a character fn get_rank(c: u8) -> u8 { match c { b'$' => 0, b'-' => 1, - _ => 2 + (c - b'A'), + _ => 2 + (c - b'A') } } @@ -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..13b4c55 100644 --- a/libsais64-rs/src/lib.rs +++ b/libsais64-rs/src/lib.rs @@ -3,7 +3,8 @@ #![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 crate::bitpacking::{BITS_PER_CHAR, bitpack_text_8, bitpack_text_16, bitpack_text_32}; include!(concat!(env!("OUT_DIR"), "/bindings.rs")); pub mod bitpacking; @@ -26,26 +27,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..50bfe06 100644 --- a/sa-builder/src/lib.rs +++ b/sa-builder/src/lib.rs @@ -1,4 +1,5 @@ use std::error::Error; + use clap::{Parser, ValueEnum}; /// Build a (sparse, compressed) suffix array from the given text @@ -55,7 +56,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) diff --git a/sa-builder/src/main.rs b/sa-builder/src/main.rs index 0c77c19..0fa10f1 100644 --- a/sa-builder/src/main.rs +++ b/sa-builder/src/main.rs @@ -5,7 +5,7 @@ use std::{ }; use clap::Parser; -use sa_builder::{build_ssa, Arguments}; +use sa_builder::{Arguments, build_ssa}; use sa_compression::dump_compressed_suffix_array; use sa_index::binary::dump_suffix_array; use sa_mappings::proteins::Proteins; diff --git a/sa-compression/src/lib.rs b/sa-compression/src/lib.rs index e9952a2..8a107c0 100644 --- a/sa-compression/src/lib.rs +++ b/sa-compression/src/lib.rs @@ -3,7 +3,7 @@ use std::{ io::{BufRead, Write} }; -use bitarray::{data_to_writer, Binary, BitArray}; +use bitarray::{Binary, BitArray, data_to_writer}; use sa_index::SuffixArray; /// Writes the compressed suffix array to a writer. diff --git a/sa-index/src/sa_searcher.rs b/sa-index/src/sa_searcher.rs index dab8577..1b51dc3 100644 --- a/sa-index/src/sa_searcher.rs +++ b/sa-index/src/sa_searcher.rs @@ -4,9 +4,9 @@ use sa_mappings::proteins::{Protein, Proteins, SEPARATION_CHARACTER, TERMINATION use text_compression::ProteinTextSlice; use crate::{ + Nullable, SuffixArray, sa_searcher::BoundSearch::{Maximum, Minimum}, - suffix_to_protein_index::{DenseSuffixToProtein, SparseSuffixToProtein, SuffixToProteinIndex}, - Nullable, SuffixArray + suffix_to_protein_index::{DenseSuffixToProtein, SparseSuffixToProtein, SuffixToProteinIndex} }; /// Enum indicating if we are searching for the minimum, or maximum bound in the suffix array @@ -495,9 +495,9 @@ mod tests { use text_compression::ProteinText; use crate::{ + SuffixArray, sa_searcher::{BoundSearchResult, SearchAllSuffixesResult, Searcher}, - suffix_to_protein_index::SparseSuffixToProtein, - SuffixArray + suffix_to_protein_index::SparseSuffixToProtein }; #[test] diff --git a/sa-index/src/suffix_to_protein_index.rs b/sa-index/src/suffix_to_protein_index.rs index a6a4e93..6cbcd91 100644 --- a/sa-index/src/suffix_to_protein_index.rs +++ b/sa-index/src/suffix_to_protein_index.rs @@ -112,10 +112,10 @@ mod tests { use text_compression::ProteinText; use crate::{ + Nullable, suffix_to_protein_index::{ DenseSuffixToProtein, SparseSuffixToProtein, SuffixToProteinIndex, SuffixToProteinMappingStyle - }, - Nullable + } }; fn build_text() -> ProteinText { diff --git a/sa-server/src/main.rs b/sa-server/src/main.rs index 1a1cedf..82e1aec 100644 --- a/sa-server/src/main.rs +++ b/sa-server/src/main.rs @@ -6,18 +6,18 @@ use std::{ }; use axum::{ + Json, Router, extract::{DefaultBodyLimit, State}, http::StatusCode, - routing::post, - Json, Router + routing::post }; use clap::Parser; use sa_compression::load_compressed_suffix_array; use sa_index::{ + SuffixArray, binary::load_suffix_array, - peptide_search::{search_all_peptides, SearchResult}, - sa_searcher::SparseSearcher, - SuffixArray + peptide_search::{SearchResult, search_all_peptides}, + sa_searcher::SparseSearcher }; use sa_mappings::proteins::Proteins; use serde::Deserialize; diff --git a/text-compression/src/lib.rs b/text-compression/src/lib.rs index 338e234..4b79f03 100644 --- a/text-compression/src/lib.rs +++ b/text-compression/src/lib.rs @@ -4,7 +4,7 @@ use std::{ io::{BufRead, Write} }; -use bitarray::{data_to_writer, Binary, BitArray}; +use bitarray::{Binary, BitArray, data_to_writer}; /// Structure representing the proteins, stored in a bit array using 5 bits per amino acid. pub struct ProteinText {