rsomics-composition 0.1.0

Compositional-data geometry, transforms, and differential abundance
Documentation
#[derive(Debug, thiserror::Error, PartialEq)]
#[non_exhaustive]
pub enum CompositionError {
    #[error("matrix must contain at least one sample and one component")]
    EmptyMatrix,
    #[error(
        "matrix has {values} values but its {samples} by {components} shape requires {expected}"
    )]
    Shape {
        samples: usize,
        components: usize,
        values: usize,
        expected: usize,
    },
    #[error("{kind} identity cannot be empty")]
    EmptyIdentity { kind: &'static str },
    #[error("duplicate {kind} identity {identity:?}")]
    DuplicateIdentity {
        kind: &'static str,
        identity: String,
    },
    #[error("row {row:?} has {found} values; expected {expected}")]
    RaggedRow {
        row: String,
        found: usize,
        expected: usize,
    },
    #[error("invalid number {value:?} at sample {sample:?}, component {component:?}")]
    InvalidNumber {
        sample: String,
        component: String,
        value: String,
    },
    #[error("value {value} at sample {sample:?}, component {component:?} is not finite")]
    NonFinite {
        sample: String,
        component: String,
        value: f64,
    },
    #[error("value {value} at sample {sample:?}, component {component:?} must be {requirement}")]
    InvalidComponent {
        sample: String,
        component: String,
        value: f64,
        requirement: &'static str,
    },
    #[error("sample {0:?} has no positive observed components")]
    EmptyComposition(String),
    #[error("component identities differ: {details}")]
    ComponentMismatch { details: String },
    #[error("sample identities differ: {details}")]
    SampleMismatch { details: String },
    #[error("reference component {0:?} does not exist")]
    UnknownReference(String),
    #[error("reference index {index} is outside a composition of width {width}")]
    ReferenceOutOfRange { index: usize, width: usize },
    #[error("operation requires at least {required} components, got {found}")]
    TooFewComponents { found: usize, required: usize },
    #[error("scalar must be finite, got {0}")]
    NonFiniteScalar(f64),
    #[error(
        "inverse transform coordinate is not finite at sample {sample:?}, component {component:?}"
    )]
    NonFiniteCoordinate { sample: String, component: String },
    #[error(
        "basis must have {expected_rows} rows and {expected_columns} columns, got {rows} by {columns}"
    )]
    BasisShape {
        rows: usize,
        columns: usize,
        expected_rows: usize,
        expected_columns: usize,
    },
    #[error("SBP row {row} contains {value}; only -1, 0, and 1 are valid")]
    InvalidPartitionValue { row: usize, value: i8 },
    #[error("SBP row {0} must contain at least one -1 and one 1")]
    EmptyPartitionSide(usize),
    #[error("basis is not orthonormal: row {left} dot row {right} is {value}")]
    NonOrthonormalBasis {
        left: usize,
        right: usize,
        value: f64,
    },
    #[error(
        "tree node {node} has {children} children; a balance tree must be strictly bifurcating"
    )]
    NonBifurcatingTree { node: usize, children: usize },
    #[error("tree tip identities differ from basis components: {0}")]
    TreeTipMismatch(String),
    #[error("parameter {name} must be finite and {requirement}, got {value}")]
    InvalidParameter {
        name: &'static str,
        requirement: &'static str,
        value: f64,
    },
    #[error("ddof {ddof} leaves no degrees of freedom for {observations} observations")]
    NoDegreesOfFreedom { ddof: usize, observations: usize },
    #[error("{purpose} would contain {rows} by {columns} cells, exceeding the limit of {maximum}")]
    DenseMatrixTooLarge {
        purpose: &'static str,
        rows: usize,
        columns: usize,
        maximum: usize,
    },
    #[error("could not allocate {cells} cells for {purpose}")]
    AllocationFailed { purpose: &'static str, cells: usize },
    #[error("component {0:?} does not exist")]
    UnknownComponent(String),
    #[error("metadata column {0:?} does not exist")]
    UnknownMetadataColumn(String),
    #[error("metadata sample {0:?} is duplicated")]
    DuplicateMetadataSample(String),
    #[error("metadata has no group for sample {0:?}")]
    MissingMetadataSample(String),
    #[error("metadata contains unused sample {0:?}")]
    UnusedMetadataSample(String),
    #[error("metadata group cannot be empty for sample {0:?}")]
    EmptyGroup(String),
    #[error("ANCOM requires at least two groups with within-group replication")]
    InvalidGrouping,
    #[error("statistical calculation failed: {0}")]
    Statistics(String),
    #[error("delimited input has no header")]
    MissingHeader,
    #[error("first header field must identify samples and remaining fields must name components")]
    InvalidHeader,
    #[error("delimited input error: {0}")]
    Delimited(String),
    #[error("I/O error: {0}")]
    Io(String),
}

pub type Result<T> = std::result::Result<T, CompositionError>;