Skip to main content

prodigal_rs/api/
types.rs

1/// Strand of a predicted gene.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum Strand {
4    Forward,
5    Reverse,
6}
7
8impl std::fmt::Display for Strand {
9    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
10        match self {
11            Strand::Forward => write!(f, "+"),
12            Strand::Reverse => write!(f, "-"),
13        }
14    }
15}
16
17/// Start codon type.
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub enum StartCodon {
20    ATG,
21    GTG,
22    TTG,
23    Edge,
24}
25
26impl std::fmt::Display for StartCodon {
27    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
28        match self {
29            StartCodon::ATG => write!(f, "ATG"),
30            StartCodon::GTG => write!(f, "GTG"),
31            StartCodon::TTG => write!(f, "TTG"),
32            StartCodon::Edge => write!(f, "Edge"),
33        }
34    }
35}
36
37/// A single predicted gene.
38#[derive(Debug, Clone)]
39pub struct PredictedGene {
40    /// 1-indexed start position in the input sequence.
41    pub begin: usize,
42    /// 1-indexed end position (inclusive).
43    pub end: usize,
44    /// Strand.
45    pub strand: Strand,
46    /// Start codon type.
47    pub start_codon: StartCodon,
48    /// Whether left/right ends are partial (run off sequence edges).
49    pub partial: (bool, bool),
50    /// RBS motif name (e.g. "AGGAG" or "None").
51    pub rbs_motif: String,
52    /// RBS spacer distance (e.g. "3-4bp" or "None").
53    pub rbs_spacer: String,
54    /// GC content of this gene.
55    pub gc_content: f64,
56    /// Confidence score (50.0 - 99.99).
57    pub confidence: f64,
58    /// Total score (coding + start).
59    pub score: f64,
60    /// Coding score.
61    pub cscore: f64,
62    /// Start score (rscore + uscore + tscore).
63    pub sscore: f64,
64    /// RBS score.
65    pub rscore: f64,
66    /// Upstream composition score.
67    pub uscore: f64,
68    /// Start codon type score.
69    pub tscore: f64,
70}
71
72/// Configuration for gene prediction.
73#[derive(Debug, Clone)]
74pub struct ProdigalConfig {
75    /// NCBI translation table (1-25, excluding 7,8,17-20). Default: 11.
76    pub translation_table: u8,
77    /// Do not allow genes to run off sequence edges.
78    pub closed_ends: bool,
79    /// Treat runs of N as masked regions.
80    pub mask_n_runs: bool,
81    /// Bypass Shine-Dalgarno trainer, force full motif scan.
82    pub force_non_sd: bool,
83}
84
85impl Default for ProdigalConfig {
86    fn default() -> Self {
87        ProdigalConfig {
88            translation_table: 11,
89            closed_ends: false,
90            mask_n_runs: false,
91            force_non_sd: false,
92        }
93    }
94}
95
96/// Errors from gene prediction.
97#[derive(Debug)]
98pub enum ProdigalError {
99    EmptySequence,
100    SequenceTooShort { length: usize, min: usize },
101    SequenceTooLong { length: usize, max: usize },
102    InvalidTranslationTable(u8),
103    Io(std::io::Error),
104}
105
106impl std::fmt::Display for ProdigalError {
107    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108        match self {
109            ProdigalError::EmptySequence => write!(f, "sequence is empty"),
110            ProdigalError::SequenceTooShort { length, min } => {
111                write!(f, "sequence too short ({length} bp, need >= {min} bp)")
112            }
113            ProdigalError::SequenceTooLong { length, max } => {
114                write!(f, "sequence too long ({length} bp, max {max} bp)")
115            }
116            ProdigalError::InvalidTranslationTable(t) => {
117                write!(f, "invalid translation table: {t}")
118            }
119            ProdigalError::Io(e) => write!(f, "I/O error: {e}"),
120        }
121    }
122}
123
124impl std::error::Error for ProdigalError {}
125
126impl From<std::io::Error> for ProdigalError {
127    fn from(e: std::io::Error) -> Self {
128        ProdigalError::Io(e)
129    }
130}