1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//! `goat-cli` is a command line interface to query the
//! [Genomes on a Tree Open API](https://goat.genomehubs.org/api-docs/) using
//! an asynchronous [`tokio`](<https://docs.rs/tokio/latest/tokio/>) runtime.
//!
//! I'm documenting the code here for others, and for future me.

use lazy_static::lazy_static;
use std::fmt;

/// Query the GoaT count API.
pub mod count;
/// Query the GoaT lookup API.
pub mod lookup;
/// A module to produce a progress
/// bar.
pub mod progress;
/// Query the GoaT record API.
pub mod report;
/// Query the GoaT search API.
pub mod search;
/// Collection of utility functions
/// used elsewhere.
pub mod utils;

/// The base URL for GoaT.
const GOAT_URL_BASE: &str = "https://goat.genomehubs.org/api/";
/// The current version of the GoaT API.
const GOAT_API_VERSION: &str = "v2/";

lazy_static! {
    /// The current GoaT URL.
    pub static ref GOAT_URL: String = format!("{}{}", GOAT_URL_BASE, GOAT_API_VERSION);
    /// The taxonomy that `goat-cli` uses.
    pub static ref TAXONOMY: String = "ncbi".into();
}

// global size limits on pinging the API
lazy_static! {
    /// Upper limit for the CLI arg `--size`.
    pub static ref UPPER_CLI_SIZE_LIMIT: usize = 50000;
    /// Upper limit for the number of entries in the file for CLI arg `-f`.
    pub static ref UPPER_CLI_FILE_LIMIT: usize = 500;
}

/// The indexes we make searches over in GoaT.
///
/// Currently implemented (to some extent) is taxon
/// and assembly. Others exist, e.g. feature/sample.
///
/// Each tuple variant can store their respective
/// [`BTreeMap`] databases.

#[derive(Clone, Copy, Debug)]
pub enum IndexType {
    /// Taxon search index. The historical main
    /// functionality of goat-cli went through taxon.
    Taxon,
    /// Assembly search index.
    Assembly,
}

impl fmt::Display for IndexType {
    /// Implement [`Display`] for [`IndexType`] so we can
    /// use `.to_string()` method.
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            IndexType::Taxon => write!(f, "taxon"),
            IndexType::Assembly => write!(f, "assembly"),
        }
    }
}