Skip to content

Commit

Permalink
Added stderr message, added some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matteobolner committed Sep 15, 2024
1 parent 5a33088 commit dfadc8e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ tokio = { version = "1.40.0", features= ["full"] }
reqwest = { version = "0.12.7", features = ["stream", "blocking"] }
url = "2.5.2"
futures-util = "0.3.30"

[profile.release]
strip = true # Automatically strip symbols from the binary.
37 changes: 37 additions & 0 deletions src/accession.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,40 @@ impl NCBIGenome {
validate_url(&assembly_sequence)
}
}

#[cfg(test)]
mod test_get_folder_url {
use crate::accession::NCBIGenome;

#[test]
fn valid_folder_url() {
let assembly_accession = "GCF_000005845.2";
let assembly_name = "ASM584v2";
let genome = NCBIGenome::from_str(assembly_accession, assembly_name);
assert_eq!(
genome.get_ftp_folder_url().to_string(),
"https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/845/GCF_000005845.2_ASM584v2"
);
}

#[test]
fn valid_report_url() {
let assembly_accession = "GCF_000005845.2";
let assembly_name = "ASM584v2";
let genome = NCBIGenome::from_str(assembly_accession, assembly_name);
assert_eq!(
genome.get_assembly_report_url().to_string(),
"https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/845/GCF_000005845.2_ASM584v2/GCF_000005845.2_ASM584v2_assembly_report.txt"
);
}
#[test]
fn valid_sequence_url() {
let assembly_accession = "GCF_000005845.2";
let assembly_name = "ASM584v2";
let genome = NCBIGenome::from_str(assembly_accession, assembly_name);
assert_eq!(
genome.get_assembly_sequence_url().to_string(),
"https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/005/845/GCF_000005845.2_ASM584v2/GCF_000005845.2_ASM584v2_genomic.fna.gz"
);
}
}
6 changes: 6 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,22 @@ struct Args {
genome: bool,
}

//-a GCF_000005845.2 -n ASM584v2

//TODO if no assembly name specified download the most recent (needs ftp?)

fn main() {
let args = Args::parse();

let genome_accession: NCBIGenome = NCBIGenome::from_str(&args.accession, &args.name);
let sequence_url = genome_accession.get_assembly_sequence_url();
let report_url = genome_accession.get_assembly_report_url();
if args.report {
eprintln!("Downloading assembly report: {}", report_url);
download(report_url.to_string()).expect("FAILURE")
}
if args.genome {
eprintln!("Downloading genome: {}", report_url);
download(sequence_url.to_string()).expect("FAILURE")
};
}

0 comments on commit dfadc8e

Please sign in to comment.