-
Notifications
You must be signed in to change notification settings - Fork 42
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
SMARTSviewer #235
base: master
Are you sure you want to change the base?
SMARTSviewer #235
Changes from all commits
376cdf4
c850ccb
bede0e0
de82db0
4e2b8b7
34bc401
6607b8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,6 @@ Imports: | |
dplyr, | ||
purrr | ||
Suggests: | ||
testthat, | ||
testthat (>= 2.1.0), | ||
rcdk | ||
RoxygenNote: 7.1.0 |
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,100 @@ | ||||||||||||||||||||||
#' Query SMARTS Viewer | ||||||||||||||||||||||
#' | ||||||||||||||||||||||
#' Submit a query to the SMARTS viewer webservice at | ||||||||||||||||||||||
#' \url{http://smartsview.zbh.uni-hamburg.de}, ZBH Center for Bioinformatics, | ||||||||||||||||||||||
#' University of Hamburg | ||||||||||||||||||||||
#' | ||||||||||||||||||||||
#' @param smarts A SMARTS string to visualize | ||||||||||||||||||||||
#' @param output The type of response generated (image or download). See | ||||||||||||||||||||||
#' description for details. | ||||||||||||||||||||||
#' @param image_format Image file format (pdf, png, or svg) | ||||||||||||||||||||||
#' @param visualization_modus 1 or 2 (1 = Complete Visualization, 2 = Element | ||||||||||||||||||||||
#' Symbols) | ||||||||||||||||||||||
#' @param legend_option both, none, static, dynamic | ||||||||||||||||||||||
#' @param filename Filename to use if output is to be downloaded | ||||||||||||||||||||||
#' | ||||||||||||||||||||||
#' @return Either a raster object (output = image) suitable for adding to an | ||||||||||||||||||||||
#' R plot using \code{rasterImage} or the image is downloaded in the specified | ||||||||||||||||||||||
#' format to the indicated filename. | ||||||||||||||||||||||
#' @export | ||||||||||||||||||||||
#' | ||||||||||||||||||||||
#' @examples | ||||||||||||||||||||||
#' \dontrun{ | ||||||||||||||||||||||
#' img <- smarts_viewer( | ||||||||||||||||||||||
#' "[CX3](=[OX1])[OX2][CX3](=[OX1])", | ||||||||||||||||||||||
#' "image", "png", 1, "both" | ||||||||||||||||||||||
#' ) | ||||||||||||||||||||||
#' plot(0:1,0:1, 'n') | ||||||||||||||||||||||
#' rasterImage(img[[1]],0,0,1,1) | ||||||||||||||||||||||
Comment on lines
+27
to
+28
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. Just based on the name, I was expecting |
||||||||||||||||||||||
#' | ||||||||||||||||||||||
#' smarts <- c("[CX3](=[OX1])[OX2][CX3](=[OX1])", | ||||||||||||||||||||||
#' "[$([nr5]:[nr5,or5,sr5]),$([nr5]:[cr5]:[nr5,or5,sr5])]", | ||||||||||||||||||||||
#' "[#6][$([NX2]=O),$(N=C=O),$(OC#N),$(SC#N)]" | ||||||||||||||||||||||
#' ) | ||||||||||||||||||||||
#' img <- smarts_viewer(smarts, "image", "png", 1, "both") | ||||||||||||||||||||||
#' par(mfcol = c(1,length(smarts))) | ||||||||||||||||||||||
#' sapply(img, function(i){ | ||||||||||||||||||||||
#' plot(0:1,0:1, 'n') | ||||||||||||||||||||||
#' rasterImage(i,0,0,1,1) | ||||||||||||||||||||||
#' }) | ||||||||||||||||||||||
#' | ||||||||||||||||||||||
#' smarts_viewer( | ||||||||||||||||||||||
#' smarts, output = "download", | ||||||||||||||||||||||
#' image_format = "pdf", | ||||||||||||||||||||||
#' visualization_modus = 1, | ||||||||||||||||||||||
#' legend_option = "both", filename = "test.pdf") | ||||||||||||||||||||||
#' } | ||||||||||||||||||||||
#' | ||||||||||||||||||||||
smarts_viewer <- | ||||||||||||||||||||||
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. Maybe a function name like |
||||||||||||||||||||||
function(smarts, | ||||||||||||||||||||||
output = c('image', 'download'), | ||||||||||||||||||||||
image_format = c('pdf', 'png', 'svg'), | ||||||||||||||||||||||
visualization_modus = c(1, 2), | ||||||||||||||||||||||
legend_option = c('both', 'none', 'static', 'dynamic'), | ||||||||||||||||||||||
filename = NULL) { | ||||||||||||||||||||||
Comment on lines
+49
to
+54
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 have some suggestion that might help streamline the API and address some of @stitam's concerns about downloading. Also, I was confused for a while because I couldn't get the download to work, and then I realized it was because I had
Suggested change
If |
||||||||||||||||||||||
entity_url <- "https://smartsview.zbh.uni-hamburg.de/auto" | ||||||||||||||||||||||
if(output == 'download' & is.null(filename)){ | ||||||||||||||||||||||
stop("Must provide a filename for output type 'download'.") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
if (length(smarts) > 1 & | ||||||||||||||||||||||
output == 'download') { | ||||||||||||||||||||||
message( | ||||||||||||||||||||||
paste( | ||||||||||||||||||||||
"Warning:", | ||||||||||||||||||||||
"Multiple SMARTS strings entered with output option = download.", | ||||||||||||||||||||||
"One file per SMARTS string will be downloaded automatically.", | ||||||||||||||||||||||
sep = '\n' | ||||||||||||||||||||||
) | ||||||||||||||||||||||
) | ||||||||||||||||||||||
resp <- NA | ||||||||||||||||||||||
while (!resp %in% c("Y", "N", "y", "n")) { | ||||||||||||||||||||||
resp <- readline(prompt = "Do you wish to continue? (Y/N)") | ||||||||||||||||||||||
} | ||||||||||||||||||||||
stopifnot(tolower(resp) == 'y') | ||||||||||||||||||||||
} | ||||||||||||||||||||||
|
||||||||||||||||||||||
lapply(seq(along = smarts), function(x) { | ||||||||||||||||||||||
entity_query <- | ||||||||||||||||||||||
paste(entity_url, | ||||||||||||||||||||||
image_format, | ||||||||||||||||||||||
visualization_modus, | ||||||||||||||||||||||
legend_option, | ||||||||||||||||||||||
utils::URLencode(smarts[x], T), | ||||||||||||||||||||||
sep = '/') | ||||||||||||||||||||||
response <- httr::GET(entity_query) | ||||||||||||||||||||||
if (response$status_code == 200) { | ||||||||||||||||||||||
if (output == 'image') { | ||||||||||||||||||||||
httr::content(response, as = 'parsed', type = 'Image/png') | ||||||||||||||||||||||
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. When I try to run the first example with
and Traceback points to 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 also get this error. |
||||||||||||||||||||||
} else { | ||||||||||||||||||||||
utils::download.file(url = response$url, | ||||||||||||||||||||||
destfile = gsub( | ||||||||||||||||||||||
pattern = paste0('.', image_format), | ||||||||||||||||||||||
paste0('_', x, '.', image_format), | ||||||||||||||||||||||
filename | ||||||||||||||||||||||
)) | ||||||||||||||||||||||
Comment on lines
+89
to
+94
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. While being able to export the image from R is a very good idea, I am not sure if this should be handled by the 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'm not sure this would work, as I think only the PNG version can be stored as an R object. If you were to implement this, you'd probably want to have one function that outputs the image data as a matrix with class |
||||||||||||||||||||||
} | ||||||||||||||||||||||
} else { | ||||||||||||||||||||||
stop(httr::http_status(response)$message) | ||||||||||||||||||||||
} | ||||||||||||||||||||||
}) | ||||||||||||||||||||||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
context("smartsview") | ||
|
||
a <- smarts_viewer("[CX3](=[OX1])[OX2][CX3](=[OX1])", "image", "png", 1, "both" ) | ||
b <- smarts_viewer("[CX3](=[OX1])[OX2][CX3](=[OX1])", "download", "png", 1, "both", "smartsview_test.png" ) | ||
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. It is CRAN policy that "packages should not write in the user’s home filespace (including clipboards), nor anywhere else on the file system apart from the R session’s temporary directory". You can use the cross-platform |
||
|
||
test_that("nist returns correct results", { | ||
skip_on_cran() | ||
|
||
expect_is(a[[1]], 'array') | ||
expect_equal(b[[1]], 0) | ||
expect_true(file.exists('smartsview_test.png')) | ||
expect_error(smarts_viewer("[CX3](=[OX1])[OX2][CX3](=[OX1])", "download", "png", 1, "both")) | ||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
test_that("multiplication works", { | ||
expect_equal(2 * 2, 4) | ||
}) | ||
Comment on lines
+1
to
+3
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 guess this second test file was pushed accidentally:) |
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.
Is it possible that you didn't update your branch before making changes? Our contributing guide contains more information about tracking upstream progress.