1use crate::F32Bw0and1;
10use derive_builder::UninitializedFieldError;
11use std::char::TryFromCharError;
12use std::fmt;
13use std::io;
14use std::num::{ParseFloatError, ParseIntError, TryFromIntError};
15use std::str::Utf8Error;
16use std::string::FromUtf8Error;
17use thiserror::Error;
18
19#[derive(Debug, Error)]
26#[non_exhaustive]
27pub enum Error {
28 #[error("unknown alignment state: `{0}`")]
30 UnknownAlignState(String),
31
32 #[error("invalid sequence length: `{0}`")]
34 InvalidSeqLength(String),
35
36 #[error("invalid alignment length: `{0}`")]
38 InvalidAlignLength(String),
39
40 #[error("invalid contig and/or start: `{0}`")]
42 InvalidContigAndStart(String),
43
44 #[error(
46 "invalid alignment coordinates (contig/start/end): `{0}`. \n\
47 In command line tool, you can use `nanalogue peek` to check contig names and contig lengths. \n\
48 In command line tool, if piping in a samtools view command, please include header with -h in samtools. "
49 )]
50 InvalidAlignCoords(String),
51
52 #[error("invalid mod coordinates: `{0}`")]
54 InvalidModCoords(String),
55
56 #[error("invalid mod probabilities: `{0}`")]
58 InvalidModProbs(String),
59
60 #[error("invalid sequence: `{0}`")]
62 InvalidSeq(String),
63
64 #[error("invalid base: `{0}`")]
66 InvalidBase(String),
67
68 #[error("invalid read id: `{0}`")]
70 InvalidReadID(String),
71
72 #[error("invalid mod type: `{0}`")]
76 InvalidModType(String),
77
78 #[error("empty mod type: `{0}`")]
80 EmptyModType(String),
81
82 #[error(
84 "rust_htslib error: `{0}` \n\
85 In command line tool, you can use `nanalogue peek` to check contig names and contig lengths. \n\
86 In command line tool, if piping in a samtools view command, please include header with -h in samtools. "
87 )]
88 RustHtslibError(#[from] rust_htslib::errors::Error),
89
90 #[error("integer conversion error: `{0}`")]
92 IntConversionError(#[from] TryFromIntError),
93
94 #[error("error involving string conversion: `{0}`")]
96 StringConversionError(#[from] Utf8Error),
97
98 #[error("UTF-8 conversion error: `{0}`")]
100 Utf8ConversionError(#[from] FromUtf8Error),
101
102 #[error("JSON parsing error: `{0}`")]
104 JsonParseError(#[from] serde_json::Error),
105
106 #[error("ordered pair conversion error: `{0}`")]
110 OrdPairConversion(String),
111
112 #[error("integer parsing error: `{0}`")]
114 IntParseError(#[from] ParseIntError),
115
116 #[error("float parsing error: `{0}`")]
118 FloatParseError(#[from] ParseFloatError),
119
120 #[error("input output error: `{0}`")]
122 InputOutputError(#[from] io::Error),
123
124 #[error("formatting error: `{0}`")]
126 FormattingError(#[from] fmt::Error),
127
128 #[error("error parsing csv: `{0}`")]
130 CsvError(#[from] csv::Error),
131
132 #[error("duplicates detected: `{0}`")]
134 InvalidDuplicates(String),
135
136 #[error("`{0}`")]
138 InvalidState(String),
139
140 #[error("error while writing output: `{0}`")]
142 WriteOutput(String),
143
144 #[error("not implemented: `{0}`")]
146 NotImplemented(String),
147
148 #[error("items in wrong order: `{0}`")]
150 WrongOrder(String),
151
152 #[error("data not available: `{0}`")]
154 UnavailableData(String),
155
156 #[error("read is unmapped: `{0}`")]
159 Unmapped(String),
160
161 #[error("zero values not allowed: `{0}`")]
163 Zero(String),
164
165 #[error("zero sequence length: `{0}`")]
167 ZeroSeqLen(String),
168
169 #[error(
171 "invalid region '{region}': position {pos} exceeds contig length {contig_length}\n\
172 In command line tool, you can use `nanalogue peek` to check contig names and contig lengths."
173 )]
174 InvalidRegion {
175 region: String,
177 pos: u64,
179 contig_length: u64,
181 },
182
183 #[error("invalid sorting: {0}")]
185 InvalidSorting(String),
186
187 #[error("window density {density} below threshold {threshold}")]
189 WindowDensBelowThres {
190 density: F32Bw0and1,
192 threshold: F32Bw0and1,
194 },
195
196 #[error("window does not contain any data: `{0}`")]
198 EmptyWindow(String),
199
200 #[error("data is not of sufficient size (e.g. in a window): `{0}`")]
202 InsufficientDataSize(String),
203
204 #[error("unanticipated arithmetic error e.g. overflow: `{0}`")]
206 Arithmetic(String),
207
208 #[error("building error, are you missing inputs?: `{0}`")]
210 BuilderError(#[from] UninitializedFieldError),
211
212 #[error("building error, input validation failed: `{0}`")]
214 BuilderValidation(String),
215
216 #[error("error converting between DNA bases: `{0}`")]
218 FromCharError(#[from] TryFromCharError),
219
220 #[error("Polars error: `{0}`")]
222 PolarsError(#[from] polars::error::PolarsError),
223
224 #[error("Simulate DNA sequence error; problem at end of CIGAR: {0}")]
226 SimulateDNASeqCIGAREndProblem(String),
227}