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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
use crate::utils::{
expression, tax_ranks, url, utils,
variable_data::{GOAT_ASSEMBLY_VARIABLE_DATA, GOAT_TAXON_VARIABLE_DATA},
};
use crate::{IndexType, GOAT_URL, TAXONOMY, UPPER_CLI_FILE_LIMIT, UPPER_CLI_SIZE_LIMIT};
use anyhow::{bail, Result};
enum TaxType {
Tree,
Name,
Lineage,
}
pub fn process_cli_args(
matches: &clap::ArgMatches,
api: &str,
unique_ids: Vec<String>,
index_type: IndexType,
) -> Result<(u64, Vec<String>, Vec<String>)> {
let print_url = matches.is_present("url");
let tax_tree_enum = match matches.is_present("descendents") {
true => TaxType::Tree,
false => TaxType::Name,
};
let tax_lineage_enum = match matches.is_present("lineage") {
true => TaxType::Lineage,
false => TaxType::Name,
};
let include_estimates = matches.is_present("include-estimates");
let expression = match matches.value_of("expression") {
Some(s) => url::format_expression(s, index_type)?,
None => "".to_string(),
};
let variable_string = matches.value_of("variables");
let print_expression = matches.is_present("print-expression");
let tax_rank = match matches.value_of("tax-rank") {
Some(t) => tax_ranks::TaxRanks::init().parse(t)?,
None => "".to_string(),
};
let size = match matches.value_of("size") {
Some(s) => s,
None => "0",
};
let ranks = match matches.value_of("ranks") {
Some(r) => r,
None => "",
};
let tax_name_op = matches.value_of("taxon");
let filename_op = matches.value_of("file");
let result = index_type.to_string();
let summarise_values_by = "count";
let taxon_include_raw_values = matches.is_present("taxon-raw");
let taxon_tidy = match taxon_include_raw_values {
true => true,
false => matches.is_present("taxon-tidy"),
};
let taxon_assembly = matches.is_present("taxon-assembly");
let taxon_cvalues = matches.is_present("taxon-c-values");
let taxon_karyotype = matches.is_present("taxon-karyotype");
let taxon_gs = matches.is_present("taxon-genome-size");
let taxon_busco = matches.is_present("taxon-busco");
let taxon_gc_percent = matches.is_present("taxon-gc-percent");
let taxon_mitochondrion = matches.is_present("taxon-mitochondria");
let taxon_plastid = matches.is_present("taxon-plastid");
let taxon_ploidy = matches.is_present("taxon-ploidy");
let taxon_sex_determination = matches.is_present("taxon-sex-determination");
let taxon_legislation = matches.is_present("taxon-legislation");
let taxon_names = matches.is_present("taxon-names");
let taxon_target_lists = matches.is_present("taxon-target-lists");
let taxon_n50 = matches.is_present("taxon-n50");
let taxon_bioproject = matches.is_present("taxon-bioproject");
let taxon_gene_count = matches.is_present("taxon-gene-count");
let taxon_date = matches.is_present("taxon-date");
let taxon_country_list = matches.is_present("taxon-country-list");
let taxon_status = matches.is_present("taxon-status");
let assembly_assembly = matches.is_present("assembly-assembly");
let assembly_karyotype = matches.is_present("assembly-karyotype");
let assembly_contig = matches.is_present("assembly-contig");
let assembly_scaffold = matches.is_present("assembly-scaffold");
let assembly_gc = matches.is_present("assembly-gc");
let assembly_gene = matches.is_present("assembly-gene-count");
let assembly_busco = matches.is_present("assembly-busco");
let assembly_btk = matches.is_present("assembly-btk");
if print_expression {
match index_type {
IndexType::Taxon => expression::print_variable_data(&*GOAT_TAXON_VARIABLE_DATA),
IndexType::Assembly => expression::print_variable_data(&*GOAT_ASSEMBLY_VARIABLE_DATA),
}
std::process::exit(0);
}
let fields = url::FieldBuilder {
taxon_assembly,
taxon_bioproject,
taxon_busco,
taxon_country_list,
taxon_cvalues,
taxon_date,
taxon_gc_percent,
taxon_gene_count,
taxon_gs,
taxon_karyotype,
taxon_legislation,
taxon_mitochondrion,
taxon_names,
taxon_n50,
taxon_plastid,
taxon_ploidy,
taxon_sex_determination,
taxon_status,
taxon_target_lists,
taxon_tidy,
assembly_assembly,
assembly_karyotype,
assembly_contig,
assembly_scaffold,
assembly_gc,
assembly_gene,
assembly_busco,
assembly_btk,
};
let size_int: u64;
match size.parse::<u64>() {
Ok(e) => {
size_int = e;
if e as usize > *UPPER_CLI_SIZE_LIMIT {
let limit_string = utils::pretty_print_usize(*UPPER_CLI_SIZE_LIMIT);
bail!(
"Searches with more than {} results are not currently supported.",
limit_string
)
}
}
Err(e) => bail!("Did you pass an integer to `--size`? Info: {}", e),
}
let tax_tree = match (tax_tree_enum, tax_lineage_enum) {
(TaxType::Tree, TaxType::Name) => "tree",
(TaxType::Name, TaxType::Lineage) => "lineage",
(TaxType::Name, TaxType::Name) => "name",
(_, _) => bail!("If we get here, I've done something wrong in the `TaxType` enum logic. Please file an issue."),
};
let url_vector: Vec<String>;
match tax_name_op {
Some(s) => {
if s == "" {
bail!("Empty string found, please specify a taxon.")
}
url_vector = utils::parse_comma_separated(s)
}
None => match filename_op {
Some(s) => {
url_vector = utils::lines_from_file(s)?;
if url_vector.len() > *UPPER_CLI_FILE_LIMIT {
let limit_string = utils::pretty_print_usize(*UPPER_CLI_FILE_LIMIT);
bail!("Number of taxa specified cannot exceed {}.", limit_string)
}
}
None => bail!("One of -f (--file) or -t (--taxon) should be specified."),
},
}
let url_vector_api = url::make_goat_urls(
api,
&url_vector,
&*GOAT_URL,
tax_tree,
include_estimates,
taxon_include_raw_values,
summarise_values_by,
&result,
&*TAXONOMY,
size,
ranks,
fields,
variable_string,
&expression,
&tax_rank,
unique_ids,
index_type,
)?;
if print_url {
for (index, url) in url_vector_api.iter().enumerate() {
println!("{}.\tGoaT API URL: {}", index, url);
}
std::process::exit(0);
}
Ok((size_int, url_vector, url_vector_api))
}