-
Notifications
You must be signed in to change notification settings - Fork 14
Added error handling to multiple functions in R/assign_job_queue.R, R/blastWrappers.R #76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 13 commits
a270156
823af96
48b7fd6
6babffe
57a6356
c1ee75c
f4b50f4
dd86b3c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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) | ||
| } | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd consider switching out these As @the-mayer mentioned, I'd also remove the |
||
|
|
||
| } | ||
|
|
||
|
|
||
|
|
@@ -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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above; |
||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above; the error handler should call
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! The path parameter is indeed named 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 | ||
| } | ||
|
|
||
| ############################ | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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 thanstop(), as you do in the rest of your code.