Skip to content

Commit

Permalink
refactor: update field name and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebedthan committed Jun 25, 2024
1 parent cd9e64b commit fdb92d5
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 49 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xgt"
version = "0.3.0"
version = "0.4.0"
edition = "2021"
authors = ["Anicet Ebou <anicet.ebou@gmail.com>"]
description = "xgt enables efficient querying and parsing of GTDB data"
Expand Down
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ xgt -h
```
# Search subcommand: search GTDB
## Search all Escherichia (genus) genomes
xgt search Escherichia
xgt search g__Escherichia
## Search all genomes with genus name containing escherichia
xgt search --partial escherichia
## Search all genomes with genus name containing Escherichia
xgt search --partial g__Escherichia -o output.json
## Search from a list
xgt search -f list.txt
Expand Down Expand Up @@ -63,8 +63,6 @@ Full help is available from `xgt --help`.
To tell `xgt` to _not_ verify the peer, use the `-k/--insecure` option.
Currently (as of Apr 28, 2024), you should add this option to your command to get the desired result as GTDB API's server has a certificate issue.



## Minimum supported Rust version
`xgt` minimum [Rust](https://www.rust-lang.org/) version is 1.70.0.

Expand Down
41 changes: 9 additions & 32 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,41 +21,30 @@ pub fn build_app() -> Command {
.short('c')
.long("count")
.action(ArgAction::SetTrue)
.help("Count the number of genomes"),
.help("count the number of genomes"),
)
.arg(
Arg::new("id")
.short('i')
.long("id")
.action(ArgAction::SetTrue)
.help("Print only genome ID"),
.help("only print genome id"),
)
.arg(
Arg::new("field")
.short('F')
.long("field")
.value_name("STR")
.default_value("gtdb_tax")
.value_parser(["all", "gtdb_tax", "ncbi_tax", "ncbi_org", "ncbi_id"])
.help("Search field"),
.default_value("gtdb")
.value_parser(["gtdb", "ncbi"])
.help("which taxonomy to search"),
)
.arg(
Arg::new("file")
.short('f')
.long("file")
.value_name("FILE")
.help("Search from name in FILE"),
)
.arg(
Arg::new("level")
.short('l')
.long("level")
.value_name("STR")
.help("Taxon level to search")
.default_value("genus")
.value_parser([
"species", "genus", "family", "order", "class", "phylum", "domain",
]),
.help("search from name in FILE"),
)
.arg(
Arg::new("out")
Expand Down Expand Up @@ -267,20 +256,14 @@ mod tests {
fn test_app() {
std::env::set_var("NO_COLOR", "true");
let app = build_app();
let args = vec![
"xgt", "search", "p__taxon", "-l", "class", "--count", "--raw",
];
let args = vec!["xgt", "search", "p__taxon", "--count", "--raw"];
let matches = app.get_matches_from(args);
assert_eq!(matches.subcommand_name(), Some("search"));
let submatches = matches.subcommand_matches("search").unwrap();
assert_eq!(
submatches.get_one::<String>("name"),
Some(&"p__taxon".to_owned())
);
assert_eq!(
submatches.get_one::<String>("level"),
Some(&"class".to_owned())
);
assert!(submatches.get_flag("count"));
assert!(submatches.get_flag("raw"));
}
Expand All @@ -291,16 +274,14 @@ mod tests {
"xgt",
"search",
"p__taxon",
"-l",
"class",
"--count",
"--raw",
"--id",
"--partial",
"--rep",
"--type",
"--field",
"ncbi_tax",
"ncbi",
]);
let subcommand_parser = arg_parser.subcommand_matches("search").unwrap();
assert!(subcommand_parser.get_flag("count"));
Expand All @@ -313,13 +294,9 @@ mod tests {
subcommand_parser.get_one::<String>("name"),
Some(&"p__taxon".to_owned())
);
assert_eq!(
subcommand_parser.get_one::<String>("level"),
Some(&"class".to_owned())
);
assert_eq!(
subcommand_parser.get_one::<String>("field"),
Some(&"ncbi_tax".to_owned())
Some(&"ncbi".to_owned())
);
}

Expand Down
8 changes: 0 additions & 8 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ fn handle_taxon_command(sub_matches: &clap::ArgMatches) -> Result<()> {
Ok(())
}

/*
#[cfg(test)]
mod tests {
use super::*;
use std::ffi::OsString;

#[test]
fn test_search_command() {
let needle = vec!["Aminobacter".to_string(), "Rhizobium".to_string()];
let level = "phylum".to_string();
let id = true;
let count = true;
let raw = true;
Expand All @@ -73,8 +70,6 @@ mod tests {
OsString::from("search"),
OsString::from("--file"),
OsString::from("test/test.txt"),
OsString::from("--level"),
OsString::from(level.clone()),
OsString::from("--id"),
OsString::from("--partial"),
OsString::from("--count"),
Expand All @@ -88,8 +83,6 @@ mod tests {
let args =
utils::SearchArgs::from_arg_matches(matches.subcommand_matches("search").unwrap());

assert_eq!(args.get_needle(), needle);
assert_eq!(args.get_level(), level);
assert_eq!(args.get_gid(), id);
assert_eq!(args.get_count(), count);
assert_eq!(args.get_raw(), raw);
Expand All @@ -115,4 +108,3 @@ mod tests {
assert_eq!(args.output, Some(String::from("met.json")));
}
}
*/
3 changes: 1 addition & 2 deletions test/test.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
Aminobacter
Rhizobium
g__Aminobacter

0 comments on commit fdb92d5

Please sign in to comment.