Skip to content

Commit

Permalink
Merge branch 'latest' into py-skipmers
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes committed Dec 20, 2024
2 parents 246a88f + 5680efc commit b63d666
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 49 deletions.
3 changes: 3 additions & 0 deletions include/sourmash.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ enum SourmashErrorCode {
SOURMASH_ERROR_CODE_INVALID_PROT = 1102,
SOURMASH_ERROR_CODE_INVALID_CODON_LENGTH = 1103,
SOURMASH_ERROR_CODE_INVALID_HASH_FUNCTION = 1104,
SOURMASH_ERROR_CODE_INVALID_SKIPMER_FRAME = 1105,
SOURMASH_ERROR_CODE_INVALID_SKIPMER_SIZE = 1106,
SOURMASH_ERROR_CODE_INVALID_TRANSLATE_FRAME = 1107,
SOURMASH_ERROR_CODE_READ_DATA = 1201,
SOURMASH_ERROR_CODE_STORAGE = 1202,
SOURMASH_ERROR_CODE_HLL_PRECISION_BOUNDS = 1301,
Expand Down
15 changes: 15 additions & 0 deletions src/core/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ pub enum SourmashError {
#[error("Codon is invalid length: {message}")]
InvalidCodonLength { message: String },

#[error("Skipmer ksize must be >= n ({n}), but got ksize: {ksize}")]
InvalidSkipmerSize { ksize: usize, n: usize },

#[error("Skipmer frame number must be < n ({n}), but got start: {start}")]
InvalidSkipmerFrame { start: usize, n: usize },

#[error("Frame number must be 0, 1, or 2, but got {frame_number}")]
InvalidTranslateFrame { frame_number: usize },

#[error("Set error rate to a value smaller than 0.367696 and larger than 0.00203125")]
HLLPrecisionBounds,

Expand Down Expand Up @@ -128,6 +137,9 @@ pub enum SourmashErrorCode {
InvalidProt = 11_02,
InvalidCodonLength = 11_03,
InvalidHashFunction = 11_04,
InvalidSkipmerFrame = 11_05,
InvalidSkipmerSize = 11_06,
InvalidTranslateFrame = 11_07,
// index-related errors
ReadData = 12_01,
Storage = 12_02,
Expand Down Expand Up @@ -170,6 +182,9 @@ impl SourmashErrorCode {
SourmashError::InvalidProt { .. } => SourmashErrorCode::InvalidProt,
SourmashError::InvalidCodonLength { .. } => SourmashErrorCode::InvalidCodonLength,
SourmashError::InvalidHashFunction { .. } => SourmashErrorCode::InvalidHashFunction,
SourmashError::InvalidSkipmerFrame { .. } => SourmashErrorCode::InvalidSkipmerFrame,
SourmashError::InvalidSkipmerSize { .. } => SourmashErrorCode::InvalidSkipmerSize,
SourmashError::InvalidTranslateFrame { .. } => SourmashErrorCode::InvalidTranslateFrame,
SourmashError::ReadDataError { .. } => SourmashErrorCode::ReadData,
SourmashError::StorageError { .. } => SourmashErrorCode::Storage,
SourmashError::HLLPrecisionBounds { .. } => SourmashErrorCode::HLLPrecisionBounds,
Expand Down
15 changes: 13 additions & 2 deletions src/core/src/ffi/minhash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,26 @@ Result<*const u64> {

let mut output: Vec<u64> = Vec::with_capacity(insize);

// Call SeqToHashes::new and handle errors
let ready_hashes = SeqToHashes::new(
buf,
mh.ksize(),
force,
is_protein,
mh.hash_function(),
mh.seed(),
)?;


if force && bad_kmers_as_zeroes{
for hash_value in SeqToHashes::new(buf, mh.ksize(), force, is_protein, mh.hash_function(), mh.seed()){
for hash_value in ready_hashes{
match hash_value{
Ok(x) => output.push(x),
Err(err) => return Err(err),
}
}
}else{
for hash_value in SeqToHashes::new(buf, mh.ksize(), force, is_protein, mh.hash_function(), mh.seed()){
for hash_value in ready_hashes {
match hash_value{
Ok(0) => continue,
Ok(x) => output.push(x),
Expand Down
Loading

0 comments on commit b63d666

Please sign in to comment.