1mod readonly;
14mod core;
15mod alias;
16mod fhr_metadata;
17mod import;
18mod persistence;
19mod export;
20
21#[cfg(test)]
22mod tests;
23
24pub use self::readonly::ReadonlyRefgetStore;
26pub use self::core::RefgetStore;
27pub use self::alias::{AliasKind, AliasManager};
28pub use self::fhr_metadata::{
29 FhrMetadata, FhrAuthor, FhrIdentifier, FhrTaxon, FhrVitalStats,
30 load_sidecars, write_sidecars, write_sidecar, remove_sidecar, sidecar_path, load_from_json,
32};
33
34use serde::{Deserialize, Serialize};
35use std::io::{BufRead, BufReader, Read};
36
37pub(crate) use crate::hashkeyable::DigestKey;
38
39
40pub(crate) const DEFAULT_SEQDATA_PATH_TEMPLATE: &str = "sequences/%s2/%s.seq";
45
46#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct PagedResult<T> {
53 pub results: Vec<T>,
54 pub pagination: Pagination,
55}
56
57#[derive(Debug, Clone, Serialize, Deserialize)]
58pub struct Pagination {
59 pub page: usize,
60 pub page_size: usize,
61 pub total: usize,
62}
63
64#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
66pub enum StorageMode {
67 Raw,
68 Encoded,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq)]
72pub struct RetrievedSequence {
73 pub sequence: String,
74 pub chrom_name: String,
75 pub start: u32,
76 pub end: u32,
77}
78
79#[derive(Clone, Copy)]
81pub struct FastaImportOptions<'a> {
82 pub(crate) force: bool,
83 pub(crate) namespaces: &'a [&'a str],
84}
85
86impl<'a> Default for FastaImportOptions<'a> {
87 fn default() -> Self {
88 Self {
89 force: false,
90 namespaces: &[],
91 }
92 }
93}
94
95impl<'a> FastaImportOptions<'a> {
96 #[must_use]
97 pub fn new() -> Self {
98 Self::default()
99 }
100
101 #[must_use]
102 pub fn force(mut self, yes: bool) -> Self {
103 self.force = yes;
104 self
105 }
106
107 #[must_use]
108 pub fn namespaces(mut self, ns: &'a [&'a str]) -> Self {
109 self.namespaces = ns;
110 self
111 }
112}
113
114#[derive(Serialize, Deserialize, Debug)]
117pub(crate) struct StoreMetadata {
118 pub(crate) version: u32,
120 pub(crate) seqdata_path_template: String,
122 pub(crate) collections_path_template: String,
124 pub(crate) sequence_index: String,
126 #[serde(default)]
128 pub(crate) collection_index: Option<String>,
129 pub(crate) mode: StorageMode,
131 pub(crate) created_at: String,
133 #[serde(default = "default_true")]
135 pub(crate) ancillary_digests: bool,
136 #[serde(default)]
138 pub(crate) attribute_index: bool,
139 #[serde(default, skip_serializing_if = "Vec::is_empty")]
141 pub(crate) sequence_alias_namespaces: Vec<String>,
142 #[serde(default, skip_serializing_if = "Vec::is_empty")]
144 pub(crate) collection_alias_namespaces: Vec<String>,
145 #[serde(default, skip_serializing_if = "Option::is_none")]
147 pub(crate) modified: Option<String>,
148 #[serde(default, skip_serializing_if = "Option::is_none")]
150 pub(crate) collections_digest: Option<String>,
151 #[serde(default, skip_serializing_if = "Option::is_none")]
153 pub(crate) sequences_digest: Option<String>,
154 #[serde(default, skip_serializing_if = "Option::is_none")]
156 pub(crate) aliases_digest: Option<String>,
157 #[serde(default, skip_serializing_if = "Option::is_none")]
159 pub(crate) fhr_digest: Option<String>,
160}
161
162pub(crate) fn default_true() -> bool {
163 true
164}
165
166#[derive(Debug, Clone)]
168pub struct StoreStats {
169 pub n_sequences: usize,
171 pub n_sequences_loaded: usize,
173 pub n_collections: usize,
175 pub n_collections_loaded: usize,
177 pub storage_mode: String,
179}
180
181pub(crate) fn format_bytes(bytes: usize) -> String {
183 const UNITS: &[&str] = &["B", "KB", "MB", "GB", "TB"];
184 let mut size = bytes as f64;
185 let mut unit_idx = 0;
186
187 while size >= 1024.0 && unit_idx < UNITS.len() - 1 {
188 size /= 1024.0;
189 unit_idx += 1;
190 }
191
192 if unit_idx == 0 {
193 format!("{} {}", bytes, UNITS[0])
194 } else {
195 format!("{:.2} {}", size, UNITS[unit_idx])
196 }
197}
198
199#[derive(Debug, Clone, Copy, PartialEq, Eq)]
205pub enum SyncStrategy {
206 KeepOurs,
208 KeepTheirs,
210 Notify,
212}
213
214#[derive(Debug, Default)]
216pub struct PullResult {
217 pub pulled: usize,
219 pub skipped: usize,
221 pub not_found: usize,
223 pub conflicts: Vec<String>,
225}
226
227#[derive(Debug)]
229pub struct AvailableAliases<'a> {
230 pub sequences: &'a [String],
231 pub collections: &'a [String],
232}
233
234pub struct SubstringsFromRegions<'a, K>
236where
237 K: AsRef<[u8]>,
238{
239 pub(crate) store: &'a ReadonlyRefgetStore,
240 pub(crate) reader: BufReader<Box<dyn Read>>,
241 pub(crate) collection_digest: K,
242 pub(crate) previous_parsed_chr: String,
243 pub(crate) current_seq_digest: String,
244 pub(crate) line_num: usize,
245}