use crate::data::err::GetCode;
use std::{error::Error, fmt};
#[derive(Debug)]
pub enum ProfileError {
EmptySequence,
GapOpenOutOfRange { gap_open: i8 },
GapExtendOutOfRange { gap_extend: i8 },
BadGapWeights { gap_open: i8, gap_extend: i8 },
}
impl fmt::Display for ProfileError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ProfileError::EmptySequence => write!(f, "The provided sequence was empty"),
ProfileError::GapOpenOutOfRange { gap_open } => {
write!(
f,
"The gap open weight must be between -127 and 0, but {gap_open} was provided"
)
}
ProfileError::GapExtendOutOfRange { gap_extend } => {
write!(
f,
"The gap extend weight must be between -127 and 0, but {gap_extend} was provided"
)
}
ProfileError::BadGapWeights { gap_open, gap_extend } => write!(
f,
"The gap open weight must be less than or equal to the gap extend weight, but {gap_open} (gap open) and {gap_extend} (gap extend) were provided"
),
}
}
}
impl Error for ProfileError {}
impl GetCode for ProfileError {}
#[derive(PartialEq)]
#[non_exhaustive]
pub enum ScoringError {
NegativeScore(i32),
QueryEnded,
ReferenceEnded,
FullQueryNotUsed,
FullReferenceNotUsed,
InvalidCigarOp(u8),
}
impl fmt::Display for ScoringError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match self {
ScoringError::NegativeScore(score) => write!(f, "The alignment produced a negative score: {score}"),
ScoringError::QueryEnded => write!(f, "The query ended before the entire CIGAR string was consumed!"),
ScoringError::ReferenceEnded => write!(f, "The reference ended before the entire CIGAR string was consumed!"),
ScoringError::FullQueryNotUsed => write!(
f,
"Failed to consume the full, provided query, which was expected to contain no more than what was represented by the CIGAR string"
),
ScoringError::FullReferenceNotUsed => {
write!(
f,
"Failed to consume the full, provided reference, which was expected to contain only the aligned region of the original reference"
)
}
ScoringError::InvalidCigarOp(op) => write!(f, "An unsupported CIGAR opcode was encountered: {op}"),
}
}
}
impl fmt::Debug for ScoringError {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{self}")
}
}
impl Error for ScoringError {}
impl GetCode for ScoringError {}