From 4a017b25f7f49cd5cc06f52b626781b626a8ff8d Mon Sep 17 00:00:00 2001 From: sbthandras Date: Fri, 26 Jul 2024 16:41:34 +0200 Subject: [PATCH 1/2] Now able to specify filenames of downloads --- R/ncbi_download_genome.R | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/R/ncbi_download_genome.R b/R/ncbi_download_genome.R index b664a0e..b9a6550 100644 --- a/R/ncbi_download_genome.R +++ b/R/ncbi_download_genome.R @@ -40,6 +40,7 @@ ncbi_download_genome <- function(query, type = "genomic.gbff", dirpath = NULL, + filename = NULL, mirror = TRUE, verbose = getOption("verbose")) { type <- match.arg(type, c( @@ -104,6 +105,9 @@ ncbi_download_genome <- function(query, translated_cds = ".faa.gz") urlpath <- paste0(ftppath, "/", prefix, "_" ,type, suffix) if (is.null(dirpath)) dirpath = getwd() + if (is.null(filename)) filename = basename(urlpath) + + basename(urlpath) if (mirror) { dirpath <- gsub( "ftp://ftp.ncbi.nlm.nih.gov/genomes", @@ -112,7 +116,8 @@ ncbi_download_genome <- function(query, ) } if (!dir.exists(dirpath)) dir.create(dirpath, recursive = TRUE) - filepath <- paste0(dirpath, "/", basename(urlpath)) + filepath <- paste0(dirpath, "/", filename) + if (file.exists(filepath)) { if (verbose) message("Done. Already downloaded.") return(NA) @@ -130,3 +135,4 @@ ncbi_download_genome <- function(query, } out <- lapply(assembly_uid, function(x) foo(x, type = type, verbose = verbose)) } +ncbi_download_genome("GCF_900095325.1",filename="please") \ No newline at end of file From 0c24b3b60207005c63e35a96dd550f374a076eaf Mon Sep 17 00:00:00 2001 From: sbthandras Date: Fri, 26 Jul 2024 16:46:35 +0200 Subject: [PATCH 2/2] removing some unnecessary code --- R/ncbi_download_genome.R | 2 -- 1 file changed, 2 deletions(-) diff --git a/R/ncbi_download_genome.R b/R/ncbi_download_genome.R index b9a6550..480513c 100644 --- a/R/ncbi_download_genome.R +++ b/R/ncbi_download_genome.R @@ -107,7 +107,6 @@ ncbi_download_genome <- function(query, if (is.null(dirpath)) dirpath = getwd() if (is.null(filename)) filename = basename(urlpath) - basename(urlpath) if (mirror) { dirpath <- gsub( "ftp://ftp.ncbi.nlm.nih.gov/genomes", @@ -135,4 +134,3 @@ ncbi_download_genome <- function(query, } out <- lapply(assembly_uid, function(x) foo(x, type = type, verbose = verbose)) } -ncbi_download_genome("GCF_900095325.1",filename="please") \ No newline at end of file