Skip to content
Merged
336 changes: 271 additions & 65 deletions R/acc2lin.R

Large diffs are not rendered by default.

543 changes: 409 additions & 134 deletions R/assign_job_queue.R

Large diffs are not rendered by default.

109 changes: 84 additions & 25 deletions R/blastWrappers.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,56 @@
#'
#' @examples
run_deltablast <- function(deltablast_path, db_search_path,
db = "refseq", query, evalue = "1e-5",
out, num_alignments, num_threads = 1) {
start <- Sys.time()
db = "refseq", query, evalue = "1e-5",
out, num_alignments, num_threads = 1) {

# Argument validation
if (!file.exists(deltablast_path)) {
stop("The DELTABLAST executable path is invalid: ", deltablast_path)
}
if (!dir.exists(db_search_path)) {
stop("The database search path is invalid: ", db_search_path)
}
if (!file.exists(query)) {
stop("The query file path is invalid: ", query)
}
if (!is.numeric(as.numeric(evalue)) || as.numeric(evalue) <= 0) {
stop("The evalue must be a positive number: ", evalue)
}
if (!is.numeric(num_alignments) || num_alignments <= 0) {
stop("The number of alignments must be a
positive integer: ", num_alignments)
}
if (!is.numeric(num_threads) || num_threads <= 0) {
stop("The number of threads must be a positive integer: ", num_threads)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

IMHO it would be better to use rlang::abort() here rather than stop(), as you do in the rest of your code.

}

start <- Sys.time()

tryCatch({
system(paste0("export BLASTDB=/", db_search_path))

system2(
command = deltablast_path,
args = c(
"-db", db,
"-query", query,
"-evalue", evalue,
"-out", out,
"-num_threads", num_threads,
"-num_alignments", num_alignments
# ,"-outfmt", outfmt
)
command = deltablast_path,
args = c(
"-db", db,
"-query", query,
"-evalue", evalue,
"-out", out,
"-num_threads", num_threads,
"-num_alignments", num_alignments
# ,"-outfmt", outfmt
)
)
print(Sys.time() - start)
}, error = function(e) {
message(paste("Error in run_deltablast: ", e))
}, warning = function(w) {
message(paste("Warning in run_deltablast: ", w))
}, finally = {
message("run_deltablast completed")
})
Comment on lines +63 to +97

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I'd consider switching out these message() calls for the rlang equivalents, e.g. rlang::error() in the error handler, and rlang::warn() in the warning.

As @the-mayer mentioned, I'd also remove the finally clause entirely, since it'll also be displayed with an error/warning output. Generally, finally should be used when you really need to clean something up, even if there's an error that would ordinarily terminate execution, not for regular reporting.


}


Expand All @@ -55,20 +86,48 @@ run_deltablast <- function(deltablast_path, db_search_path,
#'
#' @examples
run_rpsblast <- function(rpsblast_path, db_search_path,
db = "refseq", query, evalue = "1e-5",
out, num_threads = 1) {
start <- Sys.time()
db = "refseq", query, evalue = "1e-5",
out, num_threads = 1) {
# Argument validation
if (!file.exists(rpsblast_path)) {
stop("The RPSBLAST executable path is invalid: ", rpsblast_path)
}
if (!dir.exists(db_search_path)) {
stop("The database search path is invalid: ", db_search_path)
}
if (!file.exists(query)) {
stop("The query file path is invalid: ", query)
}
if (!is.numeric(as.numeric(evalue)) || as.numeric(evalue) <= 0) {
stop("The evalue must be a positive number: ", evalue)
}
if (!is.numeric(num_threads) || num_threads <= 0) {
stop("The number of threads must be a positive integer: ", num_threads)
}
Comment on lines +92 to +152

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above; rlang::abort() is a better option than stop().


start <- Sys.time()

tryCatch({

system(paste0("export BLASTDB=/", db_search_path))

system2(
command = rpsblast_path,
args = c(
"-db", db,
"-query", query,
"-evalue", evalue,
"-out", out,
"-num_threads", num_threads
# , "-outfmt", outfmt
)
command = rpsblast_path,
args = c(
"-db", db,
"-query", query,
"-evalue", evalue,
"-out", out,
"-num_threads", num_threads
)
)
print(Sys.time() - start)
}, error = function(e) {
message(paste("Error in run_rpsblast: ", e))
}, warning = function(w) {
message(paste("Warning in run_rpsblast: ", w))
}, finally = {
message("run_rpsblast completed")
})
Comment on lines +125 to +190

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same as above; the error handler should call rlang::error() rather than message(), warning should call rlang::warn(), and the finally handler should be removed.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, I haven't updated the R/blastWrappers.R file with the suggestions from @the-mayer . I've only updated the first 2 files, and I'm currently working on the said file.


}
4 changes: 2 additions & 2 deletions R/clean_clust_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@
#'
#' @examples
#' \dontrun{
#' clean_clust_file("data/pspa.op_ins_cls", writepath = NULL, query = "pspa")
#' cleanClusterFile("data/pspa.op_ins_cls", writepath = NULL, query = "pspa")
#' }
clean_clust_file <- function(path, writepath = NULL, query) {
cleanClusterFile <- function(path, writepath = NULL, query) {
# ?? does the following line need to be changed to read_lines()?
prot <- read_tsv(path, col_names = F)

Expand Down
2 changes: 1 addition & 1 deletion R/create_lineage_lookup.R
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ create_lineage_lookup <- function(lineage_file = here("data/rankedlineage.dmp"),



#' CreateLineageLookup <- function(assembly_path, updateAssembly = FALSE, file_type = "tsv")
#' create_lineage_lookup <- function(assembly_path, updateAssembly = FALSE, file_type = "tsv")
#' {
#' #' Create a look up table that goes from GCA_ID, to TaxID, to Lineage
#' #' @author Samuel Chen
Expand Down
24 changes: 12 additions & 12 deletions R/msa.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,21 @@ msa_pdf <- function(fasta_path, out_path = NULL,
#'
#' @examples
generate_msa <- function(fa_file = "", outfile = "") {
prot_aa <- readAAStringSet(
path = fa_file,
format = "fasta"
)
prot_aa
prot_aa <- readAAStringSet(
fa_file,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nice catch! The path parameter is indeed named filepath, not path as it was in the original code.

It's fine to leave it as a positional parameter as you have it here, since it's the first parameter.

format = "fasta"
)
prot_aa

## Install kalign ?rMSA_INSTALL
## Messed up! Reimplement from kalign.R
## https://github.com/mhahsler/rMSA/blob/master/R/kalign.R
## Install kalign ?rMSA_INSTALL
## Messed up! Reimplement from kalign.R
## https://github.com/mhahsler/rMSA/blob/master/R/kalign.R

# source("scripts/c2r.R")
# source("scripts/c2r.R")

## align the sequences
al <- kalign(prot_aa) # !! won't work!
al
## align the sequences
al <- kalign(prot_aa) # !! won't work!
al
}

############################
Expand Down
3 changes: 2 additions & 1 deletion man/IPG2Lineage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/acc2Lineage.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion man/advanced_opts2est_walltime.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/assign_job_queue.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/clean_clust_file.Rd → man/cleanClusterFile.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/efetchIPG.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/get_proc_weights.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion man/plot_estimated_walltimes.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions man/sinkReset.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions man/write_proc_medians_yml.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.