Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

seqtohashes errors instead of panic for frame errors #3445

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@

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

// Call SeqToHashes::new and handle errors
let ready_hashes = SeqToHashes::new(

Check warning on line 77 in src/core/src/ffi/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/minhash.rs#L77

Added line #L77 was not covered by tests
buf,
mh.ksize(),
force,
is_protein,

Check warning on line 81 in src/core/src/ffi/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/minhash.rs#L80-L81

Added lines #L80 - L81 were not covered by tests
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{

Check warning on line 88 in src/core/src/ffi/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/minhash.rs#L88

Added line #L88 was not covered by tests
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 {

Check warning on line 95 in src/core/src/ffi/minhash.rs

View check run for this annotation

Codecov / codecov/patch

src/core/src/ffi/minhash.rs#L95

Added line #L95 was not covered by tests
match hash_value{
Ok(0) => continue,
Ok(x) => output.push(x),
Expand Down
Loading
Loading