From c328cc3da246e0861f8a5be90223b68209b8716d Mon Sep 17 00:00:00 2001 From: "N. Tessa Pierce-Ward" Date: Tue, 21 May 2024 06:52:41 +0100 Subject: [PATCH] fix dl filename --- src/directsketch.rs | 7 +++---- src/utils.rs | 12 +++--------- tests/test_urlsketch.py | 3 +-- 3 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/directsketch.rs b/src/directsketch.rs index 90790b8..597f799 100644 --- a/src/directsketch.rs +++ b/src/directsketch.rs @@ -411,13 +411,12 @@ async fn dl_sketch_url( { Some(data) => { // check keep_fastas instead?? - if let Some(download_filename) = download_filename { + if let Some(ref download_filename) = download_filename { let path = location.join(download_filename); fs::write(path, &data).context("Failed to write data to file")?; } if !download_only { - // let filename = download_filename.clone().unwrap(); - let filename = "".to_string(); + let filename = download_filename.clone().unwrap_or("".to_string()); // sketch data match moltype { InputMolType::Dna => sigs.extend( @@ -451,7 +450,7 @@ async fn dl_sketch_url( name: name.clone(), moltype: moltype.to_string(), md5sum: expected_md5.map(|x| x.to_string()), - download_filename: download_filename, + download_filename, url: Some(url), }; failed.push(failed_download); diff --git a/src/utils.rs b/src/utils.rs index d6618d5..ab91ac7 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -173,7 +173,6 @@ pub fn load_gbassembly_info(input_csv: String) -> Result<(Vec, u Ok((results, row_count)) } -#[allow(dead_code)] pub fn load_accession_info( input_csv: String, keep_fasta: bool, @@ -228,14 +227,9 @@ pub fn load_accession_info( .parse::() .map_err(|_| anyhow!("Invalid 'moltype' value"))?; let expected_md5sum = record.get(3).map(|s| s.to_string()); - let mut download_filename = None; - if keep_fasta { - download_filename = Some( - record - .get(4) - .ok_or_else(|| anyhow!("Missing 'download_filename' field"))? - .to_string(), - ); + let download_filename = record.get(4).map(|s| s.to_string()); + if keep_fasta && download_filename.is_none() { + return Err(anyhow!("Missing 'download_filename' field")); } let url = record .get(5) diff --git a/tests/test_urlsketch.py b/tests/test_urlsketch.py index c7f0feb..64d1f1f 100644 --- a/tests/test_urlsketch.py +++ b/tests/test_urlsketch.py @@ -314,8 +314,7 @@ def test_urlsketch_from_gbsketch_failed(runtmp, capfd): assert acc == "GCA_000175535.1" assert name == "GCA_000175535.1 Chlamydia muridarum MopnTet14 (agent of mouse pneumonitis) strain=MopnTet14" assert moltype == "protein" - # TODO: fix download_filename - # assert download_filename == "GCA_000175535.1_protein.faa.gz" + assert download_filename == "GCA_000175535.1_protein.faa.gz" assert url == "https://ftp.ncbi.nlm.nih.gov/genomes/all/GCA/000/175/535/GCA_000175535.1_ASM17553v1/GCA_000175535.1_ASM17553v1_protein.faa.gz"