goat_cli/lib.rs
1//! `goat-cli` is a command line interface to query the
2//! [Genomes on a Tree Open API](https://goat.genomehubs.org/api-docs/) using
3//! an asynchronous [`tokio`](<https://docs.rs/tokio/latest/tokio/>) runtime.
4//!
5//! I'm documenting the code here for others, and for future me.
6
7use lazy_static::lazy_static;
8use std::fmt;
9
10/// Query the GoaT count API.
11pub mod count;
12/// Query the GoaT lookup API.
13pub mod lookup;
14/// A module to produce a progress
15/// bar.
16pub mod progress;
17/// Query the GoaT record API.
18pub mod report;
19/// Query the GoaT search API.
20pub mod search;
21/// Collection of utility functions
22/// used elsewhere.
23pub mod utils;
24
25/// The base URL for GoaT.
26const GOAT_URL_BASE: &str = "https://goat.genomehubs.org/api/";
27/// The current version of the GoaT API.
28const GOAT_API_VERSION: &str = "v2/";
29
30lazy_static! {
31 /// The current GoaT URL.
32 pub static ref GOAT_URL: String = format!("{}{}", GOAT_URL_BASE, GOAT_API_VERSION);
33 /// The taxonomy that `goat-cli` uses.
34 pub static ref TAXONOMY: String = "ncbi".into();
35}
36
37// global size limits on pinging the API
38lazy_static! {
39 /// Upper limit for the CLI arg `--size`.
40 pub static ref UPPER_CLI_SIZE_LIMIT: usize = 50000;
41 /// Upper limit for the number of entries in the file for CLI arg `-f`.
42 pub static ref UPPER_CLI_FILE_LIMIT: usize = 500;
43}
44
45/// The indexes we make searches over in GoaT.
46///
47/// Currently implemented (to some extent) is taxon
48/// and assembly. Others exist, e.g. feature/sample.
49///
50/// Each tuple variant can store their respective
51/// [`std::collections::BTreeMap`] databases.
52#[derive(Clone, Copy, Debug)]
53pub enum IndexType {
54 /// Taxon search index. The historical main
55 /// functionality of goat-cli went through taxon.
56 Taxon,
57 /// Assembly search index.
58 Assembly,
59}
60
61impl fmt::Display for IndexType {
62 /// Implement [`fmt::Display`] for [`IndexType`] so we can
63 /// use `.to_string()` method.
64 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
65 match self {
66 IndexType::Taxon => write!(f, "taxon"),
67 IndexType::Assembly => write!(f, "assembly"),
68 }
69 }
70}
71
72/// The type of result to return in GoaT.
73///
74/// Tax tree is a descendents call to the API,
75/// tax name is a single species, and tax lineage
76/// tracks back up the tree.
77#[derive(Default, Clone, Copy)]
78pub enum TaxType {
79 /// tax_tree() returns a node and all
80 /// of its descendants.
81 #[default]
82 Tree,
83 /// tax_name() returns only the taxon of
84 /// interest.
85 Name,
86 /// tax_lineage() returns all of the nodes
87 /// from a given taxon back to the root of the
88 /// tree.
89 Lineage,
90}
91
92impl fmt::Display for TaxType {
93 /// Implement [`fmt::Display`] for [`TaxType`] so we can
94 /// use `.to_string()` method.
95 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
96 match self {
97 TaxType::Tree => write!(f, "tax_tree"),
98 TaxType::Name => write!(f, "tax_name"),
99 TaxType::Lineage => write!(f, "tax_lineage"),
100 }
101 }
102}