use crate::alphabet::Alphabet;
use crate::models::SubstitutionModel;
use std::fmt;
#[derive(Debug)]
pub enum NJError {
EmptyMsa,
EmptySequence,
SequenceLengthMismatch {
expected: usize,
got: usize,
identifier: String,
},
IncompatibleModel {
model: SubstitutionModel,
alphabet: Alphabet,
},
AlgorithmFailure(String),
RngError(String),
ParseError(String),
}
impl fmt::Display for NJError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
NJError::EmptyMsa => write!(f, "Input MSA is empty"),
NJError::EmptySequence => write!(f, "Sequences must not be empty"),
NJError::SequenceLengthMismatch { expected, got, identifier } => write!(
f,
"All sequences must have the same length. Expected {expected}, got {got} for '{identifier}'"
),
NJError::IncompatibleModel { model, alphabet } => write!(
f,
"Substitution model {model:?} is incompatible with {alphabet:?} alphabet"
),
NJError::AlgorithmFailure(msg) => write!(f, "NJ algorithm failure: {msg}"),
NJError::RngError(msg) => write!(f, "RNG error: {msg}"),
NJError::ParseError(msg) => write!(f, "FASTA parse error: {msg}"),
}
}
}
impl std::error::Error for NJError {}