Skip to content

Commit

Permalink
feat(cli): print all dataset detections in terminal output
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov committed Sep 8, 2023
1 parent ac7c2d5 commit 61eef71
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions packages_rs/nextclade-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ lazy_static = "=1.4.0"
log = "=0.4.19"
nextclade = { path = "../nextclade" }
num_cpus = "=1.16.0"
ordered-float = { version = "=3.9.1", features = ["rand", "serde", "schemars"] }
owo-colors = "=3.5.0"
pretty_assertions = "=1.3.0"
rayon = "=1.7.0"
Expand Down
37 changes: 25 additions & 12 deletions packages_rs/nextclade-cli/src/cli/nextclade_seq_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use nextclade::sort::minimizer_index::{MinimizerIndexJson, MINIMIZER_INDEX_ALGO_
use nextclade::sort::minimizer_search::{run_minimizer_search, MinimizerSearchRecord};
use nextclade::utils::option::OptionMapRefFallible;
use nextclade::utils::string::truncate;
use ordered_float::OrderedFloat;
use serde::Serialize;
use std::collections::btree_map::Entry::{Occupied, Vacant};
use std::collections::BTreeMap;
Expand Down Expand Up @@ -150,15 +151,25 @@ fn writer_thread(
Ok(template)
})?;

println!("{}┐", "─".repeat(110));

println!(
"{:40} | {:40} | {:10} | {:10}",
"Seq. name", "dataset", "total hits", "max hit"
"{:^40} {:^40} {:^10} {:^10}",
"Sequence name", "Dataset", "Score", "Num. hits"
);

println!("{}┤", "─".repeat(110));

let mut writers = BTreeMap::new();

for record in result_receiver {
for dataset in &record.result.datasets {
let datasets = record
.result
.datasets
.iter()
.sorted_by_key(|dataset| -OrderedFloat(dataset.score));

for (i, dataset) in datasets.enumerate() {
let name = &dataset.name;

let names = name
Expand All @@ -167,6 +178,7 @@ fn writer_thread(
*name = name.join(component);
Some(name.clone())
})
.unique()
.map(path_to_string)
.collect::<Result<Vec<String>, Report>>()?;

Expand All @@ -178,17 +190,18 @@ fn writer_thread(
writer.write(&record.fasta_record.seq_name, &record.fasta_record.seq, false)?;
}
}

let name = if i == 0 { &record.fasta_record.seq_name } else { "" };
println!(
"{:40} │ {:40} │ {:>10.3} │ {:>10} │",
&truncate(name, 40),
&truncate(&dataset.name, 40),
&dataset.score,
&dataset.n_hits,
);
}

let dataset = record.result.datasets.first();
let name_or_empty = dataset.as_ref().map(|dataset| dataset.name.clone()).unwrap_or_default();
println!(
"{:40} | {:40} | {:>10} | {:>.3}",
&truncate(record.fasta_record.seq_name, 40),
&truncate(name_or_empty, 40),
&record.result.total_hits,
&record.result.max_score
);
println!("{}┤", "─".repeat(110));
}

Ok(())
Expand Down

0 comments on commit 61eef71

Please sign in to comment.