Skip to content

Commit

Permalink
seqtohashes errors instead of panic for frame errors
Browse files Browse the repository at this point in the history
  • Loading branch information
bluegenes committed Dec 20, 2024
1 parent 8a0600d commit 7905ac2
Show file tree
Hide file tree
Showing 4 changed files with 156 additions and 49 deletions.
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 @@ -125,6 +134,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 @@ -166,6 +178,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 7905ac2

Please sign in to comment.