Skip to content

Commit

Permalink
Merge pull request #1264 from nextstrain/fix/cli-dupes-in-sort-output
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-aksamentov authored Oct 3, 2023
2 parents f5199fb + 36bc43f commit ca54ba3
Showing 1 changed file with 28 additions and 19 deletions.
47 changes: 28 additions & 19 deletions packages_rs/nextclade-cli/src/cli/nextclade_seq_sort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,6 @@ fn writer_thread(
}

for dataset in datasets {
let name = &dataset.name;

results_csv.map_mut_fallible(|results_csv| {
results_csv.write(&SeqSortCsvEntry {
seq_name: &record.fasta_record.seq_name,
Expand All @@ -197,24 +195,22 @@ fn writer_thread(
num_hits: Some(dataset.n_hits),
})
})?;
}

let names = name
.split('/')
.scan(PathBuf::new(), |name, component| {
*name = name.join(component);
Some(name.clone())
})
.unique()
.map(path_to_string)
.collect::<Result<Vec<String>, Report>>()?;

for name in names {
let filepath = get_filepath(&name, &template, output_dir)?;

if let Some(filepath) = filepath {
let writer = get_or_insert_writer(&mut writers, filepath)?;
writer.write(&record.fasta_record.seq_name, &record.fasta_record.seq, false)?;
}
let names = datasets
.iter()
.map(|dataset| get_all_prefix_names(&dataset.name))
.collect::<Result<Vec<Vec<String>>, Report>>()?
.into_iter()
.flatten()
.unique();

for name in names {
let filepath = get_filepath(&name, &template, output_dir)?;

if let Some(filepath) = filepath {
let writer = get_or_insert_writer(&mut writers, filepath)?;
writer.write(&record.fasta_record.seq_name, &record.fasta_record.seq, false)?;
}
}
}
Expand All @@ -224,6 +220,19 @@ fn writer_thread(
Ok(())
}

pub fn get_all_prefix_names(name: impl AsRef<str>) -> Result<Vec<String>, Report> {
name
.as_ref()
.split('/')
.scan(PathBuf::new(), |name, component| {
*name = name.join(component);
Some(name.clone())
})
.unique()
.map(path_to_string)
.collect()
}

struct StatsPrinter {
enabled: bool,
stats: BTreeMap<String, usize>,
Expand Down

1 comment on commit ca54ba3

@vercel
Copy link

@vercel vercel bot commented on ca54ba3 Oct 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextclade – ./

nextclade.vercel.app
nextclade-nextstrain.vercel.app
nextclade-git-master-nextstrain.vercel.app

Please sign in to comment.