Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonVandeVyver committed Oct 24, 2024
1 parent 6dccb19 commit d2feb52
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm2/decode.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion fa-compression/benches/algorithm2/encode.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 1 addition & 1 deletion fa-compression/benches/util.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
21 changes: 8 additions & 13 deletions libsais64-rs/src/bitpacking.rs
Original file line number Diff line number Diff line change
@@ -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')
}
}

Expand All @@ -16,14 +14,14 @@ pub const BITS_PER_CHAR: usize = 5;
pub fn bitpack_text_8(text: &[u8], sparseness_factor: usize) -> Vec<u8> {
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 {
Expand All @@ -42,21 +40,20 @@ pub fn bitpack_text_8(text: &[u8], sparseness_factor: usize) -> Vec<u8> {
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<u16> {
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 {
Expand All @@ -75,21 +72,20 @@ pub fn bitpack_text_16(text: &[u8], sparseness_factor: usize) -> Vec<u16> {
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<u32> {
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 {
Expand All @@ -108,5 +104,4 @@ pub fn bitpack_text_32(text: &[u8], sparseness_factor: usize) -> Vec<u32> {
text_packed[num_ints - 1] = last_element;

text_packed

}
}
20 changes: 13 additions & 7 deletions libsais64-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,26 +27,31 @@ pub fn sais64(text: &Vec<u8>, libsais_sparseness: usize) -> Result<Vec<i64>, &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)]
Expand Down
5 changes: 4 additions & 1 deletion sa-builder/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::error::Error;

use clap::{Parser, ValueEnum};

/// Build a (sparse, compressed) suffix array from the given text
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion sa-builder/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion sa-compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions sa-index/src/sa_searcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down
4 changes: 2 additions & 2 deletions sa-index/src/suffix_to_protein_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 5 additions & 5 deletions sa-server/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion text-compression/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit d2feb52

Please sign in to comment.