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    /// Translation table used for this gene.
49    pub translation_table: u8,
50    /// Whether left/right ends are partial (run off sequence edges).
51    pub partial: (bool, bool),
52    /// RBS motif name (e.g. "AGGAG" or "None").
53    pub rbs_motif: String,
54    /// RBS spacer distance (e.g. "3-4bp" or "None").
55    pub rbs_spacer: String,
56    /// GC content of this gene.
57    pub gc_content: f64,
58    /// Confidence score (50.0 - 99.99).
59    pub confidence: f64,
60    /// Total score (coding + start).
61    pub score: f64,
62    /// Coding score.
63    pub cscore: f64,
64    /// Start score (rscore + uscore + tscore).
65    pub sscore: f64,
66    /// RBS score.
67    pub rscore: f64,
68    /// Upstream composition score.
69    pub uscore: f64,
70    /// Start codon type score.
71    pub tscore: f64,
72}
73
74/// Configuration for gene prediction.
75#[derive(Debug, Clone)]
76pub struct ProdigalConfig {
77    /// NCBI translation table (1-25, excluding 7,8,17-20). Default: 11.
78    pub translation_table: u8,
79    /// Do not allow genes to run off sequence edges.
80    pub closed_ends: bool,
81    /// Treat runs of N as masked regions.
82    pub mask_n_runs: bool,
83    /// Bypass Shine-Dalgarno trainer, force full motif scan.
84    pub force_non_sd: bool,
85}
86
87impl Default for ProdigalConfig {
88    fn default() -> Self {
89        ProdigalConfig {
90            translation_table: 11,
91            closed_ends: false,
92            mask_n_runs: false,
93            force_non_sd: false,
94        }
95    }
96}
97
98/// Errors from gene prediction.
99#[derive(Debug)]
100pub enum ProdigalError {
101    EmptySequence,
102    SequenceTooShort { length: usize, min: usize },
103    SequenceTooLong { length: usize, max: usize },
104    InvalidTranslationTable(u8),
105    Io(std::io::Error),
106}
107
108impl std::fmt::Display for ProdigalError {
109    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
110        match self {
111            ProdigalError::EmptySequence => write!(f, "sequence is empty"),
112            ProdigalError::SequenceTooShort { length, min } => {
113                write!(f, "sequence too short ({length} bp, need >= {min} bp)")
114            }
115            ProdigalError::SequenceTooLong { length, max } => {
116                write!(f, "sequence too long ({length} bp, max {max} bp)")
117            }
118            ProdigalError::InvalidTranslationTable(t) => {
119                write!(f, "invalid translation table: {t}")
120            }
121            ProdigalError::Io(e) => write!(f, "I/O error: {e}"),
122        }
123    }
124}
125
126impl std::error::Error for ProdigalError {}
127
128impl From<std::io::Error> for ProdigalError {
129    fn from(e: std::io::Error) -> Self {
130        ProdigalError::Io(e)
131    }
132}