rsomics-call 0.1.3

Typed alignment likelihood and small-variant calling workflow
Documentation
use thiserror::Error;

#[derive(Debug, Error, PartialEq, Eq)]
pub enum CallError {
    #[error("invalid allele: {0}")]
    InvalidAllele(String),

    #[error("ploidy must be greater than zero")]
    InvalidPloidy,

    #[error("ploidy input {path}: {message}")]
    PloidyInput { path: String, message: String },

    #[error("ploidy input {path} line {line}: {message}")]
    PloidyRecord {
        path: String,
        line: u64,
        message: String,
    },

    #[error("ploidy definition has no sex named {0}")]
    UnknownPloidySex(String),

    #[error("ploidy sample assignment count does not match the selected samples")]
    PloidySampleCountMismatch,

    #[error("allele and genotype likelihood dimensions are inconsistent")]
    InvalidLikelihoodDimensions,

    #[error("dependency correlation must be finite and between zero and one")]
    InvalidDependencyCorrelation,

    #[error("minimum base quality cannot exceed maximum base quality")]
    InvalidSnpQualityRange,

    #[error("at least one sample is required")]
    InvalidSampleCount,

    #[error("sample index {index} is outside the configured sample count {count}")]
    InvalidSampleIndex { index: usize, count: usize },

    #[error("invalid sample name: {0}")]
    InvalidSampleName(String),

    #[error("sample selection contains a duplicate name: {0}")]
    DuplicateSampleSelection(String),

    #[error("selected sample is absent from the input: {0}")]
    MissingSelectedSample(String),

    #[error("call sample input {path}: {message}")]
    CallSampleInput { path: String, message: String },

    #[error("call sample input {path} line {line}: {message}")]
    CallSampleRecord {
        path: String,
        line: u64,
        message: String,
    },

    #[error("likelihood reader configuration must be completed before reading records")]
    LateLikelihoodReaderConfiguration,

    #[error("alignment source ID {0} is duplicated")]
    DuplicateAlignmentSource(u32),

    #[error("alignment source ID {0} is unknown")]
    UnknownAlignmentSource(u32),

    #[error("at least one alignment input is required")]
    MissingAlignmentInputs,

    #[error("alignment input {path}: {message}")]
    AlignmentInput { path: String, message: String },

    #[error("reference dictionary in alignment input {0} differs from the first input")]
    ReferenceDictionaryMismatch(String),

    #[error("invalid region {region}: {message}")]
    InvalidRegion { region: String, message: String },

    #[error("at least one region is required")]
    MissingRegions,

    #[error("region input {path}: {message}")]
    RegionInput { path: String, message: String },

    #[error("region input {path} line {line}: {message}")]
    RegionRecord {
        path: String,
        line: u64,
        message: String,
    },

    #[error("target input {path}: {message}")]
    TargetInput { path: String, message: String },

    #[error("target input {path} line {line}: {message}")]
    TargetRecord {
        path: String,
        line: u64,
        message: String,
    },

    #[error("reference input {path}: {message}")]
    ReferenceInput { path: String, message: String },

    #[error("a FASTA reference is required for {0}")]
    MissingLikelihoodReference(&'static str),

    #[error("invalid BAQ configuration: {0}")]
    InvalidBaqConfiguration(&'static str),

    #[error(transparent)]
    Pileup(#[from] rsomics_pileup::PileupError),

    #[error("invalid or duplicate read-group ID: {0}")]
    InvalidReadGroup(String),

    #[error("BAM RG field is not a valid Z string")]
    InvalidReadGroupField,

    #[error("pileup column has an invalid reference coordinate")]
    InvalidPileupCoordinate,

    #[error("SNP evidence exceeds the supported count range")]
    SnpEvidenceOverflow,

    #[error("invalid indel likelihood configuration")]
    InvalidIndelConfig,

    #[error("invalid indel configuration: {0}")]
    InvalidIndelConfiguration(&'static str),

    #[error("invalid indel site summary")]
    InvalidIndelSummary,

    #[error("invalid likelihood annotations")]
    InvalidLikelihoodAnnotations,

    #[error("indel evidence exceeds the supported count range")]
    IndelEvidenceOverflow,

    #[error("reference data required for indel likelihoods is invalid")]
    InvalidIndelReference,

    #[error("indel realignment failed")]
    IndelRealignment,

    #[error("multiallelic mutation rate must be finite and between zero and one")]
    InvalidMutationRate,

    #[error("consensus reference probability threshold must be finite and between zero and one")]
    InvalidConsensusThreshold,

    #[error("the consensus caller requires observed compatible likelihoods")]
    UnsupportedConsensusLikelihoods,

    #[error("the multiallelic caller requires diploid input likelihoods")]
    UnsupportedLikelihoodPloidy,

    #[error("the caller ploidy count differs from the likelihood sample count")]
    CallerPloidyCountMismatch,

    #[error("the caller group count differs from the likelihood sample count")]
    CallerGroupCountMismatch,

    #[error("caller group indices must be contiguous and nonempty")]
    InvalidCallerGroups,

    #[error("sample groups require the multiallelic calling model")]
    UnsupportedCallerGroups,

    #[error("the prior chromosome count is outside the cohort ploidy range")]
    InvalidPriorChromosomeCount,

    #[error("prior allele counts are inconsistent with the site alleles or total")]
    InvalidPriorAlleleCounts,

    #[error("gVCF depth thresholds must be strictly increasing")]
    InvalidGvcfThresholds,

    #[error("gVCF input sites are not in reference and coordinate order")]
    InvalidGvcfOrder,

    #[error("gVCF block sites have different sample counts")]
    GvcfSampleCountMismatch,

    #[error("present gVCF block likelihoods must contain three diploid values per sample")]
    InvalidGvcfLikelihoods,

    #[error("gVCF blocks require the multiallelic calling model")]
    UnsupportedGvcfModel,

    #[error("gVCF input requires a FORMAT/DP definition")]
    MissingGvcfDepth,

    #[error("called allele count exceeds the supported range")]
    CalledAlleleCountOverflow,

    #[error("invalid likelihood VCF/BCF: {0}")]
    InvalidLikelihoodVariant(String),

    #[error("likelihood VCF/BCF input: {0}")]
    LikelihoodVariantInput(String),

    #[error("likelihood VCF/BCF record {record}: {message}")]
    LikelihoodVariantRecord { record: u64, message: String },

    #[error("likelihood call record {record}: {source}")]
    LikelihoodCallRecord { record: u64, source: Box<CallError> },

    #[error("variant VCF/BCF output: {0}")]
    VariantOutput(String),
}

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