|
21 | 21 | #' view all filtering options, run `delta-filter --help` in the terminal.
|
22 | 22 | #' @param remove_files Logical indicating whether to remove intermediate files
|
23 | 23 | #' generated during the process, defaults to TRUE.
|
24 |
| -#' @param output_dir Optional directory to save output files; defaults to NULL, |
25 |
| -#' which uses the input file directory for outputs. |
| 24 | +#' @param output_dir Optional directory for output files; defaults to |
| 25 | +#' \code{tempdir()} |
26 | 26 | #'
|
27 | 27 | #' @return A data frame combining all alignment results, or NULL if errors occur
|
28 | 28 | #' during processing.
|
@@ -59,31 +59,30 @@ mummer_alignment <- function(
|
59 | 59 | mummer_options = "",
|
60 | 60 | filter_options = "",
|
61 | 61 | remove_files = TRUE,
|
62 |
| - output_dir = NULL |
| 62 | + output_dir = tempdir() |
63 | 63 | ){
|
64 | 64 |
|
65 | 65 | if (!dir.exists(path)) {
|
66 | 66 | stop("The specified directory does not exist. Please check the file path.")
|
67 | 67 | }
|
68 | 68 |
|
69 |
| - # Check if the file_path contains spaces |
70 |
| - if (grepl(" ", path)) { |
71 |
| - stop("MUMmer requires a directory path without spaces.") |
| 69 | + # Ensure the output directory exists |
| 70 | + if (!dir.exists(output_dir)) { |
| 71 | + dir.create(output_dir, recursive = TRUE) |
72 | 72 | }
|
73 | 73 |
|
74 |
| - if (!is.null(output_dir) && !dir.exists(output_dir)) { |
75 |
| - stop("The specified output directory does not exist. Please check the file path.") |
| 74 | + if (grepl(" ", path)) { |
| 75 | + stop("MUMmer requires a directory path without spaces.") |
76 | 76 | }
|
77 | 77 |
|
78 |
| - # Check if the file_path contains spaces |
79 |
| - if (!is.null(output_dir) && grepl(" ", output_dir)) { |
80 |
| - stop("MUMmer requires a output directory path without spaces.") |
| 78 | + if (grepl(" ", output_dir)) { |
| 79 | + stop("MUMmer requires an output directory path without spaces.") |
81 | 80 | }
|
82 | 81 |
|
83 | 82 | all_files <- list.files(path, full.names = TRUE, pattern = "\\.gbk$|\\.gb$|\\.fasta$")
|
84 | 83 |
|
85 | 84 | # Move all files to the output dir if specified
|
86 |
| - if(!is.null(output_dir)){ |
| 85 | + if(output_dir != path){ |
87 | 86 | sapply(all_files, function(x) file.copy(x, output_dir, overwrite = TRUE))
|
88 | 87 | path <- output_dir
|
89 | 88 | all_files <- list.files(path, full.names = TRUE, pattern = "\\.gbk$|\\.gb$|\\.fasta$")
|
@@ -181,9 +180,17 @@ mummer_alignment <- function(
|
181 | 180 | links <- Filter(Negate(is.null), links)
|
182 | 181 | links <- do.call(rbind, links)
|
183 | 182 |
|
184 |
| - if (!is.null(gbk_files) && length(gbk_files) > 0 && remove_files) { |
185 |
| - remove_files <- sub("\\.gbk$|\\.gb$", ".fasta", gbk_files) |
186 |
| - file.remove(remove_files) |
| 183 | + if (remove_files) { |
| 184 | + if (output_dir == tempdir()) { |
| 185 | + |
| 186 | + files_to_remove <- all_files |
| 187 | + files_to_remove <- files_to_remove[file.exists(files_to_remove)] |
| 188 | + file.remove(files_to_remove) |
| 189 | + } else if (!is.null(gbk_files) && length(gbk_files) > 0) { |
| 190 | + fasta_files_to_remove <- sub("\\.gbk$|\\.gb$", ".fasta", gbk_files) |
| 191 | + fasta_files_to_remove <- fasta_files_to_remove[file.exists(fasta_files_to_remove)] |
| 192 | + file.remove(fasta_files_to_remove) |
| 193 | + } |
187 | 194 | }
|
188 | 195 |
|
189 | 196 | return(links)
|
|
0 commit comments